|
| 1 | +#!/usr/bin/env vpython3 |
| 2 | +# Copyright 2024 The ChromiumOS Authors |
| 3 | +# Use of this source code is governed by a BSD-style license that can be |
| 4 | +# found in the LICENSE file. |
| 5 | + |
| 6 | +import argparse |
| 7 | +import glob |
| 8 | +import os |
| 9 | +import shutil |
| 10 | +import subprocess |
| 11 | +import sys |
| 12 | + |
| 13 | + |
| 14 | +parser = argparse.ArgumentParser( |
| 15 | + description='Build the same target with C and Rust from two adhd directory.' |
| 16 | +) |
| 17 | +parser.add_argument( |
| 18 | + 'test_target', metavar='"test_target.c"', type=str, help='Build target to be test' |
| 19 | +) |
| 20 | +parser.add_argument( |
| 21 | + 'adhd_dir', |
| 22 | + metavar='"comparing adhd directory"', |
| 23 | + type=str, |
| 24 | + help='Origin adhd directory with C libraries', |
| 25 | +) |
| 26 | +parser.add_argument( |
| 27 | + 'testfiles_dir', metavar='"testfiles directory"', type=str, help='Directory with .wav testfiles' |
| 28 | +) |
| 29 | +args = parser.parse_args() |
| 30 | + |
| 31 | +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 32 | +CUR_ADHD = os.path.join(SCRIPT_DIR, "../..") |
| 33 | + |
| 34 | +if (not os.path.isfile(os.path.join(CUR_ADHD, "cras/src/dsp/tests/", args.test_target))) or ( |
| 35 | + not os.path.isfile(os.path.join(args.adhd_dir, "cras/src/dsp/tests/", args.test_target)) |
| 36 | +): |
| 37 | + raise SystemExit("Test targets not found") |
| 38 | + |
| 39 | +if not os.path.isfile(os.path.join(SCRIPT_DIR, "cmpraw")): |
| 40 | + subprocess.run(["bazel", "build", "//cras/src/dsp/tests:cmpraw"], cwd=CUR_ADHD, check=True) |
| 41 | + shutil.copy("bazel-bin/cras/src/dsp/tests/cmpraw", SCRIPT_DIR) |
| 42 | +BUILD_TARGET = args.test_target.removesuffix(".c") |
| 43 | +try: |
| 44 | + os.mkdir(os.path.join(SCRIPT_DIR, "sandbox")) |
| 45 | +except FileExistsError: |
| 46 | + pass |
| 47 | +shutil.copy( |
| 48 | + os.path.join("bazel-bin/cras/src/dsp/tests/", BUILD_TARGET), |
| 49 | + os.path.join(SCRIPT_DIR, "sandbox/rust"), |
| 50 | +) |
| 51 | +subprocess.run(["bazel", "build", "//cras/src/dsp/tests:" + BUILD_TARGET], cwd=args.adhd_dir) |
| 52 | +shutil.copy( |
| 53 | + os.path.join("bazel-bin/cras/src/dsp/tests/", BUILD_TARGET), |
| 54 | + os.path.join(SCRIPT_DIR, "sandbox/c"), |
| 55 | +) |
| 56 | +os.chdir(SCRIPT_DIR) |
| 57 | +for file in os.listdir(args.testfiles_dir): |
| 58 | + f = os.path.join(args.testfiles_dir, file) |
| 59 | + subprocess.run( |
| 60 | + [ |
| 61 | + "sox", |
| 62 | + f, |
| 63 | + "--bits", |
| 64 | + "16", |
| 65 | + "--encoding", |
| 66 | + "signed-integer", |
| 67 | + "--endian", |
| 68 | + "little", |
| 69 | + "./sandbox/test_file.raw", |
| 70 | + ], |
| 71 | + cwd=SCRIPT_DIR, |
| 72 | + check=True, |
| 73 | + ) |
| 74 | + subprocess.run( |
| 75 | + ["./sandbox/rust", "sandbox/test_file.raw", "sandbox/rust_output.raw"], |
| 76 | + cwd=SCRIPT_DIR, |
| 77 | + check=True, |
| 78 | + ) |
| 79 | + subprocess.run( |
| 80 | + ["./sandbox/c", "sandbox/test_file.raw", "sandbox/c_output.raw"], cwd=SCRIPT_DIR, check=True |
| 81 | + ) |
| 82 | + print(file + " result:", end='', flush=True) |
| 83 | + subprocess.run( |
| 84 | + ["./cmpraw", "sandbox/c_output.raw", "sandbox/rust_output.raw"], cwd=SCRIPT_DIR, check=True |
| 85 | + ) |
| 86 | +shutil.rmtree("sandbox") |
| 87 | +print("Remove generated binary with the command if there is no further testing:") |
| 88 | +print("\trm -f devtools/test_dsp_rust/cmpraw") |
0 commit comments