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

tests: ptimer: Add tests for "no counter round down" policy

PTIMER_POLICY_NO_COUNTER_ROUND_DOWN makes ptimer_get_count() return the
actual counter value and not the one less.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Message-id: 0082889309b3dc66c03c8de00b8c1ef40c1e3955.1475421224.git.digetx@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

authored by

Dmitry Osipenko and committed by
Peter Maydell
057516fe 5580ea45

+76 -41
+76 -41
tests/ptimer-test.c
··· 99 99 const uint8_t *policy = arg; 100 100 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); 101 101 ptimer_state *ptimer = ptimer_init(bh, *policy); 102 + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); 102 103 103 104 triggered = false; 104 105 ··· 108 109 109 110 qemu_clock_step(2000000 * 2 + 100000); 110 111 111 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7); 112 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); 112 113 g_assert_false(triggered); 113 114 114 115 ptimer_stop(ptimer); 115 116 116 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7); 117 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); 117 118 g_assert_false(triggered); 118 119 119 120 qemu_clock_step(2000000 * 11); 120 121 121 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7); 122 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); 122 123 g_assert_false(triggered); 123 124 124 125 ptimer_run(ptimer, 1); 125 126 126 127 qemu_clock_step(2000000 * 7 + 100000); 127 128 128 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 129 - g_assert_true(triggered); 129 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); 130 130 131 - triggered = false; 131 + if (no_round_down) { 132 + g_assert_false(triggered); 133 + } else { 134 + g_assert_true(triggered); 135 + 136 + triggered = false; 137 + } 132 138 133 139 qemu_clock_step(2000000); 134 140 135 141 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 136 - g_assert_false(triggered); 142 + 143 + if (no_round_down) { 144 + g_assert_true(triggered); 145 + 146 + triggered = false; 147 + } else { 148 + g_assert_false(triggered); 149 + } 137 150 138 151 qemu_clock_step(4000000); 139 152 ··· 158 171 159 172 qemu_clock_step(2000000 + 100000); 160 173 161 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7); 174 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7); 162 175 g_assert_false(triggered); 163 176 164 177 ptimer_set_count(ptimer, 20); 165 178 166 179 qemu_clock_step(2000000 * 19 + 100000); 167 180 168 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 181 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); 169 182 g_assert_false(triggered); 170 183 171 184 qemu_clock_step(2000000); ··· 191 204 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD); 192 205 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER); 193 206 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD); 207 + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); 194 208 195 209 triggered = false; 196 210 ··· 203 217 204 218 qemu_clock_step(100000); 205 219 206 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9); 220 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9); 207 221 g_assert_false(triggered); 208 222 209 223 qemu_clock_step(2000000 * 10 - 100000); ··· 213 227 214 228 qemu_clock_step(100000); 215 229 216 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9); 230 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 231 + wrap_policy ? 0 : (no_round_down ? 10 : 9)); 217 232 g_assert_true(triggered); 218 233 219 234 triggered = false; 220 235 221 236 qemu_clock_step(2000000); 222 237 223 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0)); 238 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 239 + (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); 224 240 g_assert_false(triggered); 225 241 226 242 ptimer_set_count(ptimer, 20); ··· 230 246 231 247 qemu_clock_step(100000); 232 248 233 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 19); 249 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 20 : 19); 234 250 g_assert_false(triggered); 235 251 236 252 qemu_clock_step(2000000 * 11 + 100000); 237 253 238 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8); 254 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 9 : 8); 239 255 g_assert_false(triggered); 240 256 241 257 qemu_clock_step(2000000 * 10); 242 258 243 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0)); 259 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 260 + (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); 244 261 g_assert_true(triggered); 245 262 246 263 triggered = false; ··· 252 269 253 270 qemu_clock_step(100000); 254 271 255 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2); 272 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2); 256 273 g_assert_false(triggered); 257 274 258 275 qemu_clock_step(2000000 * 4); 259 276 260 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0)); 277 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 278 + (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); 261 279 g_assert_true(triggered); 262 280 263 281 ptimer_stop(ptimer); ··· 265 283 266 284 qemu_clock_step(2000000); 267 285 268 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0)); 286 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 287 + (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); 269 288 g_assert_false(triggered); 270 289 271 290 ptimer_set_count(ptimer, 3); ··· 273 292 274 293 qemu_clock_step(2000000 * 3 + 100000); 275 294 276 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9); 295 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 296 + wrap_policy ? 0 : (no_round_down ? 10 : 9)); 277 297 g_assert_true(triggered); 278 298 279 299 triggered = false; 280 300 281 301 qemu_clock_step(2000000); 282 302 283 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 8 + (wrap_policy ? 1 : 0)); 303 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 304 + (no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0)); 284 305 g_assert_false(triggered); 285 306 286 307 ptimer_set_count(ptimer, 0); ··· 312 333 triggered = false; 313 334 } 314 335 315 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9); 336 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 10 : 9); 316 337 g_assert_false(triggered); 317 338 318 339 qemu_clock_step(2000000 * 12); 319 340 320 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0)); 341 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 342 + (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0)); 321 343 g_assert_true(triggered); 322 344 323 345 ptimer_stop(ptimer); ··· 326 348 327 349 qemu_clock_step(2000000 * 10); 328 350 329 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0)); 351 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 352 + (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0)); 330 353 g_assert_false(triggered); 331 354 332 355 ptimer_run(ptimer, 0); ··· 334 357 335 358 qemu_clock_step(2000000 + 100000); 336 359 337 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 7 + (wrap_policy ? 1 : 0)); 360 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 361 + (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0)); 338 362 g_assert_false(triggered); 339 363 } 340 364 ··· 344 368 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); 345 369 ptimer_state *ptimer = ptimer_init(bh, *policy); 346 370 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD); 371 + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); 347 372 348 373 triggered = false; 349 374 ··· 353 378 354 379 qemu_clock_step(2000000 * 9 + 100000); 355 380 356 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 381 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); 357 382 g_assert_false(triggered); 358 383 359 384 ptimer_run(ptimer, 0); 360 385 361 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 386 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); 362 387 g_assert_false(triggered); 363 388 364 389 qemu_clock_step(2000000); 365 390 366 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 9); 391 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 392 + wrap_policy ? 0 : (no_round_down ? 10 : 9)); 367 393 g_assert_true(triggered); 368 394 369 395 triggered = false; ··· 372 398 373 399 ptimer_run(ptimer, 1); 374 400 375 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 1 : 0); 401 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 402 + (no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0)); 376 403 g_assert_false(triggered); 377 404 378 405 qemu_clock_step(2000000 * 3); ··· 386 413 const uint8_t *policy = arg; 387 414 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); 388 415 ptimer_state *ptimer = ptimer_init(bh, *policy); 416 + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); 389 417 390 418 triggered = false; 391 419 ··· 395 423 396 424 qemu_clock_step(2000000 * 4 + 100000); 397 425 398 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3); 426 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); 399 427 g_assert_false(triggered); 400 428 401 429 ptimer_set_period(ptimer, 4000000); 402 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3); 430 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); 403 431 404 432 qemu_clock_step(4000000 * 2 + 100000); 405 433 406 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 434 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0); 407 435 g_assert_false(triggered); 408 436 409 437 qemu_clock_step(4000000 * 2); ··· 417 445 const uint8_t *policy = arg; 418 446 QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL); 419 447 ptimer_state *ptimer = ptimer_init(bh, *policy); 448 + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); 420 449 421 450 triggered = false; 422 451 ··· 426 455 427 456 qemu_clock_step(2000000 * 4 + 100000); 428 457 429 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3); 458 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); 430 459 g_assert_false(triggered); 431 460 432 461 ptimer_set_freq(ptimer, 250); 433 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3); 462 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3); 434 463 435 464 qemu_clock_step(2000000 * 4 + 100000); 436 465 437 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 466 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 2 : 0); 438 467 g_assert_false(triggered); 439 468 440 469 qemu_clock_step(2000000 * 4); ··· 468 497 bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD); 469 498 bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER); 470 499 bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD); 500 + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); 471 501 472 502 triggered = false; 473 503 ··· 489 519 qemu_clock_step(2000000 + 100000); 490 520 491 521 g_assert_cmpuint(ptimer_get_count(ptimer), ==, 492 - no_immediate_reload ? 0 : 97); 522 + no_immediate_reload ? 0 : (no_round_down ? 98 : 97)); 493 523 494 524 if (no_immediate_trigger && no_immediate_reload) { 495 525 g_assert_true(triggered); ··· 505 535 506 536 qemu_clock_step(2000000 + 100000); 507 537 508 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97); 538 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97); 509 539 g_assert_false(triggered); 510 540 511 541 qemu_clock_step(2000000 * 97); 512 542 513 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); 543 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0); 514 544 g_assert_false(triggered); 515 545 516 546 qemu_clock_step(2000000 * 2); ··· 539 569 qemu_clock_step(2000000); 540 570 } 541 571 542 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 98); 572 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 99 : 98); 543 573 544 574 if (no_immediate_reload && no_immediate_trigger) { 545 575 g_assert_true(triggered); ··· 551 581 552 582 qemu_clock_step(2000000); 553 583 554 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, 97); 584 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 98 : 97); 555 585 g_assert_false(triggered); 556 586 557 587 qemu_clock_step(2000000 * 98); 558 588 559 - g_assert_cmpuint(ptimer_get_count(ptimer), ==, wrap_policy ? 0 : 98); 589 + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 590 + wrap_policy ? 0 : (no_round_down ? 99 : 98)); 560 591 g_assert_true(triggered); 561 592 562 593 ptimer_stop(ptimer); ··· 680 711 g_strlcat(policy_name, "no_immediate_reload,", 256); 681 712 } 682 713 714 + if (policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) { 715 + g_strlcat(policy_name, "no_counter_rounddown,", 256); 716 + } 717 + 683 718 g_test_add_data_func( 684 719 g_strdup_printf("/ptimer/set_count policy=%s", policy_name), 685 720 ppolicy, check_set_count); ··· 727 762 728 763 static void add_all_ptimer_policies_comb_tests(void) 729 764 { 730 - int last_policy = PTIMER_POLICY_NO_IMMEDIATE_RELOAD; 765 + int last_policy = PTIMER_POLICY_NO_COUNTER_ROUND_DOWN; 731 766 int policy = PTIMER_POLICY_DEFAULT; 732 767 733 768 for (; policy < (last_policy << 1); policy++) {