Exemplo 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)
Exemplo n.º 2
0
    def test_initialize_binary(self, nm):
        setup = Setup()

        setup.initialize_binary('app')

        expected = {
            'app': {
                'func1': {
                    'mangled': 'func1',
                    'traced': False,
                    'parameters': {}
                },
                'func2': {
                    'mangled': 'func2',
                    'traced': False,
                    'parameters': {}
                },
                'func3': {
                    'mangled': 'func3',
                    'traced': False,
                    'parameters': {}
                }
            }
        }
        self.assertEqual(setup._setup, expected)
Exemplo n.º 3
0
 def test_init_binary_raises_error_if_binary_not_exists(self):
     setup = Setup()
     with self.assertRaises(BinaryNotExistsError):
         setup.initialize_binary('non_existent_app')
Exemplo n.º 4
0
 def test_init_binary_raises_error_if_binary_already_added(self):
     setup = Setup()
     setup._setup = dummy_setup()
     with self.assertRaises(BinaryAlreadyAddedError):
         setup.initialize_binary('app1')