diff options
author | Craig Hesling <hesling@chromium.org> | 2019-12-18 10:40:01 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-12-20 17:37:06 +0000 |
commit | f776a287369e4ac46b17eb9001f3b78621f87325 (patch) | |
tree | 4909489f341027ee17f60657ae4d4184b90d83e5 /test | |
parent | 7ac25f043ae797e6fabab215e9acf612c8a2ca76 (diff) | |
download | chrome-ec-f776a287369e4ac46b17eb9001f3b78621f87325.tar.gz |
compile_time_macros: Add GENMASK and GENMASK_ULL
BRANCH=all
BUG=none
TEST=make buildall
TEST=make run-compile_time_macros
Change-Id: I586e009dac20e33701ded9a05c51ee806e466cae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1974356
Tested-by: Craig Hesling <hesling@chromium.org>
Auto-Submit: Craig Hesling <hesling@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/build.mk | 2 | ||||
-rw-r--r-- | test/compile_time_macros.c | 47 | ||||
-rw-r--r-- | test/compile_time_macros.tasklist | 9 |
3 files changed, 58 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk index 4011fa455b..aa6b6b4483 100644 --- a/test/build.mk +++ b/test/build.mk @@ -21,6 +21,7 @@ test-list-host += cec test-list-host += charge_manager test-list-host += charge_manager_drp_charging test-list-host += charge_ramp +test-list-host += compile_time_macros test-list-host += console_edit test-list-host += crc32 test-list-host += entropy @@ -101,6 +102,7 @@ cec-y=cec.o charge_manager-y=charge_manager.o charge_manager_drp_charging-y=charge_manager.o charge_ramp-y+=charge_ramp.o +compile_time_macros-y=compile_time_macros.o console_edit-y=console_edit.o crc32-y=crc32.o entropy-y=entropy.o diff --git a/test/compile_time_macros.c b/test/compile_time_macros.c new file mode 100644 index 0000000000..28e7af500b --- /dev/null +++ b/test/compile_time_macros.c @@ -0,0 +1,47 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Test compile_time_macros.h + */ + +#include "common.h" +#include "test_util.h" + + +static int test_GENMASK(void) +{ + TEST_EQ(GENMASK(0, 0), 0x00000001U, "%u"); + TEST_EQ(GENMASK(31, 0), 0xFFFFFFFFU, "%u"); + TEST_EQ(GENMASK(4, 4), 0x00000010U, "%u"); + TEST_EQ(GENMASK(4, 0), 0x0000001FU, "%u"); + TEST_EQ(GENMASK(21, 21), 0x00200000U, "%u"); + TEST_EQ(GENMASK(31, 31), 0x80000000U, "%u"); + + return EC_SUCCESS; +} + +static int test_GENMASK_ULL(void) +{ + TEST_EQ(GENMASK_ULL(0, 0), 0x0000000000000001ULL, "%Lu"); + TEST_EQ(GENMASK_ULL(31, 0), 0x00000000FFFFFFFFULL, "%Lu"); + TEST_EQ(GENMASK_ULL(63, 0), 0xFFFFFFFFFFFFFFFFULL, "%Lu"); + TEST_EQ(GENMASK_ULL(4, 4), 0x0000000000000010ULL, "%Lu"); + TEST_EQ(GENMASK_ULL(4, 0), 0x000000000000001FULL, "%Lu"); + TEST_EQ(GENMASK_ULL(21, 21), 0x0000000000200000ULL, "%Lu"); + TEST_EQ(GENMASK_ULL(31, 31), 0x0000000080000000ULL, "%Lu"); + TEST_EQ(GENMASK_ULL(63, 63), 0x8000000000000000ULL, "%Lu"); + TEST_EQ(GENMASK_ULL(62, 60), 0x7000000000000000ULL, "%Lu"); + + return EC_SUCCESS; +} + +void run_test(void) +{ + test_reset(); + + RUN_TEST(test_GENMASK); + RUN_TEST(test_GENMASK_ULL); + + test_print_result(); +} diff --git a/test/compile_time_macros.tasklist b/test/compile_time_macros.tasklist new file mode 100644 index 0000000000..5ffe662d01 --- /dev/null +++ b/test/compile_time_macros.tasklist @@ -0,0 +1,9 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST /* No test task */ |