xref: /minix/minix/commands/swifi/systest.c (revision 83133719)
1 /*
2  * systest.c -- Test code for nooks system calls
3  *
4  * Copyright (C) 2002 Mike Swift
5  *
6  * The source code in this file can be freely used, adapted,
7  * and redistributed in source or binary form, so long as an
8  * acknowledgment appears in derived source files.
9  * No warranty is attached;
10  * we cannot take responsibility for errors or fitness for use.
11  *
12  */
13 
14 #include <sys/types.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #if 0
18 #include <asm/unistd.h>
19 #endif
20 #include <string.h>
21 #include <errno.h>
22 
23 #define swifi_inject_fault sys_inject_fault
24 
25 #include "swifi-user.h"
26 #include "extra.h"
27 
28 
29 #if 0
30 _syscall6(long, swifi_inject_fault,
31 	  char *, module_name,
32 	  unsigned long, faultType,
33 	  unsigned long, randSeed,
34 	  unsigned long, numFaults,
35 	  void *, result,
36 	  unsigned long, do_inject);
37 #endif
38 
39 int
40 main(int argc, char * argv[])
41 {
42   char * module_name = NULL;
43   int i;
44   long result = 0;
45   unsigned int cmd = 0;
46   unsigned long arg = 0;
47   unsigned long seed = 157;
48   swifi_result_t * res = NULL;
49 
50   if (argc < 2) {
51     goto Usage;
52   }
53 
54   for (i = 1; i < argc; i++ ) {
55     if (strcmp(argv[i], "-f") == 0) {
56       if (argc <= i+5) {
57 	goto Usage;
58       }
59       module_name = victim_exe = argv[++i];
60       sscanf(argv[++i],"%u", &victim_pid);
61       sscanf(argv[++i],"%u", &cmd);
62       sscanf(argv[++i],"%lu", &arg);
63       sscanf(argv[++i],"%lu", &seed);
64     } else {
65       printf("Unknown command %s\n", argv[i]);
66       goto Usage;
67     }
68   }
69 
70   res = malloc(arg * sizeof(swifi_result_t));
71   if (res == NULL) {
72     printf("Out of memory\n");
73     goto Cleanup;
74   }
75 
76   memset(res, 0, sizeof(res));
77 
78   /*
79   // Find out where the faults will be injected
80   */
81 
82   result = swifi_inject_fault(module_name,
83 			      cmd,         /* fault type */
84 			      seed,           /* random seed */
85 			      arg,         /* numFaults */
86 			      res,
87 			      0);  /* don't inject now */
88 
89   for (i = 0; (i < arg) && (res[i].address != 0) ; i++) {
90     printf("Changed 0x%lx from 0x%lx to 0x%lx\n",
91 	   res[i].address,
92 	   res[i].old,
93 	   res[i].new);
94   }
95 
96   /*
97   // do the injection
98   */
99 
100 
101   result = swifi_inject_fault(module_name,
102 			      cmd,         /* fault type */
103 			      seed,           /* random seed */
104 			      arg,         /* numFaults */
105 			      res,
106 			      1);  /* do inject now */
107 
108   printf("swifi_inject_fault returned %ld (%d)\n", result,errno);
109 
110 
111 
112  Cleanup:
113   if (res != NULL) {
114     free(res);
115   }
116   return(0);
117 
118  Usage:
119   printf("Usage: %s -f module_name pid fault-type fault-count seed\n", argv[0]);
120   goto Cleanup;
121 }
122 
123 
124