test.py (4074B)
1 # flake8: noqa: F821 2 3 from collections import defaultdict 4 5 test.compile("source.cpp") 6 test.run_analysis_script("gcTypes") 7 8 # gcFunctions should be the inverse, but we get to rely on unmangled names here. 9 gcFunctions = test.load_gcFunctions() 10 assert "void GC()" in gcFunctions 11 assert "void suppressedFunction()" not in gcFunctions 12 assert "void halfSuppressedFunction()" in gcFunctions 13 assert "void unsuppressedFunction()" in gcFunctions 14 assert "int32 Subcell::method()" in gcFunctions 15 assert "Cell* f()" in gcFunctions 16 17 hazards = test.load_hazards() 18 hazmap = {haz.variable: haz for haz in hazards} 19 assert "cell1" not in hazmap 20 assert "cell2" in hazmap 21 assert "cell3" in hazmap 22 assert "cell4" not in hazmap 23 assert "cell5" not in hazmap 24 assert "cell6" not in hazmap 25 assert "<returnvalue>" in hazmap 26 assert "this" in hazmap 27 28 assert hazmap["cell2"].function == "Cell* f()" 29 30 # Check that the correct GC call is reported for each hazard. (cell3 has a 31 # hazard from two different GC calls; it doesn't really matter which is 32 # reported.) 33 assert hazmap["cell2"].GCFunction == "void halfSuppressedFunction()" 34 assert hazmap["cell3"].GCFunction in ( 35 "void halfSuppressedFunction()", 36 "void unsuppressedFunction()", 37 ) 38 returnval_hazards = set( 39 haz.function for haz in hazards if haz.variable == "<returnvalue>" 40 ) 41 assert "Cell* f()" in returnval_hazards 42 assert "Cell* refptr_test1()" in returnval_hazards 43 assert "Cell* refptr_test2()" not in returnval_hazards 44 assert "Cell* refptr_test3()" in returnval_hazards 45 assert "Cell* refptr_test4()" in returnval_hazards 46 assert "Cell* refptr_test5()" not in returnval_hazards 47 assert "Cell* refptr_test6()" in returnval_hazards 48 assert "Cell* refptr_test7()" in returnval_hazards 49 assert "Cell* refptr_test8()" in returnval_hazards 50 assert "Cell* refptr_test9()" not in returnval_hazards 51 52 assert "container1" in hazmap 53 assert "container2" not in hazmap 54 55 # Type names are handy to have in the report. 56 assert hazmap["cell2"].type == "Cell*" 57 assert hazmap["<returnvalue>"].type == "Cell*" 58 assert hazmap["this"].type == "Subcell*" 59 60 # loopy hazards. See comments in source. 61 assert "haz1" not in hazmap 62 assert "haz2" not in hazmap 63 assert "haz3" in hazmap 64 assert "haz4" in hazmap 65 assert "haz5" in hazmap 66 assert "haz6" not in hazmap 67 assert "haz7" not in hazmap 68 assert "haz8" in hazmap 69 70 # safevals hazards. See comments in source. 71 assert "unsafe1" in hazmap 72 assert "safe2" not in hazmap 73 assert "unsafe3" in hazmap 74 assert "unsafe3b" in hazmap 75 assert "unsafe4" in hazmap 76 assert "safe5" not in hazmap 77 assert "safe6" not in hazmap 78 assert "unsafe7" in hazmap 79 assert "safe8" not in hazmap 80 assert "safe9" not in hazmap 81 assert "safe10" not in hazmap 82 assert "safe11" not in hazmap 83 assert "safe12" not in hazmap 84 assert "unsafe13" in hazmap 85 assert "unsafe14" in hazmap 86 assert "unsafe15" in hazmap 87 assert "safe16" not in hazmap 88 assert "safe17" not in hazmap 89 assert "safe18" not in hazmap 90 assert "safe19" not in hazmap 91 92 # method hazard. 93 94 byfunc = defaultdict(lambda: defaultdict(dict)) 95 for haz in hazards: 96 byfunc[haz.function][haz.variable] = haz 97 98 methhaz = byfunc["int32 Subcell::method()"] 99 assert "this" in methhaz 100 assert methhaz["this"].type == "Subcell*" 101 102 haz_functions = set(haz.function for haz in hazards) 103 104 # RefPtr<T> tests. 105 106 haz_functions = set(haz.function for haz in hazards) 107 assert "Cell* refptr_test1()" in haz_functions 108 assert "Cell* refptr_test2()" not in haz_functions 109 assert "Cell* refptr_test3()" in haz_functions 110 assert "Cell* refptr_test4()" in haz_functions 111 assert "Cell* refptr_test5()" not in haz_functions 112 assert "Cell* refptr_test6()" in haz_functions 113 assert "Cell* refptr_test7()" in haz_functions 114 assert "Cell* refptr_test8()" in haz_functions 115 assert "Cell* refptr_test9()" not in haz_functions 116 assert "Cell* refptr_test10()" in haz_functions 117 118 # aggr_init tests. 119 120 assert "void aggr_init_safe()" not in haz_functions 121 assert "void aggr_init_unsafe()" in haz_functions 122 123 # stack_array tests. 124 125 assert "void stack_array()" in haz_functions 126 haz_vars = byfunc["void stack_array()"] 127 assert "array" in haz_vars 128 assert "array2" not in haz_vars