Skip to content

Commit c38db44

Browse files
committed
test testbench
1 parent 36ef581 commit c38db44

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

tests/scripts/end_to_end_test_tracer_replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def run_test(expected_improvement_pct: int) -> bool:
1010
min_improvement_x=0.1,
1111
expected_unit_tests=1,
1212
coverage_expectations=[
13-
CoverageExpectation(function_name="funcA", expected_coverage=100.0, expected_lines=[2, 3, 4, 6, 9]),
13+
# CoverageExpectation(function_name="funcA", expected_coverage=100.0, expected_lines=[2, 3, 4, 6, 9]),
1414
CoverageExpectation(function_name="add_numbers", expected_coverage=100.0, expected_lines=[2, 3, 4, 6, 9]),
1515
],
1616
)

tests/scripts/end_to_end_test_utilities.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def run_codeflash_command(
8080
) -> bool:
8181
logging.basicConfig(level=logging.INFO)
8282
if config.trace_mode:
83-
return run_trace_test(cwd, config, expected_improvement_pct)
83+
# return run_trace_test(cwd, config, expected_improvement_pct)
84+
return run_trace_test2(cwd, config, expected_improvement_pct)
8485

8586
path_to_file = cwd / config.file_path
8687
file_contents = path_to_file.read_text("utf-8")
@@ -228,6 +229,55 @@ def run_trace_test(cwd: pathlib.Path, config: TestConfig, expected_improvement_p
228229
return validate_output(stdout, return_code, expected_improvement_pct, config)
229230

230231

232+
def run_trace_test2(cwd: pathlib.Path, config: TestConfig, expected_improvement_pct: int) -> bool:
233+
# First command: Run the tracer
234+
test_root = cwd / "tests" / (config.test_framework or "")
235+
clear_directory(test_root)
236+
command = ["python", "-m", "codeflash.tracer", "-o", "codeflash.trace", "testbench.py"]
237+
process = subprocess.Popen(
238+
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=str(cwd), env=os.environ.copy()
239+
)
240+
241+
output = []
242+
for line in process.stdout:
243+
logging.info(line.strip())
244+
output.append(line)
245+
246+
return_code = process.wait()
247+
stdout = "".join(output)
248+
249+
if return_code != 0:
250+
logging.error(f"Tracer command returned exit code {return_code}")
251+
return False
252+
253+
functions_traced = re.search(r"Traced (\d+) function calls successfully and replay test created at - (.*)$", stdout)
254+
if not functions_traced or int(functions_traced.group(1)) != 3:
255+
logging.error("Expected 3 traced functions")
256+
return False
257+
258+
replay_test_path = pathlib.Path(functions_traced.group(2))
259+
if not replay_test_path.exists():
260+
logging.error(f"Replay test file missing at {replay_test_path}")
261+
return False
262+
263+
# Second command: Run optimization
264+
command = ["python", "../../../codeflash/main.py", "--replay-test", str(replay_test_path), "--no-pr"]
265+
process = subprocess.Popen(
266+
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=str(cwd), env=os.environ.copy()
267+
)
268+
269+
output = []
270+
for line in process.stdout:
271+
logging.info(line.strip())
272+
output.append(line)
273+
274+
return_code = process.wait()
275+
stdout = "".join(output)
276+
277+
return validate_output(stdout, return_code, expected_improvement_pct, config)
278+
279+
280+
231281
def run_with_retries(test_func, *args, **kwargs) -> bool:
232282
max_retries = int(os.getenv("MAX_RETRIES", 3))
233283
retry_delay = int(os.getenv("RETRY_DELAY", 5))

0 commit comments

Comments
 (0)