gpu: nvgpu: add unit tests for utils unit

Add unit tests for posix utils unit.

Jira NVGPU-4478

Change-Id: I426e2b8cc7ed508f4e66db3796ab21eb3ce3e85f
Signed-off-by: ajesh <akv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2282760
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
ajesh
2020-01-21 12:20:56 +05:30
committed by Alex Waterman
parent 4b0499498b
commit 4bcd419a0b
9 changed files with 370 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

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-utils.o
MODULE = posix-utils
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-utils
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-utils
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,172 @@
/*
* 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/utils.h>
#include "posix-utils.h"
/*
* Test to ensure the EXPECT_BUG construct works as intended by making sure it
* behaves properly when BUG is called or not.
* In the event that EXPECT_BUG is completely broken, the call to BUG() would
* cause the unit to crash and report a failure correctly.
*/
int test_hamming_weight(struct unit_module *m,
struct gk20a *g, void *args)
{
unsigned int result;
unsigned int i;
uint8_t hwt_8bit;
uint16_t hwt_16bit;
uint32_t hwt_32bit;
uint64_t hwt_64bit;
for (i = 0; i < 8; i++) {
hwt_8bit = (unsigned int) 1 << i;
result = nvgpu_posix_hweight8(hwt_8bit);
if (result != 1) {
unit_return_fail(m,
"8 bit hwt failed for %d\n", hwt_8bit);
}
}
for (i = 0; i < 16; i++) {
hwt_16bit = (unsigned int) 1 << i;
result = nvgpu_posix_hweight16(hwt_16bit);
if (result != 1) {
unit_return_fail(m,
"16 bit hwt failed for %d\n", hwt_16bit);
}
}
for (i = 0; i < 32; i++) {
hwt_32bit = (unsigned int) 1 << i;
result = nvgpu_posix_hweight32(hwt_32bit);
if (result != 1) {
unit_return_fail(m,
"32 bit hwt failed for %d\n", hwt_32bit);
}
}
for (i = 0; i < 64; i++) {
hwt_64bit = (unsigned long) 1 << i;
result = nvgpu_posix_hweight64(hwt_64bit);
if (result != 1) {
unit_return_fail(m,
"64 bit hwt failed for %lx\n", hwt_64bit);
}
}
hwt_8bit = 0x0;
result = nvgpu_posix_hweight8(hwt_8bit);
if (result != 0) {
unit_return_fail(m,
"8 bit hwt failed for %d\n", hwt_8bit);
}
hwt_8bit = 0xff;
result = nvgpu_posix_hweight8(hwt_8bit);
if (result != 8) {
unit_return_fail(m,
"8 bit hwt failed for %d\n", hwt_8bit);
}
hwt_16bit = 0x0;
result = nvgpu_posix_hweight16(hwt_16bit);
if (result != 0) {
unit_return_fail(m,
"16 bit hwt failed for %d\n", hwt_16bit);
}
hwt_16bit = 0xffff;
result = nvgpu_posix_hweight16(hwt_16bit);
if (result != 16) {
unit_return_fail(m,
"16 bit hwt failed for %d\n", hwt_16bit);
}
hwt_32bit = 0x0;
result = nvgpu_posix_hweight32(hwt_32bit);
if (result != 0) {
unit_return_fail(m,
"32 bit hwt failed for %d\n", hwt_32bit);
}
hwt_32bit = 0xffffffff;
result = nvgpu_posix_hweight32(hwt_32bit);
if (result != 32) {
unit_return_fail(m,
"32 bit hwt failed for %d\n", hwt_32bit);
}
hwt_64bit = 0x0;
result = nvgpu_posix_hweight64(hwt_64bit);
if (result != 0) {
unit_return_fail(m,
"64 bit hwt failed for %ld\n", hwt_64bit);
}
hwt_64bit = 0xffffffffffffffff;
result = nvgpu_posix_hweight64(hwt_64bit);
if (result != 64) {
unit_return_fail(m,
"64 bit hwt failed for %ld\n", hwt_64bit);
}
return UNIT_SUCCESS;
}
int test_be32tocpu(struct unit_module *m,
struct gk20a *g, void *args)
{
uint32_t pattern;
uint32_t result;
uint8_t *ptr;
pattern = 0xaabbccdd;
ptr = (uint8_t*)&pattern;
result = be32_to_cpu(pattern);
if (*ptr == 0xdd) {
if (result != 0xddccbbaa) {
unit_return_fail(m,
"be32tocpu failed for %x %x\n",
pattern, result);
}
}
return UNIT_SUCCESS;
}
struct unit_module_test posix_utils_tests[] = {
UNIT_TEST(hweight_test, test_hamming_weight, NULL, 0),
UNIT_TEST(be32tocpu_test, test_be32tocpu, NULL, 0),
};
UNIT_MODULE(posix_utils, posix_utils_tests, UNIT_PRIO_POSIX_TEST);

View File

@@ -0,0 +1,98 @@
/*
* 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-utils
* @{
*
* Software Unit Test Specification for posix-utils
*/
#ifndef __UNIT_POSIX_UTILS_H__
#define __UNIT_POSIX_UTILS_H__
/**
* Test specification for test_hamming_weight
*
* Description: Test the hamming weight implementation.
*
* Test Type: Feature
*
* Targets: nvgpu_posix_hweight8, nvgpu_posix_hweight16,
* nvgpu_posix_hweight32, nvgpu_posix_hweight64
*
* Inputs: None
*
* Steps:
* 1) Call nvgpu_posix_hweight8 in loop with only the loop index bit position
* set.
* 2) Return FAIL if the return value from nvgpu_posix_hweight8 is not equal
* to 1 in any of the iterations.
* 3) Repeat steps 1 and 2 for nvgpu_posix_hweight16, nvgpu_posix_hweight32
* and nvgpu_posix_hweight64.
* 4) Call nvgpu_posix_hweight8 with input parameter set as 0.
* 5) Return FAIL if the return value from nvgpu_posix_hweight8 is not equal
* to 0.
* 6) Call nvgpu_posix_hweight8 with input parameter set to maximum value.
* 7) Return FAIL if the return value from nvgpu_posix_hweight8 is not equal
* to the number of bits in the input parameter.
* 8) Repeat steps 4,5,6 and 7 for nvgpu_posix_hweight16, nvgpu_posix_hweight32
* and nvgpu_posix_hweight64.
*
* Output:
* The test returns PASS if all the hamming weight function invocations return
* the expected value. Otherwise the test returns FAIL.
*
*/
int test_hamming_weight(struct unit_module *m, struct gk20a *g, void *args);
/**
* Test specification for test_be32tocpu
*
* Description: Test the endian conversion implementation.
*
* Test Type: Feature
*
* Targets: be32_to_cpu
*
* Inputs: None
*
* Steps:
* 1) Invoke function be32_to_cpu with a fixed pattern as input.
* 2) Check if the machine is little endian.
* 3) If the machine is little endian, confirm that the return value from
* be32_to_cpu is equal to the little endian order of the pattern, else
* return FAIL.
* 3) EXPECT_BUG is also tested to make sure that BUG is not called where it is
* not expected.
*
* Output:
* The test returns PASS if BUG is called as expected based on the parameters
* passed and EXPECT_BUG handles it accordingly.
* The test returns FAIL if either BUG is not called as expected or if
* EXPECT_BUG indicates that a BUG call was made which was not requested by
* the test.
*
*/
int test_be32tocpu(struct unit_module *m, struct gk20a *g, void *args);
#endif /* __UNIT_POSIX_UTILS_H__ */