mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: add tests for kref
Add unit tests for kref unit. Jira NVGPU-4417 Change-Id: Ie5c6efc72b95aa1f200a59fd9184f20e65548fee Signed-off-by: ajesh <akv@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2287553 Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
26
userspace/units/interface/kref/Makefile
Normal file
26
userspace/units/interface/kref/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 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"),
|
||||
# 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.
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
OBJS = kref.o
|
||||
MODULE = kref
|
||||
|
||||
include ../../Makefile.units
|
||||
23
userspace/units/interface/kref/Makefile.interface.tmk
Normal file
23
userspace/units/interface/kref/Makefile.interface.tmk
Normal file
@@ -0,0 +1,23 @@
|
||||
################################### tell Emacs this is a -*- makefile-gmake -*-
|
||||
#
|
||||
# Copyright (c) 2020, NVIDIA CORPORATION. All Rights Reserved.
|
||||
#
|
||||
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
||||
# and proprietary rights in and to this software, related documentation
|
||||
# and any modifications thereto. Any use, reproduction, disclosure or
|
||||
# distribution of this software and related documentation without an express
|
||||
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
||||
#
|
||||
# tmake for SW Mobile component makefile
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
NVGPU_UNIT_NAME=kref
|
||||
|
||||
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk
|
||||
|
||||
# Local Variables:
|
||||
# indent-tabs-mode: t
|
||||
# tab-width: 8
|
||||
# End:
|
||||
# vi: set tabstop=8 noexpandtab:
|
||||
24
userspace/units/interface/kref/Makefile.tmk
Normal file
24
userspace/units/interface/kref/Makefile.tmk
Normal file
@@ -0,0 +1,24 @@
|
||||
################################### tell Emacs this is a -*- makefile-gmake -*-
|
||||
#
|
||||
# Copyright (c) 2020, NVIDIA CORPORATION. All Rights Reserved.
|
||||
#
|
||||
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
||||
# and proprietary rights in and to this software, related documentation
|
||||
# and any modifications thereto. Any use, reproduction, disclosure or
|
||||
# distribution of this software and related documentation without an express
|
||||
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
||||
#
|
||||
# tmake for SW Mobile component makefile
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
NVGPU_UNIT_NAME=kref
|
||||
NVGPU_UNIT_SRCS=kref.c
|
||||
|
||||
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk
|
||||
|
||||
# Local Variables:
|
||||
# indent-tabs-mode: t
|
||||
# tab-width: 8
|
||||
# End:
|
||||
# vi: set tabstop=8 noexpandtab:
|
||||
210
userspace/units/interface/kref/kref.c
Normal file
210
userspace/units/interface/kref/kref.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 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"),
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unit/io.h>
|
||||
#include <unit/unit.h>
|
||||
|
||||
#include <nvgpu/kref.h>
|
||||
|
||||
#include "kref.h"
|
||||
|
||||
#define LOOP_COUNT 10
|
||||
|
||||
int release_count = 0;
|
||||
|
||||
static void test_ref_release(struct nvgpu_ref *ref)
|
||||
{
|
||||
release_count += 1;
|
||||
}
|
||||
|
||||
int test_kref_init(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
int ret = 0;
|
||||
struct nvgpu_ref test_ref;
|
||||
|
||||
nvgpu_ref_init(&test_ref);
|
||||
|
||||
ret = nvgpu_atomic_read(&test_ref.refcount);
|
||||
|
||||
if (ret != 1) {
|
||||
unit_return_fail(m, "nvgpu_ref_init failure\n");
|
||||
}
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
int test_kref_get(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
int ret, loop;
|
||||
struct nvgpu_ref test_ref;
|
||||
|
||||
nvgpu_ref_init(&test_ref);
|
||||
|
||||
for (loop = 1; loop < LOOP_COUNT; loop++) {
|
||||
nvgpu_ref_get(&test_ref);
|
||||
}
|
||||
|
||||
ret = nvgpu_atomic_read(&test_ref.refcount);
|
||||
|
||||
if (ret != LOOP_COUNT) {
|
||||
unit_return_fail(m, "nvgpu_ref_get failure %d\n", ret);
|
||||
}
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
int test_kref_get_unless(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
int ret;
|
||||
struct nvgpu_ref test_ref;
|
||||
|
||||
nvgpu_atomic_set(&test_ref.refcount, 0);
|
||||
ret = nvgpu_atomic_read(&test_ref.refcount);
|
||||
if (ret != 0) {
|
||||
unit_return_fail(m, "nvgpu_ref set to 0 failure %d\n", ret);
|
||||
}
|
||||
|
||||
ret = nvgpu_ref_get_unless_zero(&test_ref);
|
||||
if (ret) {
|
||||
unit_return_fail(m,
|
||||
"nvgpu_ref_get_unless_zero failure %d\n", ret);
|
||||
}
|
||||
|
||||
nvgpu_ref_init(&test_ref);
|
||||
ret = nvgpu_ref_get_unless_zero(&test_ref);
|
||||
if (!ret) {
|
||||
unit_return_fail(m,
|
||||
"nvgpu_ref_get_unless_zero failure\n");
|
||||
}
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
int test_kref_put(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
int ret, loop;
|
||||
struct nvgpu_ref test_ref;
|
||||
|
||||
release_count = 0;
|
||||
nvgpu_ref_init(&test_ref);
|
||||
|
||||
for (loop = 1; loop < LOOP_COUNT; loop++) {
|
||||
nvgpu_ref_get(&test_ref);
|
||||
}
|
||||
|
||||
ret = nvgpu_atomic_read(&test_ref.refcount);
|
||||
|
||||
if (ret != LOOP_COUNT) {
|
||||
unit_return_fail(m, "nvgpu_ref_get failure %d\n", ret);
|
||||
}
|
||||
|
||||
for (loop = 0; loop < LOOP_COUNT; loop++) {
|
||||
nvgpu_ref_put(&test_ref, test_ref_release);
|
||||
}
|
||||
|
||||
if (!release_count) {
|
||||
unit_return_fail(m,
|
||||
"release function not invoked\n");
|
||||
} else if ((release_count > 1)) {
|
||||
unit_return_fail(m,
|
||||
"release function invoked more than once\n");
|
||||
}
|
||||
|
||||
nvgpu_ref_get(&test_ref);
|
||||
|
||||
nvgpu_ref_put(&test_ref, NULL);
|
||||
|
||||
ret = nvgpu_atomic_read(&test_ref.refcount);
|
||||
if (ret) {
|
||||
unit_return_fail(m,
|
||||
"nvgpu_ref_put with NULL callback failure %d\n", ret);
|
||||
}
|
||||
|
||||
release_count = 0;
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
int test_kref_put_return(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
int ret, loop;
|
||||
struct nvgpu_ref test_ref;
|
||||
|
||||
release_count = 0;
|
||||
nvgpu_ref_init(&test_ref);
|
||||
|
||||
for (loop = 1; loop < LOOP_COUNT; loop++) {
|
||||
nvgpu_ref_get(&test_ref);
|
||||
}
|
||||
|
||||
ret = nvgpu_atomic_read(&test_ref.refcount);
|
||||
|
||||
if (ret != LOOP_COUNT) {
|
||||
unit_return_fail(m, "refcount not updated%d\n", ret);
|
||||
}
|
||||
|
||||
for (loop = 0; loop < (LOOP_COUNT - 1); loop++) {
|
||||
ret = nvgpu_ref_put_return(&test_ref, test_ref_release);
|
||||
if (ret) {
|
||||
unit_return_fail(m,
|
||||
"nvgpu_ref_put_return failure\n");
|
||||
}
|
||||
}
|
||||
|
||||
ret = nvgpu_ref_put_return(&test_ref, test_ref_release);
|
||||
if (!ret) {
|
||||
unit_return_fail(m,
|
||||
"nvgpu_ref_put_return failure\n");
|
||||
}
|
||||
|
||||
if (!release_count) {
|
||||
unit_return_fail(m,
|
||||
"release function not invoked\n");
|
||||
} else if ((release_count > 1)) {
|
||||
unit_return_fail(m,
|
||||
"release function invoked more than once\n");
|
||||
}
|
||||
|
||||
release_count = 0;
|
||||
|
||||
nvgpu_ref_get(&test_ref);
|
||||
|
||||
ret = nvgpu_ref_put_return(&test_ref, NULL);
|
||||
if (!ret) {
|
||||
unit_return_fail(m,
|
||||
"nvgpu_ref_put_return with NULL callback failure\n");
|
||||
}
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
struct unit_module_test interface_kref_tests[] = {
|
||||
UNIT_TEST(kref_init, test_kref_init, NULL, 0),
|
||||
UNIT_TEST(kref_get, test_kref_get, NULL, 0),
|
||||
UNIT_TEST(kref_get_unless, test_kref_get_unless, NULL, 0),
|
||||
UNIT_TEST(kref_put, test_kref_put, NULL, 0),
|
||||
UNIT_TEST(kref_put_return, test_kref_put_return, NULL, 0),
|
||||
};
|
||||
|
||||
UNIT_MODULE(interface_kref, interface_kref_tests, UNIT_PRIO_NVGPU_TEST);
|
||||
180
userspace/units/interface/kref/kref.h
Normal file
180
userspace/units/interface/kref/kref.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 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"),
|
||||
* 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_INTERFACE_KREF_H
|
||||
#define UNIT_INTERFACE_KREF_H
|
||||
|
||||
struct gk20a;
|
||||
struct unit_module;
|
||||
|
||||
/** @addtogroup SWUTS-interface-kref
|
||||
* @{
|
||||
*
|
||||
* Software Unit Test Specification for interface-kref
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test specification for test_kref_init
|
||||
*
|
||||
* Description: Test the reference count initialization implementation.
|
||||
*
|
||||
* Test Type: Feature
|
||||
*
|
||||
* Targets: nvgpu_ref_init
|
||||
*
|
||||
* Input: None
|
||||
*
|
||||
* Steps:
|
||||
* - Invoke the function nvgpu_ref_init to initialize nvgpu_ref structure.
|
||||
* - Read back the refcount value and confirm the value is initialized to 1.
|
||||
* Otherwise, return FAIL.
|
||||
* - Return PASS.
|
||||
*
|
||||
* Output: Returns PASS if the refcount is initialized correctly, otherwise
|
||||
* returns FAIL.
|
||||
*/
|
||||
int test_kref_init(struct unit_module *m, struct gk20a *g, void *__args);
|
||||
|
||||
/**
|
||||
* Test specification for test_kref_get
|
||||
*
|
||||
* Description: Test the reference get implementation.
|
||||
*
|
||||
* Test Type: Feature
|
||||
*
|
||||
* Targets: nvgpu_ref_get
|
||||
*
|
||||
* Input: None
|
||||
*
|
||||
* Steps:
|
||||
* - Invoke the function nvgpu_ref_init to initialize nvgpu_ref structure.
|
||||
* - Invoke the function nvgpu_ref_get in loop to increment the refcount value
|
||||
* till LOOP_COUNT.
|
||||
* - Read back the refcount value and confirm that the value returned is in
|
||||
* sync with the number of times nvgpu_ref_get is called. Otherwise return
|
||||
* FAIL.
|
||||
* - Return PASS.
|
||||
*
|
||||
* Output: Returns PASS if the refcount is incremented correctly, otherwise
|
||||
* returns FAIL.
|
||||
*/
|
||||
int test_kref_get(struct unit_module *m, struct gk20a *g, void *__args);
|
||||
|
||||
/**
|
||||
* Test specification for test_kref_get_unless
|
||||
*
|
||||
* Description: Test the reference get unless implementation.
|
||||
*
|
||||
* Test Type: Feature
|
||||
*
|
||||
* Targets: nvgpu_ref_get_unless_zero
|
||||
*
|
||||
* Input: None
|
||||
*
|
||||
* Steps:
|
||||
* - Initialize the refcount value as 0 for nvgpu_ref struct.
|
||||
* - Invoke function nvgpu_ref_get_unless_zero and confirm that the return
|
||||
* value is 0. Otherwise return FAIL.
|
||||
* - Invoke the function nvgpu_ref_init to initialize nvgpu_ref structure.
|
||||
* - Invoke the function nvgpu_ref_get_unless_zero to increment the refcount
|
||||
* value.
|
||||
* - Check and confirm that the return value is not zero. Otherwise, return
|
||||
* FAIL.
|
||||
* - Return PASS.
|
||||
*
|
||||
* Output: Returns SUCCESS if the refcount is increased correctly according to
|
||||
* the current value in refcount, otherwise return FAIL.
|
||||
*/
|
||||
int test_kref_get_unless(struct unit_module *m, struct gk20a *g, void *__args);
|
||||
|
||||
/**
|
||||
* Test specification for test_kref_put
|
||||
*
|
||||
* Description: Test the reference put implementation.
|
||||
*
|
||||
* Test Type: Feature
|
||||
*
|
||||
* Targets: nvgpu_ref_put
|
||||
*
|
||||
* Input: None
|
||||
*
|
||||
* Steps:
|
||||
* - Initialize the release_count as 0.
|
||||
* - Invoke the function nvgpu_ref_init to initialize nvgpu_ref structure.
|
||||
* - Invoke the function nvgpu_ref_get in loop to increment the refcount value
|
||||
* till LOOP_COUNT.
|
||||
* - Read back the refcount value and confirm that the value returned is in
|
||||
* sync with the number of times nvgpu_ref_get is called. Otherwise return
|
||||
* FAIL.
|
||||
* - Invoke the function nvgpu_ref_put in loop for LOOP_COUNT times to
|
||||
* decrement the refcount value to 0.
|
||||
* - Check the value of release_count value which is incremented in the
|
||||
* release callback function to confirm that the release callback function
|
||||
* is invoked and invoked only once. Otherwise return FAIL.
|
||||
* - Invoke the function nvgpu_ref_get to increment the refcount value.
|
||||
* - Invoke the function nvgpu_ref_put with callback as NULL.
|
||||
* - Read back the refcount value and confirm that the value is reset to 0.
|
||||
* Otherwise return FAIL.
|
||||
* - Return PASS.
|
||||
*
|
||||
* Output: Returns SUCCESS if the refcerence is released correctly, otherwise
|
||||
* return FAIL.
|
||||
*/
|
||||
int test_kref_put(struct unit_module *m, struct gk20a *g, void *__args);
|
||||
|
||||
/**
|
||||
* Test specification for test_kref_put_return
|
||||
*
|
||||
* Description: Test the reference put return implementation.
|
||||
*
|
||||
* Test Type: Feature
|
||||
*
|
||||
* Targets: nvgpu_ref_put_return
|
||||
*
|
||||
* Input: None
|
||||
*
|
||||
* Steps:
|
||||
* - Initialize the release_count as 0.
|
||||
* - Invoke the function nvgpu_ref_init to initialize nvgpu_ref structure.
|
||||
* - Invoke the function nvgpu_ref_get in loop to increment the refcount value.
|
||||
* - Read back the refcount value and confirm that the value returned is in
|
||||
* sync with the number of times nvgpu_ref_get is called. Otherwise return
|
||||
* FAIL.
|
||||
* - Invoke the function nvgpu_ref_put in loop for (LOOP_COUNT - 1) to
|
||||
* decrement the refcount value and confirm that the return value is always
|
||||
* zero. Otherwise return FAIL.
|
||||
* - Invoke the function nvgpu_ref_put once more and confirm that the return
|
||||
* value is equal to one. Otherwise return FAIL.
|
||||
* - Check the value of release_count value which is incremented in the
|
||||
* release callback function to confirm that the release callback function
|
||||
* is invoked and invoked only once. Otherwise return FAIL.
|
||||
* - Invoke the function nvgpu_ref_get to increment the refcount value.
|
||||
* - Invoke the function nvgpu_ref_put_return with callback as NULL.
|
||||
* - Check the return value and return FAIL if it is equal to zero.
|
||||
* - Return PASS.
|
||||
*
|
||||
* Output: Returns SUCCESS if the refcount is initialized correctly, otherwise
|
||||
* return FAIL.
|
||||
*/
|
||||
int test_kref_put_return(struct unit_module *m, struct gk20a *g, void *__args);
|
||||
|
||||
#endif /* UNIT_INTERFACE_KREF_H */
|
||||
Reference in New Issue
Block a user