From 7155ae865cb83a88efc924459513ca532c66b286 Mon Sep 17 00:00:00 2001 From: ajesh Date: Wed, 7 Jul 2021 16:11:29 +0300 Subject: [PATCH] gpu: nvgpu: update queue unit tests Update queue unit tests for code coverage. JIRA NVGPU-6904 Change-Id: I49ed6980f2d610cf8359c375a1236e8866ea6795 Signed-off-by: ajesh Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2555333 (cherry picked from commit f2311f2710cab83b82ed7f5d51c54fa897051686) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2560216 Reviewed-by: svcacv Reviewed-by: svc_kernel_abi Reviewed-by: Rajesh Devaraj Reviewed-by: Shashank Singh Reviewed-by: Vaibhav Kachore Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- userspace/units/posix/queue/posix-queue.c | 46 ++++++++++++++++++++++- userspace/units/posix/queue/posix-queue.h | 16 ++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/userspace/units/posix/queue/posix-queue.c b/userspace/units/posix/queue/posix-queue.c index f2cd3f47a..c48ba8ae3 100644 --- a/userspace/units/posix/queue/posix-queue.c +++ b/userspace/units/posix/queue/posix-queue.c @@ -190,6 +190,24 @@ int test_nvgpu_queue_in(struct unit_module *m, struct gk20a *g, void *args) goto fail; } #endif + /* + * This is for code coverage. + */ + q.in = 0; + q.out = 0; + ret = nvgpu_queue_in_locked(&q, buf, BUF_LEN, NULL); + if (ret != 0) { + err = UNIT_FAIL; + unit_err(m, "%d. queue_in failed err=%d\n", __LINE__, ret); + goto fail; + } + + ret = nvgpu_queue_in_locked(&q, buf, BUF_LEN, NULL); + if (ret != -ENOMEM) { + err = UNIT_FAIL; + unit_err(m, "%d. queue_in failed err=%d\n", __LINE__, ret); + goto fail; + } fail: if (q.data != NULL) @@ -236,6 +254,14 @@ int test_nvgpu_queue_out(struct unit_module *m, struct gk20a *g, void *args) goto fail; } + /* For code coverage. */ + ret = nvgpu_queue_out_locked(&q, buf, BUF_LEN, NULL); + if (ret != -ENOMEM) { + err = UNIT_FAIL; + unit_err(m, "%d. queue_out failed err=%d\n", __LINE__, ret); + goto fail; + } + #ifdef CONFIG_NVGPU_NON_FUSA /* * Advance "in" index by "BUF_LEN" and dequeue message of length BUF_LEN @@ -262,6 +288,16 @@ int test_nvgpu_queue_out(struct unit_module *m, struct gk20a *g, void *args) goto fail; } + /* For code coverage. */ + q.in = BUF_LEN; + q.out = 0; + ret = nvgpu_queue_out_locked(&q, buf, BUF_LEN, NULL); + if (ret != 0) { + err = UNIT_FAIL; + unit_err(m, "%d. queue_out failed err=%d\n", __LINE__, ret); + goto fail; + } + #ifdef CONFIG_NVGPU_NON_FUSA /* * Update "in" and "out" indexes and dequeue message of length BUF_LEN @@ -282,10 +318,18 @@ int test_nvgpu_queue_out(struct unit_module *m, struct gk20a *g, void *args) ret = nvgpu_queue_out_locked(&q, buf, BUF_LEN, &lock); if (ret != 0) { err = UNIT_FAIL; - unit_err(m, "%d. queue in failed err=%d\n", __LINE__, ret); + unit_err(m, "%d. queue out failed err=%d\n", __LINE__, ret); goto fail; } + q.in = (BUF_LEN/2 - 1); + q.out = UINT32_MAX - (BUF_LEN/2); + ret = nvgpu_queue_out_locked(&q, buf, BUF_LEN, &lock); + if (ret != 0) { + err = UNIT_FAIL; + unit_err(m, "%d. queue out failed err=%d\n", __LINE__, ret); + goto fail; + } /* * Fault injection so that immediate call to nvgpu_queue_out_locked() * API would return error. diff --git a/userspace/units/posix/queue/posix-queue.h b/userspace/units/posix/queue/posix-queue.h index 08d73136f..2bf4f96bf 100644 --- a/userspace/units/posix/queue/posix-queue.h +++ b/userspace/units/posix/queue/posix-queue.h @@ -109,6 +109,11 @@ int test_nvgpu_queue_alloc_and_free(struct unit_module *m, struct gk20a *g, * return 0 to indicate successful enqueue operation. * - Enqueue message of length BUF_LEN again using nvgpu_queue_in() API. Check * that the API returns error -ENOMEM. + * - Reset In and Out indexes and enqueue message of length BUF_LEN using + * nvgpu_queue_in_locked() API with lock parameter passed as NULL. This test + * is to increase the code coverage. Check that the API returns 0. + * - Enqueue message of length BUF_LEN again using nvgpu_queue_in_locked() + * API with lock parameter as NULL. Check that the API returns error -ENOMEM. * - Free the allocated resources. * * Output: Returns PASS if the steps above were executed successfully. FAIL @@ -139,15 +144,26 @@ int test_nvgpu_queue_in(struct unit_module *m, struct gk20a *g, void *args); * - Dequeue message of length BUF_LEN from the empty queue calling * nvgpu_queue_out_locked() API and check that the API returns -ENOMEM * error. + * - Dequeue message of length BUF_LEN from the empty queue calling + * nvgpu_queue_out_locked() API with lock parameter passed as NULL and check + * that the API returns -ENOMEM error. This is for code coverage. * - Set In index as BUF_LEN and dequeue message of length BUF_LEN by * calling nvgpu_queue_out() API and check that the API returns 0. * - Set In index as BUF_LEN and dequeue message of length BUF_LEN by * calling nvgpu_queue_out_locked() API and check that the API returns 0. + * - Set In index as BUF_LEN and dequeue message of length BUF_LEN by + * calling nvgpu_queue_out_locked() API with lock parameter passed as NULL + * and check that the API returns 0. This is for code coverage. * - Set In index as 0 and Out index as (UINT32_MAX - BUF_LEN). This * indicates a condition were In index has wrapped around due to an enqueue * operation. Use nvgpu_queue_out API to dequeue message of length BUF_LEN. * The dequeue operation should successfully return 0. * - Repeat the above step to test API nvgpu_queue_out_locked. + * - Set In index as (BUF_LEN/2 - 1) and Out index as (UINT32_MAX - BUF_LEN/2). + * This indicates a condition were In index has wrapped around due to an + * enqueue operation. Use nvgpu_queue_out_locked API to dequeue message of + * length BUF_LEN. This will cover the wrap around condition for Out index. + * The dequeue operation should successfully return 0. * - Do fault injection so that immediate call to nvgpu_queue_out_locked() API * would return error. * - Invoke nvgpu_queue_out_locked() API and check that API returns -1 error.