1 /* Test 73 - VM secondary cache blackbox test. 2 * 3 * Blackbox test of the VM secondary cache in isolation, implemented 4 * in testvm.c, started as a service by this test program. 5 */ 6 7 #define _MINIX_SYSTEM 1 8 9 #include <minix/sysutil.h> 10 #include <minix/syslib.h> 11 #include <minix/vm.h> 12 #include <minix/bdev.h> 13 #include <minix/paths.h> 14 #include <sys/types.h> 15 #include <sys/mman.h> 16 #include <sys/ioc_memory.h> 17 #include <stdio.h> 18 #include <stdarg.h> 19 #include <assert.h> 20 #include <string.h> 21 #include <stdlib.h> 22 #include <unistd.h> 23 #include <fcntl.h> 24 #include <math.h> 25 #include <minix/libminixfs.h> 26 27 #include "testvm.h" 28 29 int max_error = 0; 30 31 #include "common.h" 32 #include "testcache.h" 33 34 int 35 main(int argc, char *argv[]) 36 { 37 char pipefn[30], cwd[400], cmdline[400]; 38 int pipefd; 39 static struct info i; 40 ssize_t r; 41 int big = 0; 42 43 #define ITER 3 44 #define BLOCKS 200 45 46 start(73); 47 48 setuid(geteuid()); 49 50 if(getuid() != 0) { 51 printf("Test 73 has to be run as root; test aborted\n"); 52 exit(1); 53 } 54 55 unlink(pipefn); 56 57 /* 'big' as a substring indicates to testvm that it's ok to 58 * run a long test 59 */ 60 if(getenv(BIGVARNAME)) big = 1; 61 62 if(big) strcpy(pipefn, "pipe_testvm_big"); 63 else strcpy(pipefn, "pipe_testvm"); 64 65 umask(0); 66 if(mkfifo(pipefn, 0666) < 0) { e(1); exit(1); } 67 if(!getcwd(cwd, sizeof(cwd))) { e(2); exit(1); } 68 69 /* stop residual testvm service if any */ 70 snprintf(cmdline, sizeof(cmdline), "%s down testvm >/dev/null 2>&1", 71 _PATH_MINIX_SERVICE); 72 if(system(cmdline) < 0) { e(9); exit(1); } 73 74 /* start the testvm service */ 75 snprintf(cmdline, sizeof(cmdline), 76 "%s up /%s/../testvm -script /etc/rs.single " 77 "-args /%s/%s -config %s/../testvm.conf", 78 _PATH_MINIX_SERVICE, cwd, cwd, pipefn, cwd); 79 if(system(cmdline) < 0) { e(10); exit(1); } 80 81 /* don't hang forever if the open or read block */ 82 alarm(big ? 6000 : 600); 83 84 if((pipefd=open(pipefn, O_RDONLY)) < 0) { e(3); exit(1); } 85 86 if((r=read(pipefd, &i, sizeof(i))) != sizeof(i)) { 87 printf("read returned %d\n", r); 88 e(12); 89 exit(1); 90 } 91 92 if(i.result != 0) { e(i.result); } 93 94 quit(); 95 96 return 0; 97 } 98 99