usb.c 1.3 KB

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