From 9263a4f135deb87f7926ed2e91deef496bbfe818 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Mon, 9 Nov 2020 15:23:12 -0700 Subject: crc32: rename test crc32->crc to allow for crc8 Instead of creating a new test for crc8, just make the existing crc32 test more generic. BRANCH=none BUG=none TEST=none Signed-off-by: Jett Rink Change-Id: Ie630d4991d4e2c7dc441842c39d63fc0281ac809 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2532690 Reviewed-by: Tom Hughes Reviewed-by: Jack Rosenthal --- test/build.mk | 4 +-- test/crc.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ test/crc.tasklist | 9 ++++++ test/crc32.c | 75 ------------------------------------------------ test/crc32.tasklist | 9 ------ test/run_device_tests.py | 4 +-- test/test_config.h | 2 +- 7 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 test/crc.c create mode 100644 test/crc.tasklist delete mode 100644 test/crc32.c delete mode 100644 test/crc32.tasklist (limited to 'test') diff --git a/test/build.mk b/test/build.mk index 2dc413c25c..1a9f3657a8 100644 --- a/test/build.mk +++ b/test/build.mk @@ -26,7 +26,7 @@ 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 += crc test-list-host += entropy test-list-host += extpwr_gpio test-list-host += fan @@ -135,7 +135,7 @@ 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 +crc-y=crc.o entropy-y=entropy.o extpwr_gpio-y=extpwr_gpio.o fan-y=fan.o diff --git a/test/crc.c b/test/crc.c new file mode 100644 index 0000000000..3521bce4a9 --- /dev/null +++ b/test/crc.c @@ -0,0 +1,75 @@ +/* Copyright 2016 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. + * + * Tests crc32 sw implementation. + */ + +#include "common.h" +#include "console.h" +#include "crc.h" +#include "test_util.h" +#include "util.h" + +// test that static version matches context version +static int test_static_version(void) +{ + uint32_t crc; + const uint32_t input = 0xdeadbeef; + + crc32_init(); + crc32_hash32(input); + + crc32_ctx_init(&crc); + crc32_ctx_hash32(&crc, input); + + TEST_ASSERT(crc32_result() == crc32_ctx_result(&crc)); + + return EC_SUCCESS; +} + +// test that context bytes at a time matches static word at time +static int test_8(void) +{ + uint32_t crc; + const uint32_t input = 0xdeadbeef; + const uint8_t *p = (const uint8_t *) &input; + int i; + + crc32_init(); + crc32_hash32(input); + + crc32_ctx_init(&crc); + for (i = 0; i < sizeof(input); ++i) + crc32_ctx_hash8(&crc, p[i]); + + TEST_ASSERT(crc32_result() == crc32_ctx_result(&crc)); + + return EC_SUCCESS; +} + +// http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/ +static int test_kat0(void) +{ + uint32_t crc; + int i; + const char input[] = "The quick brown fox jumps over the lazy dog"; + + crc32_ctx_init(&crc); + for (i = 0; i < strlen(input); ++i) + crc32_ctx_hash8(&crc, input[i]); + TEST_ASSERT(crc32_ctx_result(&crc) == 0x414fa339); + + return EC_SUCCESS; +} + +void run_test(int argc, char **argv) +{ + test_reset(); + + RUN_TEST(test_static_version); + RUN_TEST(test_8); + RUN_TEST(test_kat0); + + test_print_result(); +} diff --git a/test/crc.tasklist b/test/crc.tasklist new file mode 100644 index 0000000000..f46a2eaa1d --- /dev/null +++ b/test/crc.tasklist @@ -0,0 +1,9 @@ +/* Copyright 2016 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 diff --git a/test/crc32.c b/test/crc32.c deleted file mode 100644 index 3521bce4a9..0000000000 --- a/test/crc32.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright 2016 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. - * - * Tests crc32 sw implementation. - */ - -#include "common.h" -#include "console.h" -#include "crc.h" -#include "test_util.h" -#include "util.h" - -// test that static version matches context version -static int test_static_version(void) -{ - uint32_t crc; - const uint32_t input = 0xdeadbeef; - - crc32_init(); - crc32_hash32(input); - - crc32_ctx_init(&crc); - crc32_ctx_hash32(&crc, input); - - TEST_ASSERT(crc32_result() == crc32_ctx_result(&crc)); - - return EC_SUCCESS; -} - -// test that context bytes at a time matches static word at time -static int test_8(void) -{ - uint32_t crc; - const uint32_t input = 0xdeadbeef; - const uint8_t *p = (const uint8_t *) &input; - int i; - - crc32_init(); - crc32_hash32(input); - - crc32_ctx_init(&crc); - for (i = 0; i < sizeof(input); ++i) - crc32_ctx_hash8(&crc, p[i]); - - TEST_ASSERT(crc32_result() == crc32_ctx_result(&crc)); - - return EC_SUCCESS; -} - -// http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/ -static int test_kat0(void) -{ - uint32_t crc; - int i; - const char input[] = "The quick brown fox jumps over the lazy dog"; - - crc32_ctx_init(&crc); - for (i = 0; i < strlen(input); ++i) - crc32_ctx_hash8(&crc, input[i]); - TEST_ASSERT(crc32_ctx_result(&crc) == 0x414fa339); - - return EC_SUCCESS; -} - -void run_test(int argc, char **argv) -{ - test_reset(); - - RUN_TEST(test_static_version); - RUN_TEST(test_8); - RUN_TEST(test_kat0); - - test_print_result(); -} diff --git a/test/crc32.tasklist b/test/crc32.tasklist deleted file mode 100644 index f46a2eaa1d..0000000000 --- a/test/crc32.tasklist +++ /dev/null @@ -1,9 +0,0 @@ -/* Copyright 2016 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 diff --git a/test/run_device_tests.py b/test/run_device_tests.py index bed942f62e..9e38576c2d 100755 --- a/test/run_device_tests.py +++ b/test/run_device_tests.py @@ -105,8 +105,8 @@ class AllTests: tests = { 'aes': TestConfig(name='aes'), - 'crc32': - TestConfig(name='crc32'), + 'crc': + TestConfig(name='crc'), 'flash_physical': TestConfig(name='flash_physical', image_to_use=ImageType.RO, toggle_power=True), diff --git a/test/test_config.h b/test/test_config.h index 889ee43d58..7e9e2cc5e6 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -219,7 +219,7 @@ enum sensor_id { #endif -#ifdef TEST_CRC32 +#ifdef TEST_CRC #define CONFIG_SW_CRC #endif -- cgit v1.2.1