upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/acphal_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/acphal_test.cpp')
-rw-r--r--runtime/test/acphal_test.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/runtime/test/acphal_test.cpp b/runtime/test/acphal_test.cpp
index 94ff8fa96..58bb48227 100644
--- a/runtime/test/acphal_test.cpp
+++ b/runtime/test/acphal_test.cpp
@@ -467,8 +467,9 @@ int main() {
467 // 8b. Loops are rounded to whole packets: the loop end packet plays in full and the read 467 // 8b. Loops are rounded to whole packets: the loop end packet plays in full and the read
468 // restarts at the packet holding the loop start. One 1-frame packet = 512 samples = 4 blocks. 468 // restarts at the packet holding the loop start. One 1-frame packet = 512 samples = 4 blocks.
469 { 469 {
470 // Two packets with one silent mono frame each. 470 // Three packets with one silent mono frame each. Packet 0 skips packet 1,
471 std::vector<uint8_t> stream(2 * 2048, 0xFFu); 471 // which belongs to another stream.
472 std::vector<uint8_t> stream(3 * 2048, 0xFFu);
472 auto put_bits = [&](size_t at, uint32_t value, size_t width) { 473 auto put_bits = [&](size_t at, uint32_t value, size_t width) {
473 for (size_t i = 0; i < width; ++i) { 474 for (size_t i = 0; i < width; ++i) {
474 const size_t p = at + i; 475 const size_t p = at + i;
@@ -478,9 +479,9 @@ int main() {
478 (bit << (7 - (p % 8)))); 479 (bit << (7 - (p % 8))));
479 } 480 }
480 }; 481 };
481 for (size_t packet = 0; packet < 2; ++packet) { 482 for (size_t packet = 0; packet < 3; ++packet) {
482 const size_t base = packet * 2048 * 8; 483 const size_t base = packet * 2048 * 8;
483 put_bits(base, 1u << 26, 32); // 1 frame, first_frame_bit = 0 484 put_bits(base, (1u << 26) | (packet == 0 ? 1u : 0u), 32);
484 const size_t at = base + 32; 485 const size_t at = base + 32;
485 put_bits(at, 31, 15); // frame length 486 put_bits(at, 31, 15); // frame length
486 put_bits(at + 15, 0b10u, 2); // fixed layout, one 512-sample subframe 487 put_bits(at + 15, 0b10u, 2); // fixed layout, one 512-sample subframe
@@ -494,8 +495,8 @@ int main() {
494 495
495 void* in_va = nullptr; 496 void* in_va = nullptr;
496 uint32_t in_apu = 0; 497 uint32_t in_apu = 0;
497 check(alloc(&in_va, &in_apu, 0x1000, 0x800, 1) == S_OK && in_va != nullptr, 498 check(alloc(&in_va, &in_apu, 0x1800, 0x800, 1) == S_OK && in_va != nullptr,
498 "ApuAlloc 2-packet loop input buffer"); 499 "ApuAlloc 3-packet loop input buffer");
499 std::memcpy(in_va, stream.data(), stream.size()); 500 std::memcpy(in_va, stream.data(), stream.size());
500 501
501 void* out_va = nullptr; 502 void* out_va = nullptr;
@@ -520,14 +521,16 @@ int main() {
520 521
521 // Decodes the stream once on voice 2 with the given loop count and returns the number of 522 // Decodes the stream once on voice 2 with the given loop count and returns the number of
522 // blocks written when the error flag rose, or -1 on timeout. 523 // blocks written when the error flag rose, or -1 on timeout.
523 auto run_blocks = [&](uint32_t loops) -> int { 524 auto run_blocks = [&](uint32_t loops, bool split_inputs = false) -> int {
524 std::memset(out_va, 0x55, 0x1000); 525 std::memset(out_va, 0x55, 0x1000);
525 words[0] = 2u | (loops << 12) | (1u << 20) | (16u << 22); 526 words[0] = (split_inputs ? 2u : 3u) | (loops << 12) |
526 words[1] = (1u << 31) | (3u << 27); // 48 kHz, mono, writable 527 ((split_inputs ? 3u : 1u) << 20) | (16u << 22);
528 words[1] = (1u << 31) | (3u << 27) | (split_inputs ? 1u : 0u);
527 words[2] = 32u; // read at packet 0 529 words[2] = 32u; // read at packet 0
528 words[3] = 32u; // loop start: packet 0 530 words[3] = 32u; // loop start: packet 0
529 words[4] = 100u; // loop end: packet 0 531 words[4] = 100u; // loop end: packet 0
530 words[5] = in_apu; 532 words[5] = in_apu;
533 words[6] = in_apu + 0x1000u;
531 words[7] = out_apu; 534 words[7] = out_apu;
532 words[9] = 0u; 535 words[9] = 0u;
533 536
@@ -547,9 +550,17 @@ int main() {
547 return blocks; 550 return blocks;
548 }; 551 };
549 552
550 check(run_blocks(0) == 8, "Two 1-frame packets without a loop write 8 blocks (1024 samples)"); 553 check(run_blocks(0) == 8, "Packets 0 and 2 write 8 blocks, skipping packet 1");
551 check(run_blocks(1) == 12, "One loop of packet 0 writes 12 blocks (packets 0, 0, 1)"); 554 check(run_blocks(1) == 12, "One loop of packet 0 writes 12 blocks (packets 0, 0, 2)");
552 check(((words[0] >> 12) & 0xFFu) == 0u, "Loop count is consumed by the single loop"); 555 check(((words[0] >> 12) & 0xFFu) == 0u, "Loop count is consumed by the single loop");
556 check(run_blocks(0, true) == 8 && (words[4] >> 31) == 1u,
557 "A skip to the end of input 0 continues at input 1");
558
559 words[0] = 3u << 22; // three ring blocks
560 words[9] = 2u;
561 const uint32_t advance_args[2] = {2u, UINT32_MAX};
562 check(fn_submit(x_acp, 18, 0xf5, 0xffffffffu, advance_args, 0) == S_OK && words[9] == 2u,
563 "ADVANCE_XMA_READ wraps at the ring size without overflowing");
553 564
554 check(fn_release(x_acp) == S_OK, "Release packet loop AcpHal succeeds"); 565 check(fn_release(x_acp) == S_OK, "Release packet loop AcpHal succeeds");
555 free_mem(in_va); 566 free_mem(in_va);
@@ -557,8 +568,7 @@ int main() {
557 check(release_ctx(&xma_ctx) == S_OK, "Release packet loop SHAPE contexts"); 568 check(release_ctx(&xma_ctx) == S_OK, "Release packet loop SHAPE contexts");
558 } 569 }
559 570
560 // 9. ENABLE_XMA (starts/wakes the decoder worker) racing bind/release (stops it). 571 // 9. ENABLE_XMA racing SHAPE allocation and release, including concurrent releases.
561 // Every release must return; a lost stop would hang this block.
562 { 572 {
563 using RaceConnectFn = HRESULT(__stdcall*)(void*, uint32_t, uint32_t); 573 using RaceConnectFn = HRESULT(__stdcall*)(void*, uint32_t, uint32_t);
564 using RaceSubmitFn = HRESULT(__stdcall*)(void*, uint32_t, uint64_t, uint32_t, const void*, uint32_t); 574 using RaceSubmitFn = HRESULT(__stdcall*)(void*, uint32_t, uint64_t, uint32_t, const void*, uint32_t);
@@ -581,6 +591,11 @@ int main() {
581 &enable_arg, 0); 591 &enable_arg, 0);
582 } 592 }
583 }); 593 });
594 std::thread releaser([&]() {
595 for (int i = 0; i < kRaceIterations; ++i) {
596 if (release_ctx(nullptr) != S_OK) ++bind_failures;
597 }
598 });
584 for (int i = 0; i < kRaceIterations; ++i) { 599 for (int i = 0; i < kRaceIterations; ++i) {
585 TestShapeContexts race_ctx{}; 600 TestShapeContexts race_ctx{};
586 race_ctx.numXmaContexts = 4; 601 race_ctx.numXmaContexts = 4;
@@ -588,7 +603,8 @@ int main() {
588 if (release_ctx(&race_ctx) != S_OK) ++bind_failures; 603 if (release_ctx(&race_ctx) != S_OK) ++bind_failures;
589 } 604 }
590 enabler.join(); 605 enabler.join();
591 check(bind_failures == 0, "20000 bind/release cycles race ENABLE_XMA without hanging"); 606 releaser.join();
607 check(bind_failures == 0, "20000 bind/release cycles race ENABLE_XMA and independent releases");
592 check(race_release(race_acp) == S_OK, "Release race AcpHal succeeds"); 608 check(race_release(race_acp) == S_OK, "Release race AcpHal succeeds");
593 } 609 }
594 610