[llvm-commits] [zorg] r150746 - in /zorg/trunk/lnt/lnt: lnttool/create.py server/db/testsuitetypes.py server/db/v4db.py

Daniel Dunbar daniel at zuster.org
Thu Feb 16 14:54:28 PST 2012


Author: ddunbar
Date: Thu Feb 16 16:54:27 2012
New Revision: 150746

URL: http://llvm.org/viewvc/llvm-project?rev=150746&view=rev
Log:
[lnt/v0.4] lnt.server.db.v4db: Instantiate test suites (and their tables) on the
fly for known types.
 - This allows us to more closely match the existing usage model wherein test
   results can just be submitted to a server and "the right thing happens"
   (instead of requiring the test suite DB to be set up ahead of time).

Added:
    zorg/trunk/lnt/lnt/server/db/testsuitetypes.py
Modified:
    zorg/trunk/lnt/lnt/lnttool/create.py
    zorg/trunk/lnt/lnt/server/db/v4db.py

Modified: zorg/trunk/lnt/lnt/lnttool/create.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/create.py?rev=150746&r1=150745&r2=150746&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/create.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/create.py Thu Feb 16 16:54:27 2012
@@ -79,50 +79,7 @@
 
 import lnt.db.perfdb
 import lnt.testing
-
-def _create_v4_nt_database(db_path):
-    from lnt.server.db import v4db, testsuite
-
-    # Create the initial database.
-    db = lnt.server.db.v4db.V4DB('sqlite:///' + db_path)
-    db.commit()
-
-    # Create an NT compatible test suite, automatically.
-    ts = testsuite.TestSuite("nts", "NT")
-
-    # Promote the natural information produced by 'runtest nt' to fields.
-    ts.machine_fields.append(testsuite.MachineField("hardware", "hardware"))
-    ts.machine_fields.append(testsuite.MachineField("os", "os"))
-
-    # The only reliable order currently is the "run_order" field. We will want
-    # to revise this over time.
-    ts.order_fields.append(testsuite.OrderField("llvm_project_revision",
-                                                "run_order", 0))
-
-    # We are only interested in simple runs, so we expect exactly four fields
-    # per test.
-    compile_status = testsuite.SampleField(
-            "compile_status", db.status_sample_type, ".compile.status")
-    compile_time = testsuite.SampleField(
-        "compile_time", db.real_sample_type, ".compile",
-        status_field = compile_status)
-    exec_status = testsuite.SampleField(
-            "execution_status", db.status_sample_type, ".exec.status")
-    exec_time = testsuite.SampleField(
-            "execution_time", db.real_sample_type, ".exec",
-            status_field = exec_status)
-    ts.sample_fields.append(compile_time)
-    ts.sample_fields.append(compile_status)
-    ts.sample_fields.append(exec_time)
-    ts.sample_fields.append(exec_status)
-
-    db.add(ts)
-    db.commit()
-
-    # Finally, ensure the tables for the test suite we just defined are
-    # constructed.
-    ts_db = db.testsuite['nts']
-    db.commit()
+import lnt.server.db.v4db
 
 def action_create(name, args):
     """create an LLVM nightly test installation"""
@@ -199,10 +156,11 @@
     os.chmod(wsgi_path, 0755)
 
     if opts.use_v4:
-        _create_v4_nt_database(db_path)
+        db_class = lnt.server.db.v4db.V4DB
     else:
-        db = lnt.db.perfdb.PerfDB('sqlite:///' + db_path)
-        db.commit()
+        db_class = lnt.db.perfdb.PerfDB
+    db = db_class('sqlite:///' + db_path)
+    db.commit()
 
     print 'created LNT configuration in %r' % basepath
     print '  configuration file: %s' % cfg_path

Added: zorg/trunk/lnt/lnt/server/db/testsuitetypes.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/db/testsuitetypes.py?rev=150746&view=auto
==============================================================================
--- zorg/trunk/lnt/lnt/server/db/testsuitetypes.py (added)
+++ zorg/trunk/lnt/lnt/server/db/testsuitetypes.py Thu Feb 16 16:54:27 2012
@@ -0,0 +1,52 @@
+"""
+This module maintains information on the "known" test suite types.
+
+In order to follow the existing usage model for LNT with the v0.4 design (in
+which test suites get customized databases), we support dynamically creating
+appropriate test suites on the fly for these known types.
+"""
+
+from lnt.server.db import testsuite
+
+def get_nts_testsuite(db):
+    # Create an NT compatible test suite, automatically.
+    ts = testsuite.TestSuite("nts", "NT")
+
+    # Promote the natural information produced by 'runtest nt' to fields.
+    ts.machine_fields.append(testsuite.MachineField("hardware", "hardware"))
+    ts.machine_fields.append(testsuite.MachineField("os", "os"))
+
+    # The only reliable order currently is the "run_order" field. We will want
+    # to revise this over time.
+    ts.order_fields.append(testsuite.OrderField("llvm_project_revision",
+                                                "run_order", 0))
+
+    # We are only interested in simple runs, so we expect exactly four fields
+    # per test.
+    compile_status = testsuite.SampleField(
+            "compile_status", db.status_sample_type, ".compile.status")
+    compile_time = testsuite.SampleField(
+        "compile_time", db.real_sample_type, ".compile",
+        status_field = compile_status)
+    exec_status = testsuite.SampleField(
+            "execution_status", db.status_sample_type, ".exec.status")
+    exec_time = testsuite.SampleField(
+            "execution_time", db.real_sample_type, ".exec",
+            status_field = exec_status)
+    ts.sample_fields.append(compile_time)
+    ts.sample_fields.append(compile_status)
+    ts.sample_fields.append(exec_time)
+    ts.sample_fields.append(exec_status)
+
+    return ts
+
+_registry = {
+    'nts' : get_nts_testsuite,
+    }
+def get_testsuite_for_type(typename, db):
+    method = _registry.get(typename)
+    if method:
+        return method(db)
+    return None
+
+__all__ = ['get_testsuite_for_type']

Modified: zorg/trunk/lnt/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/db/v4db.py?rev=150746&r1=150745&r2=150746&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/db/v4db.py (original)
+++ zorg/trunk/lnt/lnt/server/db/v4db.py Thu Feb 16 16:54:27 2012
@@ -1,9 +1,11 @@
 import sqlalchemy
-import testsuite
-import testsuitedb
 
 import lnt.testing
 
+from lnt.server.db import testsuite
+from lnt.server.db import testsuitedb
+from lnt.server.db import testsuitetypes
+
 class V4DB(object):
     """
     Wrapper object for LNT v0.4+ databases.
@@ -29,7 +31,27 @@
             ts = self.v4db.query(testsuite.TestSuite).\
                 filter(testsuite.TestSuite.name == name).first()
             if ts is None:
-                return default
+                # Check to see if this is a test suite we know how to
+                # dynamically instantiate.
+                #
+                # FIXME: For now, we assume the typename matches the test suite
+                # name. It would be nice to allow tests to report the typename.
+                ts = testsuitetypes.get_testsuite_for_type(name, self.v4db)
+                if ts is not None:
+                    self.v4db.add(ts)
+                    # FIXME: I'm not really sure why we need to commit here. It
+                    # may be an SA bug. I think we should just be able to flush
+                    # but then there is an issue when the tables will get
+                    # realized by the TestSuiteDB constructor below.
+                    #
+                    # FIXME: This commit makes me a bit nervous because clients
+                    # most likely won't expect us to be
+                    # maybe-commit'ing. However, this is unlikely to be a
+                    # problem in practice.
+                    self.v4db.commit()
+                else:
+                    # Otherwise, return the default value.
+                    return default
 
             # Instantiate the per-test suite wrapper object for this test suite.
             self._cache[name] = ts = testsuitedb.TestSuiteDB(





More information about the llvm-commits mailing list