#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "comedi_test.h" /* XXX this should come from elsewhere */ #define PAGE_SIZE 4096 #define N_SAMPLES 10000 #define BUFSZ N_SAMPLES*sizeof(sampl_t) #define MAPLEN 20480 sigjmp_buf jump_env; void segv_handler(int num) { siglongjmp(jump_env,1); } int test_segfault(void *memptr) { volatile char tmp; int ret; struct sigaction act; struct sigaction oldact; memset(&act,0,sizeof(act)); act.sa_handler=&segv_handler; ret = sigaction(SIGSEGV,&act,&oldact); if(ret) { fprintf(stderr, "sigaction failed\n"); return 0; } ret=sigsetjmp(jump_env, 1); if(!ret) tmp = *((char *)(memptr)); sigaction(SIGSEGV,&oldact,NULL); return ret; } int test_mmap(void) { comedi_cmd cmd; unsigned char *buf; unsigned int chanlist[1]; int go; int fails; int total=0; int ret; void *b; unsigned char *adr; unsigned char *map; unsigned int flags; int i; flags = comedi_get_subdevice_flags(device,subdevice); if(!(flags&SDF_CMD) || flags&SDF_WRITEABLE){ printf("not applicable\n"); return 0; } if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){ printf("E: comedi_get_cmd_generic_timed failed\n"); return 0; } buf=malloc(BUFSZ); map=mmap(NULL,MAPLEN,PROT_READ,MAP_SHARED,comedi_fileno(device),0); if(!map){ printf("E: mmap() failed\n"); return 0; } /* test readability */ for(adr=map;adr10)break; } } if(fails==0) printf("compare ok\n"); munmap(map,MAPLEN); /* test if area is really unmapped */ for(adr=map;adr