From 5728fb39d8be65c1ea9a31355447050270a2a962 Mon Sep 17 00:00:00 2001 From: ericm Date: Wed, 17 Dec 2003 14:04:15 +0000 Subject: [PATCH] liblustre: add sanity test for readdir, but one test still fail, need to be fixed tomorrow. --- lustre/liblustre/tests/sanity.c | 61 ++++++++++++++++++++++++++++++++++-- lustre/liblustre/tests/test_common.c | 23 ++++++++++++++ lustre/liblustre/tests/test_common.h | 2 +- 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/lustre/liblustre/tests/sanity.c b/lustre/liblustre/tests/sanity.c index 62af498..8b855fc 100644 --- a/lustre/liblustre/tests/sanity.c +++ b/lustre/liblustre/tests/sanity.c @@ -280,7 +280,7 @@ void t10() LEAVE(); } -void t100() +void t11() { char *base="/mnt/lustre"; char path[4096], path2[4096]; @@ -316,6 +316,58 @@ void t100() LEAVE(); } +void t12() +{ + char *dir="/mnt/lustre/test_t11_dir"; + char *file1="/mnt/lustre/test_t11_dir/file1"; + char *file2="/mnt/lustre/test_t11_dir/file2"; + char *file3="/mnt/lustre/test_t11_dir/file3"; + char buf[1024*128]; + int fd; + ENTRY("simple readdir"); + + t_mkdir(dir); + t_touch(file1); + t_touch(file2); + t_touch(file3); + fd = t_open(dir); + t_ls(fd, buf, sizeof(buf)); + t_close(fd); + t_unlink(file1); + t_unlink(file2); + t_unlink(file3); + t_rmdir(dir); + LEAVE(); +} + +void t13() +{ + char *dir="/mnt/lustre/test_t12_dir/"; + char name[1024]; + char buf[1024*4]; + const int nfiles = 300; + char *prefix = "test12_file_name_prefix_PPPPPPPPPP___"; + int fd, i; + ENTRY("large directory readdir"); + + t_mkdir(dir); + printf("Creating %d files...\n", nfiles); + for (i = 0; i < nfiles; i++) { + sprintf(name, "%s%s%05d", dir, prefix, i); + t_touch(name); + } + fd = t_open(dir); + t_ls(fd, buf, sizeof(buf)); + t_close(fd); + printf("Cleanup...\n"); + for (i = 0; i < nfiles; i++) { + sprintf(name, "%s%s%05d", dir, prefix, i); + t_unlink(name); + } + t_rmdir(dir); + LEAVE(); +} + extern void __liblustre_setup_(void); extern void __liblustre_cleanup_(void); @@ -374,8 +426,11 @@ int main(int argc, char * const argv[]) t8(); t9(); t10(); - - t100(); + t11(); + t12(); +/* + t13(); +*/ #endif printf("liblustre is about shutdown\n"); diff --git a/lustre/liblustre/tests/test_common.c b/lustre/liblustre/tests/test_common.c index 210d57e..c5c6e45 100644 --- a/lustre/liblustre/tests/test_common.c +++ b/lustre/liblustre/tests/test_common.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "test_common.h" @@ -278,3 +279,25 @@ void t_grep_v(const char *path, char *str) { _t_grep(path, str, 0); } + +void t_ls(int fd, char *buf, int size) +{ + struct dirent *ent; + int rc, pos; + off_t base = 0; + + printf("dir entries listing...\n"); + while ((rc = getdirentries(fd, buf, size, &base)) > 0) { + pos = 0; + while (pos < rc) { + ent = (struct dirent *) ((char*) buf + pos); + printf("%s\n", ent->d_name); + pos += ent->d_reclen; + } + } + + if (rc < 0) { + printf("getdents error %d\n", rc); + EXIT(-1); + } +} diff --git a/lustre/liblustre/tests/test_common.h b/lustre/liblustre/tests/test_common.h index af638f2..91d9906 100644 --- a/lustre/liblustre/tests/test_common.h +++ b/lustre/liblustre/tests/test_common.h @@ -24,8 +24,8 @@ void t_close(int fd); int t_check_stat(const char *name, struct stat *buf); int t_check_stat_fail(const char *name); void t_echo_create(const char *path, const char *str); -//int t_pread_once(const char *path, char *buf, size_t size, off_t offset); void t_grep(const char *path, char *str); void t_grep_v(const char *path, char *str); +void t_ls(int fd, char *buf, int size); #endif -- 1.8.3.1