Skip to content

Instantly share code, notes, and snippets.

@erikarvstedt
Last active March 10, 2020 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikarvstedt/e3d38fcfa0201c9742092f50d2d297f9 to your computer and use it in GitHub Desktop.
Save erikarvstedt/e3d38fcfa0201c9742092f50d2d297f9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
export TMPDIR=$(mktemp -d /tmp/demo-xchg-cache-bug.XXX)
trap "rm -rf $TMPDIR" EXIT
mkdir -p $TMPDIR
nix-build --out-link $TMPDIR/vm - <<'EOF'
(import "${builtins.fetchTarball {
# unstable
url = https://github.com/NixOS/nixpkgs-channels/archive/82b54d490663b6d87b7b34b9cfc0985df8b49c7d.tar.gz;
sha256 = "12gpsif48g5b4ys45x36g4vdf0srgal4c96351m7gd2jsgvdllyf";
}}/nixos/tests/make-test-python.nix" {
name = "xchg-dir-bug";
machine = {
networking.useDHCP = false;
};
testScript = null;
} {}).driver
EOF
read -d '' testScript <<'EOF' || true
def check_file_content_transfer(fname, content):
# write file on host
print(f"Writing to xchg/{fname}, content: '{content}'. ", end='')
with open(os.path.join(os.getenv("TMPDIR"), "vm-state-machine/xchg", fname), "w") as f:
print(content, file=f)
# read file in vm
vm_content = machine.execute(f"cat /tmp/xchg/{fname}")[1].rstrip()
if vm_content == content:
print("Success, VM content identical.")
else:
print(f"Error, VM content differs. Got content '{vm_content}'")
def demo_bug(fname="f"):
check_file_content_transfer(fname, "1")
check_file_content_transfer(fname, "2")
start_all()
machine.wait_for_unit("default.target")
print()
print("=" * 80)
demo_bug()
print()
print("Re-Mounting without cache")
machine.execute(f"umount /tmp/xchg && mount -t 9p xchg /tmp/xchg -o trans=virtio")
demo_bug()
print()
# Drop into REPL
# import code
# code.interact(local=globals())
EOF
(cd $TMPDIR;
NIX_DISK_IMAGE=$TMPDIR/img.qcow2 USE_TMPDIR=1 \
tests="$testScript" \
QEMU_OPTS='-m 1024 -smp 2 -nographic' $TMPDIR/vm/bin/nixos-test-driver)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment