From 7c933ad61b8f3f5133757c8cbaedd712e5be6f78 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 22 May 2017 17:40:54 +0200 Subject: tests/libqtest: Print error instead of aborting when env variable is missing When you currently try to run a test directly from the command line without setting the QTEST_QEMU_BINARY environment variable first, you are presented with an unhelpful assertion message like this: ERROR:tests/libqtest.c:163:qtest_init_without_qmp_handshake: assertion failed: (qemu_binary != NULL) Aborted (core dumped) Let's replace the assert() with a more user friendly error message instead. Reviewed-by: Markus Armbruster Signed-off-by: Thomas Huth Signed-off-by: Michael Tokarev --- tests/libqtest.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/libqtest.c b/tests/libqtest.c index 84ecbd2..4a5492a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -160,7 +160,10 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args) const char *qemu_binary; qemu_binary = getenv("QTEST_QEMU_BINARY"); - g_assert(qemu_binary != NULL); + if (!qemu_binary) { + fprintf(stderr, "Environment variable QTEST_QEMU_BINARY required\n"); + exit(1); + } s = g_malloc(sizeof(*s)); -- cgit v1.1 From 543f8f13e256a081dd820375e9575439b659ccd8 Mon Sep 17 00:00:00 2001 From: John Snow Date: Wed, 31 May 2017 15:28:36 -0400 Subject: ide-test: check return of fwrite To quiet patchew, add an assert for fwrite's return value. Signed-off-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Laurent Vivier Signed-off-by: Michael Tokarev --- tests/ide-test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/ide-test.c b/tests/ide-test.c index 139ebc0..bfd79dd 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -796,11 +796,13 @@ static void cdrom_pio_impl(int nblocks) int i, j; uint8_t data; uint16_t limit; + size_t ret; /* Prepopulate the CDROM with an interesting pattern */ generate_pattern(pattern, patt_len, ATAPI_BLOCK_SIZE); fh = fopen(tmp_path, "w+"); - fwrite(pattern, ATAPI_BLOCK_SIZE, patt_blocks, fh); + ret = fwrite(pattern, ATAPI_BLOCK_SIZE, patt_blocks, fh); + g_assert_cmpint(ret, ==, patt_blocks); fclose(fh); ide_test_start("-drive if=none,file=%s,media=cdrom,format=raw,id=sr0,index=0 " @@ -880,6 +882,7 @@ static void test_cdrom_pio_large(void) static void test_cdrom_dma(void) { static const size_t len = ATAPI_BLOCK_SIZE; + size_t ret; char *pattern = g_malloc(ATAPI_BLOCK_SIZE * 16); char *rx = g_malloc0(len); uintptr_t guest_buf; @@ -896,7 +899,8 @@ static void test_cdrom_dma(void) generate_pattern(pattern, ATAPI_BLOCK_SIZE * 16, ATAPI_BLOCK_SIZE); fh = fopen(tmp_path, "w+"); - fwrite(pattern, ATAPI_BLOCK_SIZE, 16, fh); + ret = fwrite(pattern, ATAPI_BLOCK_SIZE, 16, fh); + g_assert_cmpint(ret, ==, 16); fclose(fh); send_dma_request(CMD_PACKET, 0, 1, prdt, 1, send_scsi_cdb_read10); -- cgit v1.1