aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross2019-05-14 17:44:26 -0500
committerColin Cross2019-05-17 10:43:36 -0500
commit9a94287fc95617e2541bf5ac7c2c42a2c3adcaa0 (patch)
tree83994f09a4867ff3105121f466032d7348b33a4e
parent33b2fb73335547e39bdad764af249f948eb43935 (diff)
downloadplatform-build-soong-9a94287fc95617e2541bf5ac7c2c42a2c3adcaa0.tar.gz
platform-build-soong-9a94287fc95617e2541bf5ac7c2c42a2c3adcaa0.tar.xz
platform-build-soong-9a94287fc95617e2541bf5ac7c2c42a2c3adcaa0.zip
Move CreateTestContext to cc/testing.go
Allow CreateTestContext to be called by tests in other packages that need cc modules. Test: all soong tests Change-Id: I6be04dec50632baa8cb51e55ba14d0ddc0df60b8
-rw-r--r--cc/cc_test.go55
-rw-r--r--cc/prebuilt_test.go2
-rw-r--r--cc/testing.go51
3 files changed, 54 insertions, 54 deletions
diff --git a/cc/cc_test.go b/cc/cc_test.go
index ef6364b5..f5bb12c8 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -52,64 +52,13 @@ func TestMain(m *testing.M) {
52 os.Exit(run()) 52 os.Exit(run())
53} 53}
54 54
55func createTestContext(t *testing.T, config android.Config, bp string, fs map[string][]byte,
56 os android.OsType) *android.TestContext {
57
58 ctx := android.NewTestArchContext()
59 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
60 ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory))
61 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
62 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
63 ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(LibraryStaticFactory))
64 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
65 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory))
66 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory))
67 ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory))
68 ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory))
69 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory))
70 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
71 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
72 ctx.BottomUp("image", ImageMutator).Parallel()
73 ctx.BottomUp("link", LinkageMutator).Parallel()
74 ctx.BottomUp("vndk", VndkMutator).Parallel()
75 ctx.BottomUp("version", VersionMutator).Parallel()
76 ctx.BottomUp("begin", BeginMutator).Parallel()
77 })
78 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
80 })
81 ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton))
82
83 // add some modules that are required by the compiler and/or linker
84 bp = bp + GatherRequiredDepsForTest(os)
85
86 mockFS := map[string][]byte{
87 "Android.bp": []byte(bp),
88 "foo.c": nil,
89 "bar.c": nil,
90 "a.proto": nil,
91 "b.aidl": nil,
92 "my_include": nil,
93 "foo.map.txt": nil,
94 "liba.so": nil,
95 }
96
97 for k, v := range fs {
98 mockFS[k] = v
99 }
100
101 ctx.MockFileSystem(mockFS)
102
103 return ctx
104}
105
106func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext { 55func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
107 return testCcWithConfigForOs(t, bp, config, android.Android) 56 return testCcWithConfigForOs(t, bp, config, android.Android)
108} 57}
109 58
110func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext { 59func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext {
111 t.Helper() 60 t.Helper()
112 ctx := createTestContext(t, config, bp, nil, os) 61 ctx := CreateTestContext(bp, nil, os)
113 ctx.Register() 62 ctx.Register()
114 63
115 _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) 64 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
@@ -143,7 +92,7 @@ func testCcError(t *testing.T, pattern string, bp string) {
143 config.TestProductVariables.DeviceVndkVersion = StringPtr("current") 92 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
144 config.TestProductVariables.Platform_vndk_version = StringPtr("VER") 93 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
145 94
146 ctx := createTestContext(t, config, bp, nil, android.Android) 95 ctx := CreateTestContext(bp, nil, android.Android)
147 ctx.Register() 96 ctx.Register()
148 97
149 _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) 98 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index 7cc26514..98d78e81 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -70,7 +70,7 @@ func TestPrebuilt(t *testing.T) {
70 70
71 config := android.TestArchConfig(buildDir, nil) 71 config := android.TestArchConfig(buildDir, nil)
72 72
73 ctx := createTestContext(t, config, bp, fs, android.Android) 73 ctx := CreateTestContext(bp, fs, android.Android)
74 74
75 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory)) 75 ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(prebuiltSharedLibraryFactory))
76 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory)) 76 ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(prebuiltStaticLibraryFactory))
diff --git a/cc/testing.go b/cc/testing.go
index 8d76c2f5..162a7460 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -183,3 +183,54 @@ func GatherRequiredDepsForTest(os android.OsType) string {
183 } 183 }
184 return ret 184 return ret
185} 185}
186
187func CreateTestContext(bp string, fs map[string][]byte,
188 os android.OsType) *android.TestContext {
189
190 ctx := android.NewTestArchContext()
191 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
192 ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory))
193 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
194 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
195 ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(LibraryStaticFactory))
196 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
197 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory))
198 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory))
199 ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory))
200 ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory))
201 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory))
202 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
203 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
204 ctx.BottomUp("image", ImageMutator).Parallel()
205 ctx.BottomUp("link", LinkageMutator).Parallel()
206 ctx.BottomUp("vndk", VndkMutator).Parallel()
207 ctx.BottomUp("version", VersionMutator).Parallel()
208 ctx.BottomUp("begin", BeginMutator).Parallel()
209 })
210 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
211 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
212 })
213 ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton))
214
215 // add some modules that are required by the compiler and/or linker
216 bp = bp + GatherRequiredDepsForTest(os)
217
218 mockFS := map[string][]byte{
219 "Android.bp": []byte(bp),
220 "foo.c": nil,
221 "bar.c": nil,
222 "a.proto": nil,
223 "b.aidl": nil,
224 "my_include": nil,
225 "foo.map.txt": nil,
226 "liba.so": nil,
227 }
228
229 for k, v := range fs {
230 mockFS[k] = v
231 }
232
233 ctx.MockFileSystem(mockFS)
234
235 return ctx
236}