mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 15:33:42 +02:00
tests: Use real spi_send_command for all tests except spi25.c
At the moment one test (spi25.c) uses wrap of spi_send_command, and all other existing tests don't care about this function (don't call it at all). However in the next patch a new test in introduced, which needs a real spi_send_command. Following the approach "don't mock unless it is strictly necessary", all tests that don't care go into real function bucket. A declaration for __real_spi_send_command is needed for visibility, this way wrap function can redirect to real function for all other tests except spi25.c. Additionally, wrap function moves below mock_chip, so that mock_chip is visible inside wrap. BUG=b:181803212 TEST=builds and ninja test Change-Id: I22945cce3d0f36adaa8032167a3ef4e54eccb611 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/56753 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
parent
47f4c18260
commit
cdf8cf4afe
@ -20,22 +20,6 @@
|
|||||||
#include "chipdrivers.h"
|
#include "chipdrivers.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
int __wrap_spi_send_command(const struct flashctx *flash,
|
|
||||||
unsigned int writecnt, unsigned int readcnt,
|
|
||||||
const unsigned char *writearr, unsigned char *readarr)
|
|
||||||
{
|
|
||||||
check_expected_ptr(flash);
|
|
||||||
assert_int_equal(writecnt, mock_type(int));
|
|
||||||
assert_int_equal(writearr[0], mock_type(int));
|
|
||||||
|
|
||||||
int rcnt = mock_type(int);
|
|
||||||
assert_int_equal(readcnt, rcnt);
|
|
||||||
for (int i = 0; i < rcnt; i++)
|
|
||||||
readarr[i] = i;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct flashchip mock_chip = {
|
struct flashchip mock_chip = {
|
||||||
.vendor = "Generic",
|
.vendor = "Generic",
|
||||||
.name = "unknown SPI chip (RDID)",
|
.name = "unknown SPI chip (RDID)",
|
||||||
@ -49,6 +33,38 @@ struct flashchip mock_chip = {
|
|||||||
.write = NULL,
|
.write = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This declaration is needed for visibility, so that wrap below could
|
||||||
|
* redirect to real function.
|
||||||
|
*/
|
||||||
|
int __real_spi_send_command(const struct flashctx *flash,
|
||||||
|
unsigned int writecnt, unsigned int readcnt,
|
||||||
|
const unsigned char *writearr, unsigned char *readarr);
|
||||||
|
|
||||||
|
int __wrap_spi_send_command(const struct flashctx *flash,
|
||||||
|
unsigned int writecnt, unsigned int readcnt,
|
||||||
|
const unsigned char *writearr, unsigned char *readarr)
|
||||||
|
{
|
||||||
|
if (flash->chip != &mock_chip)
|
||||||
|
/*
|
||||||
|
* Caller is some other test, redirecting to real function.
|
||||||
|
* This test is the only one which uses wrap of spi_send_command,
|
||||||
|
* all other tests use real function.
|
||||||
|
*/
|
||||||
|
return __real_spi_send_command(flash, writecnt, readcnt, writearr, readarr);
|
||||||
|
|
||||||
|
check_expected_ptr(flash);
|
||||||
|
assert_int_equal(writecnt, mock_type(int));
|
||||||
|
assert_int_equal(writearr[0], mock_type(int));
|
||||||
|
|
||||||
|
int rcnt = mock_type(int);
|
||||||
|
assert_int_equal(readcnt, rcnt);
|
||||||
|
for (int i = 0; i < rcnt; i++)
|
||||||
|
readarr[i] = i;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void spi_write_enable_test_success(void **state)
|
void spi_write_enable_test_success(void **state)
|
||||||
{
|
{
|
||||||
(void) state; /* unused */
|
(void) state; /* unused */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user