2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-07-07 02:54:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <mmc.h>
|
2020-05-11 01:39:58 +08:00
|
|
|
#include <part.h>
|
2015-07-07 02:54:32 +08:00
|
|
|
#include <dm/test.h>
|
2020-07-20 00:15:37 +08:00
|
|
|
#include <test/test.h>
|
2015-07-07 02:54:32 +08:00
|
|
|
#include <test/ut.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic test of the mmc uclass. We could expand this by implementing an MMC
|
|
|
|
* stack for sandbox, or at least implementing the basic operation.
|
|
|
|
*/
|
|
|
|
static int dm_test_mmc_base(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_mmc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2016-05-02 03:52:44 +08:00
|
|
|
|
|
|
|
static int dm_test_mmc_blk(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
struct blk_desc *dev_desc;
|
2021-02-05 22:38:53 +08:00
|
|
|
int i;
|
|
|
|
char write[1024], read[1024];
|
2016-05-02 03:52:44 +08:00
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
|
|
|
|
ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
|
|
|
|
|
2021-02-05 22:38:53 +08:00
|
|
|
/* Write a few blocks and verify that we get the same data back */
|
2016-05-02 03:52:44 +08:00
|
|
|
ut_asserteq(512, dev_desc->blksz);
|
2021-02-05 22:38:53 +08:00
|
|
|
for (i = 0; i < sizeof(write); i++)
|
|
|
|
write[i] = i;
|
|
|
|
ut_asserteq(2, blk_dwrite(dev_desc, 0, 2, write));
|
|
|
|
ut_asserteq(2, blk_dread(dev_desc, 0, 2, read));
|
|
|
|
ut_asserteq_mem(write, read, sizeof(write));
|
|
|
|
|
|
|
|
/* Now erase them */
|
|
|
|
memset(write, '\0', sizeof(write));
|
|
|
|
ut_asserteq(2, blk_derase(dev_desc, 0, 2));
|
|
|
|
ut_asserteq(2, blk_dread(dev_desc, 0, 2, read));
|
|
|
|
ut_asserteq_mem(write, read, sizeof(write));
|
2016-05-02 03:52:44 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_mmc_blk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|