Commit Graph

33 Commits

Author SHA1 Message Date
Jeff Vander Stoep
408e5db8d9 Include non-local tests by path
Import paths for non-local tests because including tests
directly has proven to be fragile and burdensome. For example,
whenever a project removes or renames a test, all the TEST_MAPPING
files for its reverse dependencies must be updated or we get test
breakages. That can be many tens of projects that must updated to
prevent the reported breakage of tests that no longer exist.
Similarly when a test is added, it won't be run when the reverse
dependencies change unless/until update_crate_tests.py is run for its
depenencies. Importing TEST_MAPPING files instead of tests solves
both of these problems. When tests are removed, renamed, or added,
only files local to the project need to be modified. The downside is
that we potentially miss some tests. But this seems like a reasonable
tradeoff since it's primarily unit tests that are missing, and all
unit tests are always run on the host for every presubmit.

See aosp/2400500 as an example of what test mapping files now
look like after this change.

Test: run it over all projects in external/rust/crates
Change-Id: I2b644f9ebf97968c9928f5b1756b2ab199e8e7ca
2023-01-30 13:10:25 +01:00
Jeff Vander Stoep
2f3afc25d5 update_crate_tests.py: update location of bazel binary
The binary for bazel moved from tools/bazel to build/bazel/bin/bazel.

Test: run update_crate_tests.py in a Rust crate. Verify results.
Change-Id: I2e586b59876bfd7146cd92efc90055828bf60eac
2022-12-13 15:43:05 +01:00
Matthew Maurer
e1d07ba872 c2a: Only use postsubmit when configured
Previous logic would place tests in both presubmit and postsubmit if the
postsubmit_tests configuration was not specified. This is both
unnecessary and wastes resources because presubmit tests are also run in
postsubmit.

Bug: 236006683
Test: Regenerate all TEST_MAPPINGs, manually check postsubmit removal
Change-Id: Ie8ff0e351776711e07bf7646efd916d970254e9c
2022-06-14 16:28:36 -07:00
Matthew Maurer
037b445ed8 c2a: Denylist additional Rust tests modules
These modules are not suitable for direct execution on cuttlefish, but
are still built as `rust_test` to get the harness.

Bug: 233924440
Test: Regenerate all TEST_MAPPINGs, pass presubmit
Change-Id: I4aebdb5e36cf3a80780483e0a7ebeb83e9735d29
2022-06-14 14:32:15 -07:00
Matthew Maurer
3f7f7e2236 c2a: Do not assume test_mapping.json exists
update_crate_tests would previously assume test_mapping.json existed
when trying to generate a TEST_MAPPING update. This made updating
mappings for the majority of existing crates fail.

Bug: 233924440
Test: Regenerate all Rust TEST_MAPPINGs
Change-Id: I4d9b906f4db233ee0223a3035c1b63bf1ca681f4
2022-06-14 14:32:00 -07:00
Ivan Lozano
d7438cff3b Add test_mapping_config to update_crate_tests
Adds support for configuring TEST_MAPPING output in
update_crate_tests.py by defining a test_mapping_config.json.

The initial option that can be set is whether a test should be a
postsubmit test instead of a presubmit test.

Bug: 229727993
Test: update_crate_tests.py with test_mapping_config.json produces
      postsubmit tests
Change-Id: I2f5a336c1af12630cc5df9d2c32ab63ac6099af8
2022-04-26 13:04:08 -04:00
David LeGare
d3bbf8cb7f Add open_then_run to TEST_EXCLUDE
Test: manual - Performed bulk update of crate TEST_MAPPING files
Change-Id: I39f7696eb1a0633d002a534ad21cc5f460eeee8c
2022-03-15 16:01:49 +00:00
Ivan Lozano
69030b3994 Exclude additional rust_tests.
aidl_test_rust_service_async is a helper binary and shouldn't be added
to TEST_MAPPINGs. diced_client_test does not work in presubmit yet.

Test: update_crate_tests.py no longer adds those tests.
Change-Id: I565680d2bee31e30bf5db224c46428385ed279a3
2022-03-04 14:24:24 -05:00
Joel Galenson
79b55eadb6 Merge changes from topic "rust-tests-and-mappings-refactor"
* changes:
  cargo2android: Add tests to both test groups
  Use TEST_MAPPING imports for third-party crate tests.
2021-12-15 15:27:59 +00:00
Matthew Maurer
24758f89e2 cargo2android: Add tests to both test groups
"presubmit" will continue to handle x86_64 virtual device and host tests
"presubmit-rust" will run the test on a pool of physical arm64 devices

Bug: 204332926
Test: regenerated a few TEST_MAPPING files
Change-Id: Idd5cad5107a96031f67305b63875034b2e5a5c60
2021-12-10 20:43:21 +00:00
Joel Galenson
54d655345d Stop generating separate rust_test_host.
With b/196306316 hopefully fixed, we should be able to use a single
rust_test entry for both device and host tests.  This modifies
cargo2android.py so it generates these shared tests.

Test: Run on crates with simple tests, those with defaults, host-only,
and device-only tests.

Change-Id: Icfe8d1fb26a61bc9ed65b8a7b116a4ebcd782ce4
2021-12-06 16:17:06 -08:00
Joel Galenson
4a08c64965 Use TEST_MAPPING imports for third-party crate tests.
This script currently computes all transitive reverse dependencies for
a given crate and adds them to the generated TEST_MAPPING.  This
creates a very large file and makes it difficult to rename/remove
tests, as a given test can be in many TEST_MAPPING files in other
directories.  We fix this by instead importing the TEST_MAPPING files
of other third-party crates.

Note that we cannot do this for tests defined by this crate (as they
need to be in some TEST_MAPPING file) and for tests outside of
external.  For the latter, we do not auto-generate those TEST_MAPPING
files, so they might contain extra tests we do not want or not contain
the tests we do want.  We thus continue to list such tests
individually, which is suboptimal but at least is a strict improvement
over the current system.

Test: Run on a few crates.
Change-Id: Ibdf36e7844f5946c9e321ac60558792abd691b42
2021-12-06 16:15:49 -08:00
Joel Galenson
2811a3e162 Add more Rust tests to exclude.
Test: Run script and see it does not add these tests.
Change-Id: I46d1a5fbc12733c91febde81500f0b42dcf87806
2021-10-01 07:10:14 -07:00
Lukacs T. Berki
9206f1c08b Update the way one generates the Bazel workspace.
Test: Presubmits.
Change-Id: I0edfe61e78d04fcb468c68136ba1da3ee6e3fd1c
2021-09-06 11:36:59 +02:00
Joel Galenson
bdf3ab4d8e Let the test mapping updater handle newly-added files.
The previous commit to this file allowed it to create and upload a
commit when a TEST_MAPPING file changed.  But it did not handle the
case where the TEST_MAPPING file did not previously exist.  This fixes
that.

Test: Run script.
Change-Id: Id7b9e778c2b084f7ea2e4005a173c1fedeccd6c7
2021-08-30 08:59:47 -07:00
Joel Galenson
4a2a3a8211 Let the test mapping updater make commits and upload changes.
This will make it easier to run it on many crates and upload all of
the changes.  It puts the uploaded CLs in a topic to save resources.
If the script does not change a TEST_MAPPING, it does not upload
anything.

Test: Run on a subset of crates.
Change-Id: I47b4756d968c54d7d810c8a19a8a7419aebc6e15
2021-08-20 12:26:37 -07:00
Joel Galenson
08352445c8 Allow passing globs to update_crate_tests.py.
This makes it easier to run it on multiple directories.

Test: Call with various globs.
Change-Id: I0564369e4e8b9d62482fb2162a16d0e588f94e57
2021-08-20 11:39:48 -07:00
Joel Galenson
177910448c Allow passing multiple crates to update_crate_tests.py
Currently the script can only run on a single crate at a time, and
each time it runs it re-initializes Bazel. By passing multiple crates
we can save time by only initializing Bazel once.

Test: Call with zero, one, and multiple crate arguments.
Change-Id: Ic83c16d87066a8555b736b35bc7971586ee26e16
2021-07-02 07:39:28 -07:00
Thiébaud Weksteen
3604b75456 update_crate_tests: Add documentation
Test: pydoc update_crate_tests
Change-Id: Ice2c3a8ab901e38b2cf77433ec1ba6aac2360236
2021-06-10 14:27:16 +02:00
Thiébaud Weksteen
fc485b2384 update_crate_tests: Remove cwd
Env.cwd is misleading as it captures the location of the crate/package
being updated. Move the detection logic to the Package class and rename
the attribute.

There is the expectation that before running soong_ui, cwd is set to
ANDROID_BUILD_TOP; and before running write_mapping, that cwd is set to
the package directory. Add comments to capture this.

Test: update_crate_tests.py in external/rust/crates/libc
Change-Id: I5c4f16afe0b92b7c85173e4149ee17dd39c773c2
2021-06-10 14:27:10 +02:00
Thiébaud Weksteen
2e532bb1c1 update_crate_tests: Clean up
Rename the Crate class to Package as this script may also be used to
update TEST_MAPPING for the prebuilts/rust toolchain.

Inline get_tests function as one branch was never used.

Rename `create_test_mapping` to `create` as it is already a method of
TestMapping.

Test: update_crate_tests.py in external/rust/crates/libc
Test: update_crate_tests.py in prebuilts/rust
Change-Id: I06bd6d4f93223bb50fdb898980bd25fa3cea9019
2021-06-10 10:56:24 +02:00
Thiébaud Weksteen
df132d6056 update_crate_tests: Generate Bazel files
Bug: 190582745
Test: update_crate_tests.py in external/rust/crates/libc
Change-Id: If61239c5fe9ae3f8fc568eec906bf73baf603105
2021-06-10 10:56:13 +02:00
Thiébaud Weksteen
5212f8a43f update_crate_tests: Add init exceptions
Normalize the object initializations by raising exceptions and catching
them within main.

Test: update_crate_tests.py in external/rust/crates/libc
Change-Id: I6080fa7f22d740f5dd384c15ef74097e61dbb210
2021-06-10 10:54:02 +02:00
Thiébaud Weksteen
3e32afc5a6 update_crate_tests: Use prebuilt bazel
Bug: 181953100
Test: update_crate_tests.py in external/rust/crates/libc
Change-Id: I3c0477cf8d5aac0ae9e444d1b95b8670c9e2e588
2021-06-10 10:34:16 +02:00
Thiébaud Weksteen
76c4e232ad update_crate_tests: Use subprocess.DEVNULL
Test: update_crate_tests.py in external/rust/crates/libc
Change-Id: I0beac6e7e4f795bf8581f9c6448968f721da4b75
2021-06-10 10:14:23 +02:00
Joel Galenson
5774c85c70 Raise an exception if we encountered an error.
This allows the caller to handle it if they wish.

Test: Call with an error.
Change-Id: Ia2e0d38e8e486a2b78e42d154654332e88909e9f
2021-05-24 15:31:08 -07:00
Treehugger Robot
dbde427be6 Merge "Add Ring test timeout." 2021-04-06 20:55:52 +00:00
Joel Galenson
4f9d11f6b1 Sort Rust TEST_MAPPING tests.
We currently seem to emit TEST_MAPPING files in an arbitrary order,
which causes diffs to look confusing even when nothing has changed.
Let's sort them by the test name, which is both stable and easier to
read.

Test: Run cargo2android multiple times and see no TEST_MAPPING diff.
Change-Id: I398aa84a4891380e4292223445bd53959c024421
2021-04-06 10:18:21 -07:00
Joel Galenson
a0d4c5e5a5 Add Ring test timeout.
This test looks like it basically never passed without this.

Test: Run cargo2android.py and see timeout.
Change-Id: Ic7ef5576efb84d78130dd45db67e50ebe41f6d9a
2021-04-06 09:36:47 -07:00
Jeff Vander Stoep
82ee11ae77 update_crate_tests.py: don't use sys.exit()
If the TEST_MAPPING cannot be generated, print the reason, but
exit without error. It's not uncommon for the output of cargo2android
to fail to build e.g. if a new depencency is not satisfied, so we can
fall back to the previous TEST_MAPPING, or run update_crate_tests
locally once all dependencies are present.

Bug: 179132533
Test: tools/external_updater/updater.sh update rust/crates/textwrap
Test: tools/external_updater/updater.sh update rust/crates/libc
Change-Id: I4802c77332d1ab1d6604d48c47365f40bdbd1122
2021-02-04 12:10:39 +01:00
Jeff Vander Stoep
1b24dc3f71 update_crate_tests: fail gracefully
Allow this script to accept a path to the crate being updated.
This allows it to be run separately from cargo2android.

Also, fail gracefully on error. TEST_MAPPING update failures should
not block crate updates.

Test: tools/external_updater/updater.sh update rust/crates/libc
Bug: 179132533
Change-Id: I3a4229f479ab3d2793df16b470f0a0632b9ee495
2021-02-03 21:42:40 +01:00
Jeff Vander Stoep
0b0e24f201 update_crate_tests.py: allow excluding tests by name or path
The aidl tests and ChromeOS tests are not intended to be run in
presubmit, so exclude them.

Test: run cargo2android in external/rust/crates/libc.
Change-Id: I1ed92ed6e88886e3fea38612325ce5349db0fb69
2021-01-24 22:19:50 +01:00
Jeff Vander Stoep
cec8bac2cb Cargo2Android: add rdep tests to TEST_MAPPING
This is important because:
1. Some crates do not have their own tests enabled in presubmit.
2. As much as possible, we try to stick with one version of each
   crate. This often results in using different versions of
   dependencies than a crate has specified in its Cargo.toml.

Ensuring that a crate's tests continue to pass when its dependencies
are upgraded improves our confidence that the update is safe.

The underlying implementation uses the new Bazel queryview
to query modules and reverse dependencies.

Bug: 168167373
Test: Run cargo2android.py on a number of crates including rusqlite,
scopeguard, lock_api.

Change-Id: Id24f2d3267cf8d5e0369ece2442f8971d4ab1343
2021-01-15 20:56:59 +01:00