blob: b1eb8bee2f9d5e56fa1e2ead2d8e184c108a8587 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassd3e58e42015-07-06 12:54:32 -06002/*
3 * Copyright (C) 2015 Google, Inc
Simon Glassd3e58e42015-07-06 12:54:32 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <mmc.h>
Simon Glass655306c2020-05-10 11:39:58 -06009#include <part.h>
Simon Glassd3e58e42015-07-06 12:54:32 -060010#include <dm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060011#include <test/test.h>
Simon Glassd3e58e42015-07-06 12:54:32 -060012#include <test/ut.h>
13
Simon Glassd3e58e42015-07-06 12:54:32 -060014/*
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 */
18static 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 Glass974dccd2020-07-28 19:41:12 -060026DM_TEST(dm_test_mmc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glasse5cf4272016-05-01 13:52:44 -060027
28static int dm_test_mmc_blk(struct unit_test_state *uts)
29{
30 struct udevice *dev;
31 struct blk_desc *dev_desc;
Sean Andersonb2f1c0b2021-02-05 09:38:53 -050032 int i;
Loic Poulain1b0e2d12023-01-26 10:24:19 +010033 char write[4 * 512], read[4 * 512];
Simon Glasse5cf4272016-05-01 13:52:44 -060034
35 ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
36 ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
37
Sean Andersonb2f1c0b2021-02-05 09:38:53 -050038 /* Write a few blocks and verify that we get the same data back */
Simon Glasse5cf4272016-05-01 13:52:44 -060039 ut_asserteq(512, dev_desc->blksz);
Sean Andersonb2f1c0b2021-02-05 09:38:53 -050040 for (i = 0; i < sizeof(write); i++)
41 write[i] = i;
Loic Poulain1b0e2d12023-01-26 10:24:19 +010042 ut_asserteq(4, blk_dwrite(dev_desc, 0, 4, write));
43 ut_asserteq(4, blk_dread(dev_desc, 0, 4, read));
Sean Andersonb2f1c0b2021-02-05 09:38:53 -050044 ut_asserteq_mem(write, read, sizeof(write));
45
Loic Poulain1b0e2d12023-01-26 10:24:19 +010046 /* Now erase two of them [1 - 2] and verify all blocks */
47 memset(&write[512], '\0', 2 * 512);
48 ut_asserteq(2, blk_derase(dev_desc, 1, 2));
49 ut_asserteq(4, blk_dread(dev_desc, 0, 4, read));
Sean Andersonb2f1c0b2021-02-05 09:38:53 -050050 ut_asserteq_mem(write, read, sizeof(write));
Simon Glasse5cf4272016-05-01 13:52:44 -060051
52 return 0;
53}
Simon Glass974dccd2020-07-28 19:41:12 -060054DM_TEST(dm_test_mmc_blk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);