From 762286723a2b14e382e24cd1076a80721e4cb605 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 25 Feb 2019 16:40:34 -0800 Subject: [PATCH] Add dexpreopt_bootjars_test.go Add a test that exercises the dexpreopt_bootjars.go singleton. Test: dexpreopt_bootjars_test.go Change-Id: I01d4f6e22f6ff7b809af043391d7b6209dcb8675 --- Android.bp | 1 + java/dexpreopt_bootjars_test.go | 103 ++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 java/dexpreopt_bootjars_test.go diff --git a/Android.bp b/Android.bp index 4d7304901..0f9c2ef0a 100644 --- a/Android.bp +++ b/Android.bp @@ -276,6 +276,7 @@ bootstrap_go_package { testSrcs: [ "java/app_test.go", "java/dexpreopt_test.go", + "java/dexpreopt_bootjars_test.go", "java/java_test.go", "java/jdeps_test.go", "java/kotlin_test.go", diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go new file mode 100644 index 000000000..c99540da8 --- /dev/null +++ b/java/dexpreopt_bootjars_test.go @@ -0,0 +1,103 @@ +// Copyright 2019 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "path/filepath" + "reflect" + "sort" + "testing" + + "android/soong/android" + "android/soong/dexpreopt" +) + +func TestDexpreoptBootJars(t *testing.T) { + bp := ` + java_sdk_library { + name: "foo", + srcs: ["a.java"], + api_packages: ["foo"], + } + + java_library { + name: "bar", + srcs: ["b.java"], + installable: true, + } + ` + + config := testConfig(nil) + + pathCtx := android.PathContextForTesting(config, nil) + dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) + dexpreoptConfig.RuntimeApexJars = []string{"foo", "bar"} + setDexpreoptTestGlobalConfig(config, dexpreoptConfig) + + ctx := testContext(config, bp, nil) + + ctx.RegisterSingletonType("dex_bootjars", android.SingletonFactoryAdaptor(dexpreoptBootJarsFactory)) + + run(t, ctx, config) + + dexpreoptBootJars := ctx.SingletonForTests("dex_bootjars") + + bootArt := dexpreoptBootJars.Output("boot.art") + + expectedInputs := []string{ + "dex_bootjars_input/foo.jar", + "dex_bootjars_input/bar.jar", + } + + for i := range expectedInputs { + expectedInputs[i] = filepath.Join(buildDir, "test_device", expectedInputs[i]) + } + + inputs := bootArt.Implicits.Strings() + sort.Strings(inputs) + sort.Strings(expectedInputs) + + if !reflect.DeepEqual(inputs, expectedInputs) { + t.Errorf("want inputs %q\n got inputs %q", expectedInputs, inputs) + } + + expectedOutputs := []string{ + "dex_bootjars/system/framework/arm64/boot.invocation", + + "dex_bootjars/system/framework/arm64/boot.art", + "dex_bootjars/system/framework/arm64/boot-bar.art", + + "dex_bootjars/system/framework/arm64/boot.oat", + "dex_bootjars/system/framework/arm64/boot-bar.oat", + + "dex_bootjars/system/framework/arm64/boot.vdex", + "dex_bootjars/system/framework/arm64/boot-bar.vdex", + + "dex_bootjars_unstripped/system/framework/arm64/boot.oat", + "dex_bootjars_unstripped/system/framework/arm64/boot-bar.oat", + } + + for i := range expectedOutputs { + expectedOutputs[i] = filepath.Join(buildDir, "test_device", expectedOutputs[i]) + } + + outputs := bootArt.Outputs.Strings() + sort.Strings(outputs) + sort.Strings(expectedOutputs) + + if !reflect.DeepEqual(outputs, expectedOutputs) { + t.Errorf("want outputs %q\n got outputs %q", expectedOutputs, outputs) + } +}