aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2018-01-26 07:06:20 +0100
committerDiana Picus <diana.picus@linaro.org>2018-01-31 14:46:30 +0000
commitf73abbf2bd0b4b86f815738e35a5e1eab7802272 (patch)
treed9b1b5f70c6abd9f886576d54942c47d63c68faa
parentb368cb6384312a8dd26172202d6e33bea6b472b9 (diff)
downloadlinaro-scripts-f73abbf2bd0b4b86f815738e35a5e1eab7802272.tar.gz
Support setting up the test-suite
Add a subcommand 'setup-test-suite' which sets up a sandbox that can be used for running the test-suite. Change-Id: If6426acd0e4e8ed54d310d1159a545f762affe74
-rwxr-xr-xhelpers/llvm-test-suite4
-rw-r--r--modules/llvm.py21
-rw-r--r--scripts/llvm.py34
-rw-r--r--tests/cli/testllvmtestsuite.py30
-rw-r--r--tests/unittests/testsetuptestsuite.py31
5 files changed, 117 insertions, 3 deletions
diff --git a/helpers/llvm-test-suite b/helpers/llvm-test-suite
index 283e52f..0374749 100755
--- a/helpers/llvm-test-suite
+++ b/helpers/llvm-test-suite
@@ -19,9 +19,7 @@ lnt=$LLVM_ROOT/repos/lnt
lit=$LLVM_BLD/bin/llvm-lit
clang=$LLVM_BLD/bin/clang
-# TODO: There should be a llvm.py subcommand for setting up the sandbox
-safe_run virtualenv $sandbox
-safe_run $sandbox/bin/python $lnt/setup.py develop
+safe_run python3 $llvmtool setup-test-suite --sandbox $sandbox --lnt $lnt
safe_run python3 $llvmtool run-test-suite --sandbox $sandbox \
--test-suite $testsuite --use-lit $lit --cc $clang --cxx $clang++ "$@"
diff --git a/modules/llvm.py b/modules/llvm.py
index e70e411..298076d 100644
--- a/modules/llvm.py
+++ b/modules/llvm.py
@@ -363,6 +363,27 @@ def build_llvm(commandConsumer, buildDir, flags=[]):
commandConsumer.consume(command, buildDir)
+def setup_test_suite(commandConsumer, sandbox, lnt):
+ """
+ Generate the commands needed for setting up a sandbox for running the
+ test-suite and pass them to the 'commandConsumer'.
+
+ The 'commandConsumer' should have a 'consume' method taking two
+ parameters: the command to be consumed (in the form of a list) and the
+ directory where the command should be run. Any exceptions that may be
+ raised by that method should be handled by the calling code.
+
+ The 'sandbox' should be the path where we want to set things up (it will be
+ created if it doesn't exist) and 'lnt' should be the path to the LNT source
+ tree.
+ """
+ # These commands don't need to run in any particular directory, just use the
+ # current working directory.
+ commandConsumer.consume(["virtualenv", sandbox], None)
+ commandConsumer.consume(["{}/bin/python".format(sandbox),
+ "{}/setup.py".format(lnt), "develop"], None)
+
+
def run_test_suite(commandConsumer, sandbox, testsuite, lit, flags=[]):
"""
Generate the command needed for running the test-suite with the given
diff --git a/scripts/llvm.py b/scripts/llvm.py
index be4628f..cce0ef4 100644
--- a/scripts/llvm.py
+++ b/scripts/llvm.py
@@ -9,6 +9,7 @@ from modules.llvm import LLVMBuildConfig
from modules.llvm import LLVMSubproject
from modules.llvm import LLVMSourceConfig
from modules.llvm import run_test_suite
+from modules.llvm import setup_test_suite
from modules.utils import CommandPrinter
from modules.utils import CommandRunner
from modules.utils import get_remote_branch
@@ -133,6 +134,19 @@ def run_build(args):
die("Failed to build {} because:\n{}".format(args.build, str(exc)))
+def setup_the_test_suite(args):
+ """Setup a sandbox for the test-suite."""
+ if args.dry:
+ consumer = CommandPrinter()
+ else:
+ consumer = CommandRunner()
+
+ try:
+ setup_test_suite(consumer, args.sandbox, args.lnt)
+ except RuntimeError as exc:
+ die("Failed to setup the test-suite because:\n{}".format(str(exc)))
+
+
def run_the_test_suite(args):
"""Run the test-suite in a given sandbox."""
if args.dry:
@@ -279,6 +293,26 @@ build.add_argument(
"'--build-flag=-FLAG' to pass it.")
build.set_defaults(run_command=run_build)
+# Subcommand for setting up the test-suite
+setupTestSuite = subcommands.add_parser(
+ 'setup-test-suite',
+ help="Prepare a sandbox for running the test-suite.")
+setupTestSuite.add_argument(
+ '--sandbox',
+ required=True,
+ help="Path where we should setup the sandbox.")
+setupTestSuite.add_argument(
+ '--lnt',
+ required=True,
+ help="Path to the LNT sources.")
+setupTestSuite.add_argument(
+ '-n', '--dry-run',
+ dest='dry',
+ action='store_true',
+ default=False,
+ help="Print the commands instead of executing them.")
+setupTestSuite.set_defaults(run_command=setup_the_test_suite)
+
# Subcommand for running the test-suite
runTestSuite = subcommands.add_parser(
'run-test-suite',
diff --git a/tests/cli/testllvmtestsuite.py b/tests/cli/testllvmtestsuite.py
index be29ae1..41f8d3e 100644
--- a/tests/cli/testllvmtestsuite.py
+++ b/tests/cli/testllvmtestsuite.py
@@ -9,6 +9,36 @@ from llvmtestcase import LLVMTestCase, require_command_arg, debug
from re import escape
+class Testllvmsetuptestsuite(LLVMTestCase):
+
+ @classmethod
+ def llvm_setup_test_suite(cls, *args, **kwargs):
+ return cls.command_with_defaults("setup-test-suite", *args, **kwargs)
+
+ @require_command_arg("--sandbox")
+ def test_sandbox_is_compulsory(self):
+ """Test that we get an error if we don't pass the path to the sandbox."""
+ self.run_with_output(self.llvm_setup_test_suite("--lnt=somewhere"))
+
+ @require_command_arg("--lnt")
+ def test_lnt_is_compulsory(self):
+ """Test that we get an error if we don't pass the path to lnt."""
+ self.run_with_output(self.llvm_setup_test_suite("--sandbox=somewhere"))
+
+ def test_dry_run(self):
+ """Test that we get the correct commands for setting up a sandbox."""
+ sandbox = "path/to/sandbox"
+ lnt = "path/to/lnt"
+
+ output = self.run_with_output(self.llvm_setup_test_suite(
+ "--dry-run", "--sandbox", sandbox, "--lnt", lnt))
+
+ # We don't care about the directory where this is running.
+ self.assertRegex(
+ output,
+ "(.*)\$ virtualenv {0}\n"
+ "(.*)\$ {0}/bin/python {1}/setup.py develop\n".format(
+ sandbox, lnt))
class Testllvmruntestsuite(LLVMTestCase):
diff --git a/tests/unittests/testsetuptestsuite.py b/tests/unittests/testsetuptestsuite.py
new file mode 100644
index 0000000..9a42aac
--- /dev/null
+++ b/tests/unittests/testsetuptestsuite.py
@@ -0,0 +1,31 @@
+from modules.llvm import setup_test_suite
+
+import os
+
+from unittest import TestCase
+from unittest.mock import MagicMock
+
+
+class TestSetupTestSuite(TestCase):
+
+ def test_setup(self):
+ """Test that we generate the right commands for setting up a sandbox."""
+ sandbox = "path/to/sandbox"
+ lnt = "path/to/lnt"
+
+ consumer = MagicMock()
+ setup_test_suite(consumer, sandbox, lnt)
+
+ firstCommand, directory = consumer.consume.call_args_list[0][0]
+ self.assertIsNone(directory)
+ self.assertEqual(
+ firstCommand,
+ ["virtualenv", sandbox])
+
+ secondCommand, directory = consumer.consume.call_args_list[1][0]
+ self.assertIsNone(directory)
+ self.assertEqual(
+ secondCommand,
+ ["{}/bin/python".format(sandbox),
+ "{}/setup.py".format(lnt),
+ "develop"])