zvfs: testcase重写
This commit is contained in:
31
test/test_read_delete_file.c
Executable file
31
test/test_read_delete_file.c
Executable file
@@ -0,0 +1,31 @@
|
||||
#include "test_utils.h"
|
||||
|
||||
static int test_read_delete_file(const char *path)
|
||||
{
|
||||
printf("\n=== test_read_delete_file ===\n");
|
||||
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd < 0) { perror("open"); return 1; }
|
||||
printf("open: %s fd=%d\n", path, fd);
|
||||
|
||||
char buf[256] = {0};
|
||||
ssize_t r = read(fd, buf, sizeof(buf));
|
||||
if (r < 0) { perror("read"); close(fd); return 2; }
|
||||
printf("read: %zd bytes: %.*s\n", r, (int)r, buf);
|
||||
|
||||
close(fd);
|
||||
printf("close: ok\n");
|
||||
|
||||
if (unlink(path) != 0) { perror("unlink"); return 3; }
|
||||
printf("unlink: ok\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
make_path(path, sizeof(path), argc >= 2 ? argv[1] : NULL, "file.dat");
|
||||
int rc = test_read_delete_file(path);
|
||||
return report_result("test_read_delete_file", rc);
|
||||
}
|
||||
Reference in New Issue
Block a user