Update CoreClr, CoreFx, CoreSetup to preview-27213-02, preview.18613.4, preview-27213...
[platform/upstream/coreclr.git] / tests / runtest_helix.py
1 #!/usr/bin/env python
2
3 # This script runs tests in helix. It defines a set of test scenarios
4 # that enable various combinations of runtime configurations to be set
5 # via the test process environment.
6
7 # This script calls "corerun xunit.console.dll xunitwrapper.dll",
8 # where the xunitwrapper.dll will run a .sh/.cmd script per test in a
9 # separate process. This process will have the scenario environment
10 # variables set, but the xunit process will not.
11
12 # TODO: Factor out logic common with runtest.py
13
14 import argparse
15 import subprocess
16 import os
17 import sys
18 import tempfile
19
20 test_scenarios = {
21     "jitstress2": { "COMPlus_TieredCompilation": "0",
22                     "COMPlus_JitStress": "2" },
23 }
24
25 if sys.platform.startswith('linux') or sys.platform == "darwin":
26     platform_type = "unix"
27 elif sys.platform == "win32":
28     platform_type = "windows"
29 else:
30     print("unknown os: %s" % sys.platform)
31     sys.exit(1)
32
33 def get_testenv_script(env_dict):
34     if platform_type == "unix":
35         return ''.join([ "export %s=%s%s" % (k, v, os.linesep) for k, v in env_dict.items() ])
36     elif platform_type == "windows":
37         return ''.join([ "set %s=%s%s" % (k, v, os.linesep) for k, v in env_dict.items() ])
38
39 if __name__ == "__main__":
40     parser = argparse.ArgumentParser(description="Parse arguments")
41     parser.add_argument("-scenario", dest="scenario", default=None)
42     parser.add_argument("-wrapper", dest="wrapper", default=None, required=True)
43     args = parser.parse_args()
44     scenario = args.scenario
45     wrapper = args.wrapper
46
47     if not "HELIX_CORRELATION_PAYLOAD" in os.environ:
48         print("HELIX_CORRELATION_PAYLOAD must be defined in environment")
49         sys.exit(1)
50
51     if not "HELIX_WORKITEM_PAYLOAD" in os.environ:
52         print("HELIX_WORKITEM_PAYLOAD must be defined in environment")
53         sys.exit(1)
54
55     core_root = os.environ["HELIX_CORRELATION_PAYLOAD"]
56
57     if platform_type == "unix":
58         corerun = os.path.join(core_root, "corerun")
59     else:
60         corerun = os.path.join(core_root, "corerun.exe")
61
62     # Unlike the old test wrapper, this runs xunit.console.dll from
63     # the correlation payload. This removes the need for redundant
64     # copies of the console runner in each test directory.
65     command = [corerun,
66                os.path.join(os.environ["HELIX_CORRELATION_PAYLOAD"], "xunit.console.dll"),
67                os.path.join(os.environ["HELIX_WORKITEM_PAYLOAD"], wrapper),
68                "-noshadow",
69                "-xml", "testResults.xml",
70                "-notrait", "category=outerloop",
71                "-notrait", "category=failing"]
72
73     if scenario is None:
74         print("CORE_ROOT=%s" % core_root)
75         os.environ["CORE_ROOT"] = core_root
76
77         print("BEGIN EXECUTION")
78         print(' '.join(command))
79         proc = subprocess.Popen(command)
80         proc.communicate()
81         print("Finished running tests. Exit code = %d" % proc.returncode)
82         sys.exit(proc.returncode)
83     else:
84         print("scenario: %s" % scenario)
85         with tempfile.NamedTemporaryFile(mode="w") as testenv:
86             testenv.write(get_testenv_script(test_scenarios[scenario]))
87             testenv.flush()
88
89             print("__TestEnv=%s" % testenv.name)
90             os.environ["__TestEnv"] = testenv.name
91
92             with open(testenv.name) as testenv_written:
93                 contents = testenv_written.read()
94                 print(contents)
95
96             print("CORE_ROOT=%s" % core_root)
97             os.environ["CORE_ROOT"] = core_root
98
99             print("BEGIN EXECUTION")
100             print(' '.join(command))
101             proc = subprocess.Popen(command)
102             proc.communicate()
103             print("Finished running tests. Exit code = %d" % proc.returncode)
104             sys.exit(proc.returncode)