added segfault testing
This commit is contained in:
parent
91f2dd824b
commit
8265dded62
1 changed files with 52 additions and 2 deletions
|
@ -11,8 +11,15 @@
|
|||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue