From f2e2b29194368a00c95c2b9d4bb12194b1ad12a6 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Tue, 7 Jan 2020 17:19:04 -0500 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2275456 Reviewed-by: mobile promotions Tested-by: mobile promotions --- Makefile.umbrella.tmk | 1 + drivers/gpu/nvgpu/libnvgpu-drv_safe.export | 4 + userspace/Makefile.sources | 1 + userspace/SWUTS.h | 3 +- userspace/SWUTS.sources | 1 + userspace/required_tests.json | 18 +++ userspace/units/interface/string/Makefile | 26 ++++ .../interface/string/Makefile.interface.tmk | 23 ++++ userspace/units/interface/string/Makefile.tmk | 24 ++++ .../units/interface/string/nvgpu-string.c | 111 +++++++++++++++++ .../units/interface/string/nvgpu-string.h | 116 ++++++++++++++++++ 11 files changed, 327 insertions(+), 1 deletion(-) create mode 100644 userspace/units/interface/string/Makefile create mode 100644 userspace/units/interface/string/Makefile.interface.tmk create mode 100644 userspace/units/interface/string/Makefile.tmk create mode 100644 userspace/units/interface/string/nvgpu-string.c create mode 100644 userspace/units/interface/string/nvgpu-string.h diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index 2db5408c2..105befcf1 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -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 diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 84a33e469..2a37a52b7 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -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 diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index 2f47181ca..db04e6525 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -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 \ diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index d062e951c..107f783f8 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -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 diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index 3834d7516..f2eb5c17f 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -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 diff --git a/userspace/required_tests.json b/userspace/required_tests.json index a2bc64a47..159e5b25f 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -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", diff --git a/userspace/units/interface/string/Makefile b/userspace/units/interface/string/Makefile new file mode 100644 index 000000000..3b71668a2 --- /dev/null +++ b/userspace/units/interface/string/Makefile @@ -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 diff --git a/userspace/units/interface/string/Makefile.interface.tmk b/userspace/units/interface/string/Makefile.interface.tmk new file mode 100644 index 000000000..386169355 --- /dev/null +++ b/userspace/units/interface/string/Makefile.interface.tmk @@ -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: diff --git a/userspace/units/interface/string/Makefile.tmk b/userspace/units/interface/string/Makefile.tmk new file mode 100644 index 000000000..3c460f9f0 --- /dev/null +++ b/userspace/units/interface/string/Makefile.tmk @@ -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: diff --git a/userspace/units/interface/string/nvgpu-string.c b/userspace/units/interface/string/nvgpu-string.c new file mode 100644 index 000000000..906b5347e --- /dev/null +++ b/userspace/units/interface/string/nvgpu-string.c @@ -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 +#include +#include + +#include + +#include "nvgpu-string.h" + +#include + +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); diff --git a/userspace/units/interface/string/nvgpu-string.h b/userspace/units/interface/string/nvgpu-string.h new file mode 100644 index 000000000..32f04b6b9 --- /dev/null +++ b/userspace/units/interface/string/nvgpu-string.h @@ -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 */