diff options
author | 2023-02-10 01:51:53 +0800 | |
---|---|---|
committer | 2023-02-10 23:13:41 +0800 | |
commit | ebf48bf1e29bd07ac2aa5bafdc122a88c2035e22 (patch) | |
tree | 10bfa2f9426f1278896824fb46ea71260bb5af58 /apex/apex_test.go | |
parent | db15f9bab76fe2d3eb5fb40897ee3ad99038cc75 (diff) |
Properly check the deapexed files in tests.
The tests in bootclasspath_fragment_test setup the environment to have
two APEXes: a source one and a prebuilt one. Before this change, the
tests for prebuilt incorrectly check the contents in the source one.
This change introduces a new function that properly checks files
deapexed from the prebuilt one.
Bug: 241823638
Test: m nothing
Change-Id: I1865c20b198d50e7ebc8ebfb9f7c71394a225ab7
Diffstat (limited to 'apex/apex_test.go')
-rw-r--r-- | apex/apex_test.go | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/apex/apex_test.go b/apex/apex_test.go index e558fee03..ebb7c37dc 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -3484,14 +3484,14 @@ func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string return ret } -func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { +func assertFileListEquals(t *testing.T, expectedFiles []string, actualFiles []fileInApex) { t.Helper() var failed bool var surplus []string filesMatched := make(map[string]bool) - for _, file := range getFiles(t, ctx, moduleName, variant) { + for _, file := range actualFiles { matchFound := false - for _, expected := range files { + for _, expected := range expectedFiles { if file.match(expected) { matchFound = true filesMatched[expected] = true @@ -3509,9 +3509,9 @@ func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, var failed = true } - if len(files) > len(filesMatched) { + if len(expectedFiles) > len(filesMatched) { var missing []string - for _, expected := range files { + for _, expected := range expectedFiles { if !filesMatched[expected] { missing = append(missing, expected) } @@ -3525,6 +3525,32 @@ func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, var } } +func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { + assertFileListEquals(t, files, getFiles(t, ctx, moduleName, variant)) +} + +func ensureExactDeapexedContents(t *testing.T, ctx *android.TestContext, moduleName string, variant string, files []string) { + deapexer := ctx.ModuleForTests(moduleName+".deapexer", variant).Rule("deapexer") + outputs := make([]string, 0, len(deapexer.ImplicitOutputs)+1) + if deapexer.Output != nil { + outputs = append(outputs, deapexer.Output.String()) + } + for _, output := range deapexer.ImplicitOutputs { + outputs = append(outputs, output.String()) + } + actualFiles := make([]fileInApex, 0, len(outputs)) + for _, output := range outputs { + dir := "/deapexer/" + pos := strings.LastIndex(output, dir) + if pos == -1 { + t.Fatal("Unknown deapexer output ", output) + } + path := output[pos+len(dir):] + actualFiles = append(actualFiles, fileInApex{path: path, src: "", isLink: false}) + } + assertFileListEquals(t, files, actualFiles) +} + func TestVndkApexCurrent(t *testing.T) { commonFiles := []string{ "lib/libc++.so", |