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