blob: 57e760e62993832c302f1299e8a7b5e392dde2a7 [file] [log] [blame]
Weijia He32282f62024-11-05 22:21:04 +00001// Copyright 2024 Google Inc. All rights reserved.
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.
14package tradefed_modules
15
16import (
17 "android/soong/android"
18 "android/soong/java"
Weijia He0c79e262024-11-06 19:57:25 +000019 "encoding/json"
20 "slices"
Weijia He32282f62024-11-05 22:21:04 +000021 "testing"
22)
23
24func TestTestSuites(t *testing.T) {
25 t.Parallel()
Weijia Heaa37c162024-11-06 19:46:03 +000026 ctx := android.GroupFixturePreparers(
Weijia He0c79e262024-11-06 19:57:25 +000027 android.PrepareForTestWithArchMutator,
Weijia He32282f62024-11-05 22:21:04 +000028 java.PrepareForTestWithJavaDefaultModules,
29 android.FixtureRegisterWithContext(RegisterTestSuiteBuildComponents),
30 ).RunTestWithBp(t, `
31 android_test {
32 name: "TestModule1",
33 sdk_version: "current",
34 }
35
36 android_test {
37 name: "TestModule2",
38 sdk_version: "current",
39 }
40
41 test_suite {
42 name: "my-suite",
43 description: "a test suite",
44 tests: [
45 "TestModule1",
46 "TestModule2",
47 ]
48 }
49 `)
Weijia Heaa37c162024-11-06 19:46:03 +000050 manifestPath := ctx.ModuleForTests("my-suite", "").Output("out/soong/test_suites/my-suite/my-suite.json")
Weijia He0c79e262024-11-06 19:57:25 +000051 var actual testSuiteManifest
52 if err := json.Unmarshal([]byte(android.ContentFromFileRuleForTests(t, ctx.TestContext, manifestPath)), &actual); err != nil {
53 t.Errorf("failed to unmarshal manifest: %v", err)
Weijia Heaa37c162024-11-06 19:46:03 +000054 }
Weijia He0c79e262024-11-06 19:57:25 +000055 slices.Sort(actual.Files)
56
57 expected := testSuiteManifest{
58 Name: "my-suite",
59 Files: []string{
60 "target/testcases/TestModule1/TestModule1.config",
61 "target/testcases/TestModule1/arm64/TestModule1.apk",
62 "target/testcases/TestModule2/TestModule2.config",
63 "target/testcases/TestModule2/arm64/TestModule2.apk",
64 },
65 }
66
67 android.AssertDeepEquals(t, "manifests differ", expected, actual)
68}
69
70func TestTestSuitesNotInstalledInTestcases(t *testing.T) {
71 t.Parallel()
72 android.GroupFixturePreparers(
73 android.PrepareForTestWithArchMutator,
74 java.PrepareForTestWithJavaDefaultModules,
75 android.FixtureRegisterWithContext(RegisterTestSuiteBuildComponents),
76 ).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern([]string{
77 `"SomeHostTest" is not installed in testcases`,
78 })).RunTestWithBp(t, `
79 java_test_host {
80 name: "SomeHostTest",
81 srcs: ["a.java"],
82 }
83 test_suite {
84 name: "my-suite",
85 description: "a test suite",
86 tests: [
87 "SomeHostTest",
88 ]
89 }
90 `)
Weijia He32282f62024-11-05 22:21:04 +000091}