def test_get_nodes_returns_loaded_nodes(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 } }) expected_nodes = { 'dummy_hash1': { 'name': 'dummy_name1', 'source': 'dummy_source1', 'call_count': 3 }, 'dummy_hash2': { 'name': 'dummy_name2', 'source': 'dummy_source2', 'call_count': 1 } } self.assertEqual(call_graph.get_nodes(), expected_nodes)
def test_load_output_happy_case(self): test_file_path = Path(__file__).absolute().parent.parent.joinpath( 'resources', 'test_static_output') call_graph = CallGraph() load_trace_output_from_file_to_call_graph(str(test_file_path), call_graph) result_nodes = call_graph.get_nodes().values() sorted_nodes = sorted(result_nodes, key=lambda node: node['name']) for result, expected in zip(sorted_nodes, EXPECTED_NODES): assert result['name'] == expected['name'] assert result['call_count'] == expected['count'] assert result['source'] == expected['source']
def test_max_count_returns_maximum_call_count_among_nodes(self): call_graph = CallGraph() call_graph.load_nodes({ 'dummy_hash1': { 'name': 'dummy_name1', 'source': 'dummy_source1', 'call_count': 10 }, 'dummy_hash2': { 'name': 'dummy_name2', 'source': 'dummy_source2', 'call_count': 1 } }) self.assertEqual(call_graph.max_count(), 10)
def initialize(app): call_graph = CallGraph() trace_controller = TraceController() setup = Setup() app.layout = Layout() app.title = 'Tracerface' _setup_callbacks(app, call_graph, setup, trace_controller)
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_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)
def test_init_colors_sets_colors_based_on_node_call_counts(self): call_graph = CallGraph() call_graph.load_nodes({ 'dummy_hash1': { 'name': 'dummy_name1', 'source': 'dummy_source1', 'call_count': 10 }, 'dummy_hash2': { 'name': 'dummy_name2', 'source': 'dummy_source2', 'call_count': 1 } }) call_graph.init_colors() self.assertEqual(call_graph.get_yellow(), 3) self.assertEqual(call_graph.get_red(), 6)
def test_initial_call_graph(self): call_graph = CallGraph() self.assertEqual(call_graph._nodes, {}) self.assertEqual(call_graph._edges, {}) self.assertEqual(call_graph._yellow, 0) self.assertEqual(call_graph._red, 0)
def test_get_edges_returns_empty_dict_for_empty_call_graph(self): call_graph = CallGraph() self.assertEqual(call_graph.get_edges(), {})
def test_element_clicked_removes_element_to_returned_elements(self): call_graph = CallGraph() call_graph.element_clicked('dummy_id1') call_graph.element_clicked('dummy_id2') call_graph.element_clicked('dummy_id1') self.assertEqual(call_graph.get_expanded_elements(), ['dummy_id2'])
def test_set_colors_updates_existing_colors(self): call_graph = CallGraph() call_graph.set_colors(yellow=2, red=3) call_graph.set_colors(yellow=5, red=6) self.assertEqual(call_graph.get_yellow(), 5) self.assertEqual(call_graph.get_red(), 6)
def test_set_colors_sets_returned_colors(self): call_graph = CallGraph() call_graph.set_colors(yellow=2, red=3) self.assertEqual(call_graph.get_yellow(), 2) self.assertEqual(call_graph.get_red(), 3)
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)