Ejemplo n.º 1
0
def test_trace(tmp_path):
    call_graph = CallGraph()
    setup = Setup()
    trace_controller = TraceController()

    with create_test_binary(tmp_path) as app:
        setup.initialize_binary(app)
        setup.setup_function_to_trace(app, 'func1')
        setup.setup_function_to_trace(app, 'func2')
        setup.setup_function_to_trace(app, 'func3')
        setup.add_parameter(app, 'func1', '1', '%s')
        setup.add_parameter(app, 'func1', '2', '%s')
        setup.add_parameter(app, 'func2', '1', '%d')

        trace_controller.start_trace(setup.generate_bcc_args(),
                                     call_graph)  # start monitoring
        time.sleep(5)  # BCC trace needs a bit of time to setup
        subprocess.run(app)  # run monitored application
        trace_controller.stop_trace()  # stop

    edges = convert_edges_to_cytoscape_format(call_graph.get_nodes(),
                                              call_graph.get_edges())
    nodes = convert_nodes_to_cytoscape_format(call_graph.get_nodes(),
                                              call_graph.get_edges())
    assert_results(nodes, edges)
Ejemplo n.º 2
0
    def test_setup_function_to_trace_with_mangled_name(self):
        setup = Setup()
        setup._setup = dummy_setup()

        setup.setup_function_to_trace('app1', 'mangledfunc1')

        expected = {
            'app1': {
                'func1': {
                    'traced': True,
                    'parameters': {},
                    'mangled': 'mangledfunc1'
                },
                'func3': {
                    'traced': False,
                    'parameters': {},
                    'mangled': 'mangledfunc3'
                }
            },
            'app2': {
                'func2': {
                    'traced': False,
                    'parameters': {},
                    'mangled': 'mangledfunc2'
                },
            }
        }
        self.assertEqual(setup._setup, expected)
Ejemplo n.º 3
0
    def test_remove_function_from_trace_with_mangled_name(self):
        setup = Setup()
        setup._setup = dummy_setup()

        setup.setup_function_to_trace('app1', 'func1')
        setup.remove_function_from_trace('app1', 'mangledfunc1')

        self.assertEqual(setup._setup, dummy_setup())
Ejemplo n.º 4
0
    def test_remove_function_from_trace_with_mangled_name(self, get_offset_for_function):
        setup = Setup()
        setup._setup = dummy_setup()

        setup.setup_function_to_trace('app1', 'func1')
        setup.remove_function_from_trace('app1', 'mangledfunc1')

        expected_setup = dummy_setup()
        expected_setup['app1']['func1']['offset'] = 8

        self.assertEqual(setup._setup, expected_setup)
Ejemplo n.º 5
0
    def test_setup_function_to_trace_with_demangled_name(self, get_offset_for_function):
        setup = Setup()
        setup._setup = dummy_setup()

        setup.setup_function_to_trace('app1', 'func1')

        expected = {
            'app1': {
                'func1': {'traced': True, 'parameters': {}, 'mangled': 'mangledfunc1', 'offset': 8},
                'func3': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc3', 'offset': 0}
            },
            'app2': {
                'func2': {'traced': False, 'parameters': {}, 'mangled': 'mangledfunc2', 'offset': 0}
            }
        }
        self.assertEqual(setup._setup, expected)
Ejemplo n.º 6
0
 def test_setup_function_to_trace_raises_error_if_function_not_exists(self):
     setup = Setup()
     setup._setup = dummy_setup()
     with self.assertRaises(FunctionNotInBinaryError):
         setup.setup_function_to_trace('app1', 'func4')