blob: 4300bbd5c921c2b6e4bd248cb9fc670c8a0a4ddf [file] [log] [blame]
Simon Glasse00cb222015-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>
Simon Glass3884c982015-11-08 23:47:44 -070011#include <asm/state.h>
12#include <dm/device-internal.h>
Simon Glasse00cb222015-03-25 12:23:05 -060013#include <dm/test.h>
Joe Hershbergere721b882015-05-20 14:27:27 -050014#include <test/ut.h>
Simon Glasse00cb222015-03-25 12:23:05 -060015
16/* Test that sandbox USB works correctly */
Joe Hershbergere721b882015-05-20 14:27:27 -050017static int dm_test_usb_base(struct unit_test_state *uts)
Simon Glasse00cb222015-03-25 12:23:05 -060018{
19 struct udevice *bus;
20
21 ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 0, &bus));
22 ut_assertok(uclass_get_device(UCLASS_USB, 0, &bus));
23 ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 2, &bus));
24
25 return 0;
26}
27DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
28
29/*
30 * Test that we can use the flash stick. This is more of a functional test. It
31 * covers scanning the bug, setting up a hub and a flash stick and reading
32 * data from the flash stick.
33 */
Joe Hershbergere721b882015-05-20 14:27:27 -050034static int dm_test_usb_flash(struct unit_test_state *uts)
Simon Glasse00cb222015-03-25 12:23:05 -060035{
36 struct udevice *dev;
37 block_dev_desc_t *dev_desc;
38 char cmp[1024];
39
Simon Glass3884c982015-11-08 23:47:44 -070040 state_set_skip_delays(true);
Simon Glasse00cb222015-03-25 12:23:05 -060041 ut_assertok(usb_init());
42 ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev));
43 ut_assertok(get_device("usb", "0", &dev_desc));
44
45 /* Read a few blocks and look for the string we expect */
46 ut_asserteq(512, dev_desc->blksz);
47 memset(cmp, '\0', sizeof(cmp));
48 ut_asserteq(2, dev_desc->block_read(dev_desc->dev, 0, 2, cmp));
49 ut_assertok(strcmp(cmp, "this is a test"));
50
51 return 0;
52}
53DM_TEST(dm_test_usb_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);