mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: unit: add test for BUG() callbacks
Add unit tests for the following functions: - nvgpu_bug_register_cb - nvgpu_bug_unregister_cb Jira NVGPU-4512 Change-Id: I21a4bd55cfff080373b6234e517c1ee9cb51cb8a Signed-off-by: Thomas Fleury <tfleury@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2266392 Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com> Reviewed-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-by: Shashank Singh <shashsingh@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
Alex Waterman
parent
1f3f34b906
commit
1a3c1ee984
@@ -272,6 +272,8 @@ nvgpu_big_pages_possible
|
|||||||
nvgpu_bitmap_clear
|
nvgpu_bitmap_clear
|
||||||
nvgpu_bitmap_set
|
nvgpu_bitmap_set
|
||||||
nvgpu_bsearch
|
nvgpu_bsearch
|
||||||
|
nvgpu_bug_register_cb
|
||||||
|
nvgpu_bug_unregister_cb
|
||||||
nvgpu_can_busy
|
nvgpu_can_busy
|
||||||
nvgpu_ce_engine_interrupt_mask
|
nvgpu_ce_engine_interrupt_mask
|
||||||
nvgpu_ce_init_support
|
nvgpu_ce_init_support
|
||||||
|
|||||||
@@ -3932,6 +3932,12 @@
|
|||||||
"unit": "posix_bitops",
|
"unit": "posix_bitops",
|
||||||
"test_level": 0
|
"test_level": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"test": "test_bug_cb",
|
||||||
|
"case": "bug_cb",
|
||||||
|
"unit": "posix_bug",
|
||||||
|
"test_level": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"test": "test_expect_bug",
|
"test": "test_expect_bug",
|
||||||
"case": "expect_bug",
|
"case": "expect_bug",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
* Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
#include <unit/io.h>
|
#include <unit/io.h>
|
||||||
#include <unit/unit.h>
|
#include <unit/unit.h>
|
||||||
@@ -73,8 +74,72 @@ static int test_expect_bug(struct unit_module *m,
|
|||||||
return UNIT_SUCCESS;
|
return UNIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool cb_called = false;
|
||||||
|
|
||||||
|
static void bug_cb(void *arg)
|
||||||
|
{
|
||||||
|
jmp_buf *jmp_handler = arg;
|
||||||
|
|
||||||
|
cb_called = true;
|
||||||
|
longjmp(*jmp_handler, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool other_cb_called = false;
|
||||||
|
|
||||||
|
static void other_bug_cb(void *arg)
|
||||||
|
{
|
||||||
|
other_cb_called = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_bug_cb(struct unit_module *m,
|
||||||
|
struct gk20a *g, void *args)
|
||||||
|
{
|
||||||
|
struct nvgpu_bug_cb callback;
|
||||||
|
struct nvgpu_bug_cb other_callback;
|
||||||
|
jmp_buf handler;
|
||||||
|
|
||||||
|
|
||||||
|
/* two callbacks */
|
||||||
|
|
||||||
|
callback.cb = bug_cb;
|
||||||
|
callback.arg = &handler;
|
||||||
|
|
||||||
|
other_callback.cb = other_bug_cb;
|
||||||
|
other_callback.arg = NULL;
|
||||||
|
|
||||||
|
nvgpu_bug_register_cb(&other_callback);
|
||||||
|
nvgpu_bug_register_cb(&callback);
|
||||||
|
if (setjmp(handler) == 0) {
|
||||||
|
BUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!other_cb_called || !cb_called) {
|
||||||
|
unit_err(m, "BUG() callback was not called.\n");
|
||||||
|
return UNIT_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* one callback */
|
||||||
|
other_cb_called = false;
|
||||||
|
nvgpu_bug_register_cb(&other_callback);
|
||||||
|
nvgpu_bug_register_cb(&callback);
|
||||||
|
nvgpu_bug_unregister_cb(&other_callback);
|
||||||
|
|
||||||
|
if (setjmp(handler) == 0) {
|
||||||
|
BUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other_cb_called) {
|
||||||
|
unit_err(m, "callback unregistration failed.\n");
|
||||||
|
return UNIT_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UNIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct unit_module_test posix_bug_tests[] = {
|
struct unit_module_test posix_bug_tests[] = {
|
||||||
UNIT_TEST(expect_bug, test_expect_bug, NULL, 0),
|
UNIT_TEST(expect_bug, test_expect_bug, NULL, 0),
|
||||||
|
UNIT_TEST(bug_cb, test_bug_cb, NULL, 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
UNIT_MODULE(posix_bug, posix_bug_tests, UNIT_PRIO_POSIX_TEST);
|
UNIT_MODULE(posix_bug, posix_bug_tests, UNIT_PRIO_POSIX_TEST);
|
||||||
|
|||||||
Reference in New Issue
Block a user