Skip to content

Commit 1a3c5ac

Browse files
committed
test: ab: Add function for A/B-Tests across precompiled binaries
Currently, we have two types of pre-PR A/B-Tests: Those that depend on the repository as a whole (e.g. `cargo audit`, which checks properties of Cargo.toml), and those that depend on the pre-compiled firecracker binaries. At the moment, these tests can use the same infrastructure, because our buildkite shared build step will pre-compile binaries and then upload the entire repository as an artifact, and so both types of A/B-tests will find what they're looking for in this artifact and end up being happy. However, this model makes it very difficult to manually run A/B-tests locally (one will need to setup clones of the git repository at specific locations and then pre-compile firecracker with specific flags inside them). This patch series has the goal to simplify these manual A/B-tests, but the cost is that the pre-PR A/B tests will require different infrastructure. Thus, prepare by providing different functions for each of these types of A/B-test to use. Signed-off-by: Patrick Roy <[email protected]>
1 parent 23ab358 commit 1a3c5ac

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/framework/ab_test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@
2929
import scipy
3030

3131
from framework import utils
32+
from framework.defs import FC_WORKSPACE_DIR
3233
from framework.microvm import Microvm
3334
from framework.utils import CommandReturn
3435
from framework.with_filelock import with_filelock
35-
from host_tools.cargo_build import get_binary, get_firecracker_binaries
36+
from host_tools.cargo_build import (
37+
DEFAULT_TARGET_DIR,
38+
get_binary,
39+
get_firecracker_binaries,
40+
)
3641

3742
# Locally, this will always compare against main, even if we try to merge into, say, a feature branch.
3843
# We might want to do a more sophisticated way to determine a "parent" branch here.
@@ -96,6 +101,26 @@ def git_ab_test(
96101
return result_a, result_b, comparison
97102

98103

104+
DEFAULT_B_DIRECTORY = FC_WORKSPACE_DIR / "build" / "cargo_target" / DEFAULT_TARGET_DIR
105+
106+
107+
def binary_ab_test(
108+
test_runner: Callable[[Path, bool], T],
109+
comparator: Callable[[T, T], U] = default_comparator,
110+
*,
111+
a_directory: Path,
112+
b_directory: Path = DEFAULT_B_DIRECTORY,
113+
):
114+
"""
115+
Similar to `git_ab_test`, but instead of locally checking out different revisions, it operates on
116+
directories containing firecracker/jailer binaries
117+
"""
118+
result_a = test_runner(a_directory, True)
119+
result_b = test_runner(b_directory, False)
120+
121+
return result_a, result_b, comparator(result_a, result_b)
122+
123+
99124
def is_pr() -> bool:
100125
"""Returns `True` iff we are executing in the context of a build kite run on a pull request"""
101126
return os.environ.get("BUILDKITE_PULL_REQUEST", "false") != "false"

0 commit comments

Comments
 (0)