Merge "Convert TestApexPermittedPackagesRules to use test fixtures"
This commit is contained in:
@@ -202,7 +202,7 @@ var postDeps = []RegisterMutatorFunc{
|
|||||||
RegisterPrebuiltsPostDepsMutators,
|
RegisterPrebuiltsPostDepsMutators,
|
||||||
RegisterVisibilityRuleEnforcer,
|
RegisterVisibilityRuleEnforcer,
|
||||||
RegisterLicensesDependencyChecker,
|
RegisterLicensesDependencyChecker,
|
||||||
RegisterNeverallowMutator,
|
registerNeverallowMutator,
|
||||||
RegisterOverridePostDepsMutators,
|
RegisterOverridePostDepsMutators,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ import (
|
|||||||
// counts as a match
|
// counts as a match
|
||||||
// - it has none of the "Without" properties matched (same rules as above)
|
// - it has none of the "Without" properties matched (same rules as above)
|
||||||
|
|
||||||
func RegisterNeverallowMutator(ctx RegisterMutatorsContext) {
|
func registerNeverallowMutator(ctx RegisterMutatorsContext) {
|
||||||
ctx.BottomUp("neverallow", neverallowMutator).Parallel()
|
ctx.BottomUp("neverallow", neverallowMutator).Parallel()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,6 +661,22 @@ func neverallowRules(config Config) []Rule {
|
|||||||
// Overrides the default neverallow rules for the supplied config.
|
// Overrides the default neverallow rules for the supplied config.
|
||||||
//
|
//
|
||||||
// For testing only.
|
// For testing only.
|
||||||
func SetTestNeverallowRules(config Config, testRules []Rule) {
|
func setTestNeverallowRules(config Config, testRules []Rule) {
|
||||||
config.Once(neverallowRulesKey, func() interface{} { return testRules })
|
config.Once(neverallowRulesKey, func() interface{} { return testRules })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepares for a test by setting neverallow rules and enabling the mutator.
|
||||||
|
//
|
||||||
|
// If the supplied rules are nil then the default rules are used.
|
||||||
|
func PrepareForTestWithNeverallowRules(testRules []Rule) FixturePreparer {
|
||||||
|
return GroupFixturePreparers(
|
||||||
|
FixtureModifyConfig(func(config Config) {
|
||||||
|
if testRules != nil {
|
||||||
|
setTestNeverallowRules(config, testRules)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
|
ctx.PostDepsMutators(registerNeverallowMutator)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@@ -292,7 +292,6 @@ var prepareForNeverAllowTest = GroupFixturePreparers(
|
|||||||
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
|
ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule)
|
||||||
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
|
ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule)
|
||||||
ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
|
ctx.RegisterModuleType("makefile_goal", newMockMakefileGoalModule)
|
||||||
ctx.PostDepsMutators(RegisterNeverallowMutator)
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -301,12 +300,7 @@ func TestNeverallow(t *testing.T) {
|
|||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
GroupFixturePreparers(
|
GroupFixturePreparers(
|
||||||
prepareForNeverAllowTest,
|
prepareForNeverAllowTest,
|
||||||
FixtureModifyConfig(func(config Config) {
|
PrepareForTestWithNeverallowRules(test.rules),
|
||||||
// If the test has its own rules then use them instead of the default ones.
|
|
||||||
if test.rules != nil {
|
|
||||||
SetTestNeverallowRules(config, test.rules)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
test.fs.AddToFixture(),
|
test.fs.AddToFixture(),
|
||||||
).
|
).
|
||||||
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
|
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
|
||||||
|
@@ -6658,45 +6658,33 @@ func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJar
|
|||||||
public_key: "testkey.avbpubkey",
|
public_key: "testkey.avbpubkey",
|
||||||
private_key: "testkey.pem",
|
private_key: "testkey.pem",
|
||||||
}`
|
}`
|
||||||
fs := map[string][]byte{
|
fs := android.MockFS{
|
||||||
"lib1/src/A.java": nil,
|
"lib1/src/A.java": nil,
|
||||||
"lib2/src/B.java": nil,
|
"lib2/src/B.java": nil,
|
||||||
"system/sepolicy/apex/myapex-file_contexts": nil,
|
"system/sepolicy/apex/myapex-file_contexts": nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
config := android.TestArchConfig(t.TempDir(), nil, bp, fs)
|
errorHandler := android.FixtureExpectsNoErrors
|
||||||
android.SetTestNeverallowRules(config, rules)
|
if errmsg != "" {
|
||||||
updatableBootJars := make([]string, 0, len(apexBootJars))
|
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg)
|
||||||
for _, apexBootJar := range apexBootJars {
|
|
||||||
updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
|
|
||||||
}
|
}
|
||||||
config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars)
|
|
||||||
|
|
||||||
ctx := android.NewTestArchContext(config)
|
android.GroupFixturePreparers(
|
||||||
ctx.RegisterModuleType("apex", BundleFactory)
|
android.PrepareForTestWithAndroidBuildComponents,
|
||||||
ctx.RegisterModuleType("apex_key", ApexKeyFactory)
|
java.PrepareForTestWithJavaBuildComponents,
|
||||||
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
PrepareForTestWithApexBuildComponents,
|
||||||
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
android.PrepareForTestWithNeverallowRules(rules),
|
||||||
java.RegisterRequiredBuildComponentsForTest(ctx)
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||||
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
|
updatableBootJars := make([]string, 0, len(apexBootJars))
|
||||||
ctx.PreDepsMutators(RegisterPreDepsMutators)
|
for _, apexBootJar := range apexBootJars {
|
||||||
ctx.PostDepsMutators(RegisterPostDepsMutators)
|
updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar)
|
||||||
ctx.PostDepsMutators(android.RegisterNeverallowMutator)
|
}
|
||||||
|
variables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars)
|
||||||
ctx.Register()
|
}),
|
||||||
|
fs.AddToFixture(),
|
||||||
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
).
|
||||||
android.FailIfErrored(t, errs)
|
ExtendWithErrorHandler(errorHandler).
|
||||||
|
RunTestWithBp(t, bp)
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
if errmsg == "" {
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
} else if len(errs) > 0 {
|
|
||||||
android.FailIfNoMatchingErrors(t, errmsg, errs)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
t.Fatalf("missing expected error %q (0 errors are returned)", errmsg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApexPermittedPackagesRules(t *testing.T) {
|
func TestApexPermittedPackagesRules(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user