qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qtest: Don't perform side effects inside assertion

Assertions should be separate from the side effects, since in
theory, g_assert() can be disabled (in practice, we can't really
ever do that).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>

authored by

Eric Blake and committed by
Thomas Huth
14773125 f94b3f64

+57 -23
+57 -23
qtest.c
··· 332 332 strcmp(words[0], "outl") == 0) { 333 333 unsigned long addr; 334 334 unsigned long value; 335 + int ret; 335 336 336 337 g_assert(words[1] && words[2]); 337 - g_assert(qemu_strtoul(words[1], NULL, 0, &addr) == 0); 338 - g_assert(qemu_strtoul(words[2], NULL, 0, &value) == 0); 338 + ret = qemu_strtoul(words[1], NULL, 0, &addr); 339 + g_assert(ret == 0); 340 + ret = qemu_strtoul(words[2], NULL, 0, &value); 341 + g_assert(ret == 0); 339 342 g_assert(addr <= 0xffff); 340 343 341 344 if (words[0][3] == 'b') { ··· 352 355 strcmp(words[0], "inl") == 0) { 353 356 unsigned long addr; 354 357 uint32_t value = -1U; 358 + int ret; 355 359 356 360 g_assert(words[1]); 357 - g_assert(qemu_strtoul(words[1], NULL, 0, &addr) == 0); 361 + ret = qemu_strtoul(words[1], NULL, 0, &addr); 362 + g_assert(ret == 0); 358 363 g_assert(addr <= 0xffff); 359 364 360 365 if (words[0][2] == 'b') { ··· 372 377 strcmp(words[0], "writeq") == 0) { 373 378 uint64_t addr; 374 379 uint64_t value; 380 + int ret; 375 381 376 382 g_assert(words[1] && words[2]); 377 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 378 - g_assert(qemu_strtou64(words[2], NULL, 0, &value) == 0); 383 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 384 + g_assert(ret == 0); 385 + ret = qemu_strtou64(words[2], NULL, 0, &value); 386 + g_assert(ret == 0); 379 387 380 388 if (words[0][5] == 'b') { 381 389 uint8_t data = value; ··· 401 409 strcmp(words[0], "readq") == 0) { 402 410 uint64_t addr; 403 411 uint64_t value = UINT64_C(-1); 412 + int ret; 404 413 405 414 g_assert(words[1]); 406 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 415 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 416 + g_assert(ret == 0); 407 417 408 418 if (words[0][4] == 'b') { 409 419 uint8_t data; ··· 427 437 uint64_t addr, len, i; 428 438 uint8_t *data; 429 439 char *enc; 440 + int ret; 430 441 431 442 g_assert(words[1] && words[2]); 432 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 433 - g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0); 443 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 444 + g_assert(ret == 0); 445 + ret = qemu_strtou64(words[2], NULL, 0, &len); 446 + g_assert(ret == 0); 434 447 /* We'd send garbage to libqtest if len is 0 */ 435 448 g_assert(len); 436 449 ··· 451 464 uint64_t addr, len; 452 465 uint8_t *data; 453 466 gchar *b64_data; 467 + int ret; 454 468 455 469 g_assert(words[1] && words[2]); 456 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 457 - g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0); 470 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 471 + g_assert(ret == 0); 472 + ret = qemu_strtou64(words[2], NULL, 0, &len); 473 + g_assert(ret == 0); 458 474 459 475 data = g_malloc(len); 460 476 cpu_physical_memory_read(addr, data, len); ··· 468 484 uint64_t addr, len, i; 469 485 uint8_t *data; 470 486 size_t data_len; 487 + int ret; 471 488 472 489 g_assert(words[1] && words[2] && words[3]); 473 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 474 - g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0); 490 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 491 + g_assert(ret == 0); 492 + ret = qemu_strtou64(words[2], NULL, 0, &len); 493 + g_assert(ret == 0); 475 494 476 495 data_len = strlen(words[3]); 477 496 if (data_len < 3) { ··· 497 516 uint64_t addr, len; 498 517 uint8_t *data; 499 518 unsigned long pattern; 519 + int ret; 500 520 501 521 g_assert(words[1] && words[2] && words[3]); 502 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 503 - g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0); 504 - g_assert(qemu_strtoul(words[3], NULL, 0, &pattern) == 0); 522 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 523 + g_assert(ret == 0); 524 + ret = qemu_strtou64(words[2], NULL, 0, &len); 525 + g_assert(ret == 0); 526 + ret = qemu_strtoul(words[3], NULL, 0, &pattern); 527 + g_assert(ret == 0); 505 528 506 529 if (len) { 507 530 data = g_malloc(len); ··· 517 540 uint8_t *data; 518 541 size_t data_len; 519 542 gsize out_len; 543 + int ret; 520 544 521 545 g_assert(words[1] && words[2] && words[3]); 522 - g_assert(qemu_strtou64(words[1], NULL, 0, &addr) == 0); 523 - g_assert(qemu_strtou64(words[2], NULL, 0, &len) == 0); 546 + ret = qemu_strtou64(words[1], NULL, 0, &addr); 547 + g_assert(ret == 0); 548 + ret = qemu_strtou64(words[2], NULL, 0, &len); 549 + g_assert(ret == 0); 524 550 525 551 data_len = strlen(words[3]); 526 552 if (data_len < 3) { ··· 551 577 } else if (strcmp(words[0], "rtas") == 0) { 552 578 uint64_t res, args, ret; 553 579 unsigned long nargs, nret; 580 + int rc; 554 581 555 - g_assert(qemu_strtoul(words[2], NULL, 0, &nargs) == 0); 556 - g_assert(qemu_strtou64(words[3], NULL, 0, &args) == 0); 557 - g_assert(qemu_strtoul(words[4], NULL, 0, &nret) == 0); 558 - g_assert(qemu_strtou64(words[5], NULL, 0, &ret) == 0); 582 + rc = qemu_strtoul(words[2], NULL, 0, &nargs); 583 + g_assert(rc == 0); 584 + rc = qemu_strtou64(words[3], NULL, 0, &args); 585 + g_assert(rc == 0); 586 + rc = qemu_strtoul(words[4], NULL, 0, &nret); 587 + g_assert(rc == 0); 588 + rc = qemu_strtou64(words[5], NULL, 0, &ret); 589 + g_assert(rc == 0); 559 590 res = qtest_rtas_call(words[1], nargs, args, nret, ret); 560 591 561 592 qtest_send_prefix(chr); ··· 565 596 int64_t ns; 566 597 567 598 if (words[1]) { 568 - g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) == 0); 599 + int ret = qemu_strtoi64(words[1], NULL, 0, &ns); 600 + g_assert(ret == 0); 569 601 } else { 570 602 ns = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); 571 603 } ··· 575 607 (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); 576 608 } else if (qtest_enabled() && strcmp(words[0], "clock_set") == 0) { 577 609 int64_t ns; 610 + int ret; 578 611 579 612 g_assert(words[1]); 580 - g_assert(qemu_strtoi64(words[1], NULL, 0, &ns) == 0); 613 + ret = qemu_strtoi64(words[1], NULL, 0, &ns); 614 + g_assert(ret == 0); 581 615 qtest_clock_warp(ns); 582 616 qtest_send_prefix(chr); 583 617 qtest_sendf(chr, "OK %"PRIi64"\n",