1// Copyright (C) 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// The below module creates a standalone zip that end-to-end tests can depend
16// on for running the suite. This is a workaround since we can't use csuite.zip
17// which is defined in an external Makefile that Soong can't depend on.
18//
19// Besides listing jars we know the launcher script depends on which is
20// brittle, this is a hack for several reasons. First, we're listing our
21// dependencies in the tools attribute when we should be using the 'srcs'
22// attribute. Second, we're accessing jars using a path relative to a known
23// artifact location instead of using the Soong 'location' feature.
24
25package {
26    default_team: "trendy_team_app_compat",
27    default_applicable_licenses: ["Android-Apache-2.0"],
28}
29
30java_genrule_host {
31    name: "csuite_standalone_zip",
32    cmd: "ANDROID_CSUITE=$(genDir)/android-csuite && " +
33        "CSUITE_TOOLS=$${ANDROID_CSUITE}/tools && " +
34        "CSUITE_TESTCASES=$${ANDROID_CSUITE}/testcases && " +
35        "ANDROID_HOST_OUT=$$(dirname $(location :csuite-tradefed))/.. && " +
36        "rm -rf $${CSUITE_TOOLS} && mkdir -p $${CSUITE_TOOLS} && " +
37        "rm -rf $${CSUITE_TESTCASES} && mkdir -p $${CSUITE_TESTCASES} && " +
38        "cp $(location :csuite-tradefed) $${CSUITE_TOOLS} && " +
39        "cp $(location :test-utils-script) $${CSUITE_TOOLS} && " +
40        "cp $${ANDROID_HOST_OUT}/framework/csuite-tradefed.jar $${CSUITE_TOOLS} && " +
41        "cp $(location :tradefed) $${CSUITE_TOOLS} && " +
42        "cp $(location :compatibility-host-util) $${CSUITE_TOOLS} && " +
43        "cp $(location :csuite-app-launch) $${CSUITE_TESTCASES} && " +
44        // We skip copying the csuite-tradefed-tests jar since its location is
45        // not straight-forward to deduce and not really necessary.
46        "touch $${CSUITE_TOOLS}/csuite-tradefed-tests.jar && " +
47        "chmod a+x $${CSUITE_TOOLS}/csuite-tradefed && " +
48        "$(location soong_zip) -o $(out) -d -C $(genDir) -D $${ANDROID_CSUITE}",
49    out: ["testdata/csuite-standalone.zip"],
50    srcs: [
51        ":tradefed",
52        ":compatibility-host-util",
53        ":csuite-app-launch",
54    ],
55    tools: [
56        "soong_zip",
57        ":csuite-tradefed",
58        ":test-utils-script",
59    ],
60}
61
62python_library_host {
63    name: "csuite_test_utils",
64    srcs: [
65        "csuite_test_utils.py",
66    ],
67    java_data: [
68        "csuite_standalone_zip",
69    ],
70    libs: [
71        "csuite_test",
72    ],
73}
74
75python_test_host {
76    name: "csuite_cli_test",
77    srcs: [
78        "csuite_cli_test.py",
79    ],
80    test_config_template: "csuite_test_template.xml",
81    test_suites: [
82        "general-tests",
83    ],
84    libs: [
85        "csuite_test_utils",
86    ],
87    version: {
88        py3: {
89            embedded_launcher: true,
90        },
91    },
92}
93
94python_test_host {
95    name: "csuite_crash_detection_test",
96    srcs: [
97        "csuite_crash_detection_test.py",
98    ],
99    test_config_template: "csuite_test_template.xml",
100    test_suites: [
101        "general-tests",
102    ],
103    libs: [
104        "csuite_test_utils",
105        "csuite_crash_detection_test_data",
106    ],
107    test_options: {
108        unit_test: false,
109    },
110    version: {
111        py3: {
112            embedded_launcher: true,
113        },
114    },
115}
116
117// importlib.resources cannot load resources from the root package, so move the test apps
118// into a "testdata" subpackage
119python_library_host {
120    name: "csuite_crash_detection_test_data",
121    pkg_path: "testdata",
122    data: [
123        ":csuite_crash_on_launch_test_app",
124        ":csuite_no_crash_test_app",
125    ],
126    visibility: ["//visibility:private"],
127}
128