From bac3b84a7b880d5ce7c6155fb75db4cc27c35bfa Mon Sep 17 00:00:00 2001 From: Nicolas Benech Date: Fri, 27 Sep 2019 10:23:14 -0400 Subject: [PATCH] gpu: nvgpu: unit: SWUTS for interface.lock Add SWUTS documentation for the interface.lock unit. JIRA NVGPU-3943 Change-Id: I705755482ee98217dc5015a42fea6f13ba852a61 Signed-off-by: Nicolas Benech Reviewed-on: https://git-master.nvidia.com/r/2207311 Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/SWUTS.h | 1 + userspace/SWUTS.sources | 1 + userspace/units/interface/lock/lock.c | 18 +--- userspace/units/interface/lock/lock.h | 119 ++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 userspace/units/interface/lock/lock.h diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index 7bd7ae9cb..0cc8717d5 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -32,6 +32,7 @@ * * - @ref SWUTS-enabled * - @ref SWUTS-interface-bsearch + * - @ref SWUTS-interface-lock * - @ref SWUTS-fifo * - @ref SWUTS-fifo-channel * - @ref SWUTS-fifo-runlist diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index 68b07b9cf..7c8e4d1bb 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -2,6 +2,7 @@ INPUT += ../../../userspace/SWUTS.h INPUT += ../../../userspace/units/cg/nvgpu-cg.h INPUT += ../../../userspace/units/enabled/nvgpu-enabled.h INPUT += ../../../userspace/units/interface/bsearch/bsearch.h +INPUT += ../../../userspace/units/interface/lock/lock.h INPUT += ../../../userspace/units/fifo/nvgpu-fifo.h INPUT += ../../../userspace/units/fifo/channel/nvgpu-channel.h INPUT += ../../../userspace/units/fifo/runlist/nvgpu-runlist.h diff --git a/userspace/units/interface/lock/lock.c b/userspace/units/interface/lock/lock.c index c108d97e3..9a72771a9 100644 --- a/userspace/units/interface/lock/lock.c +++ b/userspace/units/interface/lock/lock.c @@ -32,9 +32,7 @@ #include #include -#define TYPE_MUTEX 0 -#define TYPE_SPINLOCK 1 -#define TYPE_RAW_SPINLOCK 2 +#include "lock.h" /* Parameter structure to pass to worker threads */ struct worker_parameters { @@ -47,11 +45,7 @@ struct worker_parameters { sem_t worker_sem; bool test_shared_flag; -/* - * Simple test to check mutex init routine - */ -static int test_mutex_init(struct unit_module *m, struct gk20a *g, - void *args) +int test_mutex_init(struct unit_module *m, struct gk20a *g, void *args) { struct nvgpu_mutex mutex; @@ -61,11 +55,7 @@ static int test_mutex_init(struct unit_module *m, struct gk20a *g, return UNIT_SUCCESS; } -/* - * Test to verify the behavior of mutex tryacquire function. - */ -static int test_mutex_tryacquire(struct unit_module *m, struct gk20a *g, - void *args) +int test_mutex_tryacquire(struct unit_module *m, struct gk20a *g, void *args) { struct nvgpu_mutex mutex; int status; @@ -154,7 +144,7 @@ static void *lock_worker(void *args) * release functions. * The "args" argument is an int indicating the lock type. */ -static int test_lock_acquire_release(struct unit_module *m, struct gk20a *g, +int test_lock_acquire_release(struct unit_module *m, struct gk20a *g, void *args) { struct nvgpu_mutex mutex; diff --git a/userspace/units/interface/lock/lock.h b/userspace/units/interface/lock/lock.h new file mode 100644 index 000000000..c49e26ff7 --- /dev/null +++ b/userspace/units/interface/lock/lock.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2019, 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef UNIT_LOCK_H +#define UNIT_LOCK_H + +struct gk20a; +struct unit_module; + +/** @addtogroup SWUTS-interface-lock + * @{ + * + * Software Unit Test Specification for interface.lock + */ + +/** + * \name Lock Types + * There are 3 types of locks supported by this unit test, defined as below. + */ +/** @{ */ +#define TYPE_MUTEX 0 +#define TYPE_SPINLOCK 1 +#define TYPE_RAW_SPINLOCK 2 +/** @} */ + +/** + * Test specification for: test_mutex_init + * + * Description: Simple test to check mutex init routine. + * + * Test Type: Feature + * + * Input: None + * + * Steps: + * - Initialize a mutex via the nvgpu_mutex_init function. + * - Destroy the mutex via the nvgpu_mutex_destroy function. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mutex_init(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_mutex_tryacquire + * + * Description: Test to verify the behavior of mutex tryacquire function. + * + * Test Type: Feature + * + * Input: None + * + * Steps: + * - Initialize a mutex via the nvgpu_mutex_init function. + * - Acquire the mutex. + * - Perform a nvgpu_mutex_tryacquire on the mutex and ensure that the operation + * returned a failure code. + * - Release the mutex. + * - Perform a nvgpu_mutex_tryacquire again and ensure that the operation + * succeeded. + * - Release and destroy the mutex. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_mutex_tryacquire(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_lock_acquire_release + * + * Description: Test to verify the behavior of mutex, regular and raw spinlocks + * acquire and release functions. For this purpose, there are 2 threads + * involved: the regular main thread, and a worker thread. + * + * Test Type: Feature + * + * Input: @param args [in] Type of lock as defined by TYPE_* macros. + * + * Steps: + * - Initialize the lock using the corresponding init function. + * - Create a semaphore \a worker_sem and set the \a test_shared_flag to false. + * - Acquire the lock using its corresponding acquire function. + * - Create the worker thread and wait for it to signal that it is ready thanks + * to the \a worker_sem. + * - The worker thread then blocks trying to acquire the lock. + * - The main thread then releases the lock and wait for a signal from the + * worker thread via \a worker_sem. + * - The worker thread should now be able to acquire the lock and update the + * \a test_shared_flag. + * - The main thread ensures that the \a test_shared_flag was updated. + * - Release and destroy the lock and the worker thread. + * + * Output: Returns PASS if the steps above were executed successfully. FAIL + * otherwise. + */ +int test_lock_acquire_release(struct unit_module *m, struct gk20a *g, + void *args); + +/** }@ */ +#endif /* UNIT_LOCK_H */