diff --git a/userspace/units/posix/bug/posix-bug.c b/userspace/units/posix/bug/posix-bug.c index f7598adb4..e8a098e97 100644 --- a/userspace/units/posix/bug/posix-bug.c +++ b/userspace/units/posix/bug/posix-bug.c @@ -47,6 +47,13 @@ static void bug_caller(struct unit_module *m, bool call) } } +/* + * Simple wrapper function to call BUG_ON() with condition. + */ +static void bug_on_caller(struct unit_module *m, bool cond) +{ + BUG_ON(cond); +} /* * Test to ensure the EXPECT_BUG construct works as intended by making sure it * behaves properly when BUG is called or not. @@ -73,6 +80,20 @@ int test_expect_bug(struct unit_module *m, return UNIT_FAIL; } + if (!EXPECT_BUG(bug_on_caller(m, true))) { + unit_err(m, "BUG_ON expected to invoke BUG()\n"); + return UNIT_FAIL; + } else { + unit_info(m, "BUG_ON invoked BUG() as expected\n"); + } + + if (!EXPECT_BUG(bug_on_caller(m, false))) { + unit_info(m, "BUG_ON() skipped BUG invocation as expected\n"); + } else { + unit_err(m, "BUG_ON invoked BUG but it was not expected()\n"); + return UNIT_FAIL; + } + return UNIT_SUCCESS; } diff --git a/userspace/units/posix/bug/posix-bug.h b/userspace/units/posix/bug/posix-bug.h index a7bf47da1..3661a41ec 100644 --- a/userspace/units/posix/bug/posix-bug.h +++ b/userspace/units/posix/bug/posix-bug.h @@ -37,7 +37,8 @@ * * Test Type: Feature * - * Targets: nvgpu_posix_bug, dump_stack + * Targets: nvgpu_posix_bug, dump_stack, + * BUG, BUG_ON * * Inputs: None * @@ -47,6 +48,7 @@ * which cannot be run in unit test framework will not be executed. * 3) EXPECT_BUG is also tested to make sure that BUG is not called where it is * not expected. + * 4) Steps 1 and 2 are also executed to test the macro BUG_ON. * * Output: * The test returns PASS if BUG is called as expected based on the parameters