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 <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2279609
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2020-01-15 16:46:35 -05:00
committed by Alex Waterman
parent 4e2c1c3ca4
commit cdaa77c40c
9 changed files with 229 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/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
NV_REPOSITORY_COMPONENTS += userspace/units/interface/nvgpu_gk20a NV_REPOSITORY_COMPONENTS += userspace/units/interface/nvgpu_gk20a

View File

@@ -61,6 +61,7 @@ UNITS := \
$(UNIT_SRC)/ptimer \ $(UNIT_SRC)/ptimer \
$(UNIT_SRC)/priv_ring \ $(UNIT_SRC)/priv_ring \
$(UNIT_SRC)/init \ $(UNIT_SRC)/init \
$(UNIT_SRC)/interface/bit-utils \
$(UNIT_SRC)/interface/bsearch \ $(UNIT_SRC)/interface/bsearch \
$(UNIT_SRC)/interface/lock \ $(UNIT_SRC)/interface/lock \
$(UNIT_SRC)/interface/nvgpu_gk20a \ $(UNIT_SRC)/interface/nvgpu_gk20a \

View File

@@ -31,6 +31,7 @@
* to test the NVGPU driver. * to test the NVGPU driver.
* *
* - @ref SWUTS-enabled * - @ref SWUTS-enabled
* - @ref SWUTS-interface-bit-utils
* - @ref SWUTS-interface-bsearch * - @ref SWUTS-interface-bsearch
* - @ref SWUTS-interface-lock * - @ref SWUTS-interface-lock
* - @ref SWUTS-interface-nvgpu-gk20a * - @ref SWUTS-interface-nvgpu-gk20a

View File

@@ -5,6 +5,7 @@ INPUT += ../../../userspace/units/cg/nvgpu-cg.h
======= =======
>>>>>>> gpu: nvgpu: unit: improve coverage for engines >>>>>>> gpu: nvgpu: unit: improve coverage for engines
INPUT += ../../../userspace/units/enabled/nvgpu-enabled.h 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/bsearch/bsearch.h
INPUT += ../../../userspace/units/interface/lock/lock.h INPUT += ../../../userspace/units/interface/lock/lock.h
INPUT += ../../../userspace/units/interface/nvgpu_gk20a/nvgpu_gk20a.h INPUT += ../../../userspace/units/interface/nvgpu_gk20a/nvgpu_gk20a.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 = bit-utils.o
MODULE = bit-utils
include ../../Makefile.units

View 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=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:

View 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=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:

View File

@@ -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 <unit/unit.h>
#include <unit/io.h>
#include <nvgpu/posix/io.h>
#include <nvgpu/gk20a.h>
#include <nvgpu/utils.h>
#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);

View File

@@ -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 */