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 <nbenech@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2207311
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Nicolas Benech
2019-09-27 10:23:14 -04:00
committed by Alex Waterman
parent b7066e0bf1
commit bac3b84a7b
4 changed files with 125 additions and 14 deletions

View File

@@ -32,6 +32,7 @@
* *
* - @ref SWUTS-enabled * - @ref SWUTS-enabled
* - @ref SWUTS-interface-bsearch * - @ref SWUTS-interface-bsearch
* - @ref SWUTS-interface-lock
* - @ref SWUTS-fifo * - @ref SWUTS-fifo
* - @ref SWUTS-fifo-channel * - @ref SWUTS-fifo-channel
* - @ref SWUTS-fifo-runlist * - @ref SWUTS-fifo-runlist

View File

@@ -2,6 +2,7 @@ INPUT += ../../../userspace/SWUTS.h
INPUT += ../../../userspace/units/cg/nvgpu-cg.h INPUT += ../../../userspace/units/cg/nvgpu-cg.h
INPUT += ../../../userspace/units/enabled/nvgpu-enabled.h INPUT += ../../../userspace/units/enabled/nvgpu-enabled.h
INPUT += ../../../userspace/units/interface/bsearch/bsearch.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/nvgpu-fifo.h
INPUT += ../../../userspace/units/fifo/channel/nvgpu-channel.h INPUT += ../../../userspace/units/fifo/channel/nvgpu-channel.h
INPUT += ../../../userspace/units/fifo/runlist/nvgpu-runlist.h INPUT += ../../../userspace/units/fifo/runlist/nvgpu-runlist.h

View File

@@ -32,9 +32,7 @@
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#define TYPE_MUTEX 0 #include "lock.h"
#define TYPE_SPINLOCK 1
#define TYPE_RAW_SPINLOCK 2
/* Parameter structure to pass to worker threads */ /* Parameter structure to pass to worker threads */
struct worker_parameters { struct worker_parameters {
@@ -47,11 +45,7 @@ struct worker_parameters {
sem_t worker_sem; sem_t worker_sem;
bool test_shared_flag; bool test_shared_flag;
/* int test_mutex_init(struct unit_module *m, struct gk20a *g, void *args)
* Simple test to check mutex init routine
*/
static int test_mutex_init(struct unit_module *m, struct gk20a *g,
void *args)
{ {
struct nvgpu_mutex mutex; struct nvgpu_mutex mutex;
@@ -61,11 +55,7 @@ static int test_mutex_init(struct unit_module *m, struct gk20a *g,
return UNIT_SUCCESS; return UNIT_SUCCESS;
} }
/* int test_mutex_tryacquire(struct unit_module *m, struct gk20a *g, void *args)
* Test to verify the behavior of mutex tryacquire function.
*/
static int test_mutex_tryacquire(struct unit_module *m, struct gk20a *g,
void *args)
{ {
struct nvgpu_mutex mutex; struct nvgpu_mutex mutex;
int status; int status;
@@ -154,7 +144,7 @@ static void *lock_worker(void *args)
* release functions. * release functions.
* The "args" argument is an int indicating the lock type. * 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) void *args)
{ {
struct nvgpu_mutex mutex; struct nvgpu_mutex mutex;

View File

@@ -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 */