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