diff options
Diffstat (limited to 'runtime/test/acphal_test.cpp')
| -rw-r--r-- | runtime/test/acphal_test.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/runtime/test/acphal_test.cpp b/runtime/test/acphal_test.cpp index 3ef8df4cd..be2c6f1e1 100644 --- a/runtime/test/acphal_test.cpp +++ b/runtime/test/acphal_test.cpp | |||
| @@ -22,6 +22,8 @@ | |||
| 22 | // Fail only the calling test thread's designated allocation. | 22 | // Fail only the calling test thread's designated allocation. |
| 23 | static thread_local int allocations_before_failure = -1; | 23 | static thread_local int allocations_before_failure = -1; |
| 24 | static std::atomic<bool> fail_worker_allocation{false}; | 24 | static std::atomic<bool> fail_worker_allocation{false}; |
| 25 | static std::atomic<bool> count_worker_allocations{false}; | ||
| 26 | static std::atomic<unsigned> worker_allocations{0}; | ||
| 25 | static DWORD test_thread_id; | 27 | static DWORD test_thread_id; |
| 26 | void* operator new(std::size_t size) { | 28 | void* operator new(std::size_t size) { |
| 27 | if (allocations_before_failure == 0) { | 29 | if (allocations_before_failure == 0) { |
| @@ -32,6 +34,9 @@ void* operator new(std::size_t size) { | |||
| 32 | fail_worker_allocation.exchange(false)) { | 34 | fail_worker_allocation.exchange(false)) { |
| 33 | throw std::bad_alloc(); | 35 | throw std::bad_alloc(); |
| 34 | } | 36 | } |
| 37 | if (count_worker_allocations.load() && GetCurrentThreadId() != test_thread_id) { | ||
| 38 | worker_allocations.fetch_add(1, std::memory_order_relaxed); | ||
| 39 | } | ||
| 35 | if (allocations_before_failure > 0) --allocations_before_failure; | 40 | if (allocations_before_failure > 0) --allocations_before_failure; |
| 36 | if (void* memory = std::malloc(size ? size : 1)) return memory; | 41 | if (void* memory = std::malloc(size ? size : 1)) return memory; |
| 37 | throw std::bad_alloc(); | 42 | throw std::bad_alloc(); |
| @@ -145,7 +150,7 @@ void write_xma_packet(uint8_t* packet, uint32_t frames, uint8_t packet_skip, | |||
| 145 | 150 | ||
| 146 | } // namespace | 151 | } // namespace |
| 147 | 152 | ||
| 148 | int main() { | 153 | int main(int argc, char** argv) { |
| 149 | std::setvbuf(stdout, nullptr, _IONBF, 0); | 154 | std::setvbuf(stdout, nullptr, _IONBF, 0); |
| 150 | test_thread_id = GetCurrentThreadId(); | 155 | test_thread_id = GetCurrentThreadId(); |
| 151 | std::printf("acphal_test: registered acphal.dll shim verification\n"); | 156 | std::printf("acphal_test: registered acphal.dll shim verification\n"); |
| @@ -186,6 +191,25 @@ int main() { | |||
| 186 | return 1; | 191 | return 1; |
| 187 | } | 192 | } |
| 188 | 193 | ||
| 194 | // Heap configuration is process-wide, so CTest exercises this mode separately. | ||
| 195 | if (argc == 2 && std::strcmp(argv[1], "--noncached-only") == 0) { | ||
| 196 | check(create_heap(0, 0x6000u) == S_OK, "Create only the non-cached APU heap"); | ||
| 197 | void* noncached = nullptr; | ||
| 198 | uint32_t noncached_address = 0; | ||
| 199 | check(alloc(&noncached, &noncached_address, 0x1000, 0x800, 2) == S_OK && noncached != nullptr, | ||
| 200 | "Allocate from the non-cached heap"); | ||
| 201 | void* cached = noncached; | ||
| 202 | uint32_t cached_address = noncached_address; | ||
| 203 | check(alloc(&cached, &cached_address, 0x1000, 0x800, 1) == E_OUTOFMEMORY && | ||
| 204 | cached == nullptr && cached_address == 0, | ||
| 205 | "A missing cached heap stays unavailable after explicit configuration"); | ||
| 206 | check(map_apu(noncached_address) == noncached && map_virtual(noncached) == noncached_address, | ||
| 207 | "A failed cached allocation leaves the non-cached mapping unchanged"); | ||
| 208 | free_mem(noncached); | ||
| 209 | std::printf("acphal_test complete: %d checks, %d failures\n", g_checks, g_failures); | ||
| 210 | return g_failures != 0; | ||
| 211 | } | ||
| 212 | |||
| 189 | // 1. AcpHalCreate | 213 | // 1. AcpHalCreate |
| 190 | void* acp = nullptr; | 214 | void* acp = nullptr; |
| 191 | check(create(&acp) == S_OK && acp != nullptr, | 215 | check(create(&acp) == S_OK && acp != nullptr, |
| @@ -500,6 +524,8 @@ int main() { | |||
| 500 | 524 | ||
| 501 | // ENABLE_XMA (cmd 5) on voice 1. | 525 | // ENABLE_XMA (cmd 5) on voice 1. |
| 502 | const uint32_t enable_arg = 1u; | 526 | const uint32_t enable_arg = 1u; |
| 527 | worker_allocations.store(0); | ||
| 528 | count_worker_allocations.store(true); | ||
| 503 | check(fn_submit(x_acp, 5, 0xf1, 0xffffffffu, &enable_arg, 0) == S_OK, | 529 | check(fn_submit(x_acp, 5, 0xf1, 0xffffffffu, &enable_arg, 0) == S_OK, |
| 504 | "ENABLE_XMA voice 1 succeeds"); | 530 | "ENABLE_XMA voice 1 succeeds"); |
| 505 | 531 | ||
| @@ -544,6 +570,11 @@ int main() { | |||
| 544 | } | 570 | } |
| 545 | check(advanced, "ADVANCE_XMA_READ succeeds"); | 571 | check(advanced, "ADVANCE_XMA_READ succeeds"); |
| 546 | check(written_blocks == 24, "Six frames write exactly 24 blocks before input exhaustion"); | 572 | check(written_blocks == 24, "Six frames write exactly 24 blocks before input exhaustion"); |
| 573 | count_worker_allocations.store(false); | ||
| 574 | const unsigned allocation_count = worker_allocations.load(); | ||
| 575 | std::printf("C++ worker allocations for six PCM frames: %u\n", allocation_count); | ||
| 576 | check(allocation_count > 0 && allocation_count < 16, | ||
| 577 | "PCM storage is reused across packets instead of allocating per sample block"); | ||
| 547 | check(((words[0] >> 20) & 3u) == 0u, "XMA input buffer valid bits cleared on exhaustion"); | 578 | check(((words[0] >> 20) & 3u) == 0u, "XMA input buffer valid bits cleared on exhaustion"); |
| 548 | check(((words[2] >> 31) & 1u) == 1u, "XMA error flag set on exhaustion"); | 579 | check(((words[2] >> 31) & 1u) == 1u, "XMA error flag set on exhaustion"); |
| 549 | check(((words[2] >> 26) & 0x1Fu) == 4u, "XMA error status is INPUT_INVALID (4)"); | 580 | check(((words[2] >> 26) & 0x1Fu) == 4u, "XMA error status is INPUT_INVALID (4)"); |
| @@ -647,9 +678,9 @@ int main() { | |||
| 647 | #endif | 678 | #endif |
| 648 | check(run_blocks(1, 3, 2, 1) == 9 && ((words[1] >> 24) & 7u) == 0, | 679 | check(run_blocks(1, 3, 2, 1) == 9 && ((words[1] >> 24) & 7u) == 0, |
| 649 | "Initial and loop subframe skips consume 3 blocks and clear the initial skip"); | 680 | "Initial and loop subframe skips consume 3 blocks and clear the initial skip"); |
| 650 | check(run_blocks(0, 2) == 8 && (words[4] >> 31) == 1u, | 681 | check(run_blocks(0, 2) == 8, |
| 651 | "A skip to the end of input 0 continues at input 1"); | 682 | "A skip to the end of input 0 continues at input 1"); |
| 652 | check(run_blocks(0, 1) == 8 && (words[4] >> 31) == 1u, | 683 | check(run_blocks(0, 1) == 8, |
| 653 | "An overshooting skip starts at packet 1 of input 1"); | 684 | "An overshooting skip starts at packet 1 of input 1"); |
| 654 | #if defined(LEONIDA_HAVE_XMA2_DECODER) | 685 | #if defined(LEONIDA_HAVE_XMA2_DECODER) |
| 655 | check(has_signal(ring_bytes) && has_signal(ring_bytes + 0x400), | 686 | check(has_signal(ring_bytes) && has_signal(ring_bytes + 0x400), |
| @@ -740,6 +771,22 @@ int main() { | |||
| 740 | check(has_signal(ring_bytes), "Rust decodes non-silent PCM after a double refill"); | 771 | check(has_signal(ring_bytes), "Rust decodes non-silent PCM after a double refill"); |
| 741 | #endif | 772 | #endif |
| 742 | 773 | ||
| 774 | check(fn_submit(x_acp, 8, 0, 0xffffffffu, &voice_bit, 0) == S_OK, | ||
| 775 | "Reset the voice before exhausting both inputs"); | ||
| 776 | write_xma_packet(packets, 1, 0); | ||
| 777 | write_xma_packet(packets + 0x800, 1, 0); | ||
| 778 | configure_voice(0, 1, 8, 0, 0); | ||
| 779 | words[1] = (words[1] & ~0xFFFu) | 1u; | ||
| 780 | check(fn_submit(x_acp, 6, 0, 0xffffffffu, &voice_bit, 0) == S_OK && wait_for_ring() && | ||
| 781 | ((words[0] >> 20) & 3u) == 0u, | ||
| 782 | "The voice exhausts input 0 and then input 1"); | ||
| 783 | write_xma_packet(packets, 2, 0); | ||
| 784 | words[0].fetch_or(3u << 20); | ||
| 785 | const uint32_t full_ring[2] = {voice_index, 8}; | ||
| 786 | check(fn_submit(x_acp, 18, 0, 0xffffffffu, full_ring, 0) == S_OK && wait_for_ring() && | ||
| 787 | ((words[0] >> 20) & 3u) == 2u, | ||
| 788 | "A double refill plays input 0 first even after exhausting input 1"); | ||
| 789 | |||
| 743 | // Reconfigure the still-enabled slot and verify that no queued PCM or old format survives. | 790 | // Reconfigure the still-enabled slot and verify that no queued PCM or old format survives. |
| 744 | bool reconfigured = true; | 791 | bool reconfigured = true; |
| 745 | for (uint32_t rate = 0; rate < 4; ++rate) { | 792 | for (uint32_t rate = 0; rate < 4; ++rate) { |