mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: unit: add static_analysis unit test
Add unit test for common.utils static_analysis unit. JIRA NVGPU-4825 Change-Id: Id103ab101bbca8424dd7f0d136f1101ddf4bc2b5 Signed-off-by: Philip Elcan <pelcan@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2276814 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
6afd472abe
commit
7601d1c620
@@ -51,6 +51,7 @@ 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/atomic
|
NV_REPOSITORY_COMPONENTS += userspace/units/interface/atomic
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/rbtree
|
NV_REPOSITORY_COMPONENTS += userspace/units/interface/rbtree
|
||||||
|
NV_REPOSITORY_COMPONENTS += userspace/units/interface/static_analysis
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/interface/worker
|
NV_REPOSITORY_COMPONENTS += userspace/units/interface/worker
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/bus
|
NV_REPOSITORY_COMPONENTS += userspace/units/bus
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/pramin
|
NV_REPOSITORY_COMPONENTS += userspace/units/pramin
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ UNITS := \
|
|||||||
$(UNIT_SRC)/interface/lock \
|
$(UNIT_SRC)/interface/lock \
|
||||||
$(UNIT_SRC)/interface/atomic \
|
$(UNIT_SRC)/interface/atomic \
|
||||||
$(UNIT_SRC)/interface/rbtree \
|
$(UNIT_SRC)/interface/rbtree \
|
||||||
|
$(UNIT_SRC)/interface/static_analysis \
|
||||||
$(UNIT_SRC)/interface/worker \
|
$(UNIT_SRC)/interface/worker \
|
||||||
$(UNIT_SRC)/mc \
|
$(UNIT_SRC)/mc \
|
||||||
$(UNIT_SRC)/mm/nvgpu_sgt \
|
$(UNIT_SRC)/mm/nvgpu_sgt \
|
||||||
|
|||||||
@@ -4549,5 +4549,17 @@
|
|||||||
"case": "init",
|
"case": "init",
|
||||||
"unit": "worker",
|
"unit": "worker",
|
||||||
"test_level": 0
|
"test_level": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": "test_arithmetic",
|
||||||
|
"case": "arithmetic",
|
||||||
|
"unit": "static_analysis",
|
||||||
|
"test_level": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": "test_cast",
|
||||||
|
"case": "cast",
|
||||||
|
"unit": "static_analysis",
|
||||||
|
"test_level": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
26
userspace/units/interface/static_analysis/Makefile
Normal file
26
userspace/units/interface/static_analysis/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 = static_analysis.o
|
||||||
|
MODULE = static_analysis
|
||||||
|
|
||||||
|
include ../../Makefile.units
|
||||||
@@ -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=static_analysis
|
||||||
|
|
||||||
|
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/static_analysis/Makefile.tmk
Normal file
24
userspace/units/interface/static_analysis/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=static_analysis
|
||||||
|
NVGPU_UNIT_SRCS=static_analysis.c
|
||||||
|
|
||||||
|
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# indent-tabs-mode: t
|
||||||
|
# tab-width: 8
|
||||||
|
# End:
|
||||||
|
# vi: set tabstop=8 noexpandtab:
|
||||||
274
userspace/units/interface/static_analysis/static_analysis.c
Normal file
274
userspace/units/interface/static_analysis/static_analysis.c
Normal file
@@ -0,0 +1,274 @@
|
|||||||
|
/*
|
||||||
|
* 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/static_analysis.h>
|
||||||
|
|
||||||
|
#include "static_analysis.h"
|
||||||
|
|
||||||
|
int test_arithmetic(struct unit_module *m, struct gk20a *g, void *args)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* U8 sub */
|
||||||
|
unit_assert(nvgpu_safe_sub_u8(1, 1) == 0, return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_sub_u8(U8_MAX, U8_MAX) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_u8(0, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 add */
|
||||||
|
unit_assert(nvgpu_safe_add_u32(U32_MAX-1, 1) == U32_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_add_u32(U32_MAX, 0) == U32_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_add_u32(U32_MAX, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S32 add */
|
||||||
|
unit_assert(nvgpu_safe_add_s32(INT_MAX-1, 1) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_add_s32(INT_MAX, 0) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_add_s32(INT_MIN+1, -1) == INT_MIN,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_add_s32(INT_MAX, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_add_s32(INT_MIN, -1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 sub */
|
||||||
|
unit_assert(nvgpu_safe_sub_u32(1, 1) == 0, return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_sub_u32(U32_MAX, U32_MAX) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_u32(0, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S32 sub */
|
||||||
|
unit_assert(nvgpu_safe_sub_s32(INT_MIN+1, 1) == INT_MIN,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_sub_s32(INT_MAX-1, -1) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_s32(INT_MIN, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_s32(INT_MAX, -1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 Mult */
|
||||||
|
unit_assert(nvgpu_safe_mult_u32(0, 0) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_u32(U32_MAX, 0) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_u32(U32_MAX, 1) == U32_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_mult_u32(U32_MAX, 2));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 add */
|
||||||
|
unit_assert(nvgpu_safe_add_u64(U64_MAX-1, 1) == U64_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_add_u64(U64_MAX, 0) == U64_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_add_u64(U64_MAX, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S64 add */
|
||||||
|
unit_assert(nvgpu_safe_add_s64(LONG_MAX-1, 1) == LONG_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_add_s64(LONG_MAX, 0) == LONG_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_add_s64(LONG_MIN+1, -1) == LONG_MIN,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_add_s64(LONG_MAX, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_add_s64(LONG_MIN, -1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 sub */
|
||||||
|
unit_assert(nvgpu_safe_sub_u64(1, 1) == 0, return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_sub_u64(U64_MAX, U64_MAX) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_u64(0, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S64 sub */
|
||||||
|
unit_assert(nvgpu_safe_sub_s64(LONG_MIN+1, 1) == LONG_MIN,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_sub_s64(LONG_MAX-1, -1) == LONG_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_s64(LONG_MIN, 1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_sub_s64(LONG_MAX, -1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 Mult */
|
||||||
|
unit_assert(nvgpu_safe_mult_u64(0, 0) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_u64(U64_MAX, 0) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_u64(U64_MAX, 1) == U64_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_mult_u64(U64_MAX, 2));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S64 Mult */
|
||||||
|
unit_assert(nvgpu_safe_mult_s64(LONG_MAX, 1) == LONG_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_s64(LONG_MAX, -1) == (-1 * LONG_MAX),
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_s64(-1, LONG_MAX) == (-1 * LONG_MAX),
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_s64(0, LONG_MAX) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_s64(-1, -1) == 1,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_mult_s64(0, -1) == 0,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_mult_s64(LONG_MAX, 2));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_mult_s64(LONG_MAX, -2));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_mult_s64(-1*LONG_MAX, 2));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_mult_s64(-1*LONG_MAX, -2));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
return UNIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_cast(struct unit_module *m, struct gk20a *g, void *args)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* U64 to U32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u64_to_u32(U32_MAX) == U32_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u64_to_u32(U64(U32_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 to U16 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u64_to_u16(U16_MAX) == U16_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u64_to_u16(U64(U16_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 to U8 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u64_to_u8(U8_MAX) == U8_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u64_to_u8(U64(U8_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 to S64 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u64_to_s64(LONG_MAX) == LONG_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u64_to_s64(U64(LONG_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U64 to S32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u64_to_s32(INT_MAX) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u64_to_s32(U64(INT_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S64 to U64 */
|
||||||
|
unit_assert(nvgpu_safe_cast_s64_to_u64(LONG_MAX) == LONG_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s64_to_u64(-1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S64 to U32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_s64_to_u32(U32_MAX) == U32_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s64_to_u32(-1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s64_to_u32(U64(U32_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S64 to S32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_s64_to_s32(INT_MAX) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_cast_s64_to_s32(INT_MIN) == INT_MIN,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s64_to_s32(S64(INT_MIN)-1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s64_to_s32(S64(INT_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 to U16 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u32_to_u16(U16_MAX) == U16_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u32_to_u16(U64(U16_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 to U8 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u32_to_u8(U8_MAX) == U8_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u32_to_u8(U64(U8_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 to S32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u32_to_s32(INT_MAX) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u32_to_s32(U32(INT_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* U32 to S8 */
|
||||||
|
unit_assert(nvgpu_safe_cast_u32_to_s8(SCHAR_MAX) == SCHAR_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_u32_to_s8(U32(SCHAR_MAX)+1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S32 to U64 */
|
||||||
|
unit_assert(nvgpu_safe_cast_s32_to_u64(INT_MAX) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s32_to_u64(-1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S32 to U32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_s32_to_u32(INT_MAX) == INT_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s32_to_u32(-1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* S8 to U8 */
|
||||||
|
unit_assert(nvgpu_safe_cast_s8_to_u8(SCHAR_MAX) == SCHAR_MAX,
|
||||||
|
return UNIT_FAIL);
|
||||||
|
err = EXPECT_BUG((void)nvgpu_safe_cast_s8_to_u8(-1));
|
||||||
|
unit_assert(err != 0, return UNIT_FAIL);
|
||||||
|
|
||||||
|
/* bool to U32 */
|
||||||
|
unit_assert(nvgpu_safe_cast_bool_to_u32(false) == 0, return UNIT_FAIL);
|
||||||
|
unit_assert(nvgpu_safe_cast_bool_to_u32(true) == 1, return UNIT_FAIL);
|
||||||
|
|
||||||
|
return UNIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct unit_module_test static_analysis_tests[] = {
|
||||||
|
UNIT_TEST(arithmetic, test_arithmetic, NULL, 0),
|
||||||
|
UNIT_TEST(cast, test_cast, NULL, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
UNIT_MODULE(static_analysis, static_analysis_tests, UNIT_PRIO_NVGPU_TEST);
|
||||||
91
userspace/units/interface/static_analysis/static_analysis.h
Normal file
91
userspace/units/interface/static_analysis/static_analysis.h
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* 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_STATIC_ANALYSIS_H
|
||||||
|
#define UNIT_STATIC_ANALYSIS_H
|
||||||
|
|
||||||
|
struct gk20a;
|
||||||
|
struct unit_module;
|
||||||
|
|
||||||
|
/** @addtogroup SWUTS-interface-static-analysis
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* Software Unit Test Specification for static analysis unit
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test specification for: test_arithmetic
|
||||||
|
*
|
||||||
|
* Description: Verify functionality of static analysis safe arithmetic APIs.
|
||||||
|
*
|
||||||
|
* Test Type: Feature, Error guessing
|
||||||
|
*
|
||||||
|
* Targets: nvgpu_safe_sub_u8, nvgpu_safe_add_u32, nvgpu_safe_add_s32,
|
||||||
|
* nvgpu_safe_sub_u32, nvgpu_safe_sub_s32, nvgpu_safe_mult_u32,
|
||||||
|
* nvgpu_safe_add_u64, nvgpu_safe_add_s64, nvgpu_safe_sub_u64,
|
||||||
|
* nvgpu_safe_sub_s64, nvgpu_safe_mult_u64, nvgpu_safe_mult_s64
|
||||||
|
*
|
||||||
|
* Input: None
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* - Call the static analysis arithmetic APIs. Pass in valid values and verify
|
||||||
|
* correct return.
|
||||||
|
* - Call the static analysis arithmetic APIs. Pass in values beyond type range
|
||||||
|
* and use EXPECT_BUG() to verify BUG() is called.
|
||||||
|
*
|
||||||
|
* Output: Returns PASS if expected result is met, FAIL otherwise.
|
||||||
|
*/
|
||||||
|
int test_arithmetic(struct unit_module *m, struct gk20a *g, void *args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test specification for: test_cast
|
||||||
|
*
|
||||||
|
* Description: Verify functionality of static analysis safe cast APIs.
|
||||||
|
*
|
||||||
|
* Test Type: Feature, Error guessing
|
||||||
|
*
|
||||||
|
* Targets: nvgpu_safe_cast_u64_to_u32, nvgpu_safe_cast_u64_to_u16,
|
||||||
|
* nvgpu_safe_cast_u64_to_u8, nvgpu_safe_cast_u64_to_s64,
|
||||||
|
* nvgpu_safe_cast_u64_to_s32, nvgpu_safe_cast_s64_to_u64,
|
||||||
|
* nvgpu_safe_cast_s64_to_u32, nvgpu_safe_cast_s64_to_s32,
|
||||||
|
* nvgpu_safe_cast_u32_to_u16, nvgpu_safe_cast_u32_to_u8,
|
||||||
|
* nvgpu_safe_cast_u32_to_s32, nvgpu_safe_cast_u32_to_s8,
|
||||||
|
* nvgpu_safe_cast_s32_to_u64, nvgpu_safe_cast_s32_to_u32,
|
||||||
|
* nvgpu_safe_cast_s8_to_u8, nvgpu_safe_cast_bool_to_u32
|
||||||
|
*
|
||||||
|
* Input: None
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* - Call the static analysis arithmetic APIs. Pass in valid values and verify
|
||||||
|
* correct return.
|
||||||
|
* - Call the static analysis arithmetic APIs. Pass in values beyond type range
|
||||||
|
* and use EXPECT_BUG() to verify BUG() is called.
|
||||||
|
*
|
||||||
|
* Output: Returns PASS if expected result is met, FAIL otherwise.
|
||||||
|
*/
|
||||||
|
int test_cast(struct unit_module *m, struct gk20a *g, void *args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* UNIT_WORKER_H */
|
||||||
Reference in New Issue
Block a user