Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .ci/test-sound.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

set -euo pipefail

# Source common functions and settings
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SCRIPT_DIR
source "${SCRIPT_DIR}/common.sh"

SAMPLE_SOUND="/usr/share/sounds/alsa/Front_Center.wav"

# Override timeout for sound tests
# Sound tests need different timeout: 30s for Linux, 900s for macOS
case "${OS_TYPE}" in
Darwin)
TIMEOUT=900
;;
Linux)
TIMEOUT=30
;;
*)
TIMEOUT=30
;;
esac

test_sound() {
ASSERT expect <<DONE
set timeout ${TIMEOUT}
spawn make check
expect "buildroot login:" { send "root\\n" } timeout { exit 1 }
expect "# " { send "uname -a\\n" } timeout { exit 2 }
expect "riscv32 GNU/Linux" { send "aplay ${SAMPLE_SOUND} --fatal-errors > /dev/null\\n" } timeout { exit 3 }
expect "# " { send "aplay -C -d 3 --fatal-errors -f S16_LE > /dev/null\\n" } timeout { exit 4 }
expect "# " { send "aplay -L\\n" }
expect "# " { }
DONE
}

# Clean up any existing semu processes before starting tests
cleanup

# Test sound device
test_sound
echo "✓ sound test passed"

ret="$?"
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Exit code is captured from echo instead of test_sound. With set -e, if test_sound fails the script exits immediately, making the error messages dead code. The exit status should be captured right after test_sound.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .ci/test-sound.sh, line 47:

<comment>Exit code is captured from `echo` instead of `test_sound`. With `set -e`, if `test_sound` fails the script exits immediately, making the error messages dead code. The exit status should be captured right after `test_sound`.</comment>

<file context>
@@ -0,0 +1,62 @@
+test_sound
+echo &quot;✓ sound test passed&quot;
+
+ret=&quot;$?&quot;
+
+MESSAGES=(&quot;OK!&quot; \
</file context>
Fix with Cubic


MESSAGES=("OK!" \
"Fail to boot" \
"Fail to login" \
"Playback fails" \
"Capture fails" \
)

if [ "$ret" -eq 0 ]; then
print_success "${MESSAGES["$ret"]}"
else
print_error "${MESSAGES["$ret"]}"
fi

exit "$ret"
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ jobs:
run: sudo .ci/test-netdev.sh
shell: bash
timeout-minutes: 10
- name: sound test
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The sound test runs unconditionally for all matrix variants, including when matrix.dependency == 'none' where no sound library is installed. This will likely cause the test to fail. Consider adding a condition similar to the install step.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/workflows/main.yml, line 72:

<comment>The sound test runs unconditionally for all matrix variants, including when `matrix.dependency == &#39;none&#39;` where no sound library is installed. This will likely cause the test to fail. Consider adding a condition similar to the install step.</comment>

<file context>
@@ -69,6 +69,10 @@ jobs:
       run: sudo .ci/test-netdev.sh
       shell: bash
       timeout-minutes: 10
+    - name: sound test
+      run: .ci/test-sound.sh
+      shell: bash
</file context>
Suggested change
- name: sound test
- name: sound test
if: matrix.dependency != 'none'
Fix with Cubic

run: .ci/test-sound.sh
shell: bash
timeout-minutes: 5

semu-macOS:
runs-on: macos-latest
Expand Down Expand Up @@ -118,6 +122,10 @@ jobs:
shell: bash
timeout-minutes: 20
if: ${{ success() }}
- name: sound test
run: .ci/test-sound.sh
shell: bash
timeout-minutes: 20

coding_style:
runs-on: ubuntu-24.04
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ A minimalist RISC-V system emulator capable of running Linux the kernel and corr
- Three types of I/O support using VirtIO standard:
- virtio-blk acquires disk image from the host.
- virtio-net is mapped as TAP interface.
- virtio-snd uses [PortAudio](https://github.com/PortAudio/portaudio) for sound playback on the host with one limitations:
- As some unknown issues in guest Linux OS (confirmed in v6.7 and v6.12), you need
to adjust the buffer size to more than four times of period size, or
the program cannot write the PCM frames into guest OS ALSA stack.
- virtio-snd uses [PortAudio](https://github.com/PortAudio/portaudio) for sound playback and capture on the host with one limitation:
- As a confirmed issue that `semu` cannot send/receive PCM frames in time, causing
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This sentence has grammatical issues that make it hard to parse. Consider restructuring to: "Due to a confirmed issue, semu cannot send/receive PCM frames in time, causing the ALSA stack to get stuck in XRUN state until you reboot semu."

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At README.md, line 16:

<comment>This sentence has grammatical issues that make it hard to parse. Consider restructuring to: &quot;Due to a confirmed issue, `semu` cannot send/receive PCM frames in time, causing the ALSA stack to get stuck in XRUN state until you reboot `semu`.&quot;</comment>

<file context>
@@ -12,12 +12,13 @@ A minimalist RISC-V system emulator capable of running Linux the kernel and corr
-          to adjust the buffer size to more than four times of period size, or
-          the program cannot write the PCM frames into guest OS ALSA stack.
+    - virtio-snd uses [PortAudio](https://github.com/PortAudio/portaudio) for sound playback and capture on the host with one limitation:
+        - As a confirmed issue that `semu` cannot send/receive PCM frames in time, causing
+          the ALSA stack will get stuck in XRUN state until you reboot `semu`.
+        - For playback, you can try to adjust the buffer size to more than four times of period size.
</file context>
Suggested change
- As a confirmed issue that `semu` cannot send/receive PCM frames in time, causing
- Due to a confirmed issue, `semu` cannot send/receive PCM frames in time, causing
Fix with Cubic

the ALSA stack will get stuck in XRUN state until you reboot `semu`.
Comment on lines +16 to +17
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Grammatical issue: The sentence structure is broken. "As a confirmed issue that... causing... will get stuck" doesn't form a proper sentence. Consider rephrasing to: "Due to a confirmed issue where semu cannot send/receive PCM frames in time, the ALSA stack may get stuck in XRUN state until you reboot semu."

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At README.md, line 16:

<comment>Grammatical issue: The sentence structure is broken. &quot;As a confirmed issue that... causing... will get stuck&quot; doesn&#39;t form a proper sentence. Consider rephrasing to: &quot;Due to a confirmed issue where `semu` cannot send/receive PCM frames in time, the ALSA stack may get stuck in XRUN state until you reboot `semu`.&quot;</comment>

<file context>
@@ -12,12 +12,13 @@ A minimalist RISC-V system emulator capable of running Linux the kernel and corr
-          to adjust the buffer size to more than four times of period size, or
-          the program cannot write the PCM frames into guest OS ALSA stack.
+    - virtio-snd uses [PortAudio](https://github.com/PortAudio/portaudio) for sound playback and capture on the host with one limitation:
+        - As a confirmed issue that `semu` cannot send/receive PCM frames in time, causing
+          the ALSA stack will get stuck in XRUN state until you reboot `semu`.
+        - For playback, you can try to adjust the buffer size to more than four times of period size.
</file context>
Suggested change
- As a confirmed issue that `semu` cannot send/receive PCM frames in time, causing
the ALSA stack will get stuck in XRUN state until you reboot `semu`.
- Due to a confirmed issue where `semu` cannot send/receive PCM frames in time,
the ALSA stack may get stuck in XRUN state until you reboot `semu`.
Fix with Cubic

- For playback, you can try to adjust the buffer size to more than four times of period size.
- For instance, the following buffer/period size settings on `aplay` has been tested
with broken and stutter effects yet complete with no any errors: `aplay --buffer-size=32768 --period-size=4096 /usr/share/sounds/alsa/Front_Center.wav`.
- For capture, ALSA usually gets stuck in XRUN state, so you may need to try multiple times.

## Prerequisites

Expand Down
Loading
Loading