|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | + |
| 6 | + |
| 7 | +BASE_DIR = os.path.realpath(os.path.dirname(__file__)) |
| 8 | + |
| 9 | + |
| 10 | +def run(*args, **kwargs): |
| 11 | + cwd = kwargs.pop("cwd", None) |
| 12 | + environ = kwargs.pop("environ", os.environ) |
| 13 | + assert not kwargs |
| 14 | + |
| 15 | + print("+ [running] {}".format(list(args))) |
| 16 | + subprocess.check_call(list(args), cwd=cwd, env=environ) |
| 17 | + |
| 18 | + |
| 19 | +def main(): |
| 20 | + for path in os.listdir(BASE_DIR): |
| 21 | + if ( |
| 22 | + not os.path.isdir(os.path.join(BASE_DIR, path)) or |
| 23 | + not os.path.exists(os.path.join(BASE_DIR, path, "tests.rs")) |
| 24 | + ): |
| 25 | + continue |
| 26 | + |
| 27 | + run( |
| 28 | + "cargo", "xbuild", "--target", "x86_64-linux-kernel-module", |
| 29 | + cwd=os.path.join(BASE_DIR, path), |
| 30 | + environ=dict( |
| 31 | + os.environ, |
| 32 | + RUST_TARGET_PATH=os.path.join(BASE_DIR, os.path.pardir), |
| 33 | + CARGO_TARGET_DIR=os.path.relpath( |
| 34 | + os.path.join(BASE_DIR, "target"), |
| 35 | + os.path.join(BASE_DIR, path) |
| 36 | + ), |
| 37 | + ) |
| 38 | + ) |
| 39 | + |
| 40 | + module = os.path.join( |
| 41 | + BASE_DIR, |
| 42 | + "target/x86_64-linux-kernel-module/debug/lib{}_tests.a".format( |
| 43 | + path |
| 44 | + ) |
| 45 | + ) |
| 46 | + run( |
| 47 | + "make", "-C", BASE_DIR, |
| 48 | + "TEST_LIBRARY={}".format( |
| 49 | + os.path.join( |
| 50 | + "target/x86_64-linux-kernel-module/debug/", |
| 51 | + os.path.basename(module) |
| 52 | + ) |
| 53 | + ), |
| 54 | + ) |
| 55 | + run( |
| 56 | + "rustc", |
| 57 | + "--test", |
| 58 | + "--out-dir", os.path.join(BASE_DIR, path), |
| 59 | + os.path.join(BASE_DIR, path, "tests.rs"), |
| 60 | + ) |
| 61 | + # TODO: qemu |
| 62 | + run( |
| 63 | + os.path.join(BASE_DIR, path, "tests"), |
| 64 | + environ=dict( |
| 65 | + os.environ, |
| 66 | + KERNEL_MODULE=os.path.join(BASE_DIR, "testmodule.ko") |
| 67 | + ) |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + main() |
| 74 | + |
0 commit comments