occlum/test/hostfs/main.c
Tate, Hongliang Tian d77c21f98c Add a command-line interface tool named occlum
1. All generated, build files are now in a separate build directory;
2. The CLI tool supports three sub-commands: init, build, and run;
3. Refactor tests to use the new tool.
2019-08-28 06:05:12 +00:00

45 lines
1.3 KiB
C

#include <sys/types.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
int main(int argc, const char* argv[]) {
int fd, len;
// TODO: rewrite this test so that it does not need to depend on sample.txt
#if 0
char read_buf[128] = {0};
// read
if ((fd = open("/host/hostfs/sample.txt", O_RDONLY)) < 0) {
printf("ERROR: failed to open a file for read\n");
return -1;
}
if ((len = read(fd, read_buf, sizeof(read_buf) - 1)) <= 0) {
printf("ERROR: failed to read from the file\n");
return -1;
}
close(fd);
if (strcmp("HostFS works!", read_buf) != 0) {
printf("ERROR: the message read from the file is not expected\n");
return -1;
}
printf("Read file from hostfs successfully!\n");
#endif
// write
if ((fd = open("/host/hostfs_test_write.txt", O_WRONLY | O_CREAT)) < 0) {
printf("ERROR: failed to open a file for write\n");
return -1;
}
const char WRITE_STR[] = "Write to hostfs successfully!";
if ((len = write(fd, WRITE_STR, sizeof(WRITE_STR))) <= 0) {
printf("ERROR: failed to write to the file\n");
return -1;
}
close(fd);
printf("Write file to hostfs finished. Please check its content.\n");
return 0;
}