| Weijia He | 32282f6 | 2024-11-05 22:21:04 +0000 | [diff] [blame] | 1 | // 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. |
| 14 | package tradefed_modules |
| 15 | |
| 16 | import ( |
| 17 | "android/soong/android" |
| 18 | "android/soong/java" |
| Weijia He | 0c79e26 | 2024-11-06 19:57:25 +0000 | [diff] [blame^] | 19 | "encoding/json" |
| 20 | "slices" |
| Weijia He | 32282f6 | 2024-11-05 22:21:04 +0000 | [diff] [blame] | 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | func TestTestSuites(t *testing.T) { |
| 25 | t.Parallel() |
| Weijia He | aa37c16 | 2024-11-06 19:46:03 +0000 | [diff] [blame] | 26 | ctx := android.GroupFixturePreparers( |
| Weijia He | 0c79e26 | 2024-11-06 19:57:25 +0000 | [diff] [blame^] | 27 | android.PrepareForTestWithArchMutator, |
| Weijia He | 32282f6 | 2024-11-05 22:21:04 +0000 | [diff] [blame] | 28 | 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 He | aa37c16 | 2024-11-06 19:46:03 +0000 | [diff] [blame] | 50 | manifestPath := ctx.ModuleForTests("my-suite", "").Output("out/soong/test_suites/my-suite/my-suite.json") |
| Weijia He | 0c79e26 | 2024-11-06 19:57:25 +0000 | [diff] [blame^] | 51 | 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 He | aa37c16 | 2024-11-06 19:46:03 +0000 | [diff] [blame] | 54 | } |
| Weijia He | 0c79e26 | 2024-11-06 19:57:25 +0000 | [diff] [blame^] | 55 | 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 | |
| 70 | func 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 He | 32282f6 | 2024-11-05 22:21:04 +0000 | [diff] [blame] | 91 | } |