mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: add unit test for nvgpu_wrapping_add_u32
Add BVEC unit test for the function nvgpu_wrapping_add_u32. JIRA NVGPU-7211 Change-Id: I5c4c870c75b3e7643a771110b2c0d248c1f8cb56 Signed-off-by: Sagar Kamble <skamble@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2614166 (cherry picked from commit f6a2fae67c3dd0d3f11deba2cb943a8c6420fda5) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2623633 Reviewed-by: Vaibhav Kachore <vkachore@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> GVS: Gerrit_Virtual_Submit
This commit is contained in:
committed by
mobile promotions
parent
d944313a54
commit
a1e75fe9bc
@@ -57,6 +57,31 @@
|
|||||||
unit_assert(err != 0, return UNIT_FAIL); \
|
unit_assert(err != 0, return UNIT_FAIL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapping unsigned addition tests
|
||||||
|
*
|
||||||
|
* parameters:
|
||||||
|
* type_name: type (u8, u32 etc.)
|
||||||
|
* type_max : Maximum value of the type.
|
||||||
|
* tmp_operand: random value in the set (1, Maximum value)
|
||||||
|
*
|
||||||
|
* Boundary values: (0, 1, max-1, max)
|
||||||
|
*
|
||||||
|
* Valid tests: Addition result within range for each boundary value and
|
||||||
|
* random value. Addition result wrapping for each boundary
|
||||||
|
* and random value.
|
||||||
|
*/
|
||||||
|
#define GENERATE_ARITHMETIC_WRAPPING_ADD_TESTS(type_name, type_max, tmp_operand) do {\
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(type_max, 0) == type_max, return UNIT_FAIL); \
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(type_max - 1, 1) == type_max, return UNIT_FAIL); \
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(type_max - tmp_operand, tmp_operand) == type_max, \
|
||||||
|
return UNIT_FAIL); \
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(1, type_max) == 0, return UNIT_FAIL); \
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(tmp_operand, type_max - tmp_operand + 1) == 0, return UNIT_FAIL); \
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(type_max - 1, 2) == 0, return UNIT_FAIL); \
|
||||||
|
unit_assert(nvgpu_wrapping_add_##type_name(type_max, type_max) == (type_max - 1), return UNIT_FAIL); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* signed addition tests
|
* signed addition tests
|
||||||
*
|
*
|
||||||
@@ -329,6 +354,9 @@ int test_arithmetic(struct unit_module *m, struct gk20a *g, void *args)
|
|||||||
/* U32 add */
|
/* U32 add */
|
||||||
GENERATE_ARITHMETIC_ADD_TESTS(u32, U32_MAX, tmp_u32);
|
GENERATE_ARITHMETIC_ADD_TESTS(u32, U32_MAX, tmp_u32);
|
||||||
|
|
||||||
|
/* wrapping U32 add */
|
||||||
|
GENERATE_ARITHMETIC_WRAPPING_ADD_TESTS(u32, U32_MAX, tmp_u32);
|
||||||
|
|
||||||
/* S32 add */
|
/* S32 add */
|
||||||
GENERATE_ARITHMETIC_SIGNED_ADD_TESTS(s32, INT_MIN, INT_MAX, tmp_s32, tmp_s32_neg);
|
GENERATE_ARITHMETIC_SIGNED_ADD_TESTS(s32, INT_MIN, INT_MAX, tmp_s32, tmp_s32_neg);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ struct unit_module;
|
|||||||
* Targets: nvgpu_safe_sub_u8, nvgpu_safe_add_u32, nvgpu_safe_add_s32,
|
* 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_sub_u32, nvgpu_safe_sub_s32, nvgpu_safe_mult_u32,
|
||||||
* nvgpu_safe_add_u64, nvgpu_safe_add_s64, nvgpu_safe_sub_u64,
|
* nvgpu_safe_add_u64, nvgpu_safe_add_s64, nvgpu_safe_sub_u64,
|
||||||
* nvgpu_safe_sub_s64, nvgpu_safe_mult_u64, nvgpu_safe_mult_s64
|
* nvgpu_safe_sub_s64, nvgpu_safe_mult_u64, nvgpu_safe_mult_s64,
|
||||||
|
* nvgpu_wrapping_add_u32
|
||||||
*
|
*
|
||||||
* Input: None
|
* Input: None
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user