[Refactor][CI] Reorganize test tree, and move slow e2e to weekly (#4951)

Signed-off-by: wangyu <410167048@qq.com>
This commit is contained in:
wangyu authored and GitHub committed 2026-07-29 23:53:03 +08:00
1 parent 925347332f
commit 7c17111ff5
158 files changed
+3479 -4130

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
from tests.helpers.assertions import _assert_transcript_matches
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
def test_short_transcript_repeat_passes_containment_fallback():
_assert_transcript_matches(
" How... how are you?",
audio_bytes=None,
expected_text="how are you",
threshold=0.9,
)
def test_short_transcript_unrelated_text_still_fails():
with pytest.raises(AssertionError, match="Transcript doesn't match input"):
_assert_transcript_matches(
" I don't know, sorry.",
audio_bytes=None,
expected_text="how are you",
threshold=0.9,
)
@@ -0,0 +1,157 @@
"""Functional tests for pydub removal.
Verifies that the new av/numpy/torchaudio replacements produce
identical results to the old pydub-based code for all three paths:
1. WAV PCM → duration & frame count (pure arithmetic)
2. Non-WAV (mp3/ogg) → duration & frame count (av.open)
3. TTS WER PCM export: resample to 24000Hz mono s16
"""
import base64
import io
import wave
import av
import numpy as np
import pytest
import soundfile as sf
from tests.helpers.media import _merge_base64_audio_to_segment
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
def _make_wav_bytes(sample_rate=16000, channels=1, sample_width=2, duration_sec=1.0):
"""Generate a WAV file with a sine wave, return (wav_bytes, pcm_bytes, params)."""
n_samples = int(sample_rate * duration_sec)
t = np.linspace(0, duration_sec, n_samples, endpoint=False)
samples = (np.sin(2 * np.pi * 440 * t) * 32767 * 0.5).astype(np.int16)
if channels == 2:
samples = np.column_stack([samples, samples]).flatten()
buf = io.BytesIO()
with wave.open(buf, "wb") as wf:
wf.setnchannels(channels)
wf.setsampwidth(sample_width)
wf.setframerate(sample_rate)
wf.writeframes(samples.tobytes())
wav_bytes = buf.getvalue()
# Extract raw PCM (skip WAV header)
with wave.open(io.BytesIO(wav_bytes), "rb") as wr:
pcm_bytes = wr.readframes(wr.getnframes())
params = (wr.getnchannels(), wr.getsampwidth(), wr.getframerate())
return wav_bytes, pcm_bytes, params
def _make_ogg_bytes(sample_rate=16000, channels=1, duration_sec=1.0):
"""Generate an OGG Vorbis file with a sine wave, return bytes."""
n_samples = int(sample_rate * duration_sec)
t = np.linspace(0, duration_sec, n_samples, endpoint=False)
samples = (np.sin(2 * np.pi * 440 * t) * 0.5).astype(np.float32)
buf = io.BytesIO()
sf.write(buf, samples, sample_rate, format="OGG", subtype="VORBIS")
return buf.getvalue()
def test_wav_path_duration_and_frames():
"""Path 1: WAV PCM buffer → duration & frames via arithmetic."""
for sr in [16000, 24000, 44100]:
for ch in [1, 2]:
for dur in [0.5, 1.0, 2.5]:
_, pcm_bytes, (channels, sample_width, frame_rate) = _make_wav_bytes(
sample_rate=sr, channels=ch, duration_sec=dur
)
# New code logic (from patch.py)
frame_width = sample_width * channels
audio_frames = len(pcm_bytes) // frame_width
audio_duration_sec = audio_frames / frame_rate
assert abs(audio_duration_sec - dur) < 0.001, f"sr={sr} ch={ch} dur={dur}: got {audio_duration_sec}"
expected_frames = int(sr * dur)
assert audio_frames == expected_frames, (
f"sr={sr} ch={ch} dur={dur}: frames {audio_frames} != {expected_frames}"
)
def test_non_wav_path_duration_av():
"""Path 2: non-WAV audio → duration & frames via av."""
for dur in [0.5, 1.0, 2.0]:
ogg_bytes = _make_ogg_bytes(sample_rate=16000, duration_sec=dur)
container = av.open(io.BytesIO(ogg_bytes))
stream = container.streams.audio[0]
audio_frames = sum(f.samples for f in container.decode(stream))
audio_duration_sec = audio_frames / stream.rate if stream.rate else 0.0
container.close()
# OGG encoding may add padding, allow small tolerance
assert abs(audio_duration_sec - dur) < 0.05, f"dur={dur}: got {audio_duration_sec}"
def test_tts_pcm_export_wav_path():
"""Path 3a: WAV PCM → resample to 24000Hz mono s16."""
import torch
import torchaudio
_, pcm_bytes, (channels, sample_width, frame_rate) = _make_wav_bytes(
sample_rate=16000, channels=2, sample_width=2, duration_sec=1.0
)
# New code logic
pcm_array = np.frombuffer(pcm_bytes, dtype=np.int16)
if channels > 1:
pcm_array = pcm_array.reshape(-1, channels).mean(axis=1).astype(np.int16)
if frame_rate != 24000:
t = torch.from_numpy(pcm_array.astype(np.float32)).unsqueeze(0)
t = torchaudio.functional.resample(t, frame_rate, 24000)
pcm_array = t.squeeze(0).to(torch.int16).numpy()
result_bytes = pcm_array.tobytes()
# Should be mono, 24000Hz, 2 bytes per sample
expected_samples = int(24000 * 1.0)
actual_samples = len(result_bytes) // 2
assert abs(actual_samples - expected_samples) < 10, f"expected ~{expected_samples} samples, got {actual_samples}"
assert len(pcm_array.shape) == 1, "should be mono (1D array)"
def test_tts_pcm_export_non_wav_path():
"""Path 3b: non-WAV → resample to 24000Hz mono s16 via av.AudioResampler."""
ogg_bytes = _make_ogg_bytes(sample_rate=16000, channels=1, duration_sec=1.0)
container = av.open(io.BytesIO(ogg_bytes))
resampler = av.AudioResampler(format="s16", layout="mono", rate=24000)
frames = []
for frame in container.decode(audio=0):
for rf in resampler.resample(frame):
frames.append(rf.to_ndarray().flatten())
container.close()
result = np.concatenate(frames)
result_bytes = result.tobytes()
expected_samples = int(24000 * 1.0)
actual_samples = len(result_bytes) // 2
assert abs(actual_samples - expected_samples) < 500, f"expected ~{expected_samples} samples, got {actual_samples}"
def test_media_merge_and_export():
"""media.py: _merge_base64_audio_to_segment decode + concat + export WAV."""
chunks_b64 = []
for dur in [0.5, 0.3]:
wav_bytes, _, _ = _make_wav_bytes(sample_rate=16000, channels=1, sample_width=2, duration_sec=dur)
chunks_b64.append(base64.b64encode(wav_bytes).decode())
merged = _merge_base64_audio_to_segment(chunks_b64)
# Test export to WAV
buf = io.BytesIO()
merged.export(buf, format="wav")
wav_out = buf.getvalue()
assert len(wav_out) > 44, f"WAV output too small: {len(wav_out)} bytes"
# Verify merged duration (~0.8s)
out_data, out_sr = sf.read(io.BytesIO(wav_out))
actual_dur = len(out_data) / out_sr
assert abs(actual_dur - 0.8) < 0.05, f"expected ~0.8s merged duration, got {actual_dur}"
@@ -0,0 +1,60 @@
"""Tests for OmniServerStageCli process planning helpers."""
from __future__ import annotations
from pathlib import Path
import pytest
from tests.helpers.runtime import OmniServerStageCli
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
def _write_stage_config(tmp_path: Path) -> str:
path = tmp_path / "stages.yaml"
path.write_text(
"""
stages:
- stage_id: 0
devices: "0"
- stage_id: 1
devices: "1,2,3"
num_replicas: 3
""".strip(),
encoding="utf-8",
)
return str(path)
def test_stage_cli_builds_headless_replica_cmd(tmp_path: Path) -> None:
server = OmniServerStageCli("fake-model", _write_stage_config(tmp_path), ["--disable-log-stats"])
cmd = server._build_stage_cmd(1, headless=True, replica_id=2)
assert "--headless" in cmd
assert cmd[cmd.index("--stage-id") + 1] == "1"
assert cmd[cmd.index("--replica-id") + 1] == "2"
assert cmd[cmd.index("--stage-configs-path") + 1] == server.stage_config_path
def test_stage_cli_splits_devices_per_replica(tmp_path: Path) -> None:
server = OmniServerStageCli("fake-model", _write_stage_config(tmp_path), [])
assert server._devices_for_replica(1, "1,2,3", 0) == "1"
assert server._devices_for_replica(1, "1,2,3", 1) == "2"
assert server._devices_for_replica(1, "1,2,3", 2) == "3"
def test_stage_cli_maps_visible_devices_after_replica_split(tmp_path: Path) -> None:
server = OmniServerStageCli(
"fake-model",
_write_stage_config(tmp_path),
[],
env_dict={"CUDA_VISIBLE_DEVICES": "4,5,6,7"},
)
env: dict[str, str] = {}
server._set_stage_device_env(1, env, "1,2,3", replica_id=1)
assert env["CUDA_VISIBLE_DEVICES"] == "6"