1
1
mirror of https://github.com/mgree/ffs.git synced 2024-10-05 15:18:20 +03:00

fsync, improved output test

This commit is contained in:
Michael Greenberg 2021-06-16 19:51:54 -04:00
parent fef31489de
commit 9d0ae6d682
5 changed files with 112 additions and 12 deletions

View File

@ -879,6 +879,18 @@ impl Filesystem for FS {
reply.ok()
}
fn fsync(
&mut self,
_req: &Request<'_>,
_ino: u64,
_fh: u64,
_datasync: bool,
reply: ReplyEmpty,
) {
self.sync();
reply.ok();
}
// TODO
fn copy_file_range(
&mut self,
@ -896,18 +908,6 @@ impl Filesystem for FS {
reply.error(libc::ENOSYS);
}
// TODO
fn fsync(
&mut self,
_req: &Request<'_>,
_ino: u64,
_fh: u64,
_datasync: bool,
reply: ReplyEmpty,
) {
reply.error(libc::ENOSYS);
}
// TODO
fn ioctl(
&mut self,

1
tests/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
fsync

27
tests/fsync.c Normal file
View File

@ -0,0 +1,27 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
char *path;
if (argc == 1) {
path = ".";
} else if (argc == 2) {
path = argv[1];
} else if (argc > 2) {
fprintf(stderr, "Usage: %s [path]\n", argv[0]);
return 1;
}
int fd = open(path, O_RDONLY);
if (fd == -1) {
perror(argv[0]);
return 2;
}
fsync(fd);
close(fd);
return 0;
}

69
tests/fsync.sh Executable file
View File

@ -0,0 +1,69 @@
#!/bin/sh
fail() {
echo FAILED: $1
if [ "$MNT" ]
then
cd
umount "$MNT"
rmdir "$MNT"
rm "$TGT"
rm "$TGT2"
fi
exit 1
}
gcc -o fsync fsync.c || fail gcc
MNT=$(mktemp -d)
TGT=$(mktemp)
ffs -o "$TGT" "$MNT" ../json/object.json &
PID=$!
sleep 2
mkdir "$MNT"/pockets
echo keys >"$MNT"/pockets/pants
echo pen >"$MNT"/pockets/shirt
./fsync "$MNT"
cat "$TGT"
stat "$TGT"
[ -f "$TGT" ] || fail output1
[ -s "$TGT" ] || fail output2
umount "$MNT" || fail unmount1
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process1
# easiest to just test using ffs, but would be cool to get outside validation
#if [ "$RUNNER_OS" = "Linux" ]
#then
# echo "ABORTING TEST, currently broken on Linux (see https://github.com/cberner/fuser/issues/153)"
# exit 0
#fi
ffs --no-output "$MNT" "$TGT" >"$TGT2" &
PID=$!
sleep 2
case $(ls "$MNT") in
(eyes*fingernails*human*name*pockets) ;;
(*) fail ls1;;
esac
case $(ls "$MNT"/pockets) in
(pants*shirt) ;;
(*) fail ls2;;
esac
[ "$(cat $MNT/name)" = "Michael Greenberg" ] || fail name
[ "$(cat $MNT/eyes)" -eq 2 ] || fail eyes
[ "$(cat $MNT/fingernails)" -eq 10 ] || fail fingernails
[ "$(cat $MNT/human)" = "true" ] || fail human
[ "$(cat $MNT/pockets/pants)" = "keys" ] || fail pants
[ "$(cat $MNT/pockets/shirt)" = "pen" ] || fail shirt
umount "$MNT" || fail unmount2
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process2
rmdir "$MNT" || fail mount
rm "$TGT"
rm "$TGT2"

View File

@ -62,6 +62,9 @@ umount "$MNT" || fail unmount2
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process2
stat "$TGT2"
[ -f "$TGT2" ] || fail tgt2
[ -s "$TGT2" ] && fail tgt2_nonemptty
rmdir "$MNT" || fail mount
rm "$TGT"