blob: 9939d837a90d3381866e21a5f30dfd88e0153de4 [file] [log] [blame]
Simon Glass31680482015-03-25 12:23:05 -06001/*
2 * Copyright (C) 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <usb.h>
10#include <asm/io.h>
11#include <dm/test.h>
Joe Hershberger3a77be52015-05-20 14:27:27 -050012#include <test/ut.h>
Simon Glass31680482015-03-25 12:23:05 -060013
14/* Test that sandbox USB works correctly */
Joe Hershberger3a77be52015-05-20 14:27:27 -050015static int dm_test_usb_base(struct unit_test_state *uts)
Simon Glass31680482015-03-25 12:23:05 -060016{
17 struct udevice *bus;
18
19 ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 0, &bus));
20 ut_assertok(uclass_get_device(UCLASS_USB, 0, &bus));
21 ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 2, &bus));
22
23 return 0;
24}
25DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
26
27/*
28 * Test that we can use the flash stick. This is more of a functional test. It
29 * covers scanning the bug, setting up a hub and a flash stick and reading
30 * data from the flash stick.
31 */
Joe Hershberger3a77be52015-05-20 14:27:27 -050032static int dm_test_usb_flash(struct unit_test_state *uts)
Simon Glass31680482015-03-25 12:23:05 -060033{
34 struct udevice *dev;
35 block_dev_desc_t *dev_desc;
36 char cmp[1024];
37
38 ut_assertok(usb_init());
39 ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev));
40 ut_assertok(get_device("usb", "0", &dev_desc));
41
42 /* Read a few blocks and look for the string we expect */
43 ut_asserteq(512, dev_desc->blksz);
44 memset(cmp, '\0', sizeof(cmp));
45 ut_asserteq(2, dev_desc->block_read(dev_desc->dev, 0, 2, cmp));
46 ut_assertok(strcmp(cmp, "this is a test"));
47
48 return 0;
49}
50DM_TEST(dm_test_usb_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);