gpu: nvgpu: add tests for circ_buf

Add unit tests for posix circ_buf unit.

Jira NVGPU-4417

Change-Id: Ic0b04961cdd7813aed6f9b16fd0724b0e3cfeb2a
Signed-off-by: ajesh <akv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2287141
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
ajesh
2020-01-29 20:50:23 +05:30
committed by Alex Waterman
parent 9d0d16cffd
commit d4d5da4aa0
10 changed files with 295 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/posix/kmem
NV_REPOSITORY_COMPONENTS += userspace/units/posix/rwsem
NV_REPOSITORY_COMPONENTS += userspace/units/posix/queue
NV_REPOSITORY_COMPONENTS += userspace/units/posix/utils
NV_REPOSITORY_COMPONENTS += userspace/units/posix/circ_buf
NV_REPOSITORY_COMPONENTS += userspace/units/interface/bit-utils
NV_REPOSITORY_COMPONENTS += userspace/units/interface/bsearch
NV_REPOSITORY_COMPONENTS += userspace/units/interface/lock

View File

@@ -57,6 +57,7 @@ UNITS := \
$(UNIT_SRC)/posix/rwsem \
$(UNIT_SRC)/posix/queue \
$(UNIT_SRC)/posix/utils \
$(UNIT_SRC)/posix/circ_buf \
$(UNIT_SRC)/bus \
$(UNIT_SRC)/pramin \
$(UNIT_SRC)/ptimer \

View File

@@ -119,6 +119,7 @@
* - @ref SWUTS-posix-ossched
* - @ref SWUTS-posix-rwsem
* - @ref SWUTS-posix-utils
* - @ref SWUTS-posix-circbuf
* - @ref SWUTS-priv_ring
* - @ref SWUTS-ptimer
* - @ref SWUTS-sdl

View File

@@ -97,6 +97,7 @@ INPUT += ../../../userspace/units/posix/timers/posix-timers.h
INPUT += ../../../userspace/units/posix/os_sched/posix-ossched.h
INPUT += ../../../userspace/units/posix/rwsem/posix-rwsem.h
INPUT += ../../../userspace/units/posix/utils/posix-utils.h
INPUT += ../../../userspace/units/posix/circ_buf/posix-circbuf.h
INPUT += ../../../userspace/units/priv_ring/nvgpu-priv_ring.h
INPUT += ../../../userspace/units/ptimer/nvgpu-ptimer.h
INPUT += ../../../userspace/units/therm/nvgpu-therm.h

View File

@@ -4142,6 +4142,18 @@
"unit": "posix_bug",
"test_level": 0
},
{
"test": "test_circbufcnt",
"case": "circbufcnt",
"unit": "posix_circbuf",
"test_level": 0
},
{
"test": "test_circbufspace",
"case": "circbufspace",
"unit": "posix_circbuf",
"test_level": 0
},
{
"test": "test_cond_init_destroy",
"case": "init",

View 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 = posix-circbuf.o
MODULE = posix-circbuf
include ../../Makefile.units

View File

@@ -0,0 +1,35 @@
################################### tell Emacs this is a -*- makefile-gmake -*-
#
# 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.
#
# tmake for SW Mobile component makefile
#
###############################################################################
NVGPU_UNIT_NAME=posix-circbuf
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk
# Local Variables:
# indent-tabs-mode: t
# tab-width: 8
# End:
# vi: set tabstop=8 noexpandtab:

View File

@@ -0,0 +1,35 @@
################################### tell Emacs this is a -*- makefile-gmake -*-
#
# 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.
#
# tmake for SW Mobile component makefile
#
###############################################################################
NVGPU_UNIT_NAME=posix-circbuf
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk
# Local Variables:
# indent-tabs-mode: t
# tab-width: 8
# End:
# vi: set tabstop=8 noexpandtab:

View File

@@ -0,0 +1,95 @@
/*
* 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 <stdint.h>
#include <unit/io.h>
#include <unit/unit.h>
#include <nvgpu/circ_buf.h>
#include "posix-circbuf.h"
#define BUFFER_SIZE 16UL
int test_circbufcnt(struct unit_module *m,
struct gk20a *g, void *args)
{
unsigned int i;
unsigned long head, tail, size, ret;
head = 0;
tail = 0;
size = BUFFER_SIZE;
for (i = 0; i < BUFFER_SIZE; i++) {
head = i;
ret = CIRC_CNT(head, tail, size);
if (ret != i) {
unit_return_fail(m, "CIRC_CNT failed %ld\n", ret);
}
}
head = BUFFER_SIZE - 1;
for (i = 0; i < BUFFER_SIZE; i++) {
tail = (BUFFER_SIZE - 1) - i;
ret = CIRC_CNT(head, tail, size);
if (ret != i) {
unit_return_fail(m, "CIRC_CNT failed %ld\n", ret);
}
}
head = BUFFER_SIZE/2;
tail = BUFFER_SIZE/2;
ret = CIRC_CNT(head, tail, size);
if (ret) {
unit_return_fail(m, "CIRC_CNT failed %ld\n", ret);
}
return UNIT_SUCCESS;
}
int test_circbufspace(struct unit_module *m,
struct gk20a *g, void *args)
{
unsigned int i;
unsigned long head, tail, size, ret;
tail = BUFFER_SIZE;
size = BUFFER_SIZE;
for (i = 0; i < BUFFER_SIZE; i++) {
head = i;
ret = CIRC_SPACE(head, tail, size);
if (ret != ((BUFFER_SIZE - 1) - i)) {
unit_return_fail(m, "CIRC_SPACE failed %ld\n", ret);
}
}
return UNIT_SUCCESS;
}
struct unit_module_test posix_circbuf_tests[] = {
UNIT_TEST(circbufcnt, test_circbufcnt, NULL, 0),
UNIT_TEST(circbufspace, test_circbufspace, NULL, 0),
};
UNIT_MODULE(posix_circbuf, posix_circbuf_tests, UNIT_PRIO_POSIX_TEST);

View File

@@ -0,0 +1,88 @@
/*
* 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.
*/
/**
* @addtogroup SWUTS-posix-circbuf
* @{
*
* Software Unit Test Specification for posix-circbuf
*/
#ifndef UNIT_POSIX_CIRCBUF_H
#define UNIT_POSIX_CIRCBUF_H
/**
* Test specification for test_circbufcnt
*
* Description: Test the buffer count implementation.
*
* Test Type: Feature
*
* Targets: CIRC_CNT
*
* Inputs: None
*
* Steps:
* 1) Invoke CIRC_CNT in loop with head assigned with loop index value and
* tail as zero.
* 2) Check if the return value of buffer count is equal to loop index. Else
* return fail.
* 3) Invoke CIRC_CNT in loop with head assigned as maximum index and tail
* decreased according to the loop index value.
* 4) Check if the return value of buffer count is equal to loop index. Else
* return fail.
* 5) Invoke CIRC_CNT with both head and tail assigned with same value.
* 6) Check if the return value is equal to zero, else return fail.
* 7) Return PASS.
*
* Output:
* The test returns PASS if all the invocations of CIRC_CNT returns the
* expected value as buffer count. Otherwise, test returns FAIL.
*/
int test_circbufcnt(struct unit_module *m, struct gk20a *g, void *args);
/**
* Test specification for test_circbufspace
*
* Description: Test the buffer space check implementation.
*
* Test Type: Feature
*
* Targets: CIRC_SPACE
*
* Inputs: None
*
* Steps:
* 1) Invoke CIRC_SPACE in loop with head assigned as loop index and
* tail as buffer size.
* 2) Check if the return value of buffer space is equal to the maximum
* entries that the buffer can hold minus loop index. Else
* return fail.
* 3) Return PASS.
*
* Output:
* The test returns PASS if all the invocations of CIRC_SPACE returns the
* expected value as available buffer space. Otherwise, test returns FAIL.
*/
int test_circbufspace(struct unit_module *m, struct gk20a *g, void *args);
#endif /* UNIT_POSIX_CIRCBUF_H */