Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8eb4573b authored by Paul Duffin's avatar Paul Duffin
Browse files

Test bootImageConfig/Variant fields

Most of the fields in the bootImageConfig/Variant structs are assigned
inside a Once func so are guaranteed to be only set once. However, some
are assigned outside. This change adds comprehensive tests for those
structs and verifies that the constant fields are preserved and the
mutated fields have the correct value.

The check for the constant fields is added in a new TestBootImageConfig
test.

The check for the mutated fields is added into
TestSnapshotWithBootclasspathFragment_ImageName as that test checks an
art bootclasspath_fragment in the following configurations:
* source on its own
* prebuilt on its own
* source and prebuilt with source preferred
* source and prebuilt with prebuilt

It reveals a couple of interesting facts:
* All the *installs fields are set to the same value irrespective of
  whether the source or prebuilt is preferred. The information is
  constructed solely from information already within the
  bootImageConfig/Variant and so can be moved within Once.

* The licenseMetadataFile is incorrect when prebuilt is preferred.
  That is due to both the source and prebuilt modules setting it and
  the source module always wins as the source module depends on the
  prebuilt so always runs its GenerateAndroidBuildActions after it.

Those issues will be cleaned up in following changes.

Bug: 245956352
Test: m nothing
Change-Id: If917cfbcb3b1c842a8682d51cc1ee1fed1c51add
parent 74135582
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ func makeVarsSingletonFunc() Singleton {
}

type makeVarsSingleton struct {
	varsForTesting     []makeVarsVariable
	installsForTesting []byte
}

@@ -320,8 +321,12 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
		ctx.Errorf(err.Error())
	}

	// Only save state for tests when testing.
	if ctx.Config().RunningInsideUnitTest() {
		s.varsForTesting = vars
		s.installsForTesting = installsBytes
	}
}

func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
	buf := &bytes.Buffer{}
+40 −0
Original line number Diff line number Diff line
@@ -673,6 +673,46 @@ func (ctx *TestContext) InstallMakeRulesForTesting(t *testing.T) []InstallMakeRu
	return parseMkRules(t, ctx.config, nodes)
}

// MakeVarVariable provides access to make vars that will be written by the makeVarsSingleton
type MakeVarVariable interface {
	// Name is the name of the variable.
	Name() string

	// Value is the value of the variable.
	Value() string
}

func (v makeVarsVariable) Name() string {
	return v.name
}

func (v makeVarsVariable) Value() string {
	return v.value
}

// PrepareForTestAccessingMakeVars sets up the test so that MakeVarsForTesting will work.
var PrepareForTestAccessingMakeVars = GroupFixturePreparers(
	PrepareForTestWithAndroidMk,
	PrepareForTestWithMakevars,
)

// MakeVarsForTesting returns a filtered list of MakeVarVariable objects that represent the
// variables that will be written out.
//
// It is necessary to use PrepareForTestAccessingMakeVars in tests that want to call this function.
// Along with any other preparers needed to add the make vars.
func (ctx *TestContext) MakeVarsForTesting(filter func(variable MakeVarVariable) bool) []MakeVarVariable {
	vars := ctx.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).varsForTesting
	result := make([]MakeVarVariable, 0, len(vars))
	for _, v := range vars {
		if filter(v) {
			result = append(result, v)
		}
	}

	return result
}

func (ctx *TestContext) Config() Config {
	return ctx.config
}
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ bootstrap_go_package {
        "dexpreopt_bootjars.go",
        "dexpreopt_check.go",
        "dexpreopt_config.go",
        "dexpreopt_config_testing.go",
        "droiddoc.go",
        "droidstubs.go",
        "fuzz.go",
@@ -87,6 +88,7 @@ bootstrap_go_package {
        "dex_test.go",
        "dexpreopt_test.go",
        "dexpreopt_bootjars_test.go",
        "dexpreopt_config_test.go",
        "droiddoc_test.go",
        "droidstubs_test.go",
        "genrule_test.go",
+30 −0
Original line number Diff line number Diff line
// Copyright 2022 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 (
	"testing"

	"android/soong/android"
)

func TestBootImageConfig(t *testing.T) {
	result := android.GroupFixturePreparers(
		PrepareForBootImageConfigTest,
	).RunTest(t)

	CheckArtBootImageConfig(t, result)
	CheckFrameworkBootImageConfig(t, result)
}
+768 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading