Skip to content

Commit

Permalink
Merge pull request torvalds#212 from opurdila/lklfuse-tests
Browse files Browse the repository at this point in the history
Disable multithreaded support in lklfuse
  • Loading branch information
Octavian Purdila authored Aug 19, 2016
2 parents f127d50 + 5c74652 commit b4e94fe
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 37 deletions.
11 changes: 11 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ long lkl_mount_dev(unsigned int disk_id, const char *fs_type, int flags,
*/
long lkl_umount_dev(unsigned int disk_id, int flags, long timeout_ms);

/**
* lkl_umount_timeout - umount filesystem with timeout
*
* @path - the path to unmount
* @flags - umount flags
* @timeout_ms - timeout to wait for the kernel to flush closed files so that
* umount can succeed
* @returns - 0 on success, a negative value on error
*/
long lkl_umount_timeout(char *path, int flags, long timeout_ms);

/**
* lkl_opendir - open a directory
*
Expand Down
30 changes: 19 additions & 11 deletions tools/lkl/lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,39 @@ long lkl_mount_dev(unsigned int disk_id, const char *fs_type, int flags,
return 0;
}

long lkl_umount_dev(unsigned int disk_id, int flags, long timeout_ms)
long lkl_umount_timeout(char *path, int flags, long timeout_ms)
{
char dev_str[] = { "/dev/xxxxxxxx" };
char mnt_str[] = { "/mnt/xxxxxxxx" };
long incr = 10000000; /* 10 ms */
struct lkl_timespec ts = {
.tv_sec = 0,
.tv_nsec = incr,
};
unsigned int dev;
int err;

dev = get_virtio_blkdev(disk_id);

snprintf(dev_str, sizeof(dev_str), "/dev/%08x", dev);
snprintf(mnt_str, sizeof(mnt_str), "/mnt/%08x", dev);
long err;

do {
err = lkl_sys_umount(mnt_str, flags);
err = lkl_sys_umount(path, flags);
if (err == -LKL_EBUSY) {
lkl_sys_nanosleep(&ts, NULL);
timeout_ms -= incr / 1000000;
}
} while (err == -LKL_EBUSY && timeout_ms > 0);

return err;
}

long lkl_umount_dev(unsigned int disk_id, int flags, long timeout_ms)
{
char dev_str[] = { "/dev/xxxxxxxx" };
char mnt_str[] = { "/mnt/xxxxxxxx" };
unsigned int dev;
int err;

dev = get_virtio_blkdev(disk_id);

snprintf(dev_str, sizeof(dev_str), "/dev/%08x", dev);
snprintf(mnt_str, sizeof(mnt_str), "/mnt/%08x", dev);

err = lkl_umount_timeout(mnt_str, flags, timeout_ms);
if (err)
return err;

Expand Down
6 changes: 3 additions & 3 deletions tools/lkl/lklfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@ int main(int argc, char **argv)
}

if (mt)
ret = fuse_loop_mt(fuse);
else
ret = fuse_loop(fuse);
fprintf(stderr, "warning: multithreaded mode not supported\n");

ret = fuse_loop(fuse);

stop_lkl();

Expand Down
5 changes: 5 additions & 0 deletions tools/lkl/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ define gdb_test
TEST_CMD="gdb --args" ./boot.sh -t $1
endef

define lklfuse
for fs in $(FS_TYPES); do ./lklfuse.sh -t $$fs || exit 1; done
endef

define for_fs
for fs in $(FS_TYPES); do $(call $1,$$fs); done
endef
Expand Down Expand Up @@ -41,6 +45,7 @@ endif

test:
$(call run,)
$(call lklfuse)
$(HIJACK_TEST)
./net.sh

Expand Down
54 changes: 46 additions & 8 deletions tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static int test_epoll(char *str, int len)

static char mnt_point[32];

static int test_mount(char *str, int len)
static int test_mount_dev(char *str, int len)
{
long ret;

Expand All @@ -500,11 +500,11 @@ static int test_mount(char *str, int len)
return TEST_FAILURE;
}

static int test_chdir(char *str, int len)
static int test_chdir(char *str, int len, const char *path)
{
long ret;

ret = lkl_sys_chdir(mnt_point);
ret = lkl_sys_chdir(path);

snprintf(str, len, "%ld", ret);

Expand Down Expand Up @@ -556,7 +556,7 @@ static int test_getdents64(char *str, int len)
return TEST_SUCCESS;
}

static int test_umount(char *str, int len)
static int test_umount_dev(char *str, int len)
{
long ret, ret2, ret3;

Expand All @@ -574,6 +574,36 @@ static int test_umount(char *str, int len)
return TEST_FAILURE;
}

static int test_mount_fs(char *str, int len, char *fs)
{
long ret;

ret = lkl_mount_fs(fs);

snprintf(str, len, "%s: %ld", fs, ret);

if (ret == 0)
return TEST_SUCCESS;

return TEST_FAILURE;
}

static int test_umount_fs(char *str, int len, char *fs)
{
long ret, ret2, ret3;

ret = lkl_sys_close(dir_fd);
ret2 = lkl_sys_chdir("/");
ret3 = lkl_umount_timeout(fs, 0, 1000);

snprintf(str, len, "%s: %ld %ld %ld", fs, ret, ret2, ret3);

if (!ret && !ret2 && !ret3)
return TEST_SUCCESS;

return TEST_FAILURE;
}

static int test_lo_ifup(char *str, int len)
{
long ret;
Expand Down Expand Up @@ -781,7 +811,8 @@ int main(int argc, char **argv)

lkl_host_ops.print = printk;

TEST(disk_add);
if (cla.disk_filename)
TEST(disk_add);
#ifndef __MINGW32__
if (cla.tap_ifname)
TEST(netdev_add);
Expand All @@ -807,11 +838,18 @@ int main(int argc, char **argv)
#endif /* __MINGW32__ */
TEST(pipe2);
TEST(epoll);
TEST(mount);
TEST(chdir);
TEST(mount_fs, "proc");
TEST(chdir, "proc");
TEST(opendir);
TEST(getdents64);
TEST(umount);
TEST(umount_fs, "proc");
if (cla.disk_filename) {
TEST(mount_dev);
TEST(chdir, mnt_point);
TEST(opendir);
TEST(getdents64);
TEST(umount_dev);
}
TEST(lo_ifup);
TEST(mutex);
TEST(semaphore);
Expand Down
71 changes: 71 additions & 0 deletions tools/lkl/tests/lklfuse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh -e

if ! [ -x ../lklfuse ]; then
echo "lklfuse not available, skipping tests"
exit 0
fi

if ! [ -e /dev/fuse ]; then
echo "fuse not available, skipping tests"
exit 0
fi

if [ "$1" = "-t" ]; then
shift
fstype=$1
shift
fi

if [ -z "$fstype" ]; then
fstype="ext4"
fi

file=`mktemp`
dir=`mktemp -d`

cleanup()
{
cd $olddir
sleep 1
fusermount -u $dir
rm $file
rmdir $dir
}

basic()
{
touch a
if ! [ -e ]; then exit 1; fi
rm a
mkdir a
if ! [ -d ]; then exit 1; fi
rmdir a
}

trap cleanup EXIT

olddir=`pwd`

# create empty filesystem
dd if=/dev/zero of=$file bs=1024 seek=500000 count=1
yes | mkfs.$fstype $file

# mount with fuse
../lklfuse $file $dir -o type=$fstype

cd $dir

# run basic tests
basic

# run stress-ng
if which stress-ng; then
if [ "$fstype" = "vfat" ]; then
exclude="chmod,filename,link,mknod,symlink,xattr"
fi
stress-ng --class filesystem --all 0 --timeout 10 \
--exclude fiemap,$exclude --fallocate-bytes 50m \
--sync-file-bytes 50m
else
echo "could not find stress-ng, skipping"
fi
29 changes: 14 additions & 15 deletions tools/lkl/tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
#define TEST_FAILURE 0
#define MAX_MSG_LEN 60


static int g_test_pass = 0;
#define TEST(name) { \
int ret = do_test(#name, test_##name); \
if (!ret) g_test_pass = -1; \
}

static int do_test(char *name, int (*fn)(char *, int))
{
char str[MAX_MSG_LEN];
int result;

result = fn(str, sizeof(str));
printf("%-20s %s [%s]\n", name,
result == TEST_SUCCESS ? "passed" : "failed", str);
return result;
#define TEST(name, ...) \
{ \
char str[MAX_MSG_LEN]; \
int (*fn)(char *str, int len, ...); \
int ret; \
\
fn = (int (*)(char *str, int len, ...))test_##name; \
ret = fn(str, sizeof(str), ##__VA_ARGS__); \
if (!ret) \
g_test_pass = -1; \
\
printf("%-20s %s [%s]\n", #name, \
ret == TEST_SUCCESS ? "passed" : "failed", str); \
}

0 comments on commit b4e94fe

Please sign in to comment.