summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2020-05-22 16:46:52 +1000
committerEdward O'Callaghan <quasisec@chromium.org>2020-06-17 11:07:35 +0000
commit629b8f06ec59d2112539efe161f121ab22d99ec8 (patch)
tree2cd3f3d1e603b5044e34c298a3bc2870e2d559e6
parentbe4682dc4416f1a54ab3c9592d97b622b5cd27d2 (diff)
downloadflashrom-629b8f06ec59d2112539efe161f121ab22d99ec8.tar.gz
flashrom-629b8f06ec59d2112539efe161f121ab22d99ec8.tar.bz2
flashrom-629b8f06ec59d2112539efe161f121ab22d99ec8.zip
tests/: Add flashrom.c unit tests
BUG=b:157280555 BRANCH=none TEST=builds Change-Id: I2d9213f98c6c9639f2417466ba4895117e8d600a Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/41646 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
-rw-r--r--tests/flashrom.c36
-rw-r--r--tests/meson.build1
-rw-r--r--tests/tests.c5
-rw-r--r--tests/tests.h3
4 files changed, 45 insertions, 0 deletions
diff --git a/tests/flashrom.c b/tests/flashrom.c
new file mode 100644
index 000000000..ad46dd8da
--- /dev/null
+++ b/tests/flashrom.c
@@ -0,0 +1,36 @@
+#include <include/test.h>
+
+#include "programmer.h"
+
+void flashbuses_to_text_test_success(void **state)
+{
+ (void) state; /* unused */
+
+ enum chipbustype bustype;
+
+ bustype = BUS_NONSPI;
+ assert_string_equal(flashbuses_to_text(bustype), "Non-SPI");
+
+ bustype |= BUS_PARALLEL;
+ assert_string_not_equal(flashbuses_to_text(bustype), "Non-SPI, Parallel");
+
+ bustype = BUS_PARALLEL;
+ bustype |= BUS_LPC;
+ assert_string_equal(flashbuses_to_text(bustype), "Parallel, LPC");
+
+ bustype |= BUS_FWH;
+ //BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
+ assert_string_equal(flashbuses_to_text(bustype), "Non-SPI");
+
+ bustype |= BUS_SPI;
+ assert_string_equal(flashbuses_to_text(bustype), "Parallel, LPC, FWH, SPI");
+
+ bustype |= BUS_PROG;
+ assert_string_equal(
+ flashbuses_to_text(bustype),
+ "Parallel, LPC, FWH, SPI, Programmer-specific"
+ );
+
+ bustype = BUS_NONE;
+ assert_string_equal(flashbuses_to_text(bustype), "None");
+}
diff --git a/tests/meson.build b/tests/meson.build
index 76088c275..1e7ef4a37 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -2,6 +2,7 @@ root_includes = include_directories('../subprojects')
srcs = [
'tests.c',
+ 'flashrom.c',
'spi25.c',
]
diff --git a/tests/tests.c b/tests/tests.c
index 82563acc7..247c81192 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -21,6 +21,11 @@ int main(void)
{
int ret = 0;
+ const struct CMUnitTest flashrom_tests[] = {
+ cmocka_unit_test(flashbuses_to_text_test_success),
+ };
+ ret |= cmocka_run_group_tests_name("flashrom.c tests", flashrom_tests, NULL, NULL);
+
const struct CMUnitTest spi25_tests[] = {
cmocka_unit_test(spi_write_enable_test_success),
cmocka_unit_test(spi_write_disable_test_success),
diff --git a/tests/tests.h b/tests/tests.h
index 6eafeea39..3b91f65d6 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -1,6 +1,9 @@
#ifndef TESTS_H
#define TESTS_H
+/* flashrom.c */
+void flashbuses_to_text_test_success(void **state);
+
/* spi25.c */
void spi_write_enable_test_success(void **state);
void spi_write_disable_test_success(void **state);