21
21
of both invocations is the same, the test passes (with us being alerted to this situtation via a special pipeline that
22
22
does not block PRs). If not, it fails, preventing PRs from introducing new vulnerable dependencies.
23
23
"""
24
- import os
25
24
import statistics
26
25
from pathlib import Path
27
26
from tempfile import TemporaryDirectory
31
30
32
31
from framework import utils
33
32
from framework .defs import FC_WORKSPACE_DIR
34
- from framework .microvm import Microvm
33
+ from framework .properties import global_props
35
34
from framework .utils import CommandReturn
36
35
from framework .with_filelock import with_filelock
37
- from host_tools .cargo_build import DEFAULT_TARGET_DIR , get_firecracker_binaries
36
+ from host_tools .cargo_build import DEFAULT_TARGET_DIR
38
37
39
38
# Locally, this will always compare against main, even if we try to merge into, say, a feature branch.
40
39
# We might want to do a more sophisticated way to determine a "parent" branch here.
41
- DEFAULT_A_REVISION = os . environ . get ( "BUILDKITE_PULL_REQUEST_BASE_BRANCH" ) or "main"
40
+ DEFAULT_A_REVISION = global_props . buildkite_revision_a or "main"
42
41
43
42
44
43
T = TypeVar ("T" )
@@ -120,11 +119,6 @@ def binary_ab_test(
120
119
return result_a , result_b , comparator (result_a , result_b )
121
120
122
121
123
- def is_pr () -> bool :
124
- """Returns `True` iff we are executing in the context of a build kite run on a pull request"""
125
- return os .environ .get ("BUILDKITE_PULL_REQUEST" , "false" ) != "false"
126
-
127
-
128
122
def git_ab_test_host_command_if_pr (
129
123
command : str ,
130
124
* ,
@@ -134,7 +128,7 @@ def git_ab_test_host_command_if_pr(
134
128
"""Runs the given bash command as an A/B-Test if we're in a pull request context (asserting that its stdout and
135
129
stderr did not change across the PR). Otherwise runs the command, asserting it returns a zero exit code
136
130
"""
137
- if is_pr () :
131
+ if global_props . buildkite_pr :
138
132
git_ab_test_host_command (command , comparator = comparator )
139
133
return None
140
134
@@ -176,56 +170,6 @@ def set_did_not_grow_comparator(
176
170
)
177
171
178
172
179
- def precompiled_ab_test_guest_command (
180
- microvm_factory : Callable [[Path , Path ], Microvm ],
181
- command : str ,
182
- * ,
183
- comparator : Callable [[CommandReturn , CommandReturn ], bool ] = default_comparator ,
184
- a_revision : str = DEFAULT_A_REVISION ,
185
- b_revision : Optional [str ] = None ,
186
- ):
187
- """The same as git_ab_test_command, but via SSH. The closure argument should setup a microvm using the passed
188
- paths to firecracker and jailer binaries."""
189
- b_directory = (
190
- DEFAULT_B_DIRECTORY
191
- if b_revision is None
192
- else FC_WORKSPACE_DIR / "build" / b_revision
193
- )
194
-
195
- def test_runner (bin_dir , _is_a : bool ):
196
- microvm = microvm_factory (bin_dir / "firecracker" , bin_dir / "jailer" )
197
- return microvm .ssh .run (command )
198
-
199
- (_ , old_out , old_err ), (_ , new_out , new_err ), the_same = binary_ab_test (
200
- test_runner ,
201
- comparator ,
202
- a_directory = FC_WORKSPACE_DIR / "build" / a_revision ,
203
- b_directory = b_directory ,
204
- )
205
-
206
- assert (
207
- the_same
208
- ), f"The output of running command `{ command } ` changed:\n Old:\n stdout:\n { old_out } \n stderr\n { old_err } \n \n New:\n stdout:\n { new_out } \n stderr:\n { new_err } "
209
-
210
-
211
- def precompiled_ab_test_guest_command_if_pr (
212
- microvm_factory : Callable [[Path , Path ], Microvm ],
213
- command : str ,
214
- * ,
215
- comparator = default_comparator ,
216
- check_in_nonpr = True ,
217
- ):
218
- """The same as git_ab_test_command_if_pr, but via SSH"""
219
- if is_pr ():
220
- precompiled_ab_test_guest_command (
221
- microvm_factory , command , comparator = comparator
222
- )
223
- return None
224
-
225
- microvm = microvm_factory (* get_firecracker_binaries ())
226
- return microvm .ssh .run (command , check = check_in_nonpr )
227
-
228
-
229
173
def check_regression (
230
174
a_samples : List [float ], b_samples : List [float ], * , n_resamples : int = 9999
231
175
):
0 commit comments