summaryrefslogtreecommitdiff
path: root/test/entropy.c
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-11-04 12:11:58 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-05 04:22:34 +0000
commit252457d4b21f46889eebad61d4c0a65331919cec (patch)
tree01856c4d31d710b20e85a74c8d7b5836e35c3b98 /test/entropy.c
parent08f5a1e6fc2c9467230444ac9b582dcf4d9f0068 (diff)
downloadchrome-ec-stabilize-14388.61.B-ish.tar.gz
In the interest of making long-term branch maintenance incur as little technical debt on us as possible, we should not maintain any files on the branch we are not actually using. This has the added effect of making it extremely clear when merging CLs from the main branch when changes have the possibility to affect us. The follow-on CL adds a convenience script to actually pull updates from the main branch and generate a CL for the update. BUG=b:204206272 BRANCH=ish TEST=make BOARD=arcada_ish && make BOARD=drallion_ish Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I17e4694c38219b5a0823e0a3e55a28d1348f4b18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262038 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'test/entropy.c')
-rw-r--r--test/entropy.c92
1 files changed, 0 insertions, 92 deletions
diff --git a/test/entropy.c b/test/entropy.c
deleted file mode 100644
index fb066a6c5b..0000000000
--- a/test/entropy.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Copyright 2017 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 entropy source.
- */
-
-#include "console.h"
-#include "common.h"
-#include "rollback.h"
-#include "test_util.h"
-#include "timer.h"
-#include "util.h"
-#include "watchdog.h"
-
-static int buckets[256];
-
-static const int log2_mult = 2;
-
-/*
- * log2 (multiplied by 2). For non-power of 2, this rounds to the closest
- * half-integer, otherwise the value is exact.
- */
-uint32_t log2(int32_t val)
-{
- int val1 = 31 - __builtin_clz(val);
- int val2 = 32 - __builtin_clz(val - 1);
-
- return log2_mult * (val1 + val2)/2;
-}
-
-void run_test(int argc, char **argv)
-{
- const int loopcount = 512;
-
- uint8_t buffer[32];
- timestamp_t t0, t1;
- int i, j;
- uint32_t entropy;
- const int totalcount = loopcount * sizeof(buffer);
- const int log2totalcount = log2(totalcount);
-
- memset(buckets, 0, sizeof(buckets));
-
- for (i = 0; i < loopcount; i++) {
- t0 = get_time();
- if (!board_get_entropy(buffer, sizeof(buffer))) {
- ccprintf("Cannot get entropy\n");
- test_fail();
- return;
- }
- t1 = get_time();
- if (i == 0)
- ccprintf("Got %zd bytes in %" PRId64 " us\n",
- sizeof(buffer), t1.val - t0.val);
-
- for (j = 0; j < sizeof(buffer); j++)
- buckets[buffer[j]]++;
-
- watchdog_reload();
- }
-
- ccprintf("Total count: %d\n", totalcount);
- ccprintf("Buckets: ");
- entropy = 0;
- for (j = 0; j < 256; j++) {
- /*
- * Shannon entropy (base 2) is sum of -p[j] * log_2(p[j]).
- * p[j] = buckets[j]/totalcount
- * -p[j] * log_2(p[j])
- * = -(buckets[j]/totalcount) * log_2(buckets[j]/totalcount)
- * = buckets[j] * (log_2(totalcount) - log_2(buckets[j]))
- * / totalcount
- * Our log2() function is scaled by log2_mult, and we defer the
- * division by totalcount until we get the total sum, so we need
- * to divide by (log2_mult * totalcount) at the end.
- */
- entropy += buckets[j] * (log2totalcount - log2(buckets[j]));
- ccprintf("%d;", buckets[j]);
- cflush();
- }
- ccprintf("\n");
-
- ccprintf("Entropy: %u/1000 bits\n",
- entropy * 1000 / (log2_mult * totalcount));
-
- /* We want at least 2 bits of entropy (out of a maximum of 8) */
- if ((entropy / (log2_mult * totalcount)) >= 2)
- test_pass();
- else
- test_fail();
-}