Beispiel #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)
    def test_add_parameter(self):
        setup = Setup()
        setup._setup = dummy_setup()

        setup.add_parameter('app1', 'func3', 2, '%s')

        expected = {
            'app1': {
                'func1': {
                    'traced': False,
                    'parameters': {},
                    'mangled': 'mangledfunc1'
                },
                'func3': {
                    'traced': False,
                    'parameters': {
                        2: '%s'
                    },
                    'mangled': 'mangledfunc3'
                }
            },
            'app2': {
                'func2': {
                    'traced': False,
                    'parameters': {},
                    'mangled': 'mangledfunc2'
                },
            }
        }
        self.assertEqual(setup._setup, expected)