Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> --- tests/sdcard-test.c | 54 ++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 2 ++ 2 files changed, 56 insertions(+) create mode 100644 tests/sdcard-test.c
diff --git a/tests/sdcard-test.c b/tests/sdcard-test.c new file mode 100644 index 0000000000..1358ee28c6 --- /dev/null +++ b/tests/sdcard-test.c @@ -0,0 +1,54 @@ +/* + * QTest testcase for SD protocol and cards + * + * Examples taken from: + * + * - Physical Layer Simplified Specification (chap. 4.5: Cyclic Redundancy Code) + * - http://wiki.seabright.co.nz/wiki/SdCardProtocol.html + * + * Tests written by Philippe Mathieu-Daudé <f4...@amsat.org> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "libqtest.h" +#include "hw/sd/sd.h" + +static void sd_prepare_request48(SDFrame48 *frame, uint8_t cmd, uint32_t arg) +{ + sd_prepare_request(frame, cmd, arg, /* gen_crc */ true); +} + +static void test_sd_request_frame_crc7(void) +{ + SDFrame48 frame; + + /* CMD0 */ + sd_prepare_request48(&frame, 0, 0); + g_assert_cmphex(frame.crc, ==, 0b1001010); + + /* CMD17 */ + sd_prepare_request48(&frame, 17, 0); + g_assert_cmphex(frame.crc, ==, 0b0101010); + + /* APP_CMD */ + sd_prepare_request48(&frame, 55, 0); + g_assert_cmphex(frame.crc, ==, 0x32); + + /* ACMD41 SEND_OP_COND */ + sd_prepare_request48(&frame, 41, 0x00100000); + g_assert_cmphex(frame.crc, ==, 0x5f >> 1); + + /* CMD2 ALL_SEND_CID */ + sd_prepare_request48(&frame, 2, 0); + g_assert_cmphex(frame.crc, ==, 0x4d >> 1); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("sd/req_crc7", test_sd_request_frame_crc7); + + return g_test_run(); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 3b9a5e31a2..6a70a1dbab 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -380,6 +380,7 @@ check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF) gcov-files-arm-y += hw/timer/arm_mptimer.c check-qtest-arm-y += tests/boot-serial-test$(EXESUF) check-qtest-arm-y += tests/sdhci-test$(EXESUF) +check-qtest-arm-y += tests/sdcard-test$(EXESUF) check-qtest-aarch64-y = tests/numa-test$(EXESUF) check-qtest-aarch64-y += tests/sdhci-test$(EXESUF) @@ -835,6 +836,7 @@ tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) tests/numa-test$(EXESUF): tests/numa-test.o tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y) +tests/sdcard-test$(EXESUF): tests/sdcard-test.o hw/sd/sdmmc-internal.o tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@") -- 2.17.0