diff options
| author | Robert Morris <rtm@csail.mit.edu> | 2020-08-07 14:34:39 -0400 | 
|---|---|---|
| committer | Frans Kaashoek <kaashoek@mit.edu> | 2020-08-10 11:19:10 -0400 | 
| commit | a93321cb2547dbb48bf8ce9ad623ac19eefbecea (patch) | |
| tree | ae70994dd48004e27d8037b84ad778069445900d /user | |
| parent | 1f555198d61d1c447e874ae7e5a0868513822023 (diff) | |
| download | xv6-labs-a93321cb2547dbb48bf8ce9ad623ac19eefbecea.tar.gz xv6-labs-a93321cb2547dbb48bf8ce9ad623ac19eefbecea.tar.bz2 xv6-labs-a93321cb2547dbb48bf8ce9ad623ac19eefbecea.zip | |
test pointer checking in copyin, copyout, copyinstr
Diffstat (limited to 'user')
| -rw-r--r-- | user/usertests.c | 92 | 
1 files changed, 92 insertions, 0 deletions
| diff --git a/user/usertests.c b/user/usertests.c index aefbc9f..bdf6970 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -22,6 +22,92 @@  char buf[BUFSZ];  char name[3]; +void +copyin1(char *s) +{ +  int fd = open("copyin1", O_CREATE|O_WRONLY); +  if(fd < 0){ +    printf("open(copyin1) failed\n"); +    exit(1); +  } +  int n = write(fd, (void*)0x80000000LL, 8192); +  if(n >= 0){ +    printf("write(fd, 0x80000000LL, 8192) did not fail!\n"); +    exit(1); +  } +  close(fd); +  unlink("copyin1"); +} + +void +copyin2(char *s) +{ +  int fd = open("copyin2", O_CREATE|O_WRONLY); +  if(fd < 0){ +    printf("open(copyin2) failed\n"); +    exit(1); +  } +  int n = write(fd, (void*)0xffffffffffffffffLL, 8192); +  if(n >= 0){ +    printf("write(fd, 0xffffffffffffffffLL, 8192) did not fail!\n"); +    exit(1); +  } +  close(fd); +  unlink("copyin2"); +} + +void +copyout1(char *s) +{ +  int fd = open("README", 0); +  if(fd < 0){ +    printf("open(README) failed\n"); +    exit(1); +  } +  int n = read(fd, (void*)0x80000000LL, 8192); +  if(n >= 0){ +    printf("read(fd, 0x80000000LL, 8192) returned %d, not -1\n", n); +    exit(1); +  } +  close(fd); +} + +void +copyout2(char *s) +{ +  int fd = open("README", 0); +  if(fd < 0){ +    printf("open(README) failed\n"); +    exit(1); +  } +  int n = read(fd, (void*)0xffffffffffffffffLL, 8192); +  if(n >= 0){ +    printf("read(fd, 0xffffffffffffffff, 8192) returned %d, not -1\n", n); +    exit(1); +  } +  close(fd); +} + +void +copyinstr1(char *s) +{ +  int fd = open((char *)0x80000000LL, O_CREATE|O_WRONLY); +  if(fd >= 0){ +    printf("open(0x80000000) returned %d, not -1\n", fd); +    exit(1); +  } +} + +void +copyinstr2(char *s) +{ +  int fd = open((char *)0xffffffffffffffff, O_CREATE|O_WRONLY); +  if(fd >= 0){ +    printf("open(0xffffffffffffffff) returned %d, not -1\n", fd); +    exit(1); +  } +} +  // test O_TRUNC.  void  truncate1(char *s) @@ -2307,6 +2393,12 @@ main(int argc, char *argv[])      void (*f)(char *);      char *s;    } tests[] = { +    {copyin1, "copyin1"}, +    {copyin2, "copyin2"}, +    {copyout1, "copyout1"}, +    {copyout2, "copyout2"}, +    {copyinstr1, "copyinstr1"}, +    {copyinstr2, "copyinstr2"},      {truncate1, "truncate1"},      {truncate2, "truncate2"},      {truncate3, "truncate3"}, | 
