gpu: nvgpu: unit: posix: verify U*_MAX values

While resolving MISRA 10.8 violations in our definitions of U8_MAX,
U16_MAX, etc, some of the variants tried that looked valid created
invalid values due to integer promotions. So, for sanity, we should
validate these macros in the unit test for posix-env.

JIRA NVGPU-2955

Change-Id: I9c4b66771a875728c2bf79036e9a510bbc871bfb
Signed-off-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2078365
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Adeel Raza <araza@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2019-03-21 11:22:46 -04:00
committed by mobile promotions
parent 629a8de6c4
commit c087e2c12e
2 changed files with 37 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2019, 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"),
@@ -188,11 +188,42 @@ static int sanity_test_endianness(struct unit_module *m,
return UNIT_SUCCESS;
}
static int sanity_test_type_max(struct unit_module *m,
struct gk20a *g, void *args)
{
int ret = UNIT_SUCCESS;
u64 val;
val = (1ULL << 8) - 1;
if (val != U8_MAX) {
unit_err(m, "U8_MAX != %llu\n", val);
ret = UNIT_FAIL;
}
val = (1ULL << 16) - 1;
if (val != U16_MAX) {
unit_err(m, "U16_MAX != %llu\n", val);
ret = UNIT_FAIL;
}
val = (1ULL << 32) - 1;
if (val != U32_MAX) {
unit_err(m, "U32_MAX != %llu\n", val);
ret = UNIT_FAIL;
}
val = 0ULL - 1;
if (val != U64_MAX) {
unit_err(m, "U64_MAX != %llu\n", val);
ret = UNIT_FAIL;
}
return ret;
}
struct unit_module_test posix_env_tests[] = {
UNIT_TEST(sizes, sanity_test_sizes, NULL),
UNIT_TEST(signage, sanity_test_signage, NULL),
UNIT_TEST(endianness, sanity_test_endianness, NULL),
UNIT_TEST(ptr_in_u64, sanity_test_ptr_in_u64, NULL),
UNIT_TEST(type_max, sanity_test_type_max, NULL),
};
UNIT_MODULE(posix_env, posix_env_tests, UNIT_PRIO_POSIX_TEST);