From 070e96c28007faff99bc272d40480855e7e3837a Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 17 Aug 2023 14:08:22 +0200 Subject: ["CC/test", "test"] rename implict dependency ... and document at the appropriate place --- rules/CC/test/RULES | 15 ++++++++-- rules/CC/test/runner | 69 ++++++++++++++++++++++++++++++++++++++++++++ rules/CC/test/test_runner.py | 69 -------------------------------------------- 3 files changed, 82 insertions(+), 71 deletions(-) create mode 100755 rules/CC/test/runner delete mode 100755 rules/CC/test/test_runner.py diff --git a/rules/CC/test/RULES b/rules/CC/test/RULES index 41507d7e..af413a9b 100644 --- a/rules/CC/test/RULES +++ b/rules/CC/test/RULES @@ -29,7 +29,7 @@ ] , "implicit": { "defaults": [["./", "..", "defaults"]] - , "runner": ["test_runner.py"] + , "runner": ["runner"] , "summarizer": [["./", "../../shell/test", "summarizer"]] } , "field_doc": @@ -39,7 +39,18 @@ , "Used to name the test binary as well as for staging the test result" ] , "args": ["Command line arguments for the test binary"] - , "srcs": ["The sources of the test binary"] + , "srcs": + [ "The sources of the test binary" + , "" + , "The resulting test binary in an environment where it can assume" + , "that the environment variable TEST_TMPDIR points to a" + , "director that may be used exclusively by this test." + , "" + , "This running of the test is carried out by the implicit dependency" + , "on the target \"runner\". By setting this target in the target layer" + , "of this rues repository (instead of letting it default to the" + , "respective file), the C/C++ test environment can be modified globally." + ] , "private-hdrs": [ "Any additional header files that need to be present when compiling" , "the test binary." diff --git a/rules/CC/test/runner b/rules/CC/test/runner new file mode 100755 index 00000000..0647621f --- /dev/null +++ b/rules/CC/test/runner @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# 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 json +import os +import subprocess +import time + +time_start = time.time() +time_stop = 0 +result = "UNKNOWN" +stderr = "" +stdout = "" + + +def dump_results(): + with open("result", "w") as f: + f.write("%s\n" % (result, )) + with open("time-start", "w") as f: + f.write("%d\n" % (time_start, )) + with open("time-stop", "w") as f: + f.write("%d\n" % (time_stop, )) + with open("stdout", "w") as f: + f.write("%s\n" % (stdout, )) + with open("stderr", "w") as f: + f.write("%s\n" % (stderr, )) + + +dump_results() + +TEMP_DIR = os.path.realpath("scratch") +os.makedirs(TEMP_DIR, exist_ok=True) + +WORK_DIR = os.path.realpath("work") +os.makedirs(WORK_DIR, exist_ok=True) + +ENV = dict(os.environ, TEST_TMPDIR=TEMP_DIR) + +with open('test-launcher.json') as f: + test_launcher = json.load(f) + +with open('test-args.json') as f: + test_args = json.load(f) + +ret = subprocess.run(test_launcher + ["../test"] + test_args, + cwd=WORK_DIR, + env=ENV, + capture_output=True) + +time_stop = time.time() +result = "PASS" if ret.returncode == 0 else "FAIL" +stdout = ret.stdout.decode("utf-8") +stderr = ret.stderr.decode("utf-8") + +dump_results() + +if result != "PASS": exit(1) diff --git a/rules/CC/test/test_runner.py b/rules/CC/test/test_runner.py deleted file mode 100755 index 0647621f..00000000 --- a/rules/CC/test/test_runner.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -# -# 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 json -import os -import subprocess -import time - -time_start = time.time() -time_stop = 0 -result = "UNKNOWN" -stderr = "" -stdout = "" - - -def dump_results(): - with open("result", "w") as f: - f.write("%s\n" % (result, )) - with open("time-start", "w") as f: - f.write("%d\n" % (time_start, )) - with open("time-stop", "w") as f: - f.write("%d\n" % (time_stop, )) - with open("stdout", "w") as f: - f.write("%s\n" % (stdout, )) - with open("stderr", "w") as f: - f.write("%s\n" % (stderr, )) - - -dump_results() - -TEMP_DIR = os.path.realpath("scratch") -os.makedirs(TEMP_DIR, exist_ok=True) - -WORK_DIR = os.path.realpath("work") -os.makedirs(WORK_DIR, exist_ok=True) - -ENV = dict(os.environ, TEST_TMPDIR=TEMP_DIR) - -with open('test-launcher.json') as f: - test_launcher = json.load(f) - -with open('test-args.json') as f: - test_args = json.load(f) - -ret = subprocess.run(test_launcher + ["../test"] + test_args, - cwd=WORK_DIR, - env=ENV, - capture_output=True) - -time_stop = time.time() -result = "PASS" if ret.returncode == 0 else "FAIL" -stdout = ret.stdout.decode("utf-8") -stderr = ret.stderr.decode("utf-8") - -dump_results() - -if result != "PASS": exit(1) -- cgit v1.2.3