From bdaa8519d52c1aa45ef9699df3d08bdd2cb7dc91 Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Thu, 16 Jan 2020 16:33:01 -0500 Subject: [PATCH] gpu: nvgpu: unit: improve coverage for gv11b tsg HAL Add test for the following HAL: - gv11b_tsg_enable Jira NVGPU-4890 Change-Id: Ia79be676098e18ca71f6f9983485bf107c15f37c Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2280135 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/libnvgpu-drv_safe.export | 1 + userspace/required_tests.json | 6 ++ .../units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.c | 59 +++++++++++++++++++ .../units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.h | 27 +++++++++ 4 files changed, 93 insertions(+) diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 1a08dc224..17d276552 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -192,6 +192,7 @@ gv11b_runlist_entry_size gv11b_runlist_get_tsg_entry gv11b_runlist_get_ch_entry gv11b_therm_init_elcg_mode +gv11b_tsg_enable gv11b_usermode_base gv11b_usermode_bus_base gv11b_usermode_doorbell_token diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 7dd42ee00..59e911cda 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -3491,6 +3491,12 @@ "unit": "nvgpu_tsg_gv11b", "test_level": 0 }, + { + "test": "test_gv11b_tsg_enable", + "case": "gv11b_tsg_enable", + "unit": "nvgpu_tsg_gv11b", + "test_level": 0 + }, { "test": "test_gv11b_tsg_init_eng_method_buffers", "case": "gv11b_tsg_init_eng_method_buffers", diff --git a/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.c b/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.c index c2547f1a3..dcb3397b9 100644 --- a/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.c +++ b/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.c @@ -96,6 +96,64 @@ static void subtest_setup(u32 branches) #define branches_str test_fifo_flags_str #define pruned test_fifo_subtest_pruned +static void stub_channel_enable(struct nvgpu_channel *ch) +{ + stub[0].chid = ch->chid; + stub[0].count++; +} + +static void stub_usermode_ring_doorbell(struct nvgpu_channel *ch) +{ + stub[1].chid = ch->chid; + stub[1].count++; +} + +int test_gv11b_tsg_enable(struct unit_module *m, + struct gk20a *g, void *args) +{ + struct gpu_ops gops = g->ops; + struct nvgpu_tsg *tsg = NULL; + struct nvgpu_channel *ch = NULL; + int ret = UNIT_FAIL; + int err; + + memset(stub, 0, sizeof(stub)); + g->ops.channel.enable = stub_channel_enable; + g->ops.usermode.ring_doorbell = stub_usermode_ring_doorbell; + + tsg = nvgpu_tsg_open(g, getpid()); + unit_assert(tsg != NULL, goto done); + + /* standalone TSG */ + gv11b_tsg_enable(tsg); + unit_assert(stub[0].count == 0, goto done); + unit_assert(stub[1].count == 0, goto done); + + ch = nvgpu_channel_open_new(g, ~0U, false, getpid(), getpid()); + unit_assert(ch != NULL, goto done); + + err = nvgpu_tsg_bind_channel(tsg, ch); + unit_assert(err == 0, goto done); + + /* TSG with bound channel */ + gv11b_tsg_enable(tsg); + unit_assert(stub[0].count == 1, goto done); + unit_assert(stub[0].chid == ch->chid, goto done); + unit_assert(stub[1].count == 1, goto done); + unit_assert(stub[1].chid == ch->chid, goto done); + + ret = UNIT_SUCCESS; +done: + if (ch != NULL) { + nvgpu_channel_close(ch); + } + if (tsg != NULL) { + nvgpu_ref_put(&tsg->refcount, nvgpu_tsg_release); + } + g->ops = gops; + return ret; +} + #define GR_RUNQUE 0U /* pbdma 0 */ #define ASYNC_CE_RUNQUE 2U /* pbdma 2 */ @@ -383,6 +441,7 @@ done: struct unit_module_test nvgpu_tsg_gv11b_tests[] = { UNIT_TEST(init_support, test_fifo_init_support, &unit_ctx, 0), + UNIT_TEST(gv11b_tsg_enable, test_gv11b_tsg_enable, &unit_ctx, 0), UNIT_TEST(gv11b_tsg_init_eng_method_buffers, \ test_gv11b_tsg_init_eng_method_buffers, &unit_ctx, 0), UNIT_TEST(gv11b_tsg_bind_channel_eng_method_buffers, diff --git a/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.h b/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.h index 2c0e25c79..7f1cebc9f 100644 --- a/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.h +++ b/userspace/units/fifo/tsg/gv11b/nvgpu-tsg-gv11b.h @@ -33,6 +33,33 @@ struct gk20a; * Software Unit Test Specification for fifo/tsg/gv11b */ +/** + * Test specification for: test_gv11b_tsg_enable + * + * Description: Enable TSG + * + * Test Type: Feature + * + * Targets: gops_tsg.enable, gv11b_tsg_enable + * + * Input: test_fifo_init_support() run for this GPU + * + * Steps: + * - Use stubs for gops_channel.enable and gops_usermode.ring_doorbell. + * - Call gv11b for a standalone TSG: + * - Check that gops_channel.enable is not called. + * - Check that gops_usermode.ring_doorbell is not called. + * - Call gv11b for a TSG with one bound channel: + * - Check that gops_channel.enable is called for this channel. + * - Check that gops_usermode.ring_doorbell is called for this + * channel. + * + * Output: Returns PASS if all branches gave expected results. FAIL otherwise. + */ +int test_gv11b_tsg_enable(struct unit_module *m, + struct gk20a *g, void *args); + + /** * Test specification for: test_gv11b_tsg_init_eng_method_buffers *