sf.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <fdtdec.h>
  8. #include <spi.h>
  9. #include <spi_flash.h>
  10. #include <asm/state.h>
  11. #include <dm/test.h>
  12. #include <dm/util.h>
  13. #include <test/ut.h>
  14. /* Test that sandbox SPI flash works correctly */
  15. static int dm_test_spi_flash(struct unit_test_state *uts)
  16. {
  17. /*
  18. * Create an empty test file and run the SPI flash tests. This is a
  19. * long way from being a unit test, but it does test SPI device and
  20. * emulator binding, probing, the SPI flash emulator including
  21. * device tree decoding, plus the file-based backing store of SPI.
  22. *
  23. * More targeted tests could be created to perform the above steps
  24. * one at a time. This might not increase test coverage much, but
  25. * it would make bugs easier to find. It's not clear whether the
  26. * benefit is worth the extra complexity.
  27. */
  28. ut_asserteq(0, run_command_list(
  29. "sb save hostfs - 0 spi.bin 200000;"
  30. "sf probe;"
  31. "sf test 0 10000", -1, 0));
  32. /*
  33. * Since we are about to destroy all devices, we must tell sandbox
  34. * to forget the emulation device
  35. */
  36. sandbox_sf_unbind_emul(state_get_current(), 0, 0);
  37. return 0;
  38. }
  39. DM_TEST(dm_test_spi_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);