def test_derive_file_elements(self): c = Collector(None) s1 = { collector.PATH: "/Users/behrens/Documents/projects/pebble/puncover/pebble/build/../src/puncover.c" } s2 = { collector.PATH: "/Users/thomas/work/arm-eabi-toolchain/build/gcc-final/arm-none-eabi/thumb2/libgcc/../../../../../gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.S" } s3 = {collector.PATH: "src/puncover.c"} c.symbols = { 1: s1, 2: s2, 3: s3, } c.derive_folders() self.assertEqual( "/Users/behrens/Documents/projects/pebble/puncover/pebble/src/puncover.c", s1[collector.PATH]) self.assertIsNotNone(s1[collector.FILE]) self.assertEqual( "/Users/thomas/work/arm-eabi-toolchain/gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.S", s2[collector.PATH]) self.assertIsNotNone(s2[collector.FILE]) self.assertEqual("src/puncover.c", s3[collector.PATH]) self.assertIsNotNone(s3[collector.FILE])
def test_enhance_sibling_symbols(self): c = Collector() aeabi_drsub = { collector.ADDRESS: "0000009c", collector.SIZE: 8, collector.TYPE: collector.TYPE_FUNCTION, } aeabi_dsub = { collector.ADDRESS: "000000a4", collector.SIZE: 4, collector.TYPE: collector.TYPE_FUNCTION, } adddf3 = { collector.ADDRESS: "000000a8", collector.SIZE: 123, collector.TYPE: collector.TYPE_FUNCTION, } c.symbols = {int(f[collector.ADDRESS], 16): f for f in [aeabi_drsub, aeabi_dsub, adddf3]} c.enhance_sibling_symbols() self.assertFalse(aeabi_drsub.has_key(collector.PREV_FUNCTION)) self.assertEqual(aeabi_dsub, aeabi_drsub.get(collector.NEXT_FUNCTION)) self.assertEqual(aeabi_drsub, aeabi_dsub.get(collector.PREV_FUNCTION)) self.assertEqual(adddf3, aeabi_dsub.get(collector.NEXT_FUNCTION)) self.assertEqual(aeabi_dsub, adddf3.get(collector.PREV_FUNCTION)) self.assertFalse(adddf3.has_key(collector.NEXT_FUNCTION))
def test_enhance_sibling_symbols(self): c = Collector(None) aeabi_drsub = { collector.ADDRESS: "0000009c", collector.SIZE: 8, collector.TYPE: collector.TYPE_FUNCTION, } aeabi_dsub = { collector.ADDRESS: "000000a4", collector.SIZE: 4, collector.TYPE: collector.TYPE_FUNCTION, } adddf3 = { collector.ADDRESS: "000000a8", collector.SIZE: 123, collector.TYPE: collector.TYPE_FUNCTION, } c.symbols = {int(f[collector.ADDRESS], 16): f for f in [aeabi_drsub, aeabi_dsub, adddf3]} c.enhance_sibling_symbols() self.assertFalse(aeabi_drsub.has_key(collector.PREV_FUNCTION)) self.assertEqual(aeabi_dsub, aeabi_drsub.get(collector.NEXT_FUNCTION)) self.assertEqual(aeabi_drsub, aeabi_dsub.get(collector.PREV_FUNCTION)) self.assertEqual(adddf3, aeabi_dsub.get(collector.NEXT_FUNCTION)) self.assertEqual(aeabi_dsub, adddf3.get(collector.PREV_FUNCTION)) self.assertFalse(adddf3.has_key(collector.NEXT_FUNCTION))
def test_enhance_call_tree_from_assembly_line(self): c = Collector(None) f1 = "f1" f2 = {collector.ADDRESS: "00000088"} f3 = {collector.ADDRESS: "00000930"} c.symbols = { int(f2[collector.ADDRESS], 16): f2, int(f3[collector.ADDRESS], 16): f3 } with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line( f1, " 89e: e9d3 0100 ldrd r0, r1, [r3]") self.assertFalse(m.called) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line( f1, "934: f7ff bba8 b.w 88 <jump_to_pbl_function>") m.assert_called_with(f1, f2) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line( f1, "8e4: f000 f824 bl 930 <app_log>") m.assert_called_with(f1, f3) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line( f1, "6c6: d202 bcs.n 88 <__aeabi_ddiv+0x6e>") m.assert_called_with(f1, f2) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line( f1, " 805bbac: 2471 0805 b64b 0804 b3c9 0804 b459 0804 q$..K.......Y..." ) self.assertFalse(m.called)
def test_stack_usage_line_cpp_constructor(self): line = "WString.cpp:82:1:String::String(unsigned int, unsigned char) 32 static" c = Collector(None) c.symbols = {"123": { "base_file": "WString.cpp", "line": 82, }} self.assertTrue(c.parse_stack_usage_line(line))
def test_stack_usage_line2(self): line = "puncover.c:8:43:dynamic_stack2 16 dynamic" c = Collector(None) c.symbols = {"123": { "base_file": "puncover.c", "line": 8, }} self.assertTrue(c.parse_stack_usage_line(line))
def test_stack_usage_line_header(self): line = "ILI9341_t3.h:312:15:void ILI9341_t3::updateDisplayClip() 16 static" c = Collector(None) c.symbols = {"123": { "base_file": "ILI9341_t3.h", "line": 312, }} self.assertTrue(c.parse_stack_usage_line(line))
def test_stack_usage_line2(self): line = "puncover.c:8:43:dynamic_stack2 16 dynamic" c = Collector() c.symbols = {"123": { "base_file": "puncover.c", "line": 8, }} self.assertTrue(c.parse_stack_usage_line(line))
def test_stack_usage_line(self): line = "puncover.c:14:40:0 16 dynamic,bounded" c = Collector() c.symbols = {"123": { "base_file": "puncover.c", "line": 14, }} self.assertTrue(c.parse_stack_usage_line(line)) self.assertEqual(16, c.symbols["123"]["stack_size"]) self.assertEqual("dynamic,bounded", c.symbols["123"]["stack_qualifiers"])
def test_stack_usage_line_cpp_correct_line(self): line = "Print.cpp:34:8:virtual size_t Print::write(const uint8_t*, size_t) 24 static" c = Collector(None) c.symbols = {"123": { "base_file": "Print.cpp", "line": 34, }} self.assertTrue(c.parse_stack_usage_line(line)) self.assertEqual(24, c.symbols["123"]["stack_size"]) self.assertEqual("static", c.symbols["123"]["stack_qualifiers"])
def test_stack_usage_line(self): line = "puncover.c:14:40:0 16 dynamic,bounded" c = Collector(None) c.symbols = {"123": { "base_file": "puncover.c", "line": 14, }} self.assertTrue(c.parse_stack_usage_line(line)) self.assertEqual(16, c.symbols["123"]["stack_size"]) self.assertEqual("dynamic,bounded", c.symbols["123"]["stack_qualifiers"])
def test_derive_file_elements(self): c = Collector(None) if os.name == 'nt': s1 = { collector.PATH: "C:/Users/behrens/Documents/projects/pebble/puncover/pebble/build/../src/puncover.c" } s2 = { collector.PATH: "C:/Users/thomas/work/arm-eabi-toolchain/build/gcc-final/arm-none-eabi/thumb2/libgcc/../../../../../gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.S" } s3 = {collector.PATH: "src/puncover.c"} else: s1 = { collector.PATH: "/Users/behrens/Documents/projects/pebble/puncover/pebble/build/../src/puncover.c" } s2 = { collector.PATH: "/Users/thomas/work/arm-eabi-toolchain/build/gcc-final/arm-none-eabi/thumb2/libgcc/../../../../../gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.S" } s3 = {collector.PATH: "src/puncover.c"} c.symbols = { 1: s1, 2: s2, 3: s3, } c.derive_folders() if os.name == 'nt': self.assertEqual( "C:\\Users\\behrens\\Documents\\projects\\pebble\\puncover\\pebble\\src\\puncover.c", s1[collector.PATH]) else: self.assertEqual( "/Users/behrens/Documents/projects/pebble/puncover/pebble/src/puncover.c", s1[collector.PATH]) self.assertIsNotNone(s1[collector.FILE]) if os.name == 'nt': self.assertEqual( "C:\\Users\\thomas\\work\\arm-eabi-toolchain\\gcc-4.7-2012.09\\libgcc\\config\\arm\\ieee754-df.S", s2[collector.PATH]) else: self.assertEqual( "/Users/thomas/work/arm-eabi-toolchain/gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.", s2[collector.PATH]) self.assertIsNotNone(s2[collector.FILE]) if os.name == 'nt': self.assertEqual("src\\puncover.c", s3[collector.PATH]) else: self.assertEqual("src/puncover.c", s3[collector.PATH]) self.assertIsNotNone(s3[collector.FILE])
def test_enhance_function_size_from_assembly(self): c = Collector() c.symbols = { int("0000009c", 16) : { collector.ADDRESS: "0000009c", collector.ASM: """ $t(): 9c: f081 4100 eor.w r1, r1, #2147483648 ; 0x80000000 a0: e002 b.n a8 <__adddf3> a2: bf00 nop """.split("\n") }} s = c.symbol_by_addr("9c") self.assertFalse(s.has_key(collector.SIZE)) c.enhance_function_size_from_assembly() self.assertEqual(8, s[collector.SIZE])
def test_enhance_function_size_from_assembly(self): c = Collector(None) c.symbols = { int("0000009c", 16) : { collector.ADDRESS: "0000009c", collector.ASM: """ $t(): 9c: f081 4100 eor.w r1, r1, #2147483648 ; 0x80000000 a0: e002 b.n a8 <__adddf3> a2: bf00 nop """.split("\n") }} s = c.symbol_by_addr("9c") self.assertFalse(s.has_key(collector.SIZE)) c.enhance_function_size_from_assembly() self.assertEqual(8, s[collector.SIZE])
def test_derive_file_elements(self): c = Collector(None) s1 = {collector.PATH: "/Users/behrens/Documents/projects/pebble/puncover/pebble/build/../src/puncover.c"} s2 = {collector.PATH: "/Users/thomas/work/arm-eabi-toolchain/build/gcc-final/arm-none-eabi/thumb2/libgcc/../../../../../gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.S"} s3 = {collector.PATH: "src/puncover.c"} c.symbols = { 1: s1, 2: s2, 3: s3, } c.derive_folders() self.assertEqual("/Users/behrens/Documents/projects/pebble/puncover/pebble/src/puncover.c", s1[collector.PATH]) self.assertIsNotNone(s1[collector.FILE]) self.assertEqual("/Users/thomas/work/arm-eabi-toolchain/gcc-4.7-2012.09/libgcc/config/arm/ieee754-df.S", s2[collector.PATH]) self.assertIsNotNone(s2[collector.FILE]) self.assertEqual("src/puncover.c", s3[collector.PATH]) self.assertIsNotNone(s3[collector.FILE])
def test_enhance_call_tree_from_assembly_line(self): c = Collector(None) f1 = "f1" f2 = {collector.ADDRESS: "00000088"} f3 = {collector.ADDRESS: "00000930"} c.symbols = {int(f2[collector.ADDRESS], 16): f2, int(f3[collector.ADDRESS], 16): f3} with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line(f1, " 89e: e9d3 0100 ldrd r0, r1, [r3]") self.assertFalse(m.called) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line(f1, "934: f7ff bba8 b.w 88 <jump_to_pbl_function>") m.assert_called_with(f1,f2) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line(f1, "8e4: f000 f824 bl 930 <app_log>") m.assert_called_with(f1,f3) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line(f1, "6c6: d202 bcs.n 88 <__aeabi_ddiv+0x6e>") m.assert_called_with(f1,f2) with patch.object(c, "add_function_call") as m: c.enhance_call_tree_from_assembly_line(f1, " 805bbac: 2471 0805 b64b 0804 b3c9 0804 b459 0804 q$..K.......Y...") self.assertFalse(m.called)