From: ericm Date: Thu, 4 Sep 2003 09:58:57 +0000 (+0000) Subject: [liblustre]: add test_common X-Git-Tag: v1_7_0_51~2^7~606 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=e5258a420cd3ea3b970a242d1d2ff02dd3bbc3ee;p=fs%2Flustre-release.git [liblustre]: add test_common --- diff --git a/lustre/liblustre/test_common.c b/lustre/liblustre/test_common.c new file mode 100644 index 0000000..f7b8d63 --- /dev/null +++ b/lustre/liblustre/test_common.c @@ -0,0 +1,186 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "test_common.h" + +extern int errno; + +int exit_on_err = 1; + +/****************************************************************** + * util functions + ******************************************************************/ + +#define EXIT(err) \ + do { \ + if (exit_on_err) \ + exit(err); \ + } while (0) + +#define EXIT_RET(err) \ + do { \ + if (exit_on_err) \ + exit(err); \ + else \ + return (err); \ + } while (0) + + +void t_touch(const char *path) +{ + int fd, rc; + + fd = open(path, O_RDWR|O_CREAT, 0644); + if (fd < 0) { + printf("open(%s) error: %s\n", path, strerror(errno)); + EXIT(fd); + } + + rc = close(fd); + if (rc) { + printf("close(%s) error: %s\n", path, strerror(errno)); + EXIT(rc); + } +} + +/* XXX Now libsysio don't support mcreate */ +void t_create(const char *path) +{ + return t_touch(path); +#if 0 + int rc; + + rc = mknod(path, S_IFREG | 0644, 0); + if (rc) { + printf("mknod(%s) error: %s\n", path, strerror(errno)); + exit(-1); + } +#endif +} + +void t_unlink(const char *path) +{ + int rc; + + rc = unlink(path); + if (rc) { + printf("unlink(%s) error: %s\n", path, strerror(errno)); + EXIT(-1); + } +} + +void t_mkdir(const char *path) +{ + int rc; + + rc = mkdir(path, 00644); + if (rc < 0) { + printf("mkdir(%s) error: %s\n", path, strerror(errno)); + EXIT(1); + } +} + +void t_rmdir(const char *path) +{ + int rc; + + rc = rmdir(path); + if (rc) { + printf("rmdir(%s) error: %s\n", path, strerror(errno)); + EXIT(1); + } +} + +void t_symlink(const char *src, const char *new) +{ + int rc; + + rc = symlink(src, new); + if (rc) { + printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno)); + EXIT(1); + } +} + +#define MKDEV(a,b) (((a) << 8) | (b)) +void t_mknod(const char *path, mode_t mode, int major, int minor) +{ + int rc; + + rc = mknod(path, mode, MKDEV(5, 4)); + if (rc) { + printf("mknod(%s) error: %s\n", path, strerror(errno)); + EXIT(1); + } +} + +void t_chmod_raw(const char *path, mode_t mode) +{ + int rc; + + rc = chmod(path, mode); + if (rc) { + printf("chmod(%s) error: %s\n", path, strerror(errno)); + EXIT(1); + } +} + +void t_chmod(const char *path, const char *format, ...) +{ +} + +int t_open_readonly(const char *path) +{ + int fd; + + fd = open(path, O_RDONLY); + if (fd < 0) { + printf("open(%s) error: %s\n", path, strerror(errno)); + EXIT_RET(fd); + } + return fd; +} + +int t_open(const char *path) +{ + int fd; + + fd = open(path, O_RDWR); + if (fd < 0) { + printf("open(%s) error: %s\n", path, strerror(errno)); + EXIT_RET(fd); + } + return fd; +} + +void t_close(int fd) +{ + int rc; + + rc = close(fd); + if (rc < 0) { + printf("close(%d) error: %s\n", fd, strerror(errno)); + EXIT(1); + } +} + +int t_check_stat(const char *name, struct stat *buf) +{ + struct stat stat; + int rc; + + rc = lstat(name, &stat); + if (rc) { + printf("error %d stat %s\n", rc, name); + EXIT_RET(rc); + } + if (buf) + memcpy(buf, &stat, sizeof(*buf)); + + return 0; +} diff --git a/lustre/liblustre/test_common.h b/lustre/liblustre/test_common.h new file mode 100644 index 0000000..3fa9fd4 --- /dev/null +++ b/lustre/liblustre/test_common.h @@ -0,0 +1,20 @@ +#ifndef __TEST_COMMON__H +#define __TEST_COMMON__H + +extern int exit_on_err; + +void t_touch(const char *path); +void t_create(const char *path); +void t_unlink(const char *path); +void t_mkdir(const char *path); +void t_rmdir(const char *path); +void t_symlink(const char *src, const char *new); +void t_mknod(const char *path, mode_t mode, int major, int minor); +void t_chmod_raw(const char *path, mode_t mode); +void t_chmod(const char *path, const char *format, ...); +int t_open_readonly(const char *path); +int t_open(const char *path); +void t_close(int fd); +int t_check_stat(const char *name, struct stat *buf); + +#endif