Skip to content

Commit

Permalink
add testing user app:sfs_filetest1.c in lab8
Browse files Browse the repository at this point in the history
  • Loading branch information
uuyych committed May 21, 2018
1 parent ee12939 commit 024c8ff
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions labcodes/lab8/user/sfs_filetest1.c
@@ -0,0 +1,43 @@
#include <ulib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stat.h>
#include <file.h>
#include <dir.h>
#include <unistd.h>

#define printf(...) fprintf(1, __VA_ARGS__)

static int safe_open(const char *path, int open_flags)
{
int fd = open(path, open_flags);
printf("fd is %d\n",fd);
assert(fd >= 0);
return fd;
}

static struct stat *safe_fstat(int fd)
{
static struct stat __stat, *stat = &__stat;
int ret = fstat(fd, stat);
assert(ret == 0);
return stat;
}


static void safe_read(int fd, void *data, size_t len)
{
int ret = read(fd, data, len);
assert(ret == len);
}


int main(void)
{
int fd1 = safe_open("sfs_filetest1", O_RDONLY);
struct stat *stat = safe_fstat(fd1);
assert(stat->st_size >= 0 && stat->st_blocks >= 0);
printf("sfs_filetest1 pass.\n");
return 0;
}

0 comments on commit 024c8ff

Please sign in to comment.