From ebaa5733173f687ed14c0b7aedfa72bcc990138d Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 2 May 2023 11:43:14 +0900 Subject: Prebuilt replacing source should not change partition This reveals unintended mistake (setting a wrong target partition) at build-time instead of runtime, which is much harder to debug. Bug: 280368661 Test: m nothing (soong test) Change-Id: Ic5e5e97ba918e24f7a59aceb405c2b105e28cccc --- android/prebuilt_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'android/prebuilt_test.go') diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go index fa40d1fb3..fc47cfd97 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -497,6 +497,52 @@ func TestPrebuilts(t *testing.T) { } } +func testPrebuiltError(t *testing.T, expectedError, bp string) { + t.Helper() + fs := MockFS{ + "prebuilt_file": nil, + } + GroupFixturePreparers( + PrepareForTestWithArchMutator, + PrepareForTestWithPrebuilts, + PrepareForTestWithOverrides, + fs.AddToFixture(), + FixtureRegisterWithContext(registerTestPrebuiltModules), + ). + ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern(expectedError)). + RunTestWithBp(t, bp) +} + +func TestPrebuiltShouldNotChangePartition(t *testing.T) { + testPrebuiltError(t, `partition is different`, ` + source { + name: "foo", + vendor: true, + } + prebuilt { + name: "foo", + prefer: true, + srcs: ["prebuilt_file"], + }`) +} + +func TestPrebuiltShouldNotChangePartition_WithOverride(t *testing.T) { + testPrebuiltError(t, `partition is different`, ` + source { + name: "foo", + vendor: true, + } + override_source { + name: "bar", + base: "foo", + } + prebuilt { + name: "bar", + prefer: true, + srcs: ["prebuilt_file"], + }`) +} + func registerTestPrebuiltBuildComponents(ctx RegistrationContext) { registerTestPrebuiltModules(ctx) -- cgit v1.2.3-59-g8ed1b