[LNT] r255976 - Clean up to fix all unit tests

Chris Matthews via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 17 18:22:57 PST 2015


Author: cmatthews
Date: Thu Dec 17 20:22:57 2015
New Revision: 255976

URL: http://llvm.org/viewvc/llvm-project?rev=255976&view=rev
Log:
Clean up to fix all unit tests

Modified:
    lnt/trunk/lnt/lnttool/main.py
    lnt/trunk/lnt/server/db/v4db.py
    lnt/trunk/lnt/testing/util/commands.py
    lnt/trunk/lnt/util/ImportData.py
    lnt/trunk/lnt/util/async_ops.py
    lnt/trunk/tests/runtest/multisample.py
    lnt/trunk/tests/server/ui/change_processing.py
    lnt/trunk/tests/server/ui/test_api.py

Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Thu Dec 17 20:22:57 2015
@@ -14,7 +14,7 @@ import lnt
 import lnt.util.multitool
 import lnt.util.ImportData
 from lnt import testing
-from lnt.testing.util.commands import note, warning, error, fatal
+from lnt.testing.util.commands import note, warning, error, fatal, LOGGER_NAME
 
 def action_runserver(name, args):
     """start a new development server"""
@@ -66,7 +66,7 @@ view the results.\
 
     # Setup the base LNT logger.
     # Root logger in debug.
-    logger = logging.getLogger("LNT")
+    logger = logging.getLogger(LOGGER_NAME)
     if opts.debugger:
         logger.setLevel(logging.DEBUG)
     handler = logging.StreamHandler()
@@ -160,10 +160,10 @@ def action_runtest(name, args):
             warning("--{} should be passed directly to the"
                         " test suite.".format(key))
 
-    logger = logging.getLogger("LNT")
-    logger.setLevel(logging.DEBUG)
+    logger = logging.getLogger(LOGGER_NAME)
+    logger.setLevel(logging.INFO)
     handler = logging.StreamHandler()
-    handler.setLevel(logging.DEBUG)
+    handler.setLevel(logging.INFO)
     handler.setFormatter(logging.Formatter(
             '%(asctime)s %(levelname)s: %(message)s',
             datefmt='%Y-%m-%d %H:%M:%S'))

Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Thu Dec 17 20:22:57 2015
@@ -139,7 +139,7 @@ class V4DB(object):
         in memory database."""
         V4DB._engine[db_path].dispose()
         V4DB._engine.pop(db_path)
-        #V4DB._db_updated.remove(db_path)
+        V4DB._db_updated.remove(db_path)
     
     @staticmethod
     def close_all_engines():

Modified: lnt/trunk/lnt/testing/util/commands.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/util/commands.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/util/commands.py (original)
+++ lnt/trunk/lnt/testing/util/commands.py Thu Dec 17 20:22:57 2015
@@ -11,9 +11,10 @@ import time
 from flask import current_app
 # FIXME: Find a better place for this code.
 
+LOGGER_NAME = "lnt.server.ui.app"
 
 def getLogger():
-    logger = logging.getLogger("lnt.server.ui.app")
+    logger = logging.getLogger(LOGGER_NAME)
     return logger
 
 note = lambda message: getLogger().info(message)

Modified: lnt/trunk/lnt/util/ImportData.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/ImportData.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/lnt/util/ImportData.py (original)
+++ lnt/trunk/lnt/util/ImportData.py Thu Dec 17 20:22:57 2015
@@ -97,6 +97,8 @@ def import_and_report(config, db_name, d
         report_url = "localhost"
 
     if not disable_report:
+        #  This has the side effect of building the run report for
+        #  this result.
         NTEmailReport.emailReport(result, db, run, report_url,
                                   email_config, toAddress, success, commit)
 
@@ -110,8 +112,12 @@ def import_and_report(config, db_name, d
     ts_name = data['Run']['Info'].get('tag')
     if commit:
         db.commit()
-        ts = db.testsuite.get(ts_name)
-        async_ops.async_fieldchange_calc(ts, run)
+        if db_config:
+            #  If we are not in a dummy instance, also run backgound jobs.
+            #  We have to have a commit before we run, so subprocesses can
+            #  see the submitted data.
+            ts = db.testsuite.get(ts_name)
+            async_ops.async_fieldchange_calc(db_name, ts, run)
 
     else:
         db.rollback()

Modified: lnt/trunk/lnt/util/async_ops.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/async_ops.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/lnt/util/async_ops.py (original)
+++ lnt/trunk/lnt/util/async_ops.py Thu Dec 17 20:22:57 2015
@@ -8,6 +8,7 @@ subprocesses (because they are not seria
 package in the system, but are generated on program load) we recreate the test
 suite that we need inside each subprocess before we execute the work job.
 """
+import atexit
 import os
 import time
 import logging
@@ -16,6 +17,7 @@ import sys
 import lnt.server.db.fieldchange as fieldchange
 import lnt.server.db.v4db
 import traceback
+import signal
 import contextlib
 import multiprocessing
 from multiprocessing import Pool, TimeoutError, Manager, Process
@@ -33,18 +35,37 @@ def launch_workers():
     global WORKERS
     if not WORKERS:
         note("Starting workers")
-        manager = Manager()            
-        current_app.config['mem_logger'].buffer = manager.list(current_app.config['mem_logger'].buffer)
-    
+        manager = Manager()         
+        try:
+            current_app.config['mem_logger'].buffer = manager.list(current_app.config['mem_logger'].buffer)
+        except RuntimeError:
+            #  It might be the case that we are not running in the app.
+            #  In this case, don't bother memory logging, stdout should
+            #  sufficent for console mode.
+            pass
+        atexit.register(cleanup)
+        signal.signal(signal.SIGTERM, sigHandler)
+
+def sigHandler(signo, frame):
+    sys.exit(0)
+
+
+def cleanup():
+    print "Running process cleanup."
+    for p in JOBS:
+        print "Waiting for", p.name, p.pid
+        if p.is_alive:
+            p.join()
 
-def async_fieldchange_calc(ts, run):
+def async_fieldchange_calc(db_name, ts, run):
     """Run regenerate field changes in the background."""
     func_args = {'run_id': run.id}
     #  Make sure this run is in the database!
     async_run_job(fieldchange.post_submit_tasks,
-                  ts,
+                  db_name, ts,
                   func_args)
 
+
 def check_workers(is_logged):
     global JOBS
     JOBS = [x for x in JOBS if x.is_alive()]
@@ -61,38 +82,33 @@ def check_workers(is_logged):
             logging.getLogger("lnt.server.ui.app").info("Job queue empty.")
     return len(JOBS)
         
-def async_run_job(job, ts, func_args):
+def async_run_job(job, db_name, ts, func_args):
     """Send a job to the async wrapper in the subprocess."""
     # If the run is not in the database, we can't do anything more.
     note("Queuing background job to process fieldchanges " + str(os.getpid()))
     launch_workers()
     check_workers(True)
+
     args = {'tsname': ts.name,
-            'db': g.db_name}
+            'db': db_name}
     job = Process(target=async_wrapper,
                   args=[job, args, func_args])
 
     job.start()
-    # Lets see if we crash right away?
-    # try:
-    #     stuff = job.join(timeout=1)
-    #     assert False, "This should aways fail."
-    # except TimeoutError:
     JOBS.append(job)
 
 # Flag to track if we have disposed of the parents database connections in
 # this subprocess.
 clean_db = False
-lock = Lock()
+
 def async_wrapper(job, ts_args, func_args):
     """Setup test-suite in this subprocess and run something.
     
     Because of multipocessing, capture excptions and log messages,
     and return them.
     """
-    global clean_db, lock
+    global clean_db
     try:
-
         start_time = time.time()
         
         if not clean_db:
@@ -117,7 +133,7 @@ def async_wrapper(job, ts_args, func_arg
     except:
         # Put all exception text into an exception and raise that for our
         # parent process.
-        error("".join(traceback.format_exception(*sys.exc_info())))
+        error("Subprocess failed with:" + "".join(traceback.format_exception(*sys.exc_info())))
         sys.exit(1)
     sys.exit(0)
 

Modified: lnt/trunk/tests/runtest/multisample.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/runtest/multisample.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/tests/runtest/multisample.py (original)
+++ lnt/trunk/tests/runtest/multisample.py Thu Dec 17 20:22:57 2015
@@ -4,7 +4,7 @@
 # RUN:   --sandbox %t.SANDBOX \
 # RUN:   --test-suite %S/Inputs/test-suite \
 # RUN:   --cc %{shared_inputs}/FakeCompilers/clang-r154331 \
-# RUN:   --no-timestamp --multisample 2 > %t.log 2> %t.err
+# RUN:   --no-timestamp --multisample 5 > %t.log 2> %t.err
 #
 # RUN: FileCheck --check-prefix CHECK-STDOUT < %t.log %s
 # RUN: FileCheck --check-prefix CHECK-STDERR < %t.err %s
@@ -26,4 +26,7 @@
 # CHECK-STDERR: capturing machine information
 # CHECK-STDERR: generating report
 # CHECK-STDERR: (multisample) running iteration 1
+# CHECK-STDERR: (multisample) running iteration 2
+# CHECK-STDERR: (multisample) running iteration 3
+# CHECK-STDERR: (multisample) running iteration 4
 # CHECK-STDERR: submitting result to dummy instance

Modified: lnt/trunk/tests/server/ui/change_processing.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/change_processing.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/change_processing.py (original)
+++ lnt/trunk/tests/server/ui/change_processing.py Thu Dec 17 20:22:57 2015
@@ -108,20 +108,20 @@ class ChangeProcessingTests(unittest.Tes
         ts_db.commit()
 
     def tearDown(self):
-        self.db.close_engine()
-
-    def test_fc(self):
-        pass
+        self.db.close_all_engines()
 
     def _mkorder(self, ts, rev):
         order = ts.Order()
         order.llvm_project_revision = rev
         ts.add(order)
         return order
+    
+    def test_startup(self):
+        pass
 
-    def test_rebuild_title(self):
-        ts = self.ts_db
-        
+    #def test_rebuild_title(self):
+    #    ts = self.ts_db
+    #    
     def test_change_grouping_criteria(self):
         ts_db = self.ts_db
 

Modified: lnt/trunk/tests/server/ui/test_api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_api.py?rev=255976&r1=255975&r2=255976&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_api.py (original)
+++ lnt/trunk/tests/server/ui/test_api.py Thu Dec 17 20:22:57 2015
@@ -61,9 +61,9 @@ order_expected_response = {u'id': 1,
                            u'next_order_id': 0,
                            u'previous_order_id': 2}
 
-graph_data = [[152292, 1.0,
+graph_data = [[u'152292', 1.0,
                {u'date': u'2012-05-01 16:28:23', u'label': u'152292'}],
-              [152293, 10.0,
+              [u'152293', 10.0,
                {u'date': u'2012-05-03 16:28:24', u'label': u'152293'}]]
 
 




More information about the llvm-commits mailing list