mmc.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 <mmc.h>
  9. #include <dm/test.h>
  10. #include <test/ut.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. /*
  13. * Basic test of the mmc uclass. We could expand this by implementing an MMC
  14. * stack for sandbox, or at least implementing the basic operation.
  15. */
  16. static int dm_test_mmc_base(struct unit_test_state *uts)
  17. {
  18. struct udevice *dev;
  19. ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
  20. return 0;
  21. }
  22. DM_TEST(dm_test_mmc_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  23. static int dm_test_mmc_blk(struct unit_test_state *uts)
  24. {
  25. struct udevice *dev;
  26. struct blk_desc *dev_desc;
  27. char cmp[1024];
  28. ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
  29. ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
  30. /* Read a few blocks and look for the string we expect */
  31. ut_asserteq(512, dev_desc->blksz);
  32. memset(cmp, '\0', sizeof(cmp));
  33. ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp));
  34. ut_assertok(strcmp(cmp, "this is a test"));
  35. return 0;
  36. }
  37. DM_TEST(dm_test_mmc_blk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);