arm: protect state after signal handler
[minix.git] / commands / swifi / systest.c
blob66277c748875c52682bdc62f61055818842240ee
1 /*
2 * systest.c -- Test code for nooks system calls
4 * Copyright (C) 2002 Mike Swift
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.
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>
23 #define swifi_inject_fault sys_inject_fault
25 #include "swifi-user.h"
26 #include "extra.h"
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
39 int
40 main(int argc, char * argv[])
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;
50 if (argc < 2) {
51 goto Usage;
54 for (i = 1; i < argc; i++ ) {
55 if (strcmp(argv[i], "-f") == 0) {
56 if (argc <= i+5) {
57 goto Usage;
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;
70 res = malloc(arg * sizeof(swifi_result_t));
71 if (res == NULL) {
72 printf("Out of memory\n");
73 goto Cleanup;
76 memset(res, 0, sizeof(res));
79 // Find out where the faults will be injected
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 */
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);
97 // do the injection
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 */
108 printf("swifi_inject_fault returned %ld (%d)\n", result,errno);
112 Cleanup:
113 if (res != NULL) {
114 free(res);
116 return(0);
118 Usage:
119 printf("Usage: %s -f module_name pid fault-type fault-count seed\n", argv[0]);
120 goto Cleanup;