xref: /aosp_15_r20/external/aws-crt-java/.builder/actions/aws_crt_java_test.py (revision 3c7ae9de214676c52d19f01067dc1a404272dc11)
1import Builder
2import sys
3import os
4import os.path
5
6
7class AWSCrtJavaTest(Builder.Action):
8
9    def _run_java_tests(self, *extra_args):
10        if os.path.exists('log.txt'):
11            os.remove('log.txt')
12
13        profiles = 'continuous-integration'
14
15        cmd_args = [
16            "mvn", "-B",
17            "-P", profiles,
18            "-DredirectTestOutputToFile=true",
19            "-DreuseForks=false",
20            "-Daws.crt.memory.tracing=2",
21            "-Daws.crt.debugnative=true",
22            "-Daws.crt.aws_trace_log_per_test",
23            "-Daws.crt.ci=true",
24        ]
25        cmd_args.extend(extra_args)
26        cmd_args.append("test")
27
28        result = self.env.shell.exec(*cmd_args, check=False)
29        if result.returncode:
30            if os.path.exists('log.txt'):
31                print("--- CRT logs from failing test ---")
32                with open('log.txt', 'r') as log:
33                    print(log.read())
34                print("----------------------------------")
35            sys.exit(f"Tests failed")
36
37    def start_maven_tests(self, env):
38        # tests must run with leak detection turned on
39        env.shell.setenv('AWS_CRT_MEMORY_TRACING', '2')
40
41        self._run_java_tests("-DrerunFailingTestsCount=5")
42
43        # run the ShutdownTest by itself
44        env.shell.setenv('AWS_CRT_SHUTDOWN_TESTING', '1')
45        self._run_java_tests("-Dtest=ShutdownTest")
46
47        # run the InitTest by itself.  This creates an environment where the test itself is the one that
48        # causes the CRT to be loaded and initialized.
49        self._run_java_tests("-Dtest=InitTest")
50
51        # run the elasticurl integration tests
52        python = sys.executable
53        env.shell.exec(python, 'crt/aws-c-http/integration-testing/http_client_test.py',
54                       python, 'integration-testing/java_elasticurl_runner.py', check=True)
55
56    def run(self, env):
57        self.env = env
58
59        return Builder.Script([
60            Builder.SetupCrossCICrtEnvironment(),
61            self.start_maven_tests  # Then run the Maven stuff
62        ])
63