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_generate_bcc_args_with_multiple_values(self):
     setup = Setup()
     setup._setup = {
         'app1': {
             'func1': {
                 'mangled': 'mangled1',
                 'traced': True,
                 'parameters': {
                     4: '%s',
                     2: '%d'
                 }
             },
             'func2': {
                 'mangled': 'mangled2',
                 'traced': False,
                 'parameters': {}
             }
         },
         'app2': {
             'func3': {
                 'mangled': 'mangled3',
                 'traced': True,
                 'parameters': {
                     1: '%s',
                     5: '%d'
                 }
             },
             'func4': {
                 'mangled': 'mangled4',
                 'traced': True,
                 'parameters': {
                     1: '%s',
                     2: '%f'
                 }
             }
         }
     }
     result = setup.generate_bcc_args()
     expected = [
         'app1:mangled1 "%s %d", arg4, arg2',
         'app2:mangled3 "%s %d", arg1, arg5',
         'app2:mangled4 "%s %f", arg1, arg2',
     ]
     self.assertEqual(result, expected)