-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antlir2][image_test] support static listing
Summary: Python and C++ tests in fbcode support "static listing" of test cases, which means that in most cases TPX can list available test cases without actually running the test binary for discovery. Antlir and Antlir2 have never supported this, which is a huge disadvantage for at least two reasons: 1. It's a huge perf hit when running tests on large booted images 2. Broken images can break test listing in ways that convince users it's antlir's fault (especially booted tests with broken systemd units) Test Plan: ``` ❯ buck2 test fbcode//antlir/antlir2/testing/tests:test-cpp fbcode//antlir/antlir2/testing/tests:test-cpp-booted fbcode//antlir/antlir2/testing/tests:test-py fbcode//antlir/antlir2/testing/tests:test-py-booted Buck UI: https://www.internalfb.com/buck2/269c3536-5543-4824-8ade-117d15d89fbd Test UI: https://www.internalfb.com/intern/testinfra/testrun/2533275002169707 Note: Using experimental modern dice Network: Up: 170KiB Down: 34KiB (reSessionID-bdc336c4-eeed-4c44-a701-fc177d47d23a) Jobs completed: 79. Time elapsed: 8.2s. Cache hits: 69%. Commands: 16 (cached: 11, remote: 0, local: 5) Tests finished: Pass 8. Fail 0. Fatal 0. Skip 0. Build failure 0 ``` Reviewed By: epilatow Differential Revision: D51271549 fbshipit-source-id: 6b1d1bbdb1e6eb3f41568185e04551fbfb24fe00
- Loading branch information
1 parent
6a1de1a
commit 8896979
Showing
5 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
""" | ||
The way that TPX invokes static list binaries is very unconducive to supporting | ||
it within antlir2. | ||
Since this requires some really hacky interpretation of argv, this is a simple | ||
python script that branches on the test type and then parses args and forwards | ||
them to the underlying static listing implementation. | ||
The args as received by this script are a terrible mix of the args that | ||
antlir2's image_test produces for internal use, the args for the static lister | ||
and other args that the static lister in TPX thinks are necessary for vanilla | ||
tests of this type. | ||
""" | ||
|
||
import argparse | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def main(): | ||
sys.argv.pop(0) | ||
which = sys.argv.pop(0) | ||
if which == "cpp": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("image_test_bin") | ||
parser.add_argument("--wrap", required=True) | ||
parser.add_argument("--spec", required=True) | ||
parser.add_argument("test_type", choices=["gtest"]) | ||
parser.add_argument("cmd", nargs="+") | ||
args = parser.parse_args(sys.argv) | ||
os.execv(args.wrap, [args.wrap] + args.cmd) | ||
if which == "py": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--wrap", required=True) | ||
parser.add_argument("--spec", required=True) | ||
parser.add_argument("--json-output", required=True) | ||
parser.add_argument("image_test_bin") | ||
parser.add_argument("test_type", choices=["pyunit"]) | ||
parser.add_argument("cmd", nargs="+") | ||
args = parser.parse_args(sys.argv) | ||
os.execv(args.wrap, [args.wrap, "--json-output", args.json_output] + args.cmd) | ||
|
||
raise Exception(f"Unknown static list wrapper: {which}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |