Skip to content

Commit

Permalink
lkl tools: tests: move disk tests to a separate file
Browse files Browse the repository at this point in the history
Since we run the disk tests for multiple filesystem types, lets move
them to a separate file, so that we don't run the rest of the tests for
each filesystem type.

While at it, add tests for opendir, readdir, closedir.

Signed-off-by: Octavian Purdila <tavi@cs.pub.ro>
  • Loading branch information
tavip committed Dec 22, 2017
1 parent 3b08376 commit 835d56a
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 114 deletions.
1 change: 1 addition & 0 deletions tools/lkl/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tests/valgrind*.xml
*.exe
*.dll
tests/net-test
tests/disk
7 changes: 4 additions & 3 deletions tools/lkl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ ifneq (,$(filter $(OUTPUT_DEF),__ANDROID__))
$(OUTPUT)tests/boot: LDLIBS += -lc
endif
$(OUTPUT)tests/net-test: $(OUTPUT)tests/net-test-in.o $(OUTPUT)liblkl.a
$(TEST_TARGETS): $(OUTPUT)tests/boot $(OUTPUT)tests/net-test
$(OUTPUT)tests/disk: $(OUTPUT)tests/disk-in.o $(OUTPUT)liblkl.a
$(TEST_TARGETS): $(OUTPUT)tests/boot $(OUTPUT)tests/net-test $(OUTPUT)tests/disk

# because of libdl, liblkl-hijack will not compile on windows
# fortunately, the test target will handle a missing libhijack.so correctly
Expand All @@ -159,7 +160,7 @@ $(OUTPUT)lib/lkl.o:
$(OUTPUT)liblkl.a: $(OUTPUT)lib/lkl-in.o $(OUTPUT)lib/lkl.o
$(QUIET_AR)$(AR) -rc $@ $^

$(OUTPUT)liblkl$(SOSUF) $(OUTPUT)liblkl-hijack$(SOSUF) $(OUTPUT)lklfuse$(EXESUF) $(OUTPUT)fs2tar$(EXESUF) $(OUTPUT)cptofs$(EXESUF) $(OUTPUT)tests/boot $(OUTPUT)tests/net-test:
$(OUTPUT)liblkl$(SOSUF) $(OUTPUT)liblkl-hijack$(SOSUF) $(OUTPUT)lklfuse$(EXESUF) $(OUTPUT)fs2tar$(EXESUF) $(OUTPUT)cptofs$(EXESUF) $(OUTPUT)tests/boot $(OUTPUT)tests/net-test $(OUTPUT)tests/disk:
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

$(OUTPUT)cpfromfs$(EXESUF): cptofs$(EXESUF)
Expand All @@ -183,7 +184,7 @@ clean:
$(call QUIET_CLEAN, "host libraries")$(RM) $(OUTPUT)/liblkl.a liblkl$(SOSUF)
$(call QUIET_CLEAN, "hijack library")$(RM) $(OUTPUT)/liblkl-hijack$(SOSUF)
$(call QUIET_CLEAN, programs)$(RM) $(ALL_PROGRAMS)
$(call QUIET_CLEAN, tests)$(RM) tests/boot tests/net-test
$(call QUIET_CLEAN, tests)$(RM) tests/boot tests/net-test tests/disk

$(TEST_TARGETS):
$(MAKE) -C tests $@
Expand Down
1 change: 1 addition & 0 deletions tools/lkl/tests/Build
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
boot-y += boot.o cla.o
disk-y += disk.o cla.o
net-test-y += net-test.o cla.o
7 changes: 4 additions & 3 deletions tools/lkl/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ define for_fs
for fs in $(FS_TYPES); do $(call $1,$$fs); done
endef

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

QUICK?=0
Expand All @@ -45,7 +45,8 @@ endif

ifneq ($(LKL_ANDROID_TEST),1)
test:
$(call run,)
./boot
$(call disk)
$(call lklfuse)
$(HIJACK_TEST)
./net.sh
Expand Down
106 changes: 1 addition & 105 deletions tools/lkl/tests/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@

static struct {
int printk;
const char *disk_filename;
const char *fstype;
int part;
} cla;

struct cl_arg args[] = {
{"printk", 'p', "show Linux printks", 0, CL_ARG_BOOL, &cla.printk},
{"disk", 'd', "disk file to use", 1, CL_ARG_STR, &cla.disk_filename},
{"partition", 'P', "partition to mount", 1, CL_ARG_INT, &cla.part},
{"type", 't', "filesystem type", 1, CL_ARG_STR, &cla.fstype},
{0},
};

Expand Down Expand Up @@ -292,52 +286,6 @@ int test_stat(char *str, int len)
return TEST_FAILURE;
}

static struct lkl_disk disk;
static int disk_id = -1;

int test_disk_add(char *str, int len)
{
#ifdef __MINGW32__
disk.handle = CreateFile(cla.disk_filename, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (!disk.handle)
#else
disk.fd = open(cla.disk_filename, O_RDWR);
if (disk.fd < 0)
#endif
goto out_unlink;

disk.ops = NULL;

disk_id = lkl_disk_add(&disk);
if (disk_id < 0)
goto out_close;

goto out;

out_close:
#ifdef __MINGW32__
CloseHandle(disk.handle);
#else
close(disk.fd);
#endif

out_unlink:
#ifdef __MINGW32__
DeleteFile(cla.disk_filename);
#else
unlink(cla.disk_filename);
#endif

out:
snprintf(str, len, "%x %d", disk.fd, disk_id);

if (disk_id >= 0)
return TEST_SUCCESS;

return TEST_FAILURE;
}

static int test_pipe2(char *str, int len)
{
int pipe_fds[2];
Expand Down Expand Up @@ -457,23 +405,6 @@ static int test_epoll(char *str, int len)
return TEST_SUCCESS;
}

static char mnt_point[32];

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

ret = lkl_mount_dev(disk_id, cla.part, cla.fstype, 0, NULL, mnt_point,
sizeof(mnt_point));

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

if (ret == 0)
return TEST_SUCCESS;

return TEST_FAILURE;
}

static int test_chdir(char *str, int len, const char *path)
{
long ret;
Expand Down Expand Up @@ -528,24 +459,6 @@ static int test_getdents64(char *str, int len)
return TEST_SUCCESS;
}

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

ret = lkl_sys_close(dir_fd);

ret2 = lkl_sys_chdir("/");

ret3 = lkl_umount_dev(disk_id, cla.part, 0, 1000);

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

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

return TEST_FAILURE;
}

static int test_mount_fs(char *str, int len, char *fs)
{
long ret;
Expand Down Expand Up @@ -751,21 +664,18 @@ static int test_join(char *str, int len)
}
}


int main(int argc, const char **argv)
{
if (parse_args(argc, argv, args) < 0)
return -1;


TEST(mutex);
TEST(semaphore);
TEST(join);

if (!cla.printk)
lkl_host_ops.print = NULL;

if (cla.disk_filename)
TEST(disk_add);
lkl_start_kernel(&lkl_host_ops, "mem=16M loglevel=8");

TEST(getpid);
Expand All @@ -791,13 +701,6 @@ int main(int argc, const char **argv)
TEST(opendir);
TEST(getdents64);
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(gettid);
TEST(syscall_thread);
Expand All @@ -812,12 +715,5 @@ int main(int argc, const char **argv)

lkl_sys_halt();

lkl_disk_remove(disk);
#ifdef __MINGW32__
CloseHandle(disk.handle);
#else
close(disk.fd);
#endif

return g_test_pass;
}
Loading

0 comments on commit 835d56a

Please sign in to comment.