mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-24 02:22:34 +03:00
gpu: nvgpu: posix: Add BUG() exception handling
For unit testing, this new feature allows to "catch" calls to BUG() when they are expected. JIRA NVGPU-1287 Change-Id: I29fc9cd7fc28f8697a865c173b6991e2a48a3b4d Signed-off-by: Nicolas Benech <nbenech@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1930974 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
f00d9ca1aa
commit
ee282de11b
@@ -24,6 +24,23 @@
|
||||
#include <nvgpu/posix/bug.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
static _Thread_local bool expect_bug;
|
||||
static _Thread_local jmp_buf *jmp_handler;
|
||||
|
||||
void bug_handler_register(jmp_buf *handler)
|
||||
{
|
||||
expect_bug = true;
|
||||
jmp_handler = handler;
|
||||
}
|
||||
|
||||
void bug_handler_cancel(void)
|
||||
{
|
||||
expect_bug = false;
|
||||
jmp_handler = NULL;
|
||||
}
|
||||
|
||||
static void __dump_stack(unsigned int skip_frames)
|
||||
{
|
||||
@@ -40,9 +57,14 @@ void dump_stack(void)
|
||||
*/
|
||||
void __bug(const char *fmt, ...)
|
||||
{
|
||||
if (expect_bug) {
|
||||
nvgpu_info(NULL, "Expected BUG detected!");
|
||||
expect_bug = false;
|
||||
/* Perform a long jump to where "setjmp()" was called. */
|
||||
longjmp(*jmp_handler, 1);
|
||||
}
|
||||
/* If BUG is unexpected, raise a SIGSEGV signal and kill the thread */
|
||||
nvgpu_err(NULL, "BUG detected!");
|
||||
|
||||
/* Raise a bad system call signal and kill the thread */
|
||||
(void) raise(SIGSEGV);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user