From: David Schleef Date: Tue, 23 Jan 2001 18:21:47 +0000 (+0000) Subject: added segfault testing X-Git-Tag: r0_7_15~31 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8265dded626a3430dd8e5f2d6e32fdf6b556d8e4;p=comedilib.git added segfault testing --- diff --git a/testing/mmap.c b/testing/mmap.c index 0aaab15..8a20e06 100644 --- a/testing/mmap.c +++ b/testing/mmap.c @@ -11,8 +11,15 @@ #include #include #include +#include +#include +#include + #include "comedi_test.h" +/* XXX this should come from elsewhere */ +#define PAGE_SIZE 4096 + static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd); #define N_SAMPLES 10000 @@ -21,17 +28,48 @@ static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd #define MAPLEN 20480 +jmp_buf jump_env; + +void segv_handler(int num,siginfo_t *si,void *x) +{ + longjmp(jump_env,1); +} + +int test_segfault(void *memptr) +{ + volatile char tmp; + int ret; + + ret=setjmp(jump_env); + if(!ret) tmp = *((char *)(memptr)); + return ret; +} + +void setup_segfaulter(void) +{ + struct sigaction act; + + memset(&act,0,sizeof(act)); + act.sa_sigaction=&segv_handler; + act.sa_flags = SA_SIGINFO; + sigaction(SIGSEGV,&act,NULL); +} + int test_mmap(void) { comedi_cmd cmd; - char buf[BUFSZ]; + char *buf; unsigned int chanlist[1]; int go; int total=0; int ret; - void *b; + void *b, *adr; sampl_t *map; + setup_segfaulter(); + + buf=malloc(BUFSZ); + if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){ printf(" not supported\n"); return 0; @@ -43,6 +81,16 @@ int test_mmap(void) return 0; } + /* test readability */ + for(adr=map;adr<(void *)map+MAPLEN;adr+=PAGE_SIZE){ + ret=test_segfault(adr); + if(ret){ + printf("E: %p failed\n",adr); + }else{ + printf("%p ok\n",adr); + } + } + cmd.chanlist = chanlist; cmd.scan_end_arg = 1; cmd.stop_arg = N_SAMPLES; @@ -77,6 +125,8 @@ int test_mmap(void) } munmap(map,MAPLEN); + free(buf); + return 0; }