1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 07:02:34 +02:00
flashrom/tests/spi25.c
Edward O'Callaghan 00635b0da2 Revert "libflashrom: Return progress state to the library user"
This reverts commit 40892b0c08fbc8029921e91511dd3f91fc956f90.

The feature of returning progress for libflashrom users was
introduced in original commit, however later a bug was found and
reported as https://ticket.coreboot.org/issues/390.

Reverting in a release branch to unblock release candidate, since
it is unknown how much time needed to fix the bug. Meanwhile the
feature remains in a master branch and will be fixed under
ticket 390.

TEST=scenarios below run successfully
1) flashrom -h does not show --progress
2) flashrom -p dummy:emulate=W25Q128FV -r /tmp/dump.bin
3) flashrom -p dummy:emulate=W25Q128FV -v /tmp/dump.bin
4) flashrom -p dummy:emulate=W25Q128FV -E
5) head -c 16777216 </dev/urandom >/tmp/image.bin
flashrom -p dummy:image=/tmp/image.bin,emulate=W25Q128FV \
	 -w /tmp/dump.bin

Change-Id: Id3d7ffcaf266a60a44eb453fd09b7c63c05349c2
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69283
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-11-10 17:23:07 +00:00

224 lines
6.6 KiB
C

/*
* This file is part of the flashrom project.
*
* Copyright 2020 Google LLC
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <include/test.h>
#include "wraps.h"
#include "tests.h"
#include "programmer.h"
#include "flashchips.h"
#include "chipdrivers.h"
#include "spi.h"
struct flashchip mock_chip = {
.vendor = "Generic",
.name = "unknown SPI chip (RDID)",
.bustype = BUS_SPI,
.manufacture_id = GENERIC_MANUF_ID,
.model_id = GENERIC_DEVICE_ID,
.total_size = 0,
.page_size = 256,
.tested = TEST_BAD_PREW,
.probe = PROBE_SPI_RDID,
.write = NO_WRITE_FUNC,
};
/*
* 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) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_WREN_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_WREN);
will_return(__wrap_spi_send_command, JEDEC_WREN_INSIZE);
assert_int_equal(0, spi_write_enable(&flashctx));
}
void spi_write_disable_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_WRDI_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_WRDI);
will_return(__wrap_spi_send_command, JEDEC_WRDI_INSIZE);
assert_int_equal(0, spi_write_disable(&flashctx));
}
void probe_spi_rdid_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_RDID_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_RDID);
will_return(__wrap_spi_send_command, JEDEC_RDID_INSIZE);
assert_int_equal(0, probe_spi_rdid(&flashctx));
}
void probe_spi_rdid4_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_RDID_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_RDID);
will_return(__wrap_spi_send_command, JEDEC_RDID_INSIZE + 1);
assert_int_equal(0, probe_spi_rdid4(&flashctx));
}
void probe_spi_rems_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_REMS_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_REMS);
will_return(__wrap_spi_send_command, JEDEC_REMS_INSIZE);
assert_int_equal(0, probe_spi_rems(&flashctx));
}
void probe_spi_res1_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_RES_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_RES);
will_return(__wrap_spi_send_command, JEDEC_RES_INSIZE + 1);
assert_int_equal(0, probe_spi_res2(&flashctx));
}
void probe_spi_res2_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
clear_spi_id_cache();
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_RES_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_RES);
will_return(__wrap_spi_send_command, JEDEC_RES_INSIZE + 1);
assert_int_equal(0, probe_spi_res2(&flashctx));
}
void probe_spi_res3_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, JEDEC_RES_OUTSIZE);
will_return(__wrap_spi_send_command, JEDEC_RES);
will_return(__wrap_spi_send_command, JEDEC_RES_INSIZE + 2);
assert_int_equal(0, probe_spi_res3(&flashctx));
}
void probe_spi_at25f_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
will_return(__wrap_spi_send_command, AT25F_RDID_OUTSIZE);
will_return(__wrap_spi_send_command, AT25F_RDID);
will_return(__wrap_spi_send_command, AT25F_RDID_INSIZE);
assert_int_equal(0, probe_spi_at25f(&flashctx));
}
/* spi95.c */
void probe_spi_st95_test_success(void **state)
{
(void) state; /* unused */
/* setup initial test state. */
struct flashctx flashctx = { .chip = &mock_chip };
expect_memory(__wrap_spi_send_command, flash,
&flashctx, sizeof(flashctx));
/* chip total size < 64K. */
uint32_t rdid_outsize = ST_M95_RDID_2BA_OUTSIZE; // 16 bit address
will_return(__wrap_spi_send_command, rdid_outsize);
will_return(__wrap_spi_send_command, ST_M95_RDID);
will_return(__wrap_spi_send_command, ST_M95_RDID_INSIZE);
assert_int_equal(0, probe_spi_st95(&flashctx));
}