[LNT] r198453 - In an effort refactor the code to make way for run resampling, move the run submission code into the test suites.

Chris Matthews cmatthews5 at apple.com
Fri Jan 3 14:50:32 PST 2014


Author: cmatthews
Date: Fri Jan  3 16:50:32 2014
New Revision: 198453

URL: http://llvm.org/viewvc/llvm-project?rev=198453&view=rev
Log:
In an effort refactor the code to make way for run resampling, move the run submission code into the test suites.

With resampling the submission logic will change in NT.
Deprecate runtest command line args. Move submit code into common subclass. Refactored out the result printing code, as it was common to several places.

Modified:
    lnt/trunk/lnt/lnttool/main.py
    lnt/trunk/lnt/tests/builtintest.py
    lnt/trunk/lnt/tests/compile.py
    lnt/trunk/lnt/tests/nt.py
    lnt/trunk/lnt/util/ServerUtil.py

Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=198453&r1=198452&r2=198453&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Fri Jan  3 16:50:32 2014
@@ -122,28 +122,29 @@ def action_checkformat(name, args):
 def action_runtest(name, args):
     """run a builtin test application"""
 
+    # Runtest accepting options is deprecated, but lets not break the
+    # world, so collect them anyways and pass them on.
     parser = OptionParser("%s test-name [options]" % name)
     parser.disable_interspersed_args()
-    parser.add_option("", "--submit", dest="submit_url", metavar="URLORPATH",
-                      help=("autosubmit the test result to the given server "
-                            "(or local instance) [%default]"),
-                      type=str, default=None)
-    parser.add_option("", "--commit", dest="commit",
-                      help=("whether the autosubmit result should be committed "
-                            "[%default]"),
-                      type=int, default=True)
-    parser.add_option("", "--output", dest="output", metavar="PATH",
-                      help="write raw report data to PATH (or stdout if '-')",
-                      action="store", default=None)
-    parser.add_option("-v", "--verbose", dest="verbose",
-                      help="show verbose test results",
-                      action="store_true", default=False)
+    parser.add_option("", "--submit", dest="submit", type=str, default=None)
+    parser.add_option("", "--commit", dest="commit", type=str, default=None)
+    parser.add_option("", "--output", dest="output", type=str, default=None)
+    parser.add_option("-v", "--verbose", dest="verbose", default=None)
 
-    (opts, args) = parser.parse_args(args)
+    (deprecated_opts, args) = parser.parse_args(args)
     if len(args) < 1:
         parser.error("incorrect number of argments")
 
-    test_name,args = args[0],args[1:]
+    test_name, args = args[0], args[1:]
+    # Rebuild the deprecated arguments.
+    for key, val in vars(deprecated_opts).iteritems():
+        if val is not None:
+            if isinstance(val, str):
+                args.insert(0, val)
+            args.insert(0, "--" + key)
+
+            warning("--{} should be passed directly to the"
+                        " test suite.".format(key))
 
     import lnt.tests
     try:
@@ -151,50 +152,7 @@ def action_runtest(name, args):
     except KeyError:
         parser.error('invalid test name %r' % test_name)
 
-    report = test_instance.run_test('%s %s' % (name, test_name), args)
-
-    if opts.output is not None:
-        if opts.output == '-':
-            output_stream = sys.stdout
-        else:
-            output_stream = open(opts.output, 'w')
-        print >>output_stream, report.render()
-        if output_stream is not sys.stdout:
-            output_stream.close()
-
-    # Save the report to a temporary file.
-    #
-    # FIXME: This is silly, the underlying test probably wrote the report to a
-    # file itself. We need to clean this up and make it standard across all
-    # tests. That also has the nice side effect that writing into a local
-    # database records the correct imported_from path.
-    tmp = tempfile.NamedTemporaryFile(suffix='.json')
-    print >>tmp, report.render()
-    tmp.flush()
-
-    if opts.submit_url is not None:
-        if report is None:
-            raise SystemExit,"error: report generation failed"
-
-        from lnt.util import ServerUtil
-        test_instance.log("submitting result to %r" % (opts.submit_url,))
-        ServerUtil.submitFile(opts.submit_url, tmp.name, True, opts.verbose)
-    else:
-        # Simulate a submission to retrieve the results report.
-
-        # Construct a temporary database and import the result.
-        test_instance.log("submitting result to dummy instance")
-        
-        import lnt.server.db.v4db
-        import lnt.server.config
-        db = lnt.server.db.v4db.V4DB("sqlite:///:memory:",
-                                     lnt.server.config.Config.dummyInstance())
-        result = lnt.util.ImportData.import_and_report(
-            None, None, db, tmp.name, 'json', commit = True)
-        lnt.util.ImportData.print_report_result(result, sys.stdout, sys.stderr,
-                                                opts.verbose)
-
-    tmp.close()
+    test_instance.run_test('%s %s' % (name, test_name), args)
 
 def action_showtests(name, args):
     """show the available built-in tests"""

Modified: lnt/trunk/lnt/tests/builtintest.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/builtintest.py?rev=198453&r1=198452&r2=198453&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/builtintest.py (original)
+++ lnt/trunk/lnt/tests/builtintest.py Fri Jan  3 16:50:32 2014
@@ -3,9 +3,17 @@ Base class for builtin-in tests.
 """
 
 import sys
+import os
 
 from lnt.testing.util.misc import timestamp
 
+import lnt.util.ServerUtil as ServerUtil 
+import lnt.util.ImportData as ImportData
+
+import lnt.server.db.v4db
+import lnt.server.config
+
+
 class BuiltinTest(object):
     def __init__(self):
         pass
@@ -26,3 +34,47 @@ class BuiltinTest(object):
 
     def log(self, message, ts=timestamp()):
         print >>sys.stderr, '%s: %s' % (ts, message)
+
+    @staticmethod
+    def print_report(report, output):
+        """Print the report object to the output path."""
+        if output == '-':
+            output_stream = sys.stdout
+        else:
+            output_stream = open(output, 'w')
+        print >> output_stream, report.render()
+        if output_stream is not sys.stdout:
+            output_stream.close()
+
+    def submit(self, report_path, config, commit=True):
+        """Submit the results file to the server.  If no server
+        was specified, use a local mock server.
+        
+        report_path is the location of the json report file.  config
+        holds options for submission url, and verbosity.  When commit
+        is true, results will be saved in the server, otherwise you
+        will just get back a report but server state is not altered.
+
+        """
+        assert os.path.exists(report_path), "Failed report should have never gotten here!"
+        result = None
+        if config.submit_url is not None:
+            self.log("submitting result to %r" % (config.submit_url,))
+            commit = True
+            result = ServerUtil.submitFile(config.submit_url, report_path,
+                                           commit, config.verbose)
+        else:
+            # Simulate a submission to retrieve the results report.
+
+            # Construct a temporary database and import the result.
+            self.log("submitting result to dummy instance")
+
+            db = lnt.server.db.v4db.V4DB("sqlite:///:memory:",
+                                         lnt.server.config.Config.dummyInstance())
+            result = ImportData.import_and_report(
+                None, None, db, report_path, 'json', commit = True)
+        assert result is not None, "Results were not submitted."
+        ImportData.print_report_result(result, sys.stdout, sys.stderr,
+                                                    config.verbose)
+
+

Modified: lnt/trunk/lnt/tests/compile.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/compile.py?rev=198453&r1=198452&r2=198453&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/compile.py (original)
+++ lnt/trunk/lnt/tests/compile.py Fri Jan  3 16:50:32 2014
@@ -659,9 +659,6 @@ class CompileTest(builtintest.BuiltinTes
         parser = OptionParser(
             ("%(name)s [options] [<output file>]\n" +
              usage_info) % locals())
-        parser.add_option("-v", "--verbose", dest="verbose",
-                          help="Show more test output",
-                          action="store_true", default=False)
         parser.add_option("-s", "--sandbox", dest="sandbox_path",
                           help="Parent directory to build and run tests in",
                           type=str, default=None, metavar="PATH")
@@ -743,6 +740,21 @@ class CompileTest(builtintest.BuiltinTes
         group.add_option("", "--machine-name", dest="machine_name", type='str',
                          help="Machine name to use in submission [%default]",
                          action="store", default=platform.uname()[1])
+        group.add_option("", "--submit", dest="submit_url", metavar="URLORPATH",
+                          help=("autosubmit the test result to the given server "
+                                "(or local instance) [%default]"),
+                          type=str, default=None)
+        group.add_option("", "--commit", dest="commit",
+                          help=("whether the autosubmit result should be committed "
+                                "[%default]"),
+                          type=int, default=True)
+        group.add_option("", "--output", dest="output", metavar="PATH",
+                          help="write raw report data to PATH (or stdout if '-')",
+                          action="store", default=None)
+        group.add_option("-v", "--verbose", dest="verbose",
+                          help="show verbose test results",
+                          action="store_true", default=False)
+
         parser.add_option_group(group)
 
         opts,args = parser.parse_args(args)
@@ -996,7 +1008,7 @@ class CompileTest(builtintest.BuiltinTes
             run_info['had_errors'] = 1
 
         end_time = datetime.utcnow()
-        
+
         g_log.info('run complete')
         
         # Package up the report.
@@ -1006,9 +1018,15 @@ class CompileTest(builtintest.BuiltinTes
         # Write out the report.
         lnt_report_path = os.path.join(g_output_dir, 'report.json')
         report = lnt.testing.Report(machine, run, testsamples)
-        lnt_report_file = open(lnt_report_path, 'w')
-        print >>lnt_report_file, report.render()
-        lnt_report_file.close()
+
+        # Save report to disk for submission.
+        self.print_report(report, lnt_report_path)
+
+        # Then, also print to screen if requested.
+        if opts.output is not None:
+            self.print_report(report, opts.output)
+
+        self.submit(lnt_report_path, opts)
 
         return report
 

Modified: lnt/trunk/lnt/tests/nt.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/nt.py?rev=198453&r1=198452&r2=198453&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/nt.py (original)
+++ lnt/trunk/lnt/tests/nt.py Fri Jan  3 16:50:32 2014
@@ -1272,10 +1272,20 @@ class NTTest(builtintest.BuiltinTest):
                          metavar="NAME=VAL",
                          help="Add 'NAME' = 'VAL' to the run parameters",
                          type=str, action="append", default=[])
-        group.add_option("", "--verbose", dest="verbose",
-                         help=("Be verbose in output. Print the output of"
-                               "sub-commands."),
-                         action="store_true", default=False)
+        group.add_option("", "--submit", dest="submit_url", metavar="URLORPATH",
+                         help=("autosubmit the test result to the given server"
+                               " (or local instance) [%default]"),
+                         type=str, default=None)
+        group.add_option("", "--commit", dest="commit",
+                          help=("whether the autosubmit result should be committed "
+                                "[%default]"),
+                          type=int, default=True)
+        group.add_option("", "--output", dest="output", metavar="PATH",
+                          help="write raw report data to PATH (or stdout if '-')",
+                          action="store", default=None)
+        group.add_option("-v", "--verbose", dest="verbose",
+                          help="show verbose test results",
+                          action="store_true", default=False)
 
         parser.add_option_group(group)
 
@@ -1433,10 +1443,9 @@ class NTTest(builtintest.BuiltinTest):
                 warning('expected --isysroot when executing with '
                         '--ios-simulator-sdk')
 
+        config = TestConfiguration(vars(opts), timestamp())
         # FIXME: We need to validate that there is no configured output in the
         # test-suite directory, that borks things. <rdar://problem/7876418>
-        options = dict(vars(opts).items())
-        config = TestConfiguration(options, timestamp())
         prepare_report_dir(config)
 
         # Multisample, if requested.
@@ -1462,15 +1471,20 @@ class NTTest(builtintest.BuiltinTest):
                                 for r in reports], [])
 
             # Write out the merged report.
-            lnt_report_path = os.path.join(config.report_dir, 'report.json')
+            lnt_report_path = config.report_path(None)
             report = lnt.testing.Report(machine, run, test_samples)
             lnt_report_file = open(lnt_report_path, 'w')
-            print >>lnt_report_file,report.render()
+            print >>lnt_report_file, report.render()
             lnt_report_file.close()
 
-            return report
+        else:
+            report = run_test(nick, None, config)
+
+        if config.output is not None:
+            self.print_report(report, config.output)
+
+        self.submit(config.report_path(None), config)
 
-        report = run_test(nick, None, config)
         return report
 
 def create_instance():

Modified: lnt/trunk/lnt/util/ServerUtil.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/ServerUtil.py?rev=198453&r1=198452&r2=198453&view=diff
==============================================================================
--- lnt/trunk/lnt/util/ServerUtil.py (original)
+++ lnt/trunk/lnt/util/ServerUtil.py Fri Jan  3 16:50:32 2014
@@ -59,10 +59,10 @@ def submitFile(url, file, commit, verbos
             return
     else:
         result = submitFileToInstance(url, file, commit)
-
-    # Print the test report.
-    ImportData.print_report_result(result, sys.stdout, sys.stderr, verbose)
+    return result
 
 def submitFiles(url, files, commit, verbose):
+    results = []
     for file in files:
-        submitFile(url, file, commit, verbose)
+        result = submitFile(url, file, commit, verbose)
+        results.append(result)





More information about the llvm-commits mailing list