#include #include #include #include #include #include #include #include #include "vile_interface.h" #include "gulid.h" void usage(char *progname) { fprintf(stderr,"Usage: %s [-v] [-sigsegv N] [-c N] [-o filename]\n", progname); fprintf(stderr," -v Verbose\n"); fprintf(stderr," -i Explicitly initialize vile\n"); fprintf(stderr," -c N Execute N iterations\n"); fprintf(stderr," -o filename Save vile output to filename,\n"); fprintf(stderr," otherwise please setenv VILE_LOGFILE.\n"); fprintf(stderr," -sigsegv N Force SIGSEGV after N iterations.\n"); fprintf(stderr," (useful for testing vile core extraction)\n"); exit(1); } int my_func2(int x) { vile_blkstart(__my_func2, x); /* do something useful here */ vile_blkend(__my_func2, x); return x+1; } void my_func(int x) { vile_blkstart(__my_func, x); x = my_func2(x); vile_blkend(__my_func, x); } main(int argc, char *argv[]) { struct timespec hold; struct timespec residue; int i, initialize=0, verbose=0, sigsegv = -1, N = 100000 ; char *crashme = NULL; char *vilefilename = NULL; for (i=1 ; i < argc ; i++) { if (strcmp(argv[i],"-sigsegv") == 0) { i++ ; sigsegv = atoi(argv[i]); continue ; } else if (strcmp(argv[i],"-c") == 0) { i++ ; N = atoi(argv[i]); continue ; } else if (strcmp(argv[i],"-o") == 0) { i++ ; vilefilename = argv[i] ; continue ; } else if (strcmp(argv[i],"-i") == 0) { initialize = 1; } else if (strcmp(argv[i],"-v") == 0) { verbose = 1; } else usage(argv[0]); } if (verbose && (sigsegv > 0)) printf("%s will intentionally cause a SIGSEGV after %d iterations\n", argv[0], sigsegv); if (verbose && initialize) printf("initializing vile\n"); if (initialize) vile_init(); vile_val32(vile_example, 0xdeadface); vile_val32(vile_example, 0xfeedface); // vile_val532(vile_example, 0xfeed0001, 0xfeed0002, 0xfeed0003, 0xfeed0004, 0xfeed0005); hold.tv_sec = 1; hold.tv_nsec = 0; if (verbose) printf("doing sleeper loop of 5 seconds\n"); for (i=0; i<5; i++) { vile_blkstart(vile_test_loop, i); nanosleep( & hold, & residue ); if (i == sigsegv) *crashme = 0; vile_blkend(vile_test_loop, i); } for (i=0; i < N; i++) { vile_blkstart(vile_test_loop, i); my_func(i); vile_blkend(vile_test_loop, i); if (i == sigsegv) *crashme = 0; } /* Let's see how long a printf takes */ vile_blkstart(__printf, 0); fprintf(stdout,"this is a call to fprintf\n"); vile_blkend(__printf, 0); vile_blkstart(__printf, 1); fprintf(stdout,"this is another call to fprintf\n"); vile_blkend(__printf, 1); vile_blkstart(__printf, 2); fprintf(stdout,"this is a call to fprintf followed by fflush\n"); fflush(stdout); vile_blkend(__printf, 2); for (i=0; i<5; i++) { vile_blkstart(vile_test_loop, i); vile_val532(vile_example, 0xfeed0532, 0x12341111, 0x12342222, 0x12343333, 0x12344444); vile_val32(vile_example, 0xdeadface); vile_val132_264(vile_example, 0xfeed0264, 0x1234567855555555, 0x1234567866666666); vile_val32(vile_example, 0xfeedface); vile_val132_464(vile_example, 0xfeed0464, 0x1234567877777777, 0x1234567888888888, 0x1234567899999999, 0x12345678aaaaaaaa); vile_blkend(vile_test_loop, 0xb00bfeef); } if (verbose) printf("dumping vile file\n"); vile_save2file(vilefilename); if (vilefilename) printf("VILE output should have been saved to %s\n", vilefilename); else { if (getenv("VILE_LOGFILE") == NULL) printf("Did you forget to setenv VILE_LOGFILE ?\n"); else { printf("VILE output should have been saved to "); printf( getenv("VILE_LOGFILE"), getpid() ); printf("\n"); } } }