mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
Open source GPL/LGPL release
This commit is contained in:
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