fuzzer and performance optimisations

This commit is contained in:
Hedy88 2026-08-28 00:22:49 +01:00
commit a4650fd589
No known key found for this signature in database
11 changed files with 897 additions and 146 deletions

View file

@ -273,7 +273,8 @@ on boot
"""
def build_initramfs(init: Path, busybox: Path, rc_text: str, root_password: str | None,
selinux: bool, keep: bool) -> Path:
selinux: bool, keep: bool,
bundles: list[tuple[str, Path]] | None = None) -> Path:
if not shutil.which("cpio"):
sys.exit("cpio not found (install cpio)")
root = Path(tempfile.mkdtemp(prefix="bajia-root-"))
@ -320,6 +321,12 @@ def build_initramfs(init: Path, busybox: Path, rc_text: str, root_password: str
"nobody:x:65534:\n"
"daemon:x:1:\n")
for rel, src in (bundles or []):
dst = root / rel.lstrip("/")
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(src, dst)
dst.chmod(0o644)
# The staging tree is owned by the host user and mkdtemp makes the
# top dir 0700; GNU cpio preserves both, so without this the guest's
# "/" would be mode 0700 owned by uid 1000 -- fine for root services,
@ -380,6 +387,11 @@ def main() -> int:
"build it static, cache in ~/.cache/bajia")
ap.add_argument("--config", type=Path,
help="use this init.rc instead of the bundled test config")
ap.add_argument("--bundle", action="append", default=[],
metavar="REL=HOSTPATH",
help="copy HOSTPATH into the initramfs at absolute REL "
"(repeatable; e.g. --bundle "
"etc/bajia/extra.rc=/tmp/extra.rc for @import tests)")
ap.add_argument("--root-password", default=None,
help="password for the root account in the guest "
"(default: passwordless login)")
@ -435,8 +447,20 @@ def main() -> int:
"safest inside an initramfs")
rc_text = args.config.read_text() if args.config else DEFAULT_RC
bundles: list[tuple[str, Path]] = []
for spec in args.bundle:
rel, _, path = spec.partition("=")
src = Path(path)
if not src.is_file():
sys.exit(f"--bundle: host file not found: {src}")
if not rel.startswith("/"):
sys.exit(f"--bundle: REL must be absolute, got: {rel!r}")
if ".." in [c for c in Path(rel).parts]:
sys.exit(f"--bundle: REL must not contain '..': {rel}")
bundles.append((rel, src))
initrd = build_initramfs(init, busybox, rc_text, args.root_password,
selinux=args.selinux, keep=args.keep_initramfs)
selinux=args.selinux, keep=args.keep_initramfs,
bundles=bundles)
print("initramfs:", initrd, f"({initrd.stat().st_size / 1024:.0f} KB)")
cmd = qemu_command(kernel, initrd, args)