From 47e6e7c84f008a53061e661f31ae96629bc694ef Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sun, 26 Oct 2014 12:33:50 +0400 Subject: Debian 3.9.10 --- qa/src/exercise_fault.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 qa/src/exercise_fault.c (limited to 'qa/src/exercise_fault.c') diff --git a/qa/src/exercise_fault.c b/qa/src/exercise_fault.c new file mode 100644 index 0000000..3c75471 --- /dev/null +++ b/qa/src/exercise_fault.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2011 Ken McDonell. All Rights Reserved. + * + * Exercise fault injection infrastructure. + */ + +#include +#include +#include +#include +#include + +static void +exercise(void) +{ + int i; + void *p; + for (i = 1; i <= 10; i++) { + __pmFaultInject("QA:1", PM_FAULT_ALLOC); + p = malloc(10); + if (p == NULL) + fprintf(stderr, "malloc:1[%d] %s\n", i, strerror(errno)); + else + free(p); + __pmFaultInject("QA:2", PM_FAULT_ALLOC); + p = malloc(100); + if (p == NULL) + fprintf(stderr, "malloc:2[%d] %s\n", i, strerror(errno)); + else + free(p); + __pmFaultInject("QA:3", PM_FAULT_ALLOC); + p = malloc(1000); + if (p == NULL) + fprintf(stderr, "malloc:3[%d] %s\n", i, strerror(errno)); + else + free(p); + } +} + +int +main(int argc, char *argv[]) +{ + int c; + int sts; + int errflag = 0; + char *usage = "[-D debug]"; + + __pmSetProgname(argv[0]); + + while ((c = getopt(argc, argv, "D:")) != EOF) { + switch (c) { + + case 'D': /* debug flag */ + sts = __pmParseDebug(optarg); + if (sts < 0) { + fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n", + pmProgname, optarg); + errflag++; + } + else + pmDebug |= sts; + break; + + case '?': + default: + errflag++; + break; + } + } + + if (errflag || optind != argc) { + fprintf(stderr, "Usage: %s %s\n", pmProgname, usage); + exit(1); + } + + exercise(); + + return 0; +} -- cgit v1.2.3