Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <mmc.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 8 | #include <part.h> |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 9 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 10 | #include <test/test.h> |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 11 | #include <test/ut.h> |
| 12 | |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 13 | /* |
| 14 | * Basic test of the mmc uclass. We could expand this by implementing an MMC |
| 15 | * stack for sandbox, or at least implementing the basic operation. |
| 16 | */ |
| 17 | static int dm_test_mmc_base(struct unit_test_state *uts) |
| 18 | { |
| 19 | struct udevice *dev; |
| 20 | |
| 21 | ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); |
| 22 | |
| 23 | return 0; |
| 24 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 25 | DM_TEST(dm_test_mmc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | e5cf427 | 2016-05-01 13:52:44 -0600 | [diff] [blame] | 26 | |
| 27 | static int dm_test_mmc_blk(struct unit_test_state *uts) |
| 28 | { |
| 29 | struct udevice *dev; |
| 30 | struct blk_desc *dev_desc; |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 31 | int i; |
Loic Poulain | 1b0e2d1 | 2023-01-26 10:24:19 +0100 | [diff] [blame] | 32 | char write[4 * 512], read[4 * 512]; |
Simon Glass | e5cf427 | 2016-05-01 13:52:44 -0600 | [diff] [blame] | 33 | |
| 34 | ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); |
| 35 | ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc)); |
| 36 | |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 37 | /* Write a few blocks and verify that we get the same data back */ |
Simon Glass | e5cf427 | 2016-05-01 13:52:44 -0600 | [diff] [blame] | 38 | ut_asserteq(512, dev_desc->blksz); |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 39 | for (i = 0; i < sizeof(write); i++) |
| 40 | write[i] = i; |
Loic Poulain | 1b0e2d1 | 2023-01-26 10:24:19 +0100 | [diff] [blame] | 41 | ut_asserteq(4, blk_dwrite(dev_desc, 0, 4, write)); |
| 42 | ut_asserteq(4, blk_dread(dev_desc, 0, 4, read)); |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 43 | ut_asserteq_mem(write, read, sizeof(write)); |
| 44 | |
Loic Poulain | 1b0e2d1 | 2023-01-26 10:24:19 +0100 | [diff] [blame] | 45 | /* Now erase two of them [1 - 2] and verify all blocks */ |
| 46 | memset(&write[512], '\0', 2 * 512); |
| 47 | ut_asserteq(2, blk_derase(dev_desc, 1, 2)); |
| 48 | ut_asserteq(4, blk_dread(dev_desc, 0, 4, read)); |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 49 | ut_asserteq_mem(write, read, sizeof(write)); |
Simon Glass | e5cf427 | 2016-05-01 13:52:44 -0600 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 53 | DM_TEST(dm_test_mmc_blk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |