]>
Commit | Line | Data |
---|---|---|
e00cb223 SG |
1 | /* |
2 | * Copyright (C) 2015 Google, Inc | |
3 | * | |
4 | * SPDX-License-Identifier: GPL-2.0+ | |
5 | */ | |
6 | ||
7 | #include <common.h> | |
24b852a7 | 8 | #include <console.h> |
e00cb223 SG |
9 | #include <dm.h> |
10 | #include <usb.h> | |
11 | #include <asm/io.h> | |
3884c98c SG |
12 | #include <asm/state.h> |
13 | #include <dm/device-internal.h> | |
e00cb223 | 14 | #include <dm/test.h> |
e721b882 | 15 | #include <test/ut.h> |
e00cb223 SG |
16 | |
17 | /* Test that sandbox USB works correctly */ | |
e721b882 | 18 | static int dm_test_usb_base(struct unit_test_state *uts) |
e00cb223 SG |
19 | { |
20 | struct udevice *bus; | |
21 | ||
22 | ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 0, &bus)); | |
23 | ut_assertok(uclass_get_device(UCLASS_USB, 0, &bus)); | |
24 | ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 2, &bus)); | |
25 | ||
26 | return 0; | |
27 | } | |
28 | DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); | |
29 | ||
30 | /* | |
31 | * Test that we can use the flash stick. This is more of a functional test. It | |
32 | * covers scanning the bug, setting up a hub and a flash stick and reading | |
33 | * data from the flash stick. | |
34 | */ | |
e721b882 | 35 | static int dm_test_usb_flash(struct unit_test_state *uts) |
e00cb223 SG |
36 | { |
37 | struct udevice *dev; | |
38 | block_dev_desc_t *dev_desc; | |
39 | char cmp[1024]; | |
40 | ||
3884c98c | 41 | state_set_skip_delays(true); |
e00cb223 SG |
42 | ut_assertok(usb_init()); |
43 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); | |
44 | ut_assertok(get_device("usb", "0", &dev_desc)); | |
45 | ||
46 | /* Read a few blocks and look for the string we expect */ | |
47 | ut_asserteq(512, dev_desc->blksz); | |
48 | memset(cmp, '\0', sizeof(cmp)); | |
49 | ut_asserteq(2, dev_desc->block_read(dev_desc->dev, 0, 2, cmp)); | |
50 | ut_assertok(strcmp(cmp, "this is a test")); | |
51 | ||
52 | return 0; | |
53 | } | |
54 | DM_TEST(dm_test_usb_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |