From cdaa77c40c46a69425d2d41db3b68e3ec3ee4d57 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Wed, 15 Jan 2020 16:46:35 -0500 Subject: [PATCH] gpu: nvgpu: unit: add bit-utils test Add test for common.utils.bit-utils. JIRA NVGPU-4818 Change-Id: Ibb07d01fdf312e661bba76fe3c09b69424b62420 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2279609 Tested-by: mobile promotions Reviewed-by: mobile promotions --- Makefile.umbrella.tmk | 1 + userspace/Makefile.sources | 1 + userspace/SWUTS.h | 1 + userspace/SWUTS.sources | 1 + userspace/units/interface/bit-utils/Makefile | 26 ++++++ .../bit-utils/Makefile.interface.tmk | 23 ++++++ .../units/interface/bit-utils/Makefile.tmk | 24 ++++++ .../units/interface/bit-utils/bit-utils.c | 71 ++++++++++++++++ .../units/interface/bit-utils/bit-utils.h | 81 +++++++++++++++++++ 9 files changed, 229 insertions(+) create mode 100644 userspace/units/interface/bit-utils/Makefile create mode 100644 userspace/units/interface/bit-utils/Makefile.interface.tmk create mode 100644 userspace/units/interface/bit-utils/Makefile.tmk create mode 100644 userspace/units/interface/bit-utils/bit-utils.c create mode 100644 userspace/units/interface/bit-utils/bit-utils.h diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index 5ff035e76..8109e9c08 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -48,6 +48,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/posix/timers 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/interface/bit-utils NV_REPOSITORY_COMPONENTS += userspace/units/interface/bsearch NV_REPOSITORY_COMPONENTS += userspace/units/interface/lock NV_REPOSITORY_COMPONENTS += userspace/units/interface/nvgpu_gk20a diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index f97b1e664..ea716536c 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -61,6 +61,7 @@ UNITS := \ $(UNIT_SRC)/ptimer \ $(UNIT_SRC)/priv_ring \ $(UNIT_SRC)/init \ + $(UNIT_SRC)/interface/bit-utils \ $(UNIT_SRC)/interface/bsearch \ $(UNIT_SRC)/interface/lock \ $(UNIT_SRC)/interface/nvgpu_gk20a \ diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index 818307c7c..8b3346da5 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -31,6 +31,7 @@ * to test the NVGPU driver. * * - @ref SWUTS-enabled + * - @ref SWUTS-interface-bit-utils * - @ref SWUTS-interface-bsearch * - @ref SWUTS-interface-lock * - @ref SWUTS-interface-nvgpu-gk20a diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index 6dbcdf5b3..ec96a36a6 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -5,6 +5,7 @@ INPUT += ../../../userspace/units/cg/nvgpu-cg.h ======= >>>>>>> gpu: nvgpu: unit: improve coverage for engines INPUT += ../../../userspace/units/enabled/nvgpu-enabled.h +INPUT += ../../../userspace/units/interface/bit-utils/bit-utils.h INPUT += ../../../userspace/units/interface/bsearch/bsearch.h INPUT += ../../../userspace/units/interface/lock/lock.h INPUT += ../../../userspace/units/interface/nvgpu_gk20a/nvgpu_gk20a.h diff --git a/userspace/units/interface/bit-utils/Makefile b/userspace/units/interface/bit-utils/Makefile new file mode 100644 index 000000000..13a399200 --- /dev/null +++ b/userspace/units/interface/bit-utils/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 = bit-utils.o +MODULE = bit-utils + +include ../../Makefile.units diff --git a/userspace/units/interface/bit-utils/Makefile.interface.tmk b/userspace/units/interface/bit-utils/Makefile.interface.tmk new file mode 100644 index 000000000..977eccdc0 --- /dev/null +++ b/userspace/units/interface/bit-utils/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=bit-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: diff --git a/userspace/units/interface/bit-utils/Makefile.tmk b/userspace/units/interface/bit-utils/Makefile.tmk new file mode 100644 index 000000000..9c2c37def --- /dev/null +++ b/userspace/units/interface/bit-utils/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=bit-utils +NVGPU_UNIT_SRCS=bit-utils.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/bit-utils/bit-utils.c b/userspace/units/interface/bit-utils/bit-utils.c new file mode 100644 index 000000000..2d665a52e --- /dev/null +++ b/userspace/units/interface/bit-utils/bit-utils.c @@ -0,0 +1,71 @@ +/* + * 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 + +#include "bit-utils.h" + +int test_hi_lo(struct unit_module *m, struct gk20a *g, void *args) +{ + u64 val_hi = 0xfedcba01; + u64 val_lo = 0x12345678; + u64 full_val = (val_hi << 32) | val_lo; + + unit_assert(u64_hi32(full_val) == val_hi, return UNIT_FAIL); + unit_assert(u64_lo32(full_val) == val_lo, return UNIT_FAIL); + unit_assert(hi32_lo32_to_u64(val_hi, val_lo) == full_val, + return UNIT_FAIL); + + return UNIT_SUCCESS; +} + +int test_fields(struct unit_module *m, struct gk20a *g, void *args) +{ + unit_assert(set_field(0U, 0x000ff000, 0x00055000) == 0x00055000, + return UNIT_FAIL); + unit_assert(set_field(0U, 0xffffffff, 0x00055000) == 0x00055000, + return UNIT_FAIL); + unit_assert(set_field(0xffffffff, 0xffffffff, 0x00055000) == 0x00055000, + return UNIT_FAIL); + unit_assert(set_field(0xffffffff, 0x000ff000, 0x00055000) == 0xfff55fff, + return UNIT_FAIL); + + unit_assert(get_field(0U, 0xffffffff) == 0x0, return UNIT_FAIL); + unit_assert(get_field(0xffffffff, 0xffffffff) == 0xffffffff, + return UNIT_FAIL); + unit_assert(get_field(0xffffffff, 0x000ff000) == 0x000ff000, + return UNIT_FAIL); + + return UNIT_SUCCESS; +} + +struct unit_module_test bit_utils_tests[] = { + UNIT_TEST(hi_lo, test_hi_lo, NULL, 0), + UNIT_TEST(fields, test_fields, NULL, 0), +}; + +UNIT_MODULE(bit_utils, bit_utils_tests, UNIT_PRIO_NVGPU_TEST); \ No newline at end of file diff --git a/userspace/units/interface/bit-utils/bit-utils.h b/userspace/units/interface/bit-utils/bit-utils.h new file mode 100644 index 000000000..85e94810d --- /dev/null +++ b/userspace/units/interface/bit-utils/bit-utils.h @@ -0,0 +1,81 @@ +/* + * 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_BIT_UTILS_H +#define UNIT_BIT_UTILS_H + +struct gk20a; +struct unit_module; + +/** @addtogroup SWUTS-interface-bit-utils + * @{ + * + * Software Unit Test Specification for common.utils.bit-utils + */ + +/** + * Test specification for: test_hi_lo + * + * Description: Verify functionality of hi/lo bit-utils APIs. + * + * Test Type: Feature + * + * Targets: u64_hi32, u64_lo32, hi32_lo32_to_u64 + * + * Input: None + * + * Steps: + * - Call u64_hi32 with a u64 value and verify the correct value is returned. + * - Call u64_lo32 with a u64 value and verify the correct value is returned. + * - Call hi32_lo32_to_u64 with two u32 values and verify the correct u64 value + * is returned. + * + * Output: Returns PASS if expected result is met, FAIL otherwise. + */ +int test_hi_lo(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for: test_fields + * + * Description: Verify functionality of bit field bit-util APIs. + * + * Test Type: Feature + * + * Targets: set_field, get_field + * + * Input: None + * + * Steps: + * - Call set_field() with a variety of inputs and verify the correct value is + * returned. + * - Call get_field() with a variety of inputs and verify the correct value is + * returned. + * + * Output: Returns PASS if expected result is met, FAIL otherwise. + */ +int test_fields(struct unit_module *m, struct gk20a *g, void *args); + +/** + * @} + */ + +#endif /* UNIT_BIT_UTILS_H */