summaryrefslogtreecommitdiff
path: root/site_scons/site_tools/mongo_test_execution.py
diff options
context:
space:
mode:
authorMathew Robinson <mathew.robinson@mongodb.com>2020-01-06 17:03:45 +0000
committerevergreen <evergreen@mongodb.com>2020-01-06 17:03:45 +0000
commit7099b048c2a6f4b5900c32e46ef6ac6269449a42 (patch)
tree53ab68b366a78bee7a7d5da834c2ebc8cb9df178 /site_scons/site_tools/mongo_test_execution.py
parent912ec223071b9384710da8582ea379956c1e5935 (diff)
downloadmongo-7099b048c2a6f4b5900c32e46ef6ac6269449a42.tar.gz
SERVER-44947 Allow test execution selection by test source file name
Diffstat (limited to 'site_scons/site_tools/mongo_test_execution.py')
-rw-r--r--site_scons/site_tools/mongo_test_execution.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/site_scons/site_tools/mongo_test_execution.py b/site_scons/site_tools/mongo_test_execution.py
new file mode 100644
index 00000000000..7424f726aed
--- /dev/null
+++ b/site_scons/site_tools/mongo_test_execution.py
@@ -0,0 +1,74 @@
+# Copyright 2019 MongoDB Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+
+def generate_test_execution_aliases(env, test):
+ hygienic = env.GetOption("install-mode") == "hygienic"
+ if hygienic and getattr(test.attributes, "AIB_INSTALL_ACTIONS", []):
+ installed = getattr(test.attributes, "AIB_INSTALL_ACTIONS")
+ else:
+ installed = [test]
+
+ target_name = os.path.basename(installed[0].get_path())
+ command = env.Command(
+ target="#+{}".format(target_name),
+ source=installed,
+ action="${SOURCES[0]} $UNITTEST_FLAGS",
+ NINJA_POOL="console",
+ )
+
+ env.Alias("test-execution-aliases", command)
+ for source in test.sources:
+ source_base_name = os.path.basename(source.get_path())
+ # Strip suffix
+ dot_idx = source_base_name.rfind(".")
+ suffix = source_base_name[dot_idx:]
+ if suffix in env["TEST_EXECUTION_SUFFIX_BLACKLIST"]:
+ continue
+
+ source_name = source_base_name[:dot_idx]
+ if target_name == source_name:
+ continue
+
+ source_command = env.Command(
+ target="#+{}".format(source_name),
+ source=installed,
+ action="${SOURCES[0]} -fileNameFilter $TEST_SOURCE_FILE_NAME $UNITTEST_FLAGS",
+ TEST_SOURCE_FILE_NAME=source_name,
+ NINJA_POOL="console",
+ )
+
+ env.Alias("test-execution-aliases", source_command)
+
+
+def exists(env):
+ return True
+
+
+def generate(env):
+ # Wire up dependency for Ninja generator to collect the test
+ # execution aliases
+ test_execution_aliases = env.Alias("test-execution-aliases")
+ env.Alias("all", test_execution_aliases)
+ env.Alias("install-all-meta", test_execution_aliases)
+ env.AddMethod(generate_test_execution_aliases, "GenerateTestExecutionAliases")
+
+ env["TEST_EXECUTION_SUFFIX_BLACKLIST"] = env.get(
+ "TEST_EXECUTION_SUFFIX_BLACKLIST", [".in"]
+ )
+
+ # TODO: Remove when the new ninja generator is the only supported generator
+ env["_NINJA_NO_TEST_EXECUTION"] = True