qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / exercise_fault.c
blob3c75471f1838742d6c163defc0a97cc3001b2af9
1 /*
2 * Copyright (c) 2011 Ken McDonell. All Rights Reserved.
4 * Exercise fault injection infrastructure.
5 */
7 #include <pcp/pmapi.h>
8 #include <pcp/impl.h>
9 #include <pcp/fault.h>
10 #include <string.h>
11 #include <errno.h>
13 static void
14 exercise(void)
16 int i;
17 void *p;
18 for (i = 1; i <= 10; i++) {
19 __pmFaultInject("QA:1", PM_FAULT_ALLOC);
20 p = malloc(10);
21 if (p == NULL)
22 fprintf(stderr, "malloc:1[%d] %s\n", i, strerror(errno));
23 else
24 free(p);
25 __pmFaultInject("QA:2", PM_FAULT_ALLOC);
26 p = malloc(100);
27 if (p == NULL)
28 fprintf(stderr, "malloc:2[%d] %s\n", i, strerror(errno));
29 else
30 free(p);
31 __pmFaultInject("QA:3", PM_FAULT_ALLOC);
32 p = malloc(1000);
33 if (p == NULL)
34 fprintf(stderr, "malloc:3[%d] %s\n", i, strerror(errno));
35 else
36 free(p);
40 int
41 main(int argc, char *argv[])
43 int c;
44 int sts;
45 int errflag = 0;
46 char *usage = "[-D debug]";
48 __pmSetProgname(argv[0]);
50 while ((c = getopt(argc, argv, "D:")) != EOF) {
51 switch (c) {
53 case 'D': /* debug flag */
54 sts = __pmParseDebug(optarg);
55 if (sts < 0) {
56 fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
57 pmProgname, optarg);
58 errflag++;
60 else
61 pmDebug |= sts;
62 break;
64 case '?':
65 default:
66 errflag++;
67 break;
71 if (errflag || optind != argc) {
72 fprintf(stderr, "Usage: %s %s\n", pmProgname, usage);
73 exit(1);
76 exercise();
78 return 0;