summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarius Schilder <mschilder@google.com>2018-02-23 15:41:27 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-23 23:13:01 -0800
commit3c4800e59452a7124c34f563d548e09849d59b8d (patch)
tree24d3662e78c60791366d3761f54d5a615ca0fb7d /test
parentd57e5eb3128774732e3b3fe40c0f939d9aaeff1a (diff)
downloadchrome-ec-3c4800e59452a7124c34f563d548e09849d59b8d.tar.gz
ec: add crc32_ctx..() to take context parameter.
Add crc32_ctx.. functions to take context parameter. This allows for multiple instances to exist in parallel. Signed-off-by: mschilder@google.com TEST=make buildall -j8 succeeds BRANCH=none BUG=b:73832883 Change-Id: I66bbc56377eeebf01c790caad0bc4c7a51a1bc58 Reviewed-on: https://chromium-review.googlesource.com/935825 Commit-Ready: Marius Schilder <mschilder@chromium.org> Tested-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/crc32.c75
-rw-r--r--test/crc32.tasklist17
-rw-r--r--test/test_config.h4
4 files changed, 98 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk
index 9c5dd53349..2bcd163655 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -39,6 +39,7 @@ test-list-host += charge_manager
test-list-host += charge_manager_drp_charging
test-list-host += charge_ramp
test-list-host += console_edit
+test-list-host += crc32
test-list-host += entropy
test-list-host += extpwr_gpio
test-list-host += fan
@@ -89,6 +90,7 @@ charge_manager-y=charge_manager.o
charge_manager_drp_charging-y=charge_manager.o
charge_ramp-y+=charge_ramp.o
console_edit-y=console_edit.o
+crc32-y=crc32.o
entropy-y=entropy.o
extpwr_gpio-y=extpwr_gpio.o
fan-y=fan.o
diff --git a/test/crc32.c b/test/crc32.c
new file mode 100644
index 0000000000..e3f6f8d5c6
--- /dev/null
+++ b/test/crc32.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(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(void)
+{
+ test_reset();
+
+ RUN_TEST(test_static);
+ RUN_TEST(test_8);
+ RUN_TEST(test_kat0);
+
+ test_print_result();
+}
diff --git a/test/crc32.tasklist b/test/crc32.tasklist
new file mode 100644
index 0000000000..30e5f7fc22
--- /dev/null
+++ b/test/crc32.tasklist
@@ -0,0 +1,17 @@
+/* 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.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_TEST(n, r, d, s) where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ */
+#define CONFIG_TEST_TASK_LIST
diff --git a/test/test_config.h b/test/test_config.h
index e784bb8b2e..f46e61443f 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -84,6 +84,10 @@
#endif
+#ifdef TEST_CRC32
+#define CONFIG_SW_CRC
+#endif
+
#ifdef TEST_RSA
#define CONFIG_RSA
#define CONFIG_RSA_KEY_SIZE 2048