Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use moq_audio::{Format, Layout, decode};
#[tokio::test]
async fn ts_surround_opus_decodes() {
// A 440 Hz center channel in 5.1; see `import_opus_surround_catalog` in moq-mux.
let data = include_bytes!("../../moq-mux/src/container/ts/test_data/opus_5_1.ts");
let data = include_bytes!("../../../moq-mux/src/container/ts/test_data/opus_5_1.ts");

let mut broadcast = moq_net::broadcast::Info::new().produce();
let broadcast_consumer = broadcast.consume();
Expand Down
8 changes: 8 additions & 0 deletions rs/moq-audio/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Every integration test, linked into one binary.
//!
//! Each `tests/*.rs` file is its own crate that links this package and its
//! dependencies again, so add new integration tests here as a module.

mod import;
mod playback;
mod roundtrip;
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use tokio::task::JoinHandle;

const TIMEOUT: Duration = Duration::from_secs(30);
/// About three seconds of HEVC and Opus.
const CLIP: &[u8] = include_bytes!("../../moq-mux/src/container/ts/test_data/bbb_cbr.ts");
const CLIP: &[u8] = include_bytes!("../../../moq-mux/src/container/ts/test_data/bbb_cbr.ts");
/// Five seconds of the same capture at the same rate, which leaves media to come once an export
/// has waited out the PCR-rate window and its delay (`ffmpeg -i scte35/bbb5s.ts -c copy
/// -muxrate 400000 -f mpegts bbb5s_cbr.ts`).
const LONG: &[u8] = include_bytes!("../../moq-mux/src/container/ts/test_data/bbb5s_cbr.ts");
const LONG: &[u8] = include_bytes!("../../../moq-mux/src/container/ts/test_data/bbb5s_cbr.ts");
/// Fragmented AV1, which the TS export does not carry.
const AV1: &[u8] = include_bytes!("../../moq-mux/src/container/fmp4/test_data/av1.mp4");
const AV1: &[u8] = include_bytes!("../../../moq-mux/src/container/fmp4/test_data/av1.mp4");

type Output = Arc<Mutex<Vec<u8>>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TIMEOUT: Duration = Duration::from_secs(10);
/// How long a finished import stays up: long enough for a subscriber to request its media
/// after reading the final catalog, short enough that the process exits within `TIMEOUT`.
const MAX_AGE: &str = "5s";
const BBB: &[u8] = include_bytes!("../../moq-mux/src/container/ts/test_data/scte35/bbb5s.ts");
const BBB: &[u8] = include_bytes!("../../../moq-mux/src/container/ts/test_data/scte35/bbb5s.ts");

/// Await `step` while `moq` still holds stdin open, failing as soon as the process exits.
///
Expand Down Expand Up @@ -124,7 +124,7 @@ async fn import_delivers_the_catalog_finish_at_eof() {

/// About one second of CBR HEVC and Opus: shorter than the two-second mux-rate window, so
/// the catalog is only released at EOF.
const SHORT: &[u8] = include_bytes!("../../moq-mux/src/container/ts/test_data/bbb_cbr.ts")
const SHORT: &[u8] = include_bytes!("../../../moq-mux/src/container/ts/test_data/bbb_cbr.ts")
.split_at(256 * 188)
.0;

Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions rs/moq-cli/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Every integration test, linked into one binary.
//!
//! Each `tests/*.rs` file is its own crate that links this package and its
//! dependencies again, so add new integration tests here as a module.

mod auth_serve;
mod export;
mod import;
mod listen;
Original file line number Diff line number Diff line change
@@ -1,54 +1,10 @@
//! Materializing a snapshot allocates only what the returned value owns.

use std::alloc::{GlobalAlloc, Layout, System};
use std::cell::Cell;
use std::collections::BTreeMap;

use crate::count;
use moq_json::snapshot::{Decoder, consumer};

struct Counter;

thread_local! {
// Per thread, so tests running alongside don't leak into the count.
static ALLOCATIONS: Cell<Option<usize>> = const { Cell::new(None) };
}

#[global_allocator]
static ALLOCATOR: Counter = Counter;

fn bump() {
// `try_with` because the allocator can run while the thread-local is being torn down.
let _ = ALLOCATIONS.try_with(|count| count.set(count.get().map(|n| n + 1)));
}

unsafe impl GlobalAlloc for Counter {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
bump();
unsafe { System.alloc(layout) }
}

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
bump();
unsafe { System.alloc_zeroed(layout) }
}

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
bump();
unsafe { System.realloc(ptr, layout, new_size) }
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
unsafe { System.dealloc(ptr, layout) }
}
}

fn count<R>(f: impl FnOnce() -> R) -> (R, usize) {
ALLOCATIONS.with(|count| count.set(Some(0)));
let out = f();
let allocations = ALLOCATIONS.with(|count| count.take()).unwrap();
(out, allocations)
}

#[derive(serde::Deserialize, Debug, PartialEq)]
struct Entry {
bytes: u64,
Expand Down
54 changes: 54 additions & 0 deletions rs/moq-json/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Every integration test, linked into one binary.
//!
//! Each `tests/*.rs` file is its own crate that links this package and its
//! dependencies again, so add new integration tests here as a module. Every
//! test here counts allocations, so the counting allocator is shared.

use std::alloc::{GlobalAlloc, Layout, System};
use std::cell::Cell;

mod decode_allocations;
mod window_allocations;

struct Counter;

thread_local! {
// Per thread, so tests running alongside don't leak into the count.
static ALLOCATIONS: Cell<Option<usize>> = const { Cell::new(None) };
}

#[global_allocator]
static ALLOCATOR: Counter = Counter;

fn bump() {
// `try_with` because the allocator can run while the thread-local is being torn down.
let _ = ALLOCATIONS.try_with(|count| count.set(count.get().map(|n| n + 1)));
}

unsafe impl GlobalAlloc for Counter {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
bump();
unsafe { System.alloc(layout) }
}

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
bump();
unsafe { System.alloc_zeroed(layout) }
}

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
bump();
unsafe { System.realloc(ptr, layout, new_size) }
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
unsafe { System.dealloc(ptr, layout) }
}
}

fn count<R>(f: impl FnOnce() -> R) -> (R, usize) {
ALLOCATIONS.with(|count| count.set(Some(0)));
let out = f();
let allocations = ALLOCATIONS.with(|count| count.take()).unwrap();
(out, allocations)
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,8 @@
//! Decoding a window frame allocates only what the decoded records own.

use std::alloc::{GlobalAlloc, Layout, System};
use std::cell::Cell;

use crate::count;
use moq_json::window::{ConsumerConfig, Decoder, Event};

struct Counter;

thread_local! {
// Per thread, so tests running alongside don't leak into the count.
static ALLOCATIONS: Cell<Option<usize>> = const { Cell::new(None) };
}

#[global_allocator]
static ALLOCATOR: Counter = Counter;

fn bump() {
// `try_with` because the allocator can run while the thread-local is being torn down.
let _ = ALLOCATIONS.try_with(|count| count.set(count.get().map(|n| n + 1)));
}

unsafe impl GlobalAlloc for Counter {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
bump();
unsafe { System.alloc(layout) }
}

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
bump();
unsafe { System.alloc_zeroed(layout) }
}

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
bump();
unsafe { System.realloc(ptr, layout, new_size) }
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
unsafe { System.dealloc(ptr, layout) }
}
}

fn count<R>(f: impl FnOnce() -> R) -> (R, usize) {
ALLOCATIONS.with(|count| count.set(Some(0)));
let out = f();
let allocations = ALLOCATIONS.with(|count| count.take()).unwrap();
(out, allocations)
}

#[derive(serde::Deserialize, Debug, PartialEq)]
struct Record {
bytes: u64,
Expand Down
7 changes: 7 additions & 0 deletions rs/moq-pattern/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Every integration test, linked into one binary.
//!
//! Each `tests/*.rs` file is its own crate that links this package and its
//! dependencies again, so add new integration tests here as a module.

mod pattern;
mod pattern_exhaustive;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use moq_pattern::{InvalidPattern, Pattern, Patterns, Segment};
use serde_json::Value;

fn vectors() -> Value {
serde_json::from_str(include_str!("pattern.json")).expect("pattern.json parses")
serde_json::from_str(include_str!("../pattern.json")).expect("pattern.json parses")
}

fn pattern(text: &str) -> Pattern {
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-pattern/tests/pattern.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$comment": "Golden vectors shared by rs/moq-pattern (tests/pattern.rs) and js/pattern (src/index.test.ts). Both test suites read this file, so the two implementations cannot drift apart silently.",
"$comment": "Golden vectors shared by rs/moq-pattern (tests/integration/pattern.rs) and js/pattern (src/index.test.ts). Both test suites read this file, so the two implementations cannot drift apart silently.",
"parse": [
{
"text": "",
Expand Down
Loading