Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +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 | |
| 15 | package fsgen |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/filesystem" |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 20 | "android/soong/java" |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 21 | "testing" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
| 26 | var prepareForTestWithFsgenBuildComponents = android.FixtureRegisterWithContext(registerBuildComponents) |
| 27 | |
| 28 | func TestFileSystemCreatorSystemImageProps(t *testing.T) { |
| 29 | result := android.GroupFixturePreparers( |
| 30 | android.PrepareForIntegrationTestWithAndroid, |
| 31 | android.PrepareForTestWithAndroidBuildComponents, |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 32 | android.PrepareForTestWithAllowMissingDependencies, |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 33 | filesystem.PrepareForTestWithFilesystemBuildComponents, |
| 34 | prepareForTestWithFsgenBuildComponents, |
| 35 | android.FixtureModifyConfig(func(config android.Config) { |
| 36 | config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.BoardAvbEnable = true |
| 37 | config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.PartitionQualifiedVariables = |
| 38 | map[string]android.PartitionQualifiedVariablesType{ |
| 39 | "system": { |
| 40 | BoardAvbKeyPath: "external/avb/test/data/testkey_rsa4096.pem", |
| 41 | BoardAvbAlgorithm: "SHA256_RSA4096", |
| 42 | BoardAvbRollbackIndex: "0", |
| 43 | BoardFileSystemType: "ext4", |
| 44 | }, |
| 45 | } |
| 46 | }), |
| 47 | android.FixtureMergeMockFs(android.MockFS{ |
| 48 | "external/avb/test/data/testkey_rsa4096.pem": nil, |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 49 | "build/soong/fsgen/Android.bp": []byte(` |
| 50 | soong_filesystem_creator { |
| 51 | name: "foo", |
| 52 | } |
| 53 | `), |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 54 | }), |
Cole Faust | 92ccbe2 | 2024-10-03 14:38:37 -0700 | [diff] [blame] | 55 | ).RunTest(t) |
Jihoon Kang | 98047cf | 2024-10-02 17:13:54 +0000 | [diff] [blame] | 56 | |
| 57 | fooSystem := result.ModuleForTests("test_product_generated_system_image", "android_common").Module().(interface { |
| 58 | FsProps() filesystem.FilesystemProperties |
| 59 | }) |
| 60 | android.AssertBoolEquals( |
| 61 | t, |
| 62 | "Property expected to match the product variable 'BOARD_AVB_ENABLE'", |
| 63 | true, |
| 64 | proptools.Bool(fooSystem.FsProps().Use_avb), |
| 65 | ) |
| 66 | android.AssertStringEquals( |
| 67 | t, |
| 68 | "Property expected to match the product variable 'BOARD_AVB_KEY_PATH'", |
| 69 | "external/avb/test/data/testkey_rsa4096.pem", |
| 70 | proptools.String(fooSystem.FsProps().Avb_private_key), |
| 71 | ) |
| 72 | android.AssertStringEquals( |
| 73 | t, |
| 74 | "Property expected to match the product variable 'BOARD_AVB_ALGORITHM'", |
| 75 | "SHA256_RSA4096", |
| 76 | proptools.String(fooSystem.FsProps().Avb_algorithm), |
| 77 | ) |
| 78 | android.AssertIntEquals( |
| 79 | t, |
| 80 | "Property expected to match the product variable 'BOARD_AVB_SYSTEM_ROLLBACK_INDEX'", |
| 81 | 0, |
| 82 | proptools.Int(fooSystem.FsProps().Rollback_index), |
| 83 | ) |
| 84 | android.AssertStringEquals( |
| 85 | t, |
| 86 | "Property expected to match the product variable 'BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE'", |
| 87 | "ext4", |
| 88 | proptools.String(fooSystem.FsProps().Type), |
| 89 | ) |
| 90 | } |
Jihoon Kang | 0d545b8 | 2024-10-11 00:21:57 +0000 | [diff] [blame] | 91 | |
| 92 | func TestFileSystemCreatorSetPartitionDeps(t *testing.T) { |
| 93 | result := android.GroupFixturePreparers( |
| 94 | android.PrepareForIntegrationTestWithAndroid, |
| 95 | android.PrepareForTestWithAndroidBuildComponents, |
| 96 | android.PrepareForTestWithAllowMissingDependencies, |
| 97 | filesystem.PrepareForTestWithFilesystemBuildComponents, |
| 98 | prepareForTestWithFsgenBuildComponents, |
| 99 | java.PrepareForTestWithJavaBuildComponents, |
| 100 | java.PrepareForTestWithJavaDefaultModules, |
| 101 | android.FixtureModifyConfig(func(config android.Config) { |
| 102 | config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.ProductPackages = []string{"bar", "baz"} |
| 103 | config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.PartitionQualifiedVariables = |
| 104 | map[string]android.PartitionQualifiedVariablesType{ |
| 105 | "system": { |
| 106 | BoardFileSystemType: "ext4", |
| 107 | }, |
| 108 | } |
| 109 | }), |
| 110 | android.FixtureMergeMockFs(android.MockFS{ |
| 111 | "external/avb/test/data/testkey_rsa4096.pem": nil, |
| 112 | "build/soong/fsgen/Android.bp": []byte(` |
| 113 | soong_filesystem_creator { |
| 114 | name: "foo", |
| 115 | } |
| 116 | `), |
| 117 | }), |
| 118 | ).RunTestWithBp(t, ` |
| 119 | java_library { |
| 120 | name: "bar", |
| 121 | srcs: ["A.java"], |
| 122 | } |
| 123 | java_library { |
| 124 | name: "baz", |
| 125 | srcs: ["A.java"], |
| 126 | product_specific: true, |
| 127 | } |
| 128 | `) |
| 129 | |
| 130 | android.AssertBoolEquals( |
| 131 | t, |
| 132 | "Generated system image expected to depend on system partition installed \"bar\"", |
| 133 | true, |
| 134 | java.CheckModuleHasDependency(t, result.TestContext, "test_product_generated_system_image", "android_common", "bar"), |
| 135 | ) |
| 136 | android.AssertBoolEquals( |
| 137 | t, |
| 138 | "Generated system image expected to not depend on product partition installed \"baz\"", |
| 139 | false, |
| 140 | java.CheckModuleHasDependency(t, result.TestContext, "test_product_generated_system_image", "android_common", "baz"), |
| 141 | ) |
| 142 | } |
| 143 | |
| 144 | func TestFileSystemCreatorDepsWithNamespace(t *testing.T) { |
| 145 | result := android.GroupFixturePreparers( |
| 146 | android.PrepareForIntegrationTestWithAndroid, |
| 147 | android.PrepareForTestWithAndroidBuildComponents, |
| 148 | android.PrepareForTestWithAllowMissingDependencies, |
| 149 | android.PrepareForTestWithNamespace, |
| 150 | android.PrepareForTestWithArchMutator, |
| 151 | filesystem.PrepareForTestWithFilesystemBuildComponents, |
| 152 | prepareForTestWithFsgenBuildComponents, |
| 153 | java.PrepareForTestWithJavaBuildComponents, |
| 154 | java.PrepareForTestWithJavaDefaultModules, |
| 155 | android.FixtureModifyConfig(func(config android.Config) { |
| 156 | config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.ProductPackages = []string{"bar"} |
| 157 | config.TestProductVariables.NamespacesToExport = []string{"a/b"} |
| 158 | config.TestProductVariables.PartitionVarsForSoongMigrationOnlyDoNotUse.PartitionQualifiedVariables = |
| 159 | map[string]android.PartitionQualifiedVariablesType{ |
| 160 | "system": { |
| 161 | BoardFileSystemType: "ext4", |
| 162 | }, |
| 163 | } |
| 164 | config.Targets[android.Android] = []android.Target{ |
| 165 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: "", HostCross: false}, |
| 166 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: "", HostCross: false}, |
| 167 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64", HostCross: false}, |
| 168 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm", HostCross: false}, |
| 169 | } |
| 170 | }), |
| 171 | android.FixtureMergeMockFs(android.MockFS{ |
| 172 | "external/avb/test/data/testkey_rsa4096.pem": nil, |
| 173 | "build/soong/fsgen/Android.bp": []byte(` |
| 174 | soong_filesystem_creator { |
| 175 | name: "foo", |
| 176 | } |
| 177 | `), |
| 178 | "a/b/Android.bp": []byte(` |
| 179 | soong_namespace{ |
| 180 | } |
| 181 | java_library { |
| 182 | name: "bar", |
| 183 | srcs: ["A.java"], |
| 184 | compile_multilib: "64", |
| 185 | } |
| 186 | `), |
| 187 | "c/d/Android.bp": []byte(` |
| 188 | soong_namespace{ |
| 189 | } |
| 190 | java_library { |
| 191 | name: "bar", |
| 192 | srcs: ["A.java"], |
| 193 | } |
| 194 | `), |
| 195 | }), |
| 196 | ).RunTest(t) |
| 197 | |
| 198 | var packagingProps android.PackagingProperties |
| 199 | for _, prop := range result.ModuleForTests("test_product_generated_system_image", "android_common").Module().GetProperties() { |
| 200 | if packagingPropStruct, ok := prop.(*android.PackagingProperties); ok { |
| 201 | packagingProps = *packagingPropStruct |
| 202 | } |
| 203 | } |
| 204 | moduleDeps := packagingProps.Multilib.Lib64.Deps |
| 205 | |
| 206 | eval := result.ModuleForTests("test_product_generated_system_image", "android_common").Module().ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext)) |
| 207 | android.AssertStringListContains( |
| 208 | t, |
| 209 | "Generated system image expected to depend on \"bar\" defined in \"a/b\" namespace", |
| 210 | moduleDeps.GetOrDefault(eval, nil), |
| 211 | "//a/b:bar", |
| 212 | ) |
| 213 | android.AssertStringListDoesNotContain( |
| 214 | t, |
| 215 | "Generated system image expected to not depend on \"bar\" defined in \"c/d\" namespace", |
| 216 | moduleDeps.GetOrDefault(eval, nil), |
| 217 | "//c/d:bar", |
| 218 | ) |
| 219 | } |