Index: user/pho/stress2/lib/main.c =================================================================== --- user/pho/stress2/lib/main.c (revision 338487) +++ user/pho/stress2/lib/main.c (revision 338488) @@ -1,219 +1,218 @@ /*- * Copyright (c) 2008 Peter Holm * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ /* Main program for all test programs */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include "stress.h" static char const rcsid[] __unused = "$Name: $ $FreeBSD$"; volatile int done_testing; static int cleanupcalled = 0; char *home; static pid_t *r; static void handler(int i __unused) { int j; done_testing = 1; for (j = 0; j < op->incarnations; j++) { if (op->verbose > 2) printf("handler: kill -HUP %d\n", r[j]); if (r[j] != 0 && kill(r[j], SIGHUP) == -1) if (errno != ESRCH) warn("kill(%d, SIGHUP), %s:%d", r[j], __FILE__, __LINE__); } if (op->kill == 1) { sleep(5); /* test programs may have blocked for the SIGHUP, so try harder */ for (j = 0; j < op->incarnations; j++) { if (op->verbose > 2) printf("handler: kill -KILL %d\n", r[j]); if (r[j] != 0) (void) kill(r[j], SIGKILL); } } } static void run_test_handler(int i __unused) { done_testing = 1; } static void exit_handler(int i __unused) { _exit(1); } static void callcleanup(void) { if (cleanupcalled == 0) cleanup(); cleanupcalled = 1; } static void run_tests(int i) { time_t start; int e; signal(SIGHUP, run_test_handler); signal(SIGINT, exit_handler); atexit(callcleanup); - arc4random_stir(); setup(i); if ((strcmp(getprogname(), "run") != 0) && (op->nodelay == 0)) sleep(random_int(1,10)); e = 0; start = time(NULL); while (done_testing == 0 && e == 0 && (time(NULL) - start) < op->run_time) { e = test(); } callcleanup(); exit(e); } static void run_incarnations(void) { int e, i, s; e = 0; signal(SIGHUP, handler); for (i = 0; i < op->incarnations && done_testing == 0; i++) { if ((r[i] = fork()) == 0) { run_tests(i); } if (r[i] < 0) { warn("fork(), %s:%d", __FILE__, __LINE__); r[i] = 0; break; } } for (i = 0; i < op->incarnations; i++) { if (r[i] != 0 && waitpid(r[i], &s, 0) == -1) warn("waitpid(%d), %s:%d", r[i], __FILE__, __LINE__); if (s != 0) e = 1; } exit(e); } static int run_test(void) { pid_t p; time_t start; int status = 0; if (random_int(1,100) > op->load) return (status); show_status(); start = time(NULL); done_testing = 0; fflush(stdout); rmval(); p = fork(); if (p == 0) run_incarnations(); if (p < 0) err(1, "fork() in %s:%d", __FILE__, __LINE__); while (done_testing != 1 && (time(NULL) - start) < op->run_time) { sleep(1); if (waitpid(p, &status, WNOHANG) == p) return (status != 0); } if (kill(p, SIGHUP) == -1) warn("kill(%d, SIGHUP), %s:%d", p, __FILE__, __LINE__); if (waitpid(p, &status, 0) == -1) err(1, "waitpid(%d), %s:%d", p, __FILE__, __LINE__); return (status != 0); } int main(int argc, char **argv) { struct stat sb; int status = 0; options(argc, argv); umask(0); if (stat(op->wd, &sb) == -1) { if (mkdir(op->wd, 0770) == -1) if (errno != EEXIST) err(1, "mkdir(%s) %s:%d", op->wd, __FILE__, __LINE__); } else if ((sb.st_mode & S_IRWXU) == 0) errx(1, "No RWX access to %s", op->wd); if (stat(op->cd, &sb) == -1) { if (mkdir(op->cd, 0770) == -1) if (errno != EEXIST) err(1, "mkdir(%s) %s:%d", op->cd, __FILE__, __LINE__); } if ((home = getcwd(NULL, 0)) == NULL) err(1, "getcwd(), %s:%d", __FILE__, __LINE__); if (chdir(op->wd) == -1) err(1, "chdir(%s) %s:%d", op->wd, __FILE__, __LINE__); r = (pid_t *)calloc(1, op->incarnations * sizeof(pid_t)); status = run_test(); return (status); } Index: user/pho/stress2/testcases/badcode/badcode.c =================================================================== --- user/pho/stress2/testcases/badcode/badcode.c (revision 338487) +++ user/pho/stress2/testcases/badcode/badcode.c (revision 338488) @@ -1,136 +1,135 @@ /* * COPYRIGHT (c) 1990 BY * * GEORGE J. CARRETTE, CONCORD, MASSACHUSETTS. * * ALL RIGHTS RESERVED * Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. This code is based on crashme.c */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include "stress.h" pid_t pid; int failsafe; static int tobemangled(void) { volatile int i, j; j = 2; for (i = 0; i < 100; i++) j = j + 3; j = j / 2; return (j); } static void mangle(void) { /* Change one byte in the code */ int i; char *p = (void *)tobemangled; i = arc4random() % 50; p[i] = arc4random() & 0xff; } static void hand(int i __unused) { /* handler */ _exit(1); } static void ahand(int i __unused) { /* alarm handler */ if (pid != 0) { kill(pid, SIGKILL); } _exit(EXIT_SUCCESS); } int setup(int nb __unused) { return (0); } void cleanup(void) { } int test(void) { void *st; struct rlimit rl; if (failsafe) return (0); while (done_testing == 0) { signal(SIGALRM, ahand); alarm(3); if ((pid = fork()) == 0) { rl.rlim_max = rl.rlim_cur = 0; if (setrlimit(RLIMIT_CORE, &rl) == -1) warn("setrlimit"); - arc4random_stir(); st = (void *)trunc_page((unsigned long)tobemangled); if (mprotect(st, PAGE_SIZE, PROT_WRITE | PROT_READ | PROT_EXEC) == -1) err(1, "mprotect()"); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); mangle(); failsafe = 1; (void)tobemangled(); _exit(EXIT_SUCCESS); } else if (pid > 0) { if (waitpid(pid, NULL, 0) == -1) warn("waitpid(%d)", pid); alarm(0); } else err(1, "fork(), %s:%d", __FILE__, __LINE__); } return (0); }