diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/vb2_host_flashrom_tests.c | 54 | ||||
-rw-r--r-- | tests/vb2_host_nvdata_flashrom_tests.c | 24 |
2 files changed, 47 insertions, 31 deletions
diff --git a/tests/vb2_host_flashrom_tests.c b/tests/vb2_host_flashrom_tests.c index 8552d0ad..815657d4 100644 --- a/tests/vb2_host_flashrom_tests.c +++ b/tests/vb2_host_flashrom_tests.c @@ -145,10 +145,11 @@ int subprocess_run(const char *const argv[], static void test_read_whole_chip(void) { - uint8_t *buf; - uint32_t buf_sz; + struct firmware_image image = { + .programmer = "someprog", + }; - TEST_SUCC(flashrom_read("someprog", NULL, &buf, &buf_sz), + TEST_SUCC(flashrom_read(&image, NULL), "Flashrom read succeeds"); TEST_STR_EQ(captured_programmer, "someprog", "Using specified programmer"); @@ -158,19 +159,20 @@ static void test_read_whole_chip(void) TEST_STR_EQ(captured_op_filename, MOCK_TMPFILE_NAME, "Reading to correct file"); TEST_PTR_EQ(captured_region_param, NULL, "Not operating on a region"); - TEST_EQ(buf_sz, strlen(MOCK_ROM_CONTENTS), "Contents correct size"); - TEST_SUCC(memcmp(buf, MOCK_ROM_CONTENTS, buf_sz), + TEST_EQ(image.size, strlen(MOCK_ROM_CONTENTS), "Contents correct size"); + TEST_SUCC(memcmp(image.data, MOCK_ROM_CONTENTS, image.size), "Buffer has correct contents"); - free(buf); + free(image.data); } static void test_read_region(void) { - uint8_t *buf; - uint32_t buf_sz; + struct firmware_image image = { + .programmer = "someprog", + }; - TEST_SUCC(flashrom_read("someprog", "SOME_REGION", &buf, &buf_sz), + TEST_SUCC(flashrom_read(&image, "SOME_REGION"), "Flashrom read succeeds"); TEST_STR_EQ(captured_programmer, "someprog", "Using specified programmer"); @@ -181,20 +183,21 @@ static void test_read_region(void) "Not doing a read of the whole ROM"); TEST_STR_EQ(captured_region_param, "SOME_REGION:" MOCK_TMPFILE_NAME, "Reading to correct file and from correct region"); - TEST_EQ(buf_sz, strlen(MOCK_ROM_CONTENTS), "Contents correct size"); - TEST_SUCC(memcmp(buf, MOCK_ROM_CONTENTS, buf_sz), + TEST_EQ(image.size, strlen(MOCK_ROM_CONTENTS), "Contents correct size"); + TEST_SUCC(memcmp(image.data, MOCK_ROM_CONTENTS, image.size), "Buffer has correct contents"); - free(buf); + free(image.data); } static void test_read_failure(void) { - uint8_t *buf; - uint32_t buf_sz; + struct firmware_image image = { + .programmer = "someprog", + }; flashrom_mock_success = false; - TEST_NEQ(flashrom_read("someprog", "SOME_REGION", &buf, &buf_sz), + TEST_NEQ(flashrom_read(&image, "SOME_REGION"), VB2_SUCCESS, "Flashrom read fails"); flashrom_mock_success = true; } @@ -202,10 +205,15 @@ static void test_read_failure(void) static void test_write_whole_chip(void) { uint8_t buf[sizeof(MOCK_ROM_CONTENTS) - 1]; + struct firmware_image image = { + .programmer = "someprog", + .data = buf, + .size = sizeof(buf), + }; memcpy(buf, MOCK_ROM_CONTENTS, sizeof(buf)); - TEST_SUCC(flashrom_write("someprog", NULL, buf, sizeof(buf)), + TEST_SUCC(flashrom_write(&image, NULL), "Flashrom write succeeds"); TEST_STR_EQ(captured_programmer, "someprog", "Using specified programmer"); @@ -224,10 +232,15 @@ static void test_write_whole_chip(void) static void test_write_region(void) { uint8_t buf[sizeof(MOCK_ROM_CONTENTS) - 1]; + struct firmware_image image = { + .programmer = "someprog", + .data = buf, + .size = sizeof(buf), + }; memcpy(buf, MOCK_ROM_CONTENTS, sizeof(buf)); - TEST_SUCC(flashrom_write("someprog", "SOME_REGION", buf, sizeof(buf)), + TEST_SUCC(flashrom_write(&image, "SOME_REGION"), "Flashrom write succeeds"); TEST_STR_EQ(captured_programmer, "someprog", "Using specified programmer"); @@ -247,9 +260,14 @@ static void test_write_region(void) static void test_write_failure(void) { uint8_t buf[20] = { 0 }; + struct firmware_image image = { + .programmer = "someprog", + .data = buf, + .size = sizeof(buf), + }; flashrom_mock_success = false; - TEST_NEQ(flashrom_write("someprog", "SOME_REGION", buf, sizeof(buf)), + TEST_NEQ(flashrom_write(&image, "SOME_REGION"), VB2_SUCCESS, "Flashrom write fails"); flashrom_mock_success = true; } diff --git a/tests/vb2_host_nvdata_flashrom_tests.c b/tests/vb2_host_nvdata_flashrom_tests.c index 33b435d9..068b23a4 100644 --- a/tests/vb2_host_nvdata_flashrom_tests.c +++ b/tests/vb2_host_nvdata_flashrom_tests.c @@ -81,35 +81,33 @@ static void reset_test_data(struct vb2_context *ctx, int nvdata_size) } /* Mocked flashrom_read for tests. */ -vb2_error_t flashrom_read(const char *programmer, const char *region, - uint8_t **data_out, uint32_t *size_out) +vb2_error_t flashrom_read(struct firmware_image *image, const char *region) { if (mock_flashrom_fail) { - *data_out = NULL; - *size_out = 0; + image->data = NULL; + image->size = 0; return VB2_ERROR_FLASHROM; } - assert_mock_params(programmer, region); + assert_mock_params(image->programmer, region); - *data_out = malloc(sizeof(fake_flash_region)); - *size_out = sizeof(fake_flash_region); - memcpy(*data_out, fake_flash_region, sizeof(fake_flash_region)); + image->data = malloc(sizeof(fake_flash_region)); + image->size = sizeof(fake_flash_region); + memcpy(image->data, fake_flash_region, sizeof(fake_flash_region)); return VB2_SUCCESS; } /* Mocked flashrom_write for tests. */ -vb2_error_t flashrom_write(const char *programmer, const char *region, - uint8_t *data, uint32_t data_size) +vb2_error_t flashrom_write(struct firmware_image *image, const char *region) { if (mock_flashrom_fail) return VB2_ERROR_FLASHROM; - assert_mock_params(programmer, region); + assert_mock_params(image->programmer, region); - TEST_EQ(data_size, sizeof(fake_flash_region), + TEST_EQ(image->size, sizeof(fake_flash_region), "The flash size is correct"); - memcpy(fake_flash_region, data, data_size); + memcpy(fake_flash_region, image->data, image->size); return VB2_SUCCESS; } |