10 #include "test_common.h"
14 /******************************************************************
16 ******************************************************************/
24 #define EXIT_RET(err) \
33 void t_touch(const char *path)
37 fd = open(path, O_RDWR|O_CREAT, 0644);
39 printf("open(%s) error: %s\n", path, strerror(errno));
45 printf("close(%s) error: %s\n", path, strerror(errno));
50 /* XXX Now libsysio don't support mcreate */
51 void t_create(const char *path)
57 rc = mknod(path, S_IFREG | 0644, 0);
59 printf("mknod(%s) error: %s\n", path, strerror(errno));
65 void t_link(const char *src, const char *dst)
71 printf("link(%s -> %s) error: %s\n", src, dst, strerror(errno));
76 void t_unlink(const char *path)
82 printf("unlink(%s) error: %s\n", path, strerror(errno));
87 void t_mkdir(const char *path)
91 rc = mkdir(path, 00644);
93 printf("mkdir(%s) error: %s\n", path, strerror(errno));
98 void t_rmdir(const char *path)
104 printf("rmdir(%s) error: %s\n", path, strerror(errno));
109 void t_symlink(const char *src, const char *new)
113 rc = symlink(src, new);
115 printf("symlink(%s<-%s) error: %s\n", src, new, strerror(errno));
120 #define MKDEV(a,b) (((a) << 8) | (b))
121 void t_mknod(const char *path, mode_t mode, int major, int minor)
125 rc = mknod(path, mode, MKDEV(5, 4));
127 printf("mknod(%s) error: %s\n", path, strerror(errno));
132 void t_chmod_raw(const char *path, mode_t mode)
136 rc = chmod(path, mode);
138 printf("chmod(%s) error: %s\n", path, strerror(errno));
143 void t_chmod(const char *path, const char *format, ...)
147 void t_rename(const char *oldpath, const char *newpath)
151 rc = rename(oldpath, newpath);
153 printf("rename(%s -> %s) error: %s\n",
154 oldpath, newpath, strerror(errno));
159 int t_open_readonly(const char *path)
163 fd = open(path, O_RDONLY);
165 printf("open(%s) error: %s\n", path, strerror(errno));
171 int t_open(const char *path)
175 fd = open(path, O_RDWR);
177 printf("open(%s) error: %s\n", path, strerror(errno));
189 printf("close(%d) error: %s\n", fd, strerror(errno));
194 int t_check_stat(const char *name, struct stat *buf)
199 rc = lstat(name, &stat);
201 printf("error %d stat %s\n", rc, name);
205 memcpy(buf, &stat, sizeof(*buf));
210 int t_check_stat_fail(const char *name)
215 rc = lstat(name, &stat);
217 printf("%s still exists\n", name);
224 void t_echo_create(const char *path, const char *str)
228 fd = open(path, O_RDWR|O_CREAT, 0644);
230 printf("open(%s) error: %s\n", path, strerror(errno));
234 if (write(fd, str, strlen(str)+1) != strlen(str)+1) {
235 printf("write(%s) error: %s\n", path, strerror(errno));
241 printf("close(%s) error: %s\n", path, strerror(errno));
246 void _t_grep(const char *path, char *str, int should_contain)
252 fd = t_open_readonly(path);
253 if (lseek(fd, 0, SEEK_SET) == -1) {
254 printf("pread_once: seek to 0 error: %s\n", strerror(errno));
258 rc = read(fd, buf, 1023);
260 printf("grep: read error: %s\n", strerror(errno));
266 if ((strstr(buf, str) != 0) ^ should_contain) {
267 printf("grep: can't find string %s\n", str);
272 void t_grep(const char *path, char *str)
274 _t_grep(path, str, 1);
277 void t_grep_v(const char *path, char *str)
279 _t_grep(path, str, 0);