From c087e2c12ec8284d06ad8ec9db9883182256728b Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Thu, 21 Mar 2019 11:22:46 -0400 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/2078365 Reviewed-by: svc-misra-checker GVS: Gerrit_Virtual_Submit Reviewed-by: Adeel Raza Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/required_tests.json | 6 ++++- userspace/units/posix/env/posix-env.c | 33 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 099c4226a..33673dd73 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -864,6 +864,10 @@ "test": "sizes", "unit": "posix_env" }, + { + "test": "type_max", + "unit": "posix_env" + }, { "test": "__readl", "unit": "posix_mockio" @@ -934,4 +938,4 @@ "uid": "6434840", "unit": "vm" } -] \ No newline at end of file +] diff --git a/userspace/units/posix/env/posix-env.c b/userspace/units/posix/env/posix-env.c index fc090352b..8d99bfc12 100644 --- a/userspace/units/posix/env/posix-env.c +++ b/userspace/units/posix/env/posix-env.c @@ -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);