[comp.arch] CRASHME.C, test your hardware and software robustness

gjc@buitc.bu.edu (George J. Carrette) (01/04/91)

Here is the promised CRASHME.C. 

It has been reported that the behavior of this program is highly dependant
on system load, amount of system memory, etc. The results are not
easily to reproduce in many cases.

If you really want to give a system the acid test then create a shell
script with thousands of different calls to crashme, and run multiple
copies of these at the same time in different processes.

BEWARE: Obviously, DO NOT RUN THIS on a MACHINE WHICH HAS OTHER USERS,
or is a FILESERVER. 

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  crashme.1 crashme.c makefile readme
# Wrapped by gjc@bucsf on Fri Sep 21 20:08:44 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f crashme.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"crashme.1\"
else
echo shar: Extracting \"crashme.1\" \(1250 characters\)
sed "s/^X//" >crashme.1 <<'END_OF_crashme.1'
X.TH CRASHME 1C LOCAL 
X.SH NAME
Xcrashme \- test operating environment software robustness
X.SH SYNOPSIS
X.B crashme
X[NBYTES] [SRAND] [NRYTES]
X.SH DESCRIPTION
X.I crashme
Xis a very simple program that tests the operating environment's
Xrobustness by invoking random data as if it were a procedure.
XThe standard signals are caught and handled with a setjmp back
Xto a loop which will try again to produce a fault by executing
Xrandom data.
X
X.RE
X.SS COMMAND LINE OPTIONS
X.TP 8
X.BI [NBYTES]
XThe
X.I [NBYTES]
Xshould be an integer, specifying the size of the random data string
Xin bytes.
X.TP
X.BI [SRAND]
XThe 
X.I [SRAND]
Xis an input seed to the random number generator, passed to srand.
X.TP
X.BI [NTRIES]
XThe
X.I [NTRIES]
Xis how many times to loop before exiting normally from the program.
X.SH FILES
Xcrashme.c
X.PD
X.SH DIAGNOSTICS
XWhen a signal is caught the number and nature of the signal is indicated.
X.SH BUGS
XNot all signals are caught, and the state of the user program/process
Xenviroment can be sufficiently damaged such that the program terminates
Xbefore going through all [NTRIES] operations.
X
XBeware: This program can crash your computer and possibly corrupt
Xyour files if the operating system on it is buggy.
X.SH AUTHOR
XGeorge J Carrette. GJC\@BU-IT.BU.EDU
END_OF_crashme.1
if test 1250 -ne `wc -c <crashme.1`; then
    echo shar: \"crashme.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f crashme.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"crashme.c\"
else
echo shar: Extracting \"crashme.c\" \(4457 characters\)
sed "s/^X//" >crashme.c <<'END_OF_crashme.c'
X/* crashme: Create a string of random bytes and then jump to it.
X            crashme <nbytes> <srand> <ntrys>   */
X
Xchar *crashme_version = "1.1 19-SEP-1990";
X
X/*
X *             COPYRIGHT (c) 1990 BY             *
X *  GEORGE J. CARRETTE, CONCORD, MASSACHUSETTS.  *
X *             ALL RIGHTS RESERVED               *
X
XPermission to use, copy, modify, distribute and sell this software
Xand its documentation for any purpose and without fee is hereby
Xgranted, provided that the above copyright notice appear in all copies
Xand that both that copyright notice and this permission notice appear
Xin supporting documentation, and that the name of the author
Xnot be used in advertising or publicity pertaining to distribution
Xof the software without specific, written prior permission.
X
XTHE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XHE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
XA signal handler is set up so that in most cases the machine exception
Xgenerated by the illegal instructions, bad operands, etc in the procedure
Xmade up of random data are caught; and another round of randomness may
Xbe tried. Eventually a random instruction may corrupt the program or
Xthe machine state in such a way that the program must halt. This is
Xa test of the robustness of the hardware/software for instruction
Xfault handling.
X
X  Note:
XSeen to be able to crash a SUN-4/110 OS 4.1, SUN-4/280 OS 4.0.3:
X  %crashme 1000 10 200
XAlso various combinations of inputs have been reported to crash
Xother machines.
X
XComments may be addressed to the author at GJC@BU-IT.BU.EDU
X
XVersion Date         Description
X----------------------------------------------------------------------
X 1.0    early 1990   initial hack.
X 1.1    19-SEP-1990  added more signals and an alarm to abort looping.
X
X*/
X
X
X#include <stdio.h>
X#include <signal.h>
X#include <setjmp.h>
X
Xlong nbytes,nseed,ntrys;
Xunsigned char *the_data;
X
Xjmp_buf again_buff;
X
Xvoid (*badboy)();
X
Xvoid again_handler(sig, code, scp, addr)
X     int sig, code;
X     struct sigcontext *scp;
X     char *addr;
X{char *ss;
X switch(sig)
X   {case SIGILL: ss =   " illegal instruction"; break;
X    case SIGTRAP: ss =   " trace trap"; break;
X    case SIGFPE: ss =   " arithmetic exception"; break;
X    case SIGBUS: ss =  " bus error"; break;
X    case SIGSEGV: ss =  " segmentation violation"; break;
X    case SIGIOT: ss = " IOT instruction"; break;
X    case SIGEMT: ss = " EMT instruction"; break;
X    case SIGALRM: ss = " alarm clock"; break;
X    default: ss = "";}
X fprintf(stderr,"Got signal %d%s\n",sig,ss);
X longjmp(again_buff,3);}
X 
Xset_up_signals()
X{signal(SIGILL,again_handler);
X signal(SIGTRAP,again_handler);
X signal(SIGFPE,again_handler);
X signal(SIGBUS,again_handler);
X signal(SIGSEGV,again_handler);
X signal(SIGIOT,again_handler);
X signal(SIGEMT,again_handler);
X signal(SIGALRM,again_handler);}
X
Xcompute_badboy()
X{long j,n;
X n = (nbytes < 0) ? - nbytes : nbytes;
X for(j=0;j<n;++j) the_data[j] = (rand() >> 7) & 0xFF;
X if (nbytes < 0)
X   {fprintf(stdout,"Dump of %ld bytes of data\n",n);
X    for(j=0;j<n;++j)
X      {fprintf(stdout,"%3d",the_data[j]);
X       if ((j % 20) == 19) putc('\n',stdout); else putc(' ',stdout);}
X    putc('\n',stdout);}}
X
Xtry_one_crash()
X{compute_badboy();
X if (nbytes > 0)
X   (*badboy)();
X else if (nbytes == 0)
X   while(1);}
X 
Xmain(argc,argv)
X int argc; char **argv;
X{if (argc != 4) {fprintf(stderr,"crashme <nbytes> <srand> <ntrys>\n");
X		 exit(1);}
X fprintf(stdout,"Crashme: (c) Copyright 1990 George J. Carrette\n");
X fprintf(stdout,"Version: %s\n",crashme_version);
X nbytes = atol(argv[1]);
X nseed = atol(argv[2]);
X ntrys = atol(argv[3]);
X fprintf(stdout,"crashem %ld %ld %ld\n",nbytes,nseed,ntrys);
X fflush(stdout);
X the_data = (unsigned char *) malloc((nbytes < 0) ? -nbytes : nbytes);
X badboy = (void (*)()) the_data;
X fprintf(stdout,"Badboy at %d. 0x%X\n",badboy,badboy);
X srand(nseed);
X badboy_loop();}
X
Xbadboy_loop()
X{int i;
X for(i=0;i<ntrys;++i)
X   {fprintf(stderr,"%ld\n",i);
X    if(setjmp(again_buff) == 3)
X      fprintf(stderr,"Barfed\n");
X    else
X      {set_up_signals();
X       alarm(10);
X       try_one_crash();
X       fprintf(stderr,"didn't barf!\n");}}}
END_OF_crashme.c
if test 4457 -ne `wc -c <crashme.c`; then
    echo shar: \"crashme.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"makefile\"
else
echo shar: Extracting \"makefile\" \(82 characters\)
sed "s/^X//" >makefile <<'END_OF_makefile'
Xcrashme:	crashme.o
X	cc -o crashme crashme.o
Xcrashme.o: crashme.c
X	cc -c crashme.c
END_OF_makefile
if test 82 -ne `wc -c <makefile`; then
    echo shar: \"makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f readme -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"readme\"
else
echo shar: Extracting \"readme\" \(859 characters\)
sed "s/^X//" >readme <<'END_OF_readme'
XThe purpose of the crashme program is to cause instruction faults
Xthat would otherwise be only rarely seen in the normal operation
Xof a system (where "normal" includes conditions of user programs
Xwith bugs in them, and to executable code corruption due to
Xmemory, disk, and network problems).
X
XCaution: Don't even *think* about running this program on a
Xsystem without a projected mode operating of some kind.
X
XFor more information see the comments in the code.
X
XNote: The use of srand and rand is unlikely to result in a very
Xgood random mapping unto a machine instruction set.
X
XInfinite loops will be broken out of (presumably) by the ALARM
Xsignal. 10 seconds are given for this. Adjust as needed.
X
XIdeally a shell script should be set up to run crashme again and
Xagain for hours and hours with different input settings.
X
X-George Carrette. GJC@BU-IT.BU.EDU
END_OF_readme
if test 859 -ne `wc -c <readme`; then
    echo shar: \"readme\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0