build-and-test: Make it possible to customize test suite run

Allow the user to pass flags to LNT when running the test-suite.

Change-Id: Idb66ac25934281613f6392750b38d5c53f99761a
diff --git a/scripts/llvm.py b/scripts/llvm.py
index bdeae85..8d9a4c1 100644
--- a/scripts/llvm.py
+++ b/scripts/llvm.py
@@ -206,6 +206,7 @@
 
     enableTestSuite = args.enableTestSuite
     sandboxDir = args.sandbox
+    testSuiteFlags = args.testSuiteFlags
 
     if dryRun:
         consumer = CommandPrinter()
@@ -266,7 +267,7 @@
             lit = os.path.join(testedBuildDir, "bin", "llvm-lit")
             clang = os.path.join(testedBuildDir, "bin", "clang")
             run_test_suite(consumer, sandboxDir, testSuiteDir, lit,
-                           ["--cc={}".format(clang)])
+                           ["--cc={}".format(clang)] + testSuiteFlags)
 
     except RuntimeError as exc:
         die("Failed because:\n{}".format(str(exc)))
@@ -567,6 +568,15 @@
     "--sandbox",
     help="Path to the sandbox where the test-suite should be setup.")
 buildAndTest.add_argument(
+    '--lnt-flag',
+    dest='testSuiteFlags',
+    metavar='FLAG',
+    default=[],
+    action='append',
+    help="Additional flags to be passed to LNT when running the test-suite."
+    "May be passed several times. If your flag starts with a '-', use "
+    "'--lnt-flag=-FLAG' to pass it.")
+buildAndTest.add_argument(
     '-n', '--dry-run',
     dest='dry',
     action='store_true',
diff --git a/tests/cli/testbuildandtest.py b/tests/cli/testbuildandtest.py
index f7996ad..86e2203 100644
--- a/tests/cli/testbuildandtest.py
+++ b/tests/cli/testbuildandtest.py
@@ -76,7 +76,7 @@
                          "{build}\$ ninja -j8 check-all".format(build=buildDir))
 
 
-    def test_stage1_and_testsuite(self):
+    def test_stage1_and_default_testsuite(self):
         """
         Test that we dump the correct commands for a single stage build of LLVM
         and a run of the test-suite with the resulting compiler.
@@ -123,6 +123,54 @@
             "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format(
                 sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir))
 
+    def test_stage1_and_custom_testsuite(self):
+        """Test that we can add custom flags to our test-suite run."""
+        reposDir = "path-to-repos"
+        sourceDir = "path-to-sources"
+        buildDir = "path-to-stage1"
+        sandboxDir = "path-to-sandbox"
+
+        testSuiteDir = os.path.join(reposDir, "test-suite")
+        lntDir = os.path.join(reposDir, "lnt")
+
+        output = self.run_with_output(
+            self.llvm_build_and_test(
+                "--dry-run",
+                "--repos-dir", reposDir,
+                "--source-dir", sourceDir,
+                "--stage1-build-dir", buildDir,
+                "--enable-test-suite",
+                "--sandbox", sandboxDir,
+                "--lnt-flag=--threads=4",
+                "--lnt-flag=--cppflags",
+                "--lnt-flag", "'-mcpu=cortex-a15 -marm'"))
+
+        commands = output.splitlines()
+
+        self.assertRegex(commands[0],
+                         "{build}\$ cmake -G Ninja .* {sources}".format(
+                             build=buildDir, sources=sourceDir))
+
+        self.assertRegex(commands[1],
+                         "{build}\$ ninja".format(build=buildDir))
+
+        self.assertRegex(
+            commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))
+
+        self.assertRegex(
+            commands[3],
+            ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
+                sandbox=sandboxDir,
+                lnt=lntDir))
+
+        self.assertRegex(
+            commands[4],
+            ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
+            "--sandbox={sandbox} --test-suite={testsuite} "
+            "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang "
+            "--threads=4 --cppflags '-mcpu=cortex-a15 -marm'".format(
+                sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir))
+
     def test_default_stage2(self):
         """
         Test that we dump the correct commands for a 2-stage build of LLVM.