From 1a3c1ee984a497c2fa178eb23d7e4319009b2d79 Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Thu, 19 Dec 2019 16:10:32 -0500 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2266392 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Deepak Nibade Reviewed-by: Shashank Singh GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/libnvgpu-drv_safe.export | 2 + userspace/required_tests.json | 6 ++ userspace/units/posix/bug/posix-bug.c | 67 +++++++++++++++++++++- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 7429041ff..fd30f94d4 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -272,6 +272,8 @@ nvgpu_big_pages_possible nvgpu_bitmap_clear nvgpu_bitmap_set nvgpu_bsearch +nvgpu_bug_register_cb +nvgpu_bug_unregister_cb nvgpu_can_busy nvgpu_ce_engine_interrupt_mask nvgpu_ce_init_support diff --git a/userspace/required_tests.json b/userspace/required_tests.json index abb80213f..6ed7a36bb 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -3932,6 +3932,12 @@ "unit": "posix_bitops", "test_level": 0 }, + { + "test": "test_bug_cb", + "case": "bug_cb", + "unit": "posix_bug", + "test_level": 0 + }, { "test": "test_expect_bug", "case": "expect_bug", diff --git a/userspace/units/posix/bug/posix-bug.c b/userspace/units/posix/bug/posix-bug.c index 651005305..6b4fb6918 100644 --- a/userspace/units/posix/bug/posix-bug.c +++ b/userspace/units/posix/bug/posix-bug.c @@ -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 * copy of this software and associated documentation files (the "Software"), @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -73,8 +74,72 @@ static int test_expect_bug(struct unit_module *m, 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[] = { 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);