Bug 1480129 - Testing for virtual function annotations, r=jonco
☠☠ backed out by 056d6eeb2111 ☠ ☠
authorSteve Fink <sfink@mozilla.com>
Fri, 27 Jul 2018 16:08:21 -0700
changeset 489837 de5dbc800bc7a347dca946f76e6fdaefea9316b5
parent 489836 66d022f720b698c8fced2c8628866445ddea6262
child 489838 056d6eeb21116e843a51e6503b2670243252788d
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjonco
bugs1480129
milestone64.0a1
Bug 1480129 - Testing for virtual function annotations, r=jonco
js/src/devtools/rootAnalysis/t/suppression/test.py
js/src/devtools/rootAnalysis/t/testlib.py
js/src/devtools/rootAnalysis/t/virtual/source.cpp
js/src/devtools/rootAnalysis/t/virtual/test.py
--- a/js/src/devtools/rootAnalysis/t/suppression/test.py
+++ b/js/src/devtools/rootAnalysis/t/suppression/test.py
@@ -1,24 +1,20 @@
 # flake8: noqa: F821
 test.compile("source.cpp")
 test.run_analysis_script('gcTypes', upto='gcFunctions')
 
-# The suppressions file uses only mangled names since it's for internal use,
-# though I may change that soon given (1) the unfortunate non-uniqueness of
-# mangled constructor names, and (2) the usefulness of this file for
-# mrgiggles's reporting.
+# The suppressions file uses mangled names.
 suppressed = test.load_suppressed_functions()
 
 # Only one of these is fully suppressed (ie, *always* called within the scope
 # of an AutoSuppressGC).
-assert(len(list(filter(lambda f: 'suppressedFunction' in f, suppressed))) == 1)
-assert(len(list(filter(lambda f: 'halfSuppressedFunction' in f, suppressed))) == 0)
-assert(len(list(filter(lambda f: 'unsuppressedFunction' in f, suppressed))) == 0)
+assert len(list(filter(lambda f: 'suppressedFunction' in f, suppressed))) == 1
+assert len(list(filter(lambda f: 'halfSuppressedFunction' in f, suppressed))) == 0
+assert len(list(filter(lambda f: 'unsuppressedFunction' in f, suppressed))) == 0
 
 # gcFunctions should be the inverse, but we get to rely on unmangled names here.
 gcFunctions = test.load_gcFunctions()
-print(gcFunctions)
-assert('void GC()' in gcFunctions)
-assert('void suppressedFunction()' not in gcFunctions)
-assert('void halfSuppressedFunction()' in gcFunctions)
-assert('void unsuppressedFunction()' in gcFunctions)
-assert('void f()' in gcFunctions)
+assert 'void GC()' in gcFunctions
+assert 'void suppressedFunction()' not in gcFunctions
+assert 'void halfSuppressedFunction()' in gcFunctions
+assert 'void unsuppressedFunction()' in gcFunctions
+assert 'void f()' in gcFunctions
--- a/js/src/devtools/rootAnalysis/t/testlib.py
+++ b/js/src/devtools/rootAnalysis/t/testlib.py
@@ -114,16 +114,20 @@ sixgill_bin = '{bindir}'
                 return (m.group(1) + 's', m.group(2))
             return None
 
         gctypes = defaultdict(list)
         for collection, typename in self.load_text_file('gcTypes.txt', extract=grab_type):
             gctypes[collection].append(typename)
         return gctypes
 
+    def load_typeInfo(self, filename="typeInfo.txt"):
+        with open(os.path.join(self.outdir, filename)) as fh:
+            return json.load(fh)
+
     def load_gcFunctions(self):
         return self.load_text_file('gcFunctions.lst', extract=extract_unmangled)
 
     def load_callgraph(self):
         data = Callgraph(
             functionNames=['dummy'],
             nameToId={},
             mangledToUnmangled={},
--- a/js/src/devtools/rootAnalysis/t/virtual/source.cpp
+++ b/js/src/devtools/rootAnalysis/t/virtual/source.cpp
@@ -12,17 +12,17 @@ struct Cell { int f; } ANNOTATE("GC Thin
 
 extern void foo();
 
 typedef void (*func_t)();
 
 class Base {
   public:
     int ANNOTATE("field annotation") dummy;
-    virtual void someGC() = 0;
+    virtual void someGC() ANNOTATE("Base pure virtual method") = 0;
     func_t functionField;
 
     // For now, this is just to verify that the plugin doesn't crash. The
     // analysis code does not yet look at this annotation or output it anywhere
     // (though it *is* being recorded.)
     static float testAnnotations() ANNOTATE("static func");
 
     // Similar, though sixgill currently completely ignores parameter annotations.
@@ -47,19 +47,24 @@ class Super : public Base {
 
 void bar() {
     GC();
 }
 
 class Sub1 : public Super {
   public:
     void noneGC() override { foo(); }
-    void someGC() override { foo(); }
+    void someGC() override
+      ANNOTATE("Sub1 override")
+      ANNOTATE("second attr")
+    {
+        foo();
+    }
     void allGC() override { foo(); bar(); }
-};
+} ANNOTATE("CSU1") ANNOTATE("CSU2");
 
 class Sub2 : public Super {
   public:
     void noneGC() override { foo(); }
     void someGC() override { foo(); bar(); }
     void allGC() override { foo(); bar(); }
 };
 
--- a/js/src/devtools/rootAnalysis/t/virtual/test.py
+++ b/js/src/devtools/rootAnalysis/t/virtual/test.py
@@ -1,35 +1,40 @@
 test.compile("source.cpp")
 test.run_analysis_script('gcTypes')
 
-# The suppressions file uses only mangled names since it's for internal use,
-# though I may change that soon given (1) the unfortunate non-uniqueness of
-# mangled constructor names, and (2) the usefulness of this file for
-# mrgiggles's reporting.
-suppressed = test.load_suppressed_functions()
+info = test.load_typeInfo()
 
-# gcFunctions should be the inverse, but we get to rely on unmangled names here.
+assert 'Sub1' in info['OtherCSUTags']
+assert ['CSU1', 'CSU2'] == sorted(info['OtherCSUTags']['Sub1'])
+assert 'Base' in info['OtherFieldTags']
+assert 'someGC' in info['OtherFieldTags']['Base']
+assert 'Sub1' in info['OtherFieldTags']
+assert 'someGC' in info['OtherFieldTags']['Sub1']
+assert ['Sub1 override', 'second attr'] == sorted(info['OtherFieldTags']['Sub1']['someGC'])
+
 gcFunctions = test.load_gcFunctions()
 
 assert 'void Sub1::noneGC()' not in gcFunctions
 assert 'void Sub1::someGC()' not in gcFunctions
 assert 'void Sub1::allGC()' in gcFunctions
 assert 'void Sub2::noneGC()' not in gcFunctions
 assert 'void Sub2::someGC()' in gcFunctions
 assert 'void Sub2::allGC()' in gcFunctions
 
 callgraph = test.load_callgraph()
+
 assert callgraph.calleeGraph['void f()']['Super.noneGC']
 assert callgraph.calleeGraph['Super.noneGC']['void Sub1::noneGC()']
 assert callgraph.calleeGraph['Super.noneGC']['void Sub2::noneGC()']
 assert 'void Sibling::noneGC()' not in callgraph.calleeGraph['Super.noneGC']
 
 hazards = test.load_hazards()
 hazmap = {haz.variable: haz for haz in hazards}
+
 assert 'c1' not in hazmap
 assert 'c2' in hazmap
 assert 'c3' in hazmap
 assert 'c4' not in hazmap
 assert 'c5' in hazmap
 assert 'c6' in hazmap
 assert 'c7' not in hazmap
 assert 'c8' in hazmap