mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-22 15:47:37 +01:00
tests: unw_init_local_signal test
This commit is contained in:
parent
14c48b3d51
commit
ab868ece1a
4 changed files with 68 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -66,6 +66,7 @@ tests/test-static-link
|
|||
tests/[GL]test-trace
|
||||
tests/[GL]perf-trace
|
||||
tests/Ltest-cxx-exceptions
|
||||
tests/Ltest-init-local-signal
|
||||
tests/[GL]ia64-test-nat
|
||||
tests/[GL]ia64-test-rbs
|
||||
tests/[GL]ia64-test-readonly
|
||||
|
|
6
tests/Ltest-init-local-signal-lib.c
Normal file
6
tests/Ltest-init-local-signal-lib.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* To prevent inlining and optimizing away */
|
||||
int foo(int* f) {
|
||||
return *f;
|
||||
}
|
57
tests/Ltest-init-local-signal.c
Normal file
57
tests/Ltest-init-local-signal.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "libunwind.h"
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int stepper(unw_cursor_t* c) {
|
||||
int steps = 0;
|
||||
int ret = 1;
|
||||
while (ret) {
|
||||
|
||||
ret = unw_step(c);
|
||||
if (!ret) {
|
||||
break;
|
||||
}
|
||||
steps++;
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
/* Verify that we can step from both ucontext, and from getcontext()
|
||||
* roughly the same. This tests that the IP from ucontext is used
|
||||
* correctly (see impl of unw_init_local_signal) */
|
||||
void handler(int num, siginfo_t* info, void* ucontext) {
|
||||
unw_cursor_t c;
|
||||
unw_context_t context;
|
||||
unw_getcontext(&context);
|
||||
int ret = unw_init_local_signal(&c, ucontext);
|
||||
assert(!ret);
|
||||
int ucontext_steps = stepper(&c);
|
||||
|
||||
ret = unw_init_local(&c, &context);
|
||||
assert(!ret);
|
||||
int getcontext_steps = stepper(&c);
|
||||
if (ucontext_steps == getcontext_steps - 2) {
|
||||
exit(0);
|
||||
}
|
||||
printf("unw_getcontext steps was %i, ucontext steps was %i, should be %i\n",
|
||||
getcontext_steps, ucontext_steps, getcontext_steps - 2);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int foo(int* f);
|
||||
|
||||
int main(){
|
||||
struct sigaction a;
|
||||
memset(&a, 0, sizeof(struct sigaction));
|
||||
a.sa_sigaction = &handler;
|
||||
sigaction(SIGSEGV, &a, NULL);
|
||||
|
||||
foo(NULL);
|
||||
}
|
|
@ -45,6 +45,7 @@ endif #!ARCH_IA64
|
|||
Gtest-resume-sig Ltest-resume-sig \
|
||||
Gtest-resume-sig-rt Ltest-resume-sig-rt \
|
||||
Gtest-trace Ltest-trace \
|
||||
Ltest-init-local-signal \
|
||||
test-async-sig test-flush-cache test-init-remote \
|
||||
test-mem Ltest-varargs Ltest-nomalloc \
|
||||
Ltest-nocalloc Lrs-race
|
||||
|
@ -134,6 +135,8 @@ Gtest_init_SOURCES = Gtest-init.cxx
|
|||
Ltest_init_SOURCES = Ltest-init.cxx
|
||||
Ltest_cxx_exceptions_SOURCES = Ltest-cxx-exceptions.cxx
|
||||
|
||||
Ltest_init_local_signal_SOURCES = Ltest-init-local-signal.c Ltest-init-local-signal-lib.c
|
||||
|
||||
Gtest_dyn1_SOURCES = Gtest-dyn1.c flush-cache.S flush-cache.h
|
||||
Ltest_dyn1_SOURCES = Ltest-dyn1.c flush-cache.S flush-cache.h
|
||||
test_static_link_SOURCES = test-static-link-loc.c test-static-link-gen.c
|
||||
|
@ -174,6 +177,7 @@ test_static_link_LDADD = $(LIBUNWIND)
|
|||
test_strerror_LDADD = $(LIBUNWIND)
|
||||
Lrs_race_LDADD = $(LIBUNWIND_local) -lpthread
|
||||
Ltest_varargs_LDADD = $(LIBUNWIND_local)
|
||||
Ltest_init_local_signal_LDADD = $(LIBUNWIND)
|
||||
|
||||
Gtest_bt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
|
||||
Gtest_concurrent_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) -lpthread
|
||||
|
|
Loading…
Reference in a new issue