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 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <mmc.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 9 | #include <part.h> |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 10 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 12 | #include <test/ut.h> |
| 13 | |
Simon Glass | d3e58e4 | 2015-07-06 12:54:32 -0600 | [diff] [blame] | 14 | /* |
| 15 | * Basic test of the mmc uclass. We could expand this by implementing an MMC |
| 16 | * stack for sandbox, or at least implementing the basic operation. |
| 17 | */ |
| 18 | static int dm_test_mmc_base(struct unit_test_state *uts) |
| 19 | { |
| 20 | struct udevice *dev; |
| 21 | |
| 22 | ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); |
| 23 | |
| 24 | return 0; |
| 25 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 26 | 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] | 27 | |
| 28 | static int dm_test_mmc_blk(struct unit_test_state *uts) |
| 29 | { |
| 30 | struct udevice *dev; |
| 31 | struct blk_desc *dev_desc; |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 32 | int i; |
| 33 | char write[1024], read[1024]; |
Simon Glass | e5cf427 | 2016-05-01 13:52:44 -0600 | [diff] [blame] | 34 | |
| 35 | ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); |
| 36 | ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc)); |
| 37 | |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 38 | /* 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] | 39 | ut_asserteq(512, dev_desc->blksz); |
Sean Anderson | b2f1c0b | 2021-02-05 09:38:53 -0500 | [diff] [blame] | 40 | for (i = 0; i < sizeof(write); i++) |
| 41 | write[i] = i; |
| 42 | ut_asserteq(2, blk_dwrite(dev_desc, 0, 2, write)); |
| 43 | ut_asserteq(2, blk_dread(dev_desc, 0, 2, read)); |
| 44 | ut_asserteq_mem(write, read, sizeof(write)); |
| 45 | |
| 46 | /* Now erase them */ |
| 47 | memset(write, '\0', sizeof(write)); |
| 48 | ut_asserteq(2, blk_derase(dev_desc, 0, 2)); |
| 49 | ut_asserteq(2, blk_dread(dev_desc, 0, 2, read)); |
| 50 | ut_asserteq_mem(write, read, sizeof(write)); |
Simon Glass | e5cf427 | 2016-05-01 13:52:44 -0600 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 54 | DM_TEST(dm_test_mmc_blk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |