mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
test cases for signal handling
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1069 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
71589d2246
commit
ae4a52e0ed
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
|
||||
while (1) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
struct timespec sleeptime;
|
||||
|
||||
while (1) {
|
||||
sleeptime.tv_sec=1;
|
||||
sleeptime.tv_nsec=0;
|
||||
nanosleep(&sleeptime,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
struct timeval sleeptime;
|
||||
|
||||
while (1) {
|
||||
sleeptime.tv_sec=1;
|
||||
sleeptime.tv_usec=0;
|
||||
select(0,NULL,NULL,NULL,&sleeptime);
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* small etst program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
static pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/**
|
||||
* actual test program
|
||||
*/
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
|
||||
while (1) {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_mutex_lock(&Mutex);
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
sigset_t sigset;
|
||||
struct timespec sleeptime;
|
||||
|
||||
while (1) {
|
||||
sleeptime.tv_sec=1;
|
||||
sleeptime.tv_nsec=0;
|
||||
sigemptyset(&sigset);
|
||||
pselect(0,NULL,NULL,NULL,&sleeptime,&sigset);
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
|
||||
while (1) {
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* small test program whether signals between threads work as they should
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void sighandler(int sig) {
|
||||
write(2,".",1);
|
||||
return;
|
||||
}
|
||||
|
||||
void* threadstart(void* arg) {
|
||||
char buf[1024];
|
||||
|
||||
while (1) {
|
||||
read(1,buf,512);
|
||||
}
|
||||
}
|
||||
|
||||
int main(char** argc, int argv) {
|
||||
|
||||
pthread_t testthread1;
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_handler=sighandler;
|
||||
action.sa_flags=0;
|
||||
sigfillset( &action.sa_mask );
|
||||
sigaction(SIGUSR1,&action,NULL);
|
||||
|
||||
pthread_create(&testthread1,NULL,threadstart,NULL);
|
||||
while (1) {
|
||||
pthread_kill(testthread1,SIGUSR1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user