|
| 1 | +/* unit-sdhci-response-bits.c |
| 2 | + * |
| 3 | + * Unit tests for sdhci response bit extraction. |
| 4 | + * |
| 5 | + * Copyright (C) 2026 wolfSSL Inc. |
| 6 | + * |
| 7 | + * This file is part of wolfBoot. |
| 8 | + * |
| 9 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 3 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * wolfBoot is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 22 | + */ |
| 23 | + |
| 24 | +#define DISK_SDCARD 1 |
| 25 | + |
| 26 | +#include <check.h> |
| 27 | +#include <stdint.h> |
| 28 | +#include <string.h> |
| 29 | + |
| 30 | +static uint32_t mock_regs[0x260 / sizeof(uint32_t)]; |
| 31 | + |
| 32 | +uint64_t hal_get_timer_us(void) |
| 33 | +{ |
| 34 | + return 0; |
| 35 | +} |
| 36 | + |
| 37 | +uint32_t sdhci_reg_read(uint32_t offset) |
| 38 | +{ |
| 39 | + return mock_regs[offset / sizeof(uint32_t)]; |
| 40 | +} |
| 41 | + |
| 42 | +void sdhci_reg_write(uint32_t offset, uint32_t val) |
| 43 | +{ |
| 44 | + mock_regs[offset / sizeof(uint32_t)] = val; |
| 45 | +} |
| 46 | + |
| 47 | +void sdhci_platform_init(void) |
| 48 | +{ |
| 49 | +} |
| 50 | + |
| 51 | +void sdhci_platform_irq_init(void) |
| 52 | +{ |
| 53 | +} |
| 54 | + |
| 55 | +void sdhci_platform_set_bus_mode(int is_emmc) |
| 56 | +{ |
| 57 | + (void)is_emmc; |
| 58 | +} |
| 59 | + |
| 60 | +#include "../../src/sdhci.c" |
| 61 | + |
| 62 | +static void set_response(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3) |
| 63 | +{ |
| 64 | + memset(mock_regs, 0, sizeof(mock_regs)); |
| 65 | + mock_regs[SDHCI_SRS04 / sizeof(uint32_t)] = r0; |
| 66 | + mock_regs[SDHCI_SRS05 / sizeof(uint32_t)] = r1; |
| 67 | + mock_regs[SDHCI_SRS06 / sizeof(uint32_t)] = r2; |
| 68 | + mock_regs[SDHCI_SRS07 / sizeof(uint32_t)] = r3; |
| 69 | +} |
| 70 | + |
| 71 | +START_TEST(test_csd_struct_does_not_cross_registers) |
| 72 | +{ |
| 73 | + set_response(0, 0, 0, 2U << 22); |
| 74 | + |
| 75 | + ck_assert_uint_eq(sdhci_get_response_bits(126, 2), 2); |
| 76 | +} |
| 77 | +END_TEST |
| 78 | + |
| 79 | +Suite *sdhci_suite(void) |
| 80 | +{ |
| 81 | + Suite *s = suite_create("sdhci"); |
| 82 | + TCase *tc = tcase_create("response_bits"); |
| 83 | + |
| 84 | + tcase_add_test(tc, test_csd_struct_does_not_cross_registers); |
| 85 | + suite_add_tcase(s, tc); |
| 86 | + |
| 87 | + return s; |
| 88 | +} |
| 89 | + |
| 90 | +int main(void) |
| 91 | +{ |
| 92 | + int fails; |
| 93 | + Suite *s = sdhci_suite(); |
| 94 | + SRunner *sr = srunner_create(s); |
| 95 | + |
| 96 | + srunner_run_all(sr, CK_NORMAL); |
| 97 | + fails = srunner_ntests_failed(sr); |
| 98 | + srunner_free(sr); |
| 99 | + |
| 100 | + return fails; |
| 101 | +} |
0 commit comments