def test_get_function_signature_include_files(self): # Arrange test_line_parser = GprofLineParser.get_instance( ' 0.00 0.00 1/34841 snprintf ' '(/usr/include/x86_64-linux-gnu/bits/stdio2.h:64 @ 47d37b) ' '[650457]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual( '/usr/include/x86_64-linux-gnu/bits/stdio2.h', test_function_signature ) # Arrange test_line_parser = GprofLineParser.get_instance( ' 0.00 0.00 1/589 atoi ' '(/usr/include/stdlib.h:280 @ 57c1fc) [26713]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual('/usr/include/stdlib.h', test_function_signature)
def from_gprof(cls, gprof_line): gprof_line_parser = GprofLineParser.get_instance(gprof_line) new_instance = cls(gprof_line_parser.get_function_name(), gprof_line_parser.get_function_signature(), Environments.C) return new_instance
def test_get_function_signature_with_called_only(self): # Arrange test_line_parser = GprofLineParser.get_instance( ' 8 ' 'recursive_a <cycle 1> (greetings.c:38 @ 581033) [3]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual('greetings.c', test_function_signature)
def test_get_function_name_entry(self): # Arrange test_line_parser = GprofLineParser.get_instance( '[4] 0.0 0.00 0.00 2 greet ' '(greetings.c:38 @ 581033) [4]' ) # Act test_function_name = test_line_parser.get_function_name() # Assert self.assertEqual('greet', test_function_name)
def test_get_function_signature_with_self_and_children(self): # Arrange test_line_parser = GprofLineParser.get_instance( ' 0.00 0.00 1/2 greet_b ' '(helloworld.c:38 @ 581033) [9]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual('helloworld.c', test_function_signature)
def test_load_recursive_call_line(self): # Arrange test_line_parser = GprofLineParser.get_instance( '[86901 0.0 0.00 0.00 12+12 _init [869011]' ) # Act test_function_name = test_line_parser.get_function_name() test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual('_init', test_function_name) self.assertEqual('', test_function_signature)
def test_get_function_signature_with_path(self): # Arrange test_line_parser = GprofLineParser.get_instance( '[12] 0.0 0.00 0.00 72000 hScale_MMX ' '(./libswscale/x86/swscale_template.c:1921 @ 9f46e0) [12]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual( './libswscale/x86/swscale_template.c', test_function_signature ) # Arrange test_line_parser = GprofLineParser.get_instance( ' 0.00 0.00 2590/5180 opt_find ' '(./libavcodec/options.c:53 @ 77e710) [316705]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual('./libavcodec/options.c', test_function_signature) # Arrange test_line_parser = GprofLineParser.get_instance( '[49220 0.0 0.00 0.00 ' '__do_global_ctors_aux [492203]' ) # Act test_function_signature = test_line_parser.get_function_signature() # Assert self.assertEqual('', test_function_signature)
def test_issue_46(self): '''Unit test to test the fix for issue #46. Specifics: https://github.com/andymeneely/attack-surface-metrics/issues/46 ''' # Arrange line = ( ' 0.00 0.00 11361600/11361600 ' 'ff_h264_decode_mb_cabac (./libavcodec/h264_cabac.c:' '2141 @ cfeb13) [6]' ) expected = 'ff_h264_decode_mb_cabac' # Act target = GprofLineParser.get_instance(line) actual = target.get_function_name() # Assert self.assertEqual(expected, actual)
def from_gprof(cls, gprof_line, granularity=Granularity.FUNC): """Instantiate Call by parsing a line from gprof call graph. Parameters ---------- gprof_line : str A line of string from the gprof call graph. granularity : str The granularity of the call graph into which the instance of Call will be added to. See attacksurfacemeter.granularity.Granularity for available choices. Returns ------- new_instance : Call An instance of Call. """ gprof_line_parser = GprofLineParser.get_instance(gprof_line) new_instance = cls(gprof_line_parser.get_function_name(), gprof_line_parser.get_function_signature(), Environments.C, granularity) return new_instance