From e14ef4b8a90a0f7866688026b4325c2ebb7deb36 Mon Sep 17 00:00:00 2001 From: Ernest Wong Date: Fri, 7 Sep 2018 12:34:17 +1200 Subject: [PATCH] Filesystem: Add tests for whole-file locks. --- tests/devices/virtio_9p.js | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/devices/virtio_9p.js b/tests/devices/virtio_9p.js index 5b4dee00..95bf1193 100755 --- a/tests/devices/virtio_9p.js +++ b/tests/devices/virtio_9p.js @@ -957,6 +957,49 @@ const tests = done(); }, }, + { + name: "File Locks", + timeout: 60, + start: () => + { + emulator.serial0_send("touch /mnt/file\n"); + emulator.serial0_send("mkfifo /mnt/fifo1\n"); + emulator.serial0_send("mkfifo /mnt/fifo2\n"); + + emulator.serial0_send("flock -s /mnt/file -c 'cat /mnt/fifo1 >> /mnt/file' &\n"); + emulator.serial0_send("flock -s /mnt/file -c 'echo lock-shared-2 >> /mnt/file' \n"); + emulator.serial0_send("echo lock-shared-1 > /mnt/fifo1\n"); + + emulator.serial0_send("flock -x /mnt/file -c 'cat /mnt/fifo1 >> /mnt/file' &\n"); + emulator.serial0_send("flock -x /mnt/file -c 'echo lock-exclusive-2 >> /mnt/file' &\n"); + emulator.serial0_send("echo lock-exclusive-1 > /mnt/fifo1\n"); + + emulator.serial0_send("flock -s /mnt/file -c 'cat /mnt/fifo1 >> /mnt/file' &\n"); + emulator.serial0_send("flock -s /mnt/file -c 'cat /mnt/fifo2 >> /mnt/file' &\n"); + emulator.serial0_send("flock -x /mnt/file -c 'echo lock-exclusive-3 >> /mnt/file' &\n"); + emulator.serial0_send("echo lock-shared-4 > /mnt/fifo2\n"); + emulator.serial0_send("echo lock-shared-3 > /mnt/fifo1\n"); + + emulator.serial0_send("echo start-capture;\\\n"); + emulator.serial0_send("cat /mnt/file;\\\n"); + emulator.serial0_send("echo done-locks\n"); + }, + capture_trigger: "start-capture", + end_trigger: "done-locks", + end: (capture, done) => + { + assert_equal(capture, + "lock-shared-2\n" + + "lock-shared-1\n" + + "lock-exclusive-1\n" + + "lock-exclusive-2\n" + + "lock-shared-4\n" + + "lock-shared-3\n" + + "lock-exclusive-3\n"); + + done(); + }, + }, { name: "Stress Files", timeout: 360,