]> Git Repo - u-boot.git/blame - test/dm/mmc.c
Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-sh
[u-boot.git] / test / dm / mmc.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
8e6cc461
SG
2/*
3 * Copyright (C) 2015 Google, Inc
8e6cc461
SG
4 */
5
8e6cc461
SG
6#include <dm.h>
7#include <mmc.h>
e6f6f9e6 8#include <part.h>
8e6cc461 9#include <dm/test.h>
0e1fad43 10#include <test/test.h>
8e6cc461
SG
11#include <test/ut.h>
12
8e6cc461
SG
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 */
17static 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}
725c438c 25DM_TEST(dm_test_mmc_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
341392dd
SG
26
27static int dm_test_mmc_blk(struct unit_test_state *uts)
28{
29 struct udevice *dev;
30 struct blk_desc *dev_desc;
3f6fb771 31 int i;
94f40b94 32 char write[4 * 512], read[4 * 512];
341392dd
SG
33
34 ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
35 ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
36
3f6fb771 37 /* Write a few blocks and verify that we get the same data back */
341392dd 38 ut_asserteq(512, dev_desc->blksz);
3f6fb771
SA
39 for (i = 0; i < sizeof(write); i++)
40 write[i] = i;
94f40b94
LP
41 ut_asserteq(4, blk_dwrite(dev_desc, 0, 4, write));
42 ut_asserteq(4, blk_dread(dev_desc, 0, 4, read));
3f6fb771
SA
43 ut_asserteq_mem(write, read, sizeof(write));
44
94f40b94
LP
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));
3f6fb771 49 ut_asserteq_mem(write, read, sizeof(write));
341392dd
SG
50
51 return 0;
52}
725c438c 53DM_TEST(dm_test_mmc_blk, UTF_SCAN_PDATA | UTF_SCAN_FDT);
This page took 0.243827 seconds and 4 git commands to generate.