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> |
| 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 | } |
| 25 | DM_TEST(dm_test_mmc_base, DM_TESTF_SCAN_PDATA | DM_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; |
| 31 | char cmp[1024]; |
| 32 | |
| 33 | ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); |
| 34 | ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc)); |
| 35 | |
| 36 | /* Read a few blocks and look for the string we expect */ |
| 37 | ut_asserteq(512, dev_desc->blksz); |
| 38 | memset(cmp, '\0', sizeof(cmp)); |
| 39 | ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp)); |
| 40 | ut_assertok(strcmp(cmp, "this is a test")); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | DM_TEST(dm_test_mmc_blk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |