Files
zvfs/test/test_basic.c
2026-03-02 07:27:48 +00:00

52 lines
1.4 KiB
C
Executable File

#include "test_utils.h"
static int test_basic(const char *path)
{
printf("\n=== test_basic ===\n");
printf("open: %s\n", path);
int fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644);
if (fd < 0) { perror("open"); return 1; }
const char *msg = "ABCDEFGHIJKL";
ssize_t w = write(fd, msg, strlen(msg));
if (w < 0) { perror("write"); return 2; }
printf("write: %zd\n", w);
const char *msg2 = "MNOPQRSTUVWXYZ";
ssize_t w2 = write(fd, msg2, strlen(msg2));
if (w2 < 0) { perror("write"); return 2; }
printf("write: %zd\n", w2);
close(fd);
fd = open(path, O_RDONLY);
if (fd < 0) { perror("open R"); return 3; }
char buf[10];
memset(buf, 0, sizeof(buf));
ssize_t r = read(fd, buf, sizeof(buf));
if (r < 0) { perror("read"); return 4; }
printf("read: %zd bytes: %.*s\n", r, (int)r, buf);
char buf2[512];
memset(buf2, 0, sizeof(buf2));
ssize_t r2 = read(fd, buf2, sizeof(buf2));
if (r2 < 0) { perror("read"); return 4; }
printf("read: %zd bytes: %.*s\n", r2, (int)r2, buf2);
close(fd);
if (unlink(path) != 0) { perror("unlink"); return 5; }
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_basic(path);
return report_result("test_basic", rc);
}