summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2020-09-14 07:46:19 -0600
committerAaron Durbin <adurbin@chromium.org>2020-09-16 03:24:50 +0000
commita01ee36288b26f31fc1e912324293104f33211c3 (patch)
treebce1967dab34f331666679524e7d487529cd3038 /tests
parentfcd7d0518c0719701c7ed58cd0e0869be492d34c (diff)
device/dram: Add method for converting MHz to MT/s
Add method for converting DDR4 speed in MHz to MT/s. Checks that MHz is within a speed grade range. BUG=b:167155849 TEST=ddr4-test unit test BRANCH=Zork Change-Id: I1433f028afb794fe3e397b03f5bd0565494c8130 Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/45343 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/device/Makefile.inc5
-rw-r--r--tests/device/ddr4-test.c41
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/device/Makefile.inc b/tests/device/Makefile.inc
index 10223c52cc..4626c3cf3d 100644
--- a/tests/device/Makefile.inc
+++ b/tests/device/Makefile.inc
@@ -1,7 +1,12 @@
# SPDX-License-Identifier: GPL-2.0-only
tests-y += i2c-test
+tests-y += ddr4-test
i2c-test-srcs += tests/device/i2c-test.c
i2c-test-srcs += src/device/i2c.c
i2c-test-mocks += platform_i2c_transfer
+
+ddr4-test-srcs += tests/device/ddr4-test.c
+ddr4-test-srcs += tests/stubs/console.c
+ddr4-test-srcs += src/device/dram/ddr4.c \ No newline at end of file
diff --git a/tests/device/ddr4-test.c b/tests/device/ddr4-test.c
new file mode 100644
index 0000000000..0a9831da75
--- /dev/null
+++ b/tests/device/ddr4-test.c
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <device/dram/ddr4.h>
+#include <tests/test.h>
+
+static void ddr4_speed_mhz_to_mts_test(void **state)
+{
+ assert_int_equal(0, ddr4_speed_mhz_to_reported_mts(0));
+ assert_int_equal(0, ddr4_speed_mhz_to_reported_mts(667));
+
+ assert_int_equal(1600, ddr4_speed_mhz_to_reported_mts(668));
+ assert_int_equal(1600, ddr4_speed_mhz_to_reported_mts(800));
+
+ assert_int_equal(1866, ddr4_speed_mhz_to_reported_mts(801));
+ assert_int_equal(1866, ddr4_speed_mhz_to_reported_mts(933));
+ assert_int_equal(1866, ddr4_speed_mhz_to_reported_mts(934));
+
+ assert_int_equal(2133, ddr4_speed_mhz_to_reported_mts(1066));
+ assert_int_equal(2133, ddr4_speed_mhz_to_reported_mts(1067));
+
+ assert_int_equal(2400, ddr4_speed_mhz_to_reported_mts(1200));
+
+ assert_int_equal(2666, ddr4_speed_mhz_to_reported_mts(1333));
+
+ assert_int_equal(2933, ddr4_speed_mhz_to_reported_mts(1466));
+
+ assert_int_equal(3200, ddr4_speed_mhz_to_reported_mts(1467));
+ assert_int_equal(3200, ddr4_speed_mhz_to_reported_mts(1600));
+
+ assert_int_equal(0, ddr4_speed_mhz_to_reported_mts(1601));
+ assert_int_equal(0, ddr4_speed_mhz_to_reported_mts(INT16_MAX));
+}
+
+int main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(ddr4_speed_mhz_to_mts_test)
+ };
+
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}