Example #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)
Example #2
0
 def test_clear_removes_all_nodes_and_edges_and_color_boundaries(self):
     call_graph = CallGraph()
     call_graph.load_nodes({
         'dummy_hash1': {
             'name': 'dummy_name1',
             'source': 'dummy_source1',
             'call_count': 3
         },
         'dummy_hash2': {
             'name': 'dummy_name2',
             'source': 'dummy_source2',
             'call_count': 1
         }
     })
     call_graph.load_edges({
         ('node_hash1', 'node_hash2'): {
             'param': [],
             'call_count': 0
         },
         ('node_hash3', 'node_hash4'): {
             'param': ['dummy_param'],
             'call_count': 3
         }
     })
     call_graph.clear()
     self.assertEqual(call_graph.get_nodes(), {})
     self.assertEqual(call_graph.get_edges(), {})
     self.assertEqual(call_graph.get_yellow(), 0)
     self.assertEqual(call_graph.get_red(), 0)
Example #3
0
 def test_get_edges_returns_loaded_edges(self):
     call_graph = CallGraph()
     call_graph.load_edges({
         ('node_hash1', 'node_hash2'): {
             'param': [],
             'call_count': 0
         },
         ('node_hash3', 'node_hash4'): {
             'param': ['dummy_param'],
             'call_count': 3
         }
     })
     expected_edges = {
         ('node_hash1', 'node_hash2'): {
             'params': [],
             'call_count': 0
         },
         ('node_hash3', 'node_hash4'): {
             'params': [['dummy_param']],
             'call_count': 3
         }
     }
     self.assertEqual(call_graph.get_edges(), expected_edges)
Example #4
0
 def test_get_edges_returns_empty_dict_for_empty_call_graph(self):
     call_graph = CallGraph()
     self.assertEqual(call_graph.get_edges(), {})