Commit graph

50 commits

Author SHA1 Message Date
Chris Parsons
5011e61c71 Add unit test for parsing build files in bp2build
This involves some minor changes to testing infrastructure.

This is a rollforward of aosp/2628496 with a couple of minor changes:

- In ParseBuildFiles, filter out all build files that are kept due
  to ShouldKeepExistingBuildFileForDir

- Add some minor test infrastructure for StubbedBuildDefinitions, with a
  couple of proof of concept tests used to demonstrate its usage. This
  pattern will become immensely more common as we implement allowlist v2
  (as we will need to update all tests which today simulate build
  definitions that have missing deps)

Bug: 285631638
Fixes: 286545783
Test: bp2build.sh
Test: m nothing
Change-Id: I7c3a03b02098e39dd8e51d327482b440f294478f
2023-09-14 19:19:28 +00:00
Cole Faust
f8231dd0ea Platform mapping-based product config
This allows us to set product variables as build settings instead
of loading them from a target's provider, which further allows us
to read product config variables in transitions.

Bug: 287539062
Bug: 269577299
Test: Presubmits
Change-Id: I8497703f706162572ceb3486240e1eb02a37f5f6
2023-07-17 16:27:08 -07:00
Cole Faust
3d927238cc Revert "Add unit test for parsing build files in bp2build"
This reverts commit e1f25230df.

Reason for revert: breaks bp2build ci

Change-Id: I7320ef679d8a1ba1d605cf0d3781854b97816358
2023-06-27 22:52:07 +00:00
Chris Parsons
e1f25230df Add unit test for parsing build files in bp2build
This involves some minor changes to testing infrastructure.

Bug: 285631638
Fixes: 286545783
Test: unit test
Change-Id: If64ba29308d99e63a1cc5526feaf077f2cb14478
2023-06-16 21:09:19 +00:00
Colin Cross
5dc62c9456 Add sanitizer tests for musl
Add tests that verify sanitizer behaviors for musl.

Test: sanitize_test.go
Change-Id: I1f0a51cc103ac14d1738cb223e216ee0e32d8550
2023-03-22 12:58:38 -07:00
Paul Duffin
4c0765a669 Support running bp2build tests in fixtures
Previously, the fixture test infrastructure was hard coded to
initialize itself in preparation for invoking the PrepareBuildActions()
method. That meant it could not be used for testing the bp2build and
apiBp2build modes which required different initialization and called a
different method.

This change extracts that behavior into a FixtureTestRunner and adds an
implementation that allows it to test the above two modes. It then uses
that to implement the runBp2BuildTestCaseWithSetup method.

The TestPrebuiltLibraryAdditionalAttrs was the only test which broke as
it supplied an invalid path to the MockFS (it does not support using a
trailing / to represent an empty build directory). So, it was modified
to add a couple of files inside those directories instead.

Test: m nothing
Change-Id: I6798a4f761160af8d1bfed81d46de9628bda3eb9
2022-12-02 11:14:17 +00:00
Paul Duffin
3f7bf9fa0d Allow namespace config to be tested properly
Previously, the NewTextContext created a context that always called
NewNameResolver with a export filter that always returned true.

This change fixes that by:
1. Changing NewNameResolver to take a Config parameter instead of a
   filter parameter and pushing the code to create the filter from the
   Config from newNameResolver() in cmd/soong_build/main.go into the
   NewNameResolver function.

2. Extracting a newTestContextForFixture that does not create a
   NameResolver or set it on the context. That avoids creating a
   NameResolver before the test has prepared the config.

3. Modify the fixture to create and set the NameResolver in the Context
   after the config has been prepared by the test.

4. Added test to verify that it all works.

Bug: 234825639
Test: m nothing
Change-Id: Ie4b13f18093dc01a0ab65a9ecfd143585d843b55
2022-11-08 17:38:56 +00:00
Sam Delmerico
2351eacb19 AIDL source generation accounts for Bazel paths
The AIDL source generation rule sets include flags based on the relative
path of .aidl sources. For .aidl sources provided by Bazel targets, e.g.
in a filegroup, the same directory could be added to the include path
twice. Instead we need to ensure that if a Bazel source provides the
include path, that we don't add it again from a Soong source.

Bug: 229251008
Test: USE_BAZEL_ANALYSIS=1 m api-stubs-docs-non-updatable
Change-Id: I4997039003242b43e0e52ccf41729acb4ad11324
2022-08-25 14:47:41 -04:00
Colin Cross
d079e0b270 Reformat build/soong for go 1.19
Test: none
Change-Id: I132368f0fcbdb5ea088b5b84dbe4ccfdd9e94cad
2022-08-17 10:43:13 -07:00
Paul Duffin
0fc6d32c82 Switch the namespace tests to fully use test fixtures
Indented the bp contents to make it easier to differentiate between
them and the directory in which they belong.

Bug: 181070625
Test: m nothing
Change-Id: Iae7495fb7c88769dc688006a41f4d21f57cf03b8
2022-05-11 17:30:58 +00:00
Lukacs T. Berki
9f6c24a887 Rename BuildDir and NinjaBuildDir.
These are just out/ and out/soong/ and the old names were quite
confusing.

Test: Presubmits.
Merged-In: I999ca62162062f27e449f83ffb00fa580d4065b8
Merged-In: I2fcd80a9e376a6842a06aa104a9f6f5c5e16f8c7
Change-Id: Ib481d2aac40df8da1b74174dc8ec576c1cb48be0
2021-08-27 10:08:49 +02:00
Paul Duffin
64715ba9a4 Add PrepareForDebug_DO_NOT_SUBMIT
Simplifies the process of debugging failing tests by making it easy for
the test fixture to produce debug output on a case by case basis.

Bug: 181070625
Test: m nothing
Change-Id: I22620a1bfb1737cffd017bdf7bbbfb609b60468c
2021-04-21 10:16:31 +01:00
Paul Duffin
79abe57f53 Remove FixturePreparer.Extend()
Use GroupFixturePreparers instead.

Bug: 182885307
Test: m nothing
Change-Id: Idc01d3cc5a57576a4cf417e9105d1ab851126e10
2021-04-01 10:33:20 +01:00
Paul Duffin
4814bb814a Remove FixtureFactory
Bug: 182885307
Test: m nothing
Change-Id: I644db99cc6905f544d3e7479b435be26dbf6c59b
2021-04-01 10:33:02 +01:00
Paul Duffin
34a7fff9e0 Remove varargs from Fixture(t *testing.T)
Bug: 182885307
Test: m nothing
Change-Id: I71c3cf47ba1dc8d29d1533789c4c991cb825bd88
2021-03-31 16:04:07 +01:00
Paul Duffin
55e740e9a6 Remove varargs from RunTest(t *testing.T)
Use GroupFixturePreparers instead.

Bug: 182885307
Test: m nothing
Change-Id: Iaedb0ddc9d6a704f4d41363e705f3025a1291dc8
2021-03-31 16:03:59 +01:00
Paul Duffin
3cb2c06b44 Cleanup some issues left over from previous reviews
Bug: 183235980
Test: m nothing
Change-Id: I187765c56b889445de3a4729405ee745e5f73729
2021-03-24 22:08:05 +00:00
Paul Duffin
ff2aa69a86 Deprecate FixtureFactory in favor of FixturePreparer
Prior to this FixtureFactory was basically a FixturePreparer with the
additional support for buildDirSupplier. This makes that a reality by
moving the functionality of FixtureFactory into FixturePreparer and
making FixtureFactory extend that with buildDirSupplier.

This also deprecates the Extend() method in favour of simply using the
GroupFixturePreparers() method.

Once all usages of buildDir have been removed so the buildDirSupplier
is no longer required then FixtureFactory will be removed altogether.
In the meantime follow up changes will migrate those tests that do not
require a buildDirSupplier to just use FixturePreparers in preparation
for the eventual removal of FixtureFactory.

Bug: 183235980
Test: m nothing
Change-Id: Ibb4e5bfec2f76ee34dd7de6aed6bbbfe27d337b8
2021-03-22 18:31:53 +00:00
Paul Duffin
4ca6752b21 Replace FixturePreparer.visit() with list()
The visit() method was dropped in favor of a list() method as the
latter makes it easier to treat fixtureFactory, simpleFixturePreparer
and compositeFixturePreparer as simple collections of already flattened
and deduped *simpleFixturePreparers. That will be used in a follow up
change.

Bug: 183235980
Test: m nothing
Change-Id: Ia41ae9bd4f9c39c85865ba698e0da6be00519caf
2021-03-22 18:31:53 +00:00
Paul Duffin
cff464f794 Remove errorHandler from FixtureFactory
The ExtendWithErrorHandler method simply wraps the FixtureErrorHandler
in a FixturePreparer that will set the error handler in the fixture.

Bug: 183235980
Test: m nothing

Change-Id: Icf9a5f62cb532efc120300c2f906cd3397aa6763
2021-03-22 18:31:53 +00:00
Paul Duffin
592518290f Allow access to preparers that produced a TestResult
The Preparer() method allows for another test to be run using the same
preparers as were used to create the TestResult. That is useful when
testing functionality like the sdk snapshot mechanism that generates an
Android.bp and a set of files that are intended to be reconsumed by
Soong. This method allows the test to process that output to ensure
that it is valid. A follow up change will migrate the CheckSnapshot()
method to use this as part of the migration of the sdk package to the
test fixture model.

Previously, the dedupAndFlattenPreparers() would not construct a list
containing all the preparers passed to it as it was trying to avoid
constructing such a list unless necessary. However, as every usage of
this method now needs to construct such a list that functionality has
been added to it.

Bug: 181070625
Test: m nothing
Change-Id: Iab34e2c861bdfd05c44e982224f70c5abc19e468
2021-03-22 18:31:53 +00:00
Paul Duffin
3d5f6a1034 Merge "Prevent invalid paths being added to mock file system" 2021-03-22 08:58:54 +00:00
Paul Duffin
80f4cea1ad Prevent invalid paths being added to mock file system
Bug: 182885307
Test: m nothing
Change-Id: Ie9f60fd02e2a2bc44811dbcadf0eada4e52c9749
2021-03-20 12:11:20 +00:00
Paul Duffin
ae542a58af Allow customization of all fixture state at once
Adds FixtureCustomPreparer.

Bug: 181070625
Test: m nothing
Change-Id: I310e16661a0f032f778481d9b69da2e0e9a084cf
2021-03-20 10:25:45 +00:00
Paul Duffin
78c36216a8 Add NinjaDeps to TestResult
Bug: 182885307
Test: m nothing
Change-Id: I1eb49f2514b13f52f367cd8f57e5cb0ab3336bd7
2021-03-18 12:18:09 +00:00
Paul Duffin
85034e92b6 Add FixtureIgnoreErrors
Bug: 182885307
Test: m nothing
Change-Id: Ib7e70b624db2f70374b755e97757ed21462b485a
2021-03-17 16:18:17 +00:00
Paul Duffin
50deaae872 Add OptionalFixturePreparer
Sometimes it is necessary to optionally add a preparer. e.g. There are
many parameterized tests where one of the parameters is some additional
test setup but not every test provides it so it will default to the
"zero" value of whatever type is used for the test setup parameter
Migrating those tests to use test fixtures will typically require that
the test setup parameter be changed to a FixturePreparer, which by
default will be nil.

Attempting to use a nil FixturePreparer in the test fixtures will fail
so the OptionalFixturePreparer was added to wrap a possibly nil
FixturePreparer and thereby avoiding complicating each test with
similar logic.

Bug: 182885307
Test: m nothing
Change-Id: Ia12b2af2105fdc69af4e0b909a37a7b86f1af299
2021-03-17 16:10:56 +00:00
Paul Duffin
dff5ff064e Use test specific build dir when needed
If a FixtureFactory was created with a nil buildDirSupplier then this
change will cause it to create a test specific directory instead. This
will allow packages whose tests have been fully converted to the test
fixture model to remove the need for the package level buildDir
variable.

Bug: 182885307
Test: m nothing
Change-Id: Ifa70acadbd90356fadbe39675bac3214d925aa2f
2021-03-16 12:35:04 +00:00
Paul Duffin
d7aea1dbe5 Remove TestHelper
Bug: 181070625
Test: m nothing
Change-Id: Idc39c8621424e25c1b4310c72ed2943d34a66bbc
2021-03-13 16:02:30 +00:00
Paul Duffin
c81854a642 Stop error handler relying on testing.T being embedded in TestResult
This change is in preparation for removing testing.T from TestResult.

Bug: 181070625
Test: m nothing
Change-Id: Iac627cc3c9f922ec4a41ce657442e4139fe7defb
2021-03-13 16:00:51 +00:00
Paul Duffin
e84b1338c5 Migrate from result methods to function Asserts
Bug: 181070625
Test: m nothing
Change-Id: Iadb85270290acb52c55f2ad70c9f145f1c34b611
2021-03-12 22:24:51 +00:00
Paul Duffin
0550055007 Separate TestHelper from fixtures
Although they are intended to be used together they are separate pieces
of functionality so should be separate.

Bug: 181070625
Test: m nothing
Change-Id: I3b2ccf66748a3c53b63c112256a8eb20e0448179
2021-03-12 14:25:33 +00:00
Paul Duffin
3fdb1bd9a2 Remove unused TestResult methods
Left over from a previous incarnation of the fixture mechanism.

Bug: 181070625
Test: m nothing
Change-Id: Ifb3811b7b030613cbff93994f7d370d402b1e73d
2021-03-12 14:25:33 +00:00
Paul Duffin
6e9a4007b5 Prevent mock filesystem files being overridden by accident
Bug: 181070625
Test: m nothing
Change-Id: Ib12b5cbe9af980706620d7d7d85bcfe31f36b07f
2021-03-11 19:21:12 +00:00
Paul Duffin
1ef166e411 Correct error in documentation of AssertDeepEquals
Bug: 181070625
Test: m nothing
Change-Id: Ie9bb46a7c29e800822d4bc67b23a457e17e5e29a
2021-03-11 14:34:10 +00:00
Paul Duffin
93706aeef2 Add AssertStringListContains to TestHelper
Bug: 181070625
Test: m nothing
Change-Id: I5b36b748a2f0b7c189aa9e12cf0ad0f663c92a9a
2021-03-11 07:26:19 +00:00
Paul Duffin
67e848ab04 Merge changes Ib2c6ac28,I7c76ed6d,I00415f10,I4be2a16c,I6f269c9c, ...
* changes:
  Support test fixtures in sh package
  Support test fixtures in bpf package
  Support test fixtures in cc package
  Add temporary RunTestWithConfig method to simplify migration
  Support test fixtures in etc package
  Convert license tests to use test fixtures
2021-03-10 21:52:17 +00:00
Paul Duffin
3b2636fdf3 Merge "Remove duplicate sdk.TestHelper" 2021-03-10 19:59:56 +00:00
Paul Duffin
a3cb2b396f Remove duplicate sdk.TestHelper
As part of the work on the new fixture mechanism some of the TestHelper
functionality was moved into the android/fixture.go package. This moves
the rest and removes the now duplicated TestHelper from the sdk
package.

Also removed some unnecessary & operators.

Bug: 181070625
Test: m nothing
Change-Id: Ia09a5d05e4fab3a4e28cf44b2d947a33541e3925
2021-03-10 14:07:20 +00:00
Paul Duffin
72018ad136 Add temporary RunTestWithConfig method to simplify migration
Bug: 181070625
Test: m nothing
Change-Id: I4be2a16cff750bbe05010ff427cec1831e260267
2021-03-09 23:06:00 +00:00
Paul Duffin
46e37741a9 Rename SetErrorHandler to ExtendWithErrorHandler
Bug: 181070625
Test: m nothing
Change-Id: Iacab525cb47fbd7ff54e5a95ec230ac6c71f20eb
2021-03-09 14:14:48 +00:00
Paul Duffin
2e0323dd1b Allow customization of product variables in a test fixture
Adds FixtureModifyProductVariables.

Bug: 181070625
Test: m nothing
Change-Id: Iad7e125ed722d99dc1e62479b04b625075b89d58
2021-03-09 14:14:48 +00:00
Paul Duffin
bbccfcfb70 Allow customization of the env configuration in a test fixture
Adds FixtureModifyEnv and FixtureMergeEnv.

Bug: 181070625
Test: m nothing
Change-Id: I1b6eb88907efa2476d96912961fea2df2d902659
2021-03-09 14:14:48 +00:00
Paul Duffin
fa29885380 Avoid accidentally sharing preparers slice across factories
Previously, there was a bug that caused tests which ran successfully on
their own to fail when run together in parallel. They each extended the
same factory and ended up sharing the preparers slice which meant that
they overwrote each other's preparers causing the tests to fail.

This change fixes that by creating a new slice for each factory.

Bug: 181070625
Test: m nothing
Change-Id: If340c125c5b03a9d5c36a59ff4da4ec189808f9b
2021-03-08 22:45:09 +00:00
Paul Duffin
942481b3f5 Add Errs to TestResult
Makes the error handler a little cleaner.

Bug: 181070625
Test: m nothing
Change-Id: I0f9050a98346d7d214eed570957d9810aaf26def
2021-03-05 18:20:33 +00:00
Paul Duffin
ea8a386346 Make error handlers treat any failures as fatal
A lot of existing tests that expect errors to be reported do not check
the returned result. This change treats failures of the error handler
in that situation as fatal.

The default error handler already behaved that way. The others did not.

FixtureExpectsAllErrorsToMatchAPattern uses
CheckErrorsAgainstExpectations and it was safe to just make that func
treat any unmatching errors as fatal as all the existing usages are at
the end of test functions.

FixtureExpectsAtLeastOneErrorMatchingPattern uses the
FailIfNoMatchingErrors function which is used in a number of places
(including CheckErrorsAgainstExpectations) that do not want to treat
a test failure as fatal. So, that was modified to return false if no
matching error was found and the error handler treated that as fatal.

Bug: 181070625
Test: m nothing
Change-Id: I6e4df53f93250348bc050d4ff098134e6314ae30
2021-03-05 18:20:33 +00:00
Paul Duffin
52323b5113 Avoid SetErrorHandler mutating FixtureFactory
A FixtureFactory is supposed to be immutable to allow them to be safely
shared but unfortunately the implementation of SetErrorHandler broke
that constraint. That made it very easy to mistakenly add an error
handler specific to a test to a shared factory breaking other tests
that use that factory.

This change causes SetErrorHandler to create a new instance of the
factory to avoid that.

Bug: 181070625
Test: m nothing
Change-Id: Ia5356a04189099c88880a2a521af29ab72560f30
2021-03-05 18:20:33 +00:00
Paul Duffin
a560d5a91d Rename FixturePreparers to GroupFixturePreparers
FixturePreparers is a bad name for a method that creates a collection
of FixturePreparers for a couple of reasons:
* Conventionally it would be used as the name for []FixturePreparer if
  it is necessary to add behavior to that.
* There are many different types of collection, particularly when order
  matters.

Bug: 181070625
Test: m nothing
Change-Id: I55394ff369375dcac2d7b72e4d803a4818762d36
2021-03-05 18:20:33 +00:00
Paul Duffin
cfd3374da0 Add error handling to test fixtures
Adds support for customizing the error handling behavior of test
fixtures and converts a test to use it.

Bug: 181070625
Test: m nothing
Change-Id: I736c41311819d57d8688fc3b0e021dbb50c491c1
2021-03-02 20:17:19 +00:00
Paul Duffin
358161232c Add test fixture support
Adds the test fixture support and converts a few tests to exercise the
code and show how it works.

Bug: 181070625
Test: m nothing
Change-Id: I0a2b40fff93b6041f9aa8c4ef0aba91da1bc8bf3
2021-02-26 23:01:50 +00:00