Files
graphene/LibOS/shim/test/fs/delete.c
Rafał Wojdyła baab561a75 [LibOS] Add tests for some typical FS use cases
These tests perform common FS operations in various ways:
- open/close
- read/write
- create/delete
- read/change size
- seek/tell
- memory-mapped read/write
- copy directory in different ways

Tests use both direct syscalls and stdio wrappers (FILE).

To run, call `make test` in `LibOS/shim/test/fs`.
2019-12-03 15:25:47 +01:00

42 lines
1.4 KiB
C

#include "common.h"
void file_delete(const char* file_path_1, const char* file_path_2, bool writable) {
const char* type = writable ? "output" : "input";
int fd = writable ? open_output_fd(file_path_1, /*rdwr=*/false) : open_input_fd(file_path_1);
printf("open(%s) %s 1 OK\n", file_path_1, type);
close_fd(file_path_1, fd);
printf("close(%s) %s 1 OK\n", file_path_1, type);
if (unlink(file_path_1) != 0)
fatal_error("Failed to unlink file %s: %s\n", file_path_1, strerror(errno));
printf("unlink(%s) %s 1 OK\n", file_path_1, type);
fd = writable ? open_output_fd(file_path_2, /*rdwr=*/false) : open_input_fd(file_path_2);
printf("open(%s) %s 2 OK\n", file_path_2, type);
if (unlink(file_path_2) != 0)
fatal_error("Failed to unlink file %s: %s\n", file_path_2, strerror(errno));
printf("unlink(%s) %s 2 OK\n", file_path_2, type);
close_fd(file_path_2, fd);
printf("close(%s) %s 2 OK\n", file_path_2, type);
}
int main(int argc, char* argv[])
{
if (argc < 6)
fatal_error("Usage: %s <path1> <path2> <path3> <path4> <path5>\n", argv[0]);
setup();
if (unlink(argv[1]) != 0)
fatal_error("Failed to unlink file %s: %s\n", argv[1], strerror(errno));
printf("unlink(%s) OK\n", argv[1]);
file_delete(argv[2], argv[3], /*writable=*/false);
file_delete(argv[4], argv[5], /*writable=*/true);
return 0;
}