Debian Codegraph @

js/src/devtools/rootAnalysis/t/graph/test.py

raw
1 # 'test' is provided by the calling script.
2 # flake8: noqa: F821
3
4 test.compile("source.cpp")
5 test.run_analysis_script("gcTypes")
6
7 info = test.load_typeInfo()
8
9 gcFunctions = test.load_gcFunctions()
10
11 f = "void f(int32)"
12 g = "void g(int32)"
13 h = "void h(int32)"
14
15 assert f in gcFunctions
16 assert g in gcFunctions
17 assert h in gcFunctions
18 assert "void leaf()" not in gcFunctions
19 assert "void nonrecursive_root()" in gcFunctions
20
21 callgraph = test.load_callgraph()
22 assert callgraph.calleeGraph[f][g]
23 assert callgraph.calleeGraph[f][h]
24 assert callgraph.calleeGraph[g][f]
25 assert callgraph.calleeGraph[g][h]
26
27 node = [f"void n{i}(int32)" for i in range(10)]
28 mnode = [callgraph.unmangledToMangled.get(f) for f in node]
29 for src, dst in [
30 (1, 2),
31 (2, 1),
32 (4, 5),
33 (5, 4),
34 (2, 3),
35 (5, 3),
36 (3, 6),
37 (6, 7),
38 (7, 8),
39 (8, 7),
40 (8, 9),
41 ]:
42 assert callgraph.calleeGraph[node[src]][node[dst]]
43
44 funcInfo = test.load_funcInfo()
45 rroots = set(
46 [
47 callgraph.mangledToUnmangled[f]
48 for f in funcInfo
49 if funcInfo[f].get("recursive_root")
50 ]
51 )
52 assert len(set([node[1], node[2]]) & rroots) == 1
53 assert len(set([node[4], node[5]]) & rroots) == 1
54 assert len(rroots) == 4, f"rroots = {rroots}" # n1, n4, f, self_recursive