mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: unit: add test for common.utils.string
Add unit test for the common.utils.string unit. JIRA NVGPU-4826 Change-Id: I4bfca346fb2202f9572199590f33a0461443fbc9 Signed-off-by: Philip Elcan <pelcan@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2275456 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
Alex Waterman
parent
0b0c4e6bd4
commit
f2e2b29194
@@ -52,6 +52,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/interface/lock
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/atomic
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/rbtree
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/static_analysis
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/string
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/worker
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/bus
|
||||
NV_REPOSITORY_COMPONENTS += userspace/units/pramin
|
||||
|
||||
@@ -518,11 +518,14 @@ nvgpu_mc_intr_nonstall_unit_config
|
||||
nvgpu_mc_intr_stall_pause
|
||||
nvgpu_mc_intr_stall_resume
|
||||
nvgpu_mc_intr_stall_unit_config
|
||||
nvgpu_memcmp
|
||||
nvgpu_memcpy
|
||||
nvgpu_memset
|
||||
nvgpu_mem_create_from_phys
|
||||
nvgpu_mem_get_addr
|
||||
nvgpu_mem_iommu_translate
|
||||
nvgpu_mem_is_sysmem
|
||||
nvgpu_mem_is_word_aligned
|
||||
nvgpu_mem_posix_create_from_list
|
||||
nvgpu_mem_rd
|
||||
nvgpu_mem_rd32
|
||||
@@ -683,6 +686,7 @@ nvgpu_sgt_ipa_to_pa
|
||||
nvgpu_spinlock_acquire
|
||||
nvgpu_spinlock_init
|
||||
nvgpu_spinlock_release
|
||||
nvgpu_strnadd_u32
|
||||
nvgpu_sw_quiesce
|
||||
nvgpu_sw_quiesce_remove_support
|
||||
nvgpu_thread_create
|
||||
|
||||
@@ -65,6 +65,7 @@ UNITS := \
|
||||
$(UNIT_SRC)/interface/atomic \
|
||||
$(UNIT_SRC)/interface/rbtree \
|
||||
$(UNIT_SRC)/interface/static_analysis \
|
||||
$(UNIT_SRC)/interface/string \
|
||||
$(UNIT_SRC)/interface/worker \
|
||||
$(UNIT_SRC)/mc \
|
||||
$(UNIT_SRC)/mm/nvgpu_sgt \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
* Copyright (c) 2019-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"),
|
||||
@@ -34,6 +34,7 @@
|
||||
* - @ref SWUTS-interface-bsearch
|
||||
* - @ref SWUTS-interface-lock
|
||||
* - @ref SWUTS-interface-rbtree
|
||||
* - @ref SWUTS-interface-string
|
||||
* - @ref SWUTS-bus
|
||||
* - @ref SWUTS-falcon
|
||||
* - @ref SWUTS-netlist
|
||||
|
||||
@@ -4,6 +4,7 @@ INPUT += ../../../userspace/units/enabled/nvgpu-enabled.h
|
||||
INPUT += ../../../userspace/units/interface/bsearch/bsearch.h
|
||||
INPUT += ../../../userspace/units/interface/lock/lock.h
|
||||
INPUT += ../../../userspace/units/interface/rbtree/rbtree.h
|
||||
INPUT += ../../../userspace/units/interface/string/nvgpu-string.h
|
||||
INPUT += ../../../userspace/units/bus/nvgpu-bus.h
|
||||
INPUT += ../../../userspace/units/falcon/falcon_tests/nvgpu-falcon.h
|
||||
INPUT += ../../../userspace/units/netlist/nvgpu-netlist.h
|
||||
|
||||
@@ -4292,6 +4292,24 @@
|
||||
"unit": "ptimer",
|
||||
"test_level": 0
|
||||
},
|
||||
{
|
||||
"test": "test_mem_is_word_aligned",
|
||||
"case": "mem_is_word_aligned",
|
||||
"unit": "string",
|
||||
"test_level": 0
|
||||
},
|
||||
{
|
||||
"test": "test_memcpy_memcmp",
|
||||
"case": "memcpy_memcmp",
|
||||
"unit": "string",
|
||||
"test_level": 0
|
||||
},
|
||||
{
|
||||
"test": "test_strnadd_u32",
|
||||
"case": "strnadd_u32",
|
||||
"unit": "string",
|
||||
"test_level": 0
|
||||
},
|
||||
{
|
||||
"test": "test_gv11b_elcg_init_idle_filters",
|
||||
"case": "gv11b_elcg_init_idle_filters",
|
||||
|
||||
26
userspace/units/interface/string/Makefile
Normal file
26
userspace/units/interface/string/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 = nvgpu-string.o
|
||||
MODULE = nvgpu-string
|
||||
|
||||
include ../../Makefile.units
|
||||
23
userspace/units/interface/string/Makefile.interface.tmk
Normal file
23
userspace/units/interface/string/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=nvgpu-string
|
||||
|
||||
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/string/Makefile.tmk
Normal file
24
userspace/units/interface/string/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=nvgpu-string
|
||||
NVGPU_UNIT_SRCS=nvgpu-string.c
|
||||
|
||||
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk
|
||||
|
||||
# Local Variables:
|
||||
# indent-tabs-mode: t
|
||||
# tab-width: 8
|
||||
# End:
|
||||
# vi: set tabstop=8 noexpandtab:
|
||||
111
userspace/units/interface/string/nvgpu-string.c
Normal file
111
userspace/units/interface/string/nvgpu-string.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 <unit/unit.h>
|
||||
#include <unit/io.h>
|
||||
#include <nvgpu/posix/io.h>
|
||||
|
||||
#include <nvgpu/string.h>
|
||||
|
||||
#include "nvgpu-string.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int test_memcpy_memcmp(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
const size_t len = 10;
|
||||
u8 dest[len];
|
||||
u8 src[len];
|
||||
u8 i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
dest[i] = 0;
|
||||
src[i] = i;
|
||||
}
|
||||
nvgpu_memcpy(dest, src, len);
|
||||
unit_assert(nvgpu_memcmp(dest, src, len) == 0, return UNIT_FAIL);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
dest[i] = 0;
|
||||
}
|
||||
nvgpu_memcpy(dest, src, len - 1U);
|
||||
unit_assert(nvgpu_memcmp(dest, src, len - 1U) == 0, return UNIT_FAIL);
|
||||
unit_assert(dest[len - 1] == 0, return UNIT_FAIL);
|
||||
unit_assert(nvgpu_memcmp(dest, src, len) != 0, return UNIT_FAIL);
|
||||
|
||||
/* test size==0 */
|
||||
unit_assert(nvgpu_memcmp(dest, src, 0) == 0, return UNIT_FAIL);
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
int test_strnadd_u32(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
const size_t len = 10;
|
||||
char dest[len];
|
||||
|
||||
/* test invalid radices */
|
||||
unit_assert(nvgpu_strnadd_u32(dest, 10U, len, 1U) == 0,
|
||||
return UNIT_FAIL);
|
||||
unit_assert(nvgpu_strnadd_u32(dest, 10U, len, 17U) == 0,
|
||||
return UNIT_FAIL);
|
||||
/* test insufficient space */
|
||||
unit_assert(nvgpu_strnadd_u32(dest, 1000U, 2, 10U) == 0,
|
||||
return UNIT_FAIL);
|
||||
unit_assert(nvgpu_strnadd_u32(dest, 1000U, 4, 10U) == 0,
|
||||
return UNIT_FAIL);
|
||||
|
||||
unit_assert(nvgpu_strnadd_u32(dest, 1000U, len, 10U) == 4,
|
||||
return UNIT_FAIL);
|
||||
unit_assert(strncmp(dest, "1000", 4) == 0, return UNIT_FAIL);
|
||||
|
||||
unit_assert(nvgpu_strnadd_u32(dest, 0xdeadbeef, len, 16U) == 8,
|
||||
return UNIT_FAIL);
|
||||
|
||||
unit_assert(strncmp(dest, "deadbeef", 8) == 0, return UNIT_FAIL);
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
int test_mem_is_word_aligned(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
unit_assert(nvgpu_mem_is_word_aligned(g, (u8 *)0x1000),
|
||||
return UNIT_FAIL);
|
||||
unit_assert(!nvgpu_mem_is_word_aligned(g, (u8 *)0x1001),
|
||||
return UNIT_FAIL);
|
||||
unit_assert(!nvgpu_mem_is_word_aligned(g, (u8 *)0x1002),
|
||||
return UNIT_FAIL);
|
||||
unit_assert(!nvgpu_mem_is_word_aligned(g, (u8 *)0x1003),
|
||||
return UNIT_FAIL);
|
||||
unit_assert(nvgpu_mem_is_word_aligned(g, (u8 *)0x1004),
|
||||
return UNIT_FAIL);
|
||||
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
struct unit_module_test string_tests[] = {
|
||||
UNIT_TEST(memcpy_memcmp, test_memcpy_memcmp, NULL, 0),
|
||||
UNIT_TEST(strnadd_u32, test_strnadd_u32, NULL, 0),
|
||||
UNIT_TEST(mem_is_word_aligned, test_mem_is_word_aligned, NULL, 0),
|
||||
};
|
||||
|
||||
UNIT_MODULE(string, string_tests, UNIT_PRIO_NVGPU_TEST);
|
||||
116
userspace/units/interface/string/nvgpu-string.h
Normal file
116
userspace/units/interface/string/nvgpu-string.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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_STRING_H
|
||||
#define UNIT_STRING_H
|
||||
|
||||
struct gk20a;
|
||||
struct unit_module;
|
||||
|
||||
/** @addtogroup SWUTS-interface-string
|
||||
* @{
|
||||
*
|
||||
* Software Unit Test Specification for worker unit
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Test specification for: test_memcpy_memcmp
|
||||
*
|
||||
* Description: Test functionality of the utility functions nvgpu_memcpy and
|
||||
* nvgpu_memcmp.
|
||||
*
|
||||
* Test Type: Feature, Error guessing, Boundary values
|
||||
*
|
||||
* Targets: nvgpu_memcpy, nvgpu_memcmp
|
||||
*
|
||||
* Input: None.
|
||||
*
|
||||
* Steps:
|
||||
* - Initialize source array to the values 1-10.
|
||||
* - Initialize destination array to all 0's.
|
||||
* - Call nvgpu_memcpy with the source & destination arrays, passing the full
|
||||
* length.
|
||||
* - Call nvgpu_memcmp with the source & destination arrays, passing the full
|
||||
* length. Verify it returns a match.
|
||||
* - Re-init destination to 0.
|
||||
* - Call nvgpu_memcpy with the source & destination arrays, passing length-1.
|
||||
* - Call nvgpu_memcmp with the source & destination arrays, passing length-1.
|
||||
* Verify it returns a match.
|
||||
* - Verify the final element of the destination array is still 0.
|
||||
* - Call nvgpu_memcmp with the source & destination arrays, passing length.
|
||||
* Verify it returns a non-match.
|
||||
* - Call nvgpu_memcmp with a length 0. Verify a match is returned.
|
||||
*
|
||||
* Output: Returns PASS if expected result is met, FAIL otherwise.
|
||||
*/
|
||||
int test_memcpy_memcmp(struct unit_module *m, struct gk20a *g, void *args);
|
||||
|
||||
/**
|
||||
* Test specification for: test_strnadd_u32
|
||||
*
|
||||
* Description: Test functionality of the utility function test_strnadd_u32.
|
||||
*
|
||||
* Test Type: Feature, Error guessing, Boundary values
|
||||
*
|
||||
* Targets: nvgpu_strnadd_u32
|
||||
*
|
||||
* Input: None.
|
||||
*
|
||||
* Steps:
|
||||
* - Call nvgpu_strnadd_u32 with invalid radices. Verify 0 is returned.
|
||||
* - Call nvgpu_strnadd_u32 with an insufficient string size for the requested.
|
||||
* number. Verify 0 is returned.
|
||||
* - Call nvgpu_strnadd_u32 with a decimal value of 1000. Verify returned size
|
||||
* is 4 and the string contains "1000".
|
||||
* - Call nvgpu_strnadd_u32 with a hexidecimal value of 0xdeadbeef. Verify
|
||||
* returned size is 8 and the string contains "deadbeef".
|
||||
*
|
||||
* Output: Returns PASS if expected result is met, FAIL otherwise.
|
||||
*/
|
||||
int test_strnadd_u32(struct unit_module *m, struct gk20a *g, void *args);
|
||||
|
||||
/**
|
||||
* Test specification for: test_mem_is_word_aligned
|
||||
*
|
||||
* Description: Test functionality of the utility function
|
||||
* nvgpu_mem_is_word_aligned.
|
||||
*
|
||||
* Test Type: Feature, Error guessing, Boundary values
|
||||
*
|
||||
* Targets: nvgpu_mem_is_word_aligned
|
||||
*
|
||||
* Input: None.
|
||||
*
|
||||
* Steps:
|
||||
* - Call nvgpu_mem_is_word_aligned with various addresses and verify the
|
||||
* correct value is returned.
|
||||
*
|
||||
* Output: Returns PASS if expected result is met, FAIL otherwise.
|
||||
*/
|
||||
int test_mem_is_word_aligned(struct unit_module *m, struct gk20a *g, void *args);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* UNIT_STRING_H */
|
||||
Reference in New Issue
Block a user