diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2012-01-11 15:33:00 +0100 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2012-01-11 15:33:00 +0100 |
commit | cbaa8a389e47695e6612eb0f76faaf7d0979fee3 (patch) | |
tree | 64ab19f46493ebd89c5c5855e256e7bc9e83aba8 /lib | |
parent | 36d25cc7440ef9d37d16ea95ee0d51e5e6e2c5e2 (diff) |
lib/drmtest: extract helpers for signal interruptions
Also add some hackish stat to check it works.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/drmtest.c | 43 | ||||
-rw-r--r-- | lib/drmtest.h | 3 |
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c index f3f05347..bfb36a86 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -31,6 +31,8 @@ #include <sys/ioctl.h> #include <string.h> #include <sys/mman.h> +#include <signal.h> + #include "drmtest.h" #include "i915_drm.h" #include "intel_chipset.h" @@ -219,3 +221,44 @@ void *gem_mmap(int fd, uint32_t handle, int size, int prot) return ptr; } +static pid_t signal_helper = -1; +long long int sig_stat; +static void signal_helper_process(pid_t pid) +{ + /* Interrupt the parent process at 500Hz, just to be annoying */ + while (1) { + usleep(1000 * 1000 / 500); + if (kill(pid, SIGUSR1)) /* Parent has died, so must we. */ + exit(0); + } +} + +static void sig_handler(int i) +{ + sig_stat++; +} + +void drmtest_fork_signal_helper(void) +{ + pid_t pid; + + signal(SIGUSR1, sig_handler); + pid = fork(); + if (pid == 0) { + signal_helper_process(getppid()); + return; + } + + signal_helper = pid; +} + +void drmtest_stop_signal_helper(void) +{ + if (signal_helper != -1) + kill(signal_helper, SIGQUIT); + + if (sig_stat) + fprintf(stderr, "signal handler called %llu times\n", sig_stat); + + signal_helper = -1; +} diff --git a/lib/drmtest.h b/lib/drmtest.h index 38118f17..a10a0521 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -46,3 +46,6 @@ void gem_set_domain(int fd, uint32_t handle, void gem_sync(int fd, uint32_t handle); uint32_t gem_create(int fd, int size); void *gem_mmap(int fd, uint32_t handle, int size, int prot); + +void drmtest_fork_signal_helper(void); +void drmtest_stop_signal_helper(void); |