Skip to content

Commit

Permalink
Add a werk_test crate to contain test binaries for the opus testsuite
Browse files Browse the repository at this point in the history
This works like this:

* build.rs of the werk crate compiles libopus into a static library
* build.rs of the werk_test crate compiles the test programs into static
  libraries, each with still unresolved dependencies to libopus
* werk_test contains a binary for each test binary. Each binary has:
  * #![no_main] in order to not create any rust based main machinery
  * #[link(name="...", kind="static")] extern {} in order to use the
    main provided by the C test executable
  * extern crate werk test; in order to get libopus linked

The proposed process is as following:

* Piece by piece we port over libopus from C to Rust, into the werk crate.
* The API gets retained, so usable by the test code
* The test code gets rewritten in Rust.
* The API gets rustified component per component
* All while never really breaking the testsuite. If it gets broken, we
  immediately know which part of the rewrite to blame.

Of course while there is dependence between these steps, they can be
mixed to some degree.
  • Loading branch information
est31 committed Jul 11, 2017
1 parent 7dd5c6f commit 713e22a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
@@ -1,2 +1,5 @@
[workspace]
members = ["werk"]
members = [
"werk",
"werk_test",
]
11 changes: 11 additions & 0 deletions werk_test/Cargo.toml
@@ -0,0 +1,11 @@
[package]
name = "werk_test"
version = "0.1.0"
authors = ["est31 <MTest31@outlook.com>", "The opus project developers"]
license = "BSD-3-Clause"

[dependencies]
werk = { path = "../werk" }

[build-dependencies]
gcc = "0.3"
57 changes: 57 additions & 0 deletions werk_test/build.rs
@@ -0,0 +1,57 @@
// Werk - a pure Rust opus library
//
// Copyright (c) 2001-2011 the opus developers, and
// Copyright (c) 2017 est31 <MTest31@outlook.com>
// and contributors, All rights reserved.
// Licensed under the BSD 3 clause license.
// Please see the COPYING file attached to
// this source distribution for details.

extern crate gcc;

use gcc::Config;

macro_rules! test_program {
($name:ident; $($($pathseg:ident)/ *.c),*; $libname:expr) => {
fn $name() {
let mut cfg = Config::new();
cfg
.include("../libopus/include")
.include("../libopus/celt")
.include("../libopus/silk")
.include("../libopus/silk/fixed")
.include("../libopus/silk/float")
// Note in configure.ac there are a bunch of such variables defined,
// each with AC_DEFINE.
// But these two are the required ones
.define("OPUS_BUILD", None)
.define("USE_ALLOCA", None);
// Always optimize, this is no fun otherwise
cfg.opt_level(3);
cfg $(.file(concat!("../libopus/",
$("/", stringify!($pathseg)),*,
".c"
)))*;
cfg.compile($libname);
}
}
}

test_program! { compile_test_opus_decode;
tests/test_opus_decode.c;
"libopus_decode.a"
}

test_program! { compile_test_opus_encode;
tests/test_opus_encode.c,
tests/opus_encode_regressions.c;
"libopus_encode.a"
}

// TODO: add other tests


fn main() {
compile_test_opus_decode();
compile_test_opus_encode();
}
15 changes: 15 additions & 0 deletions werk_test/src/bin/test_opus_decode.rs
@@ -0,0 +1,15 @@
// Werk - a pure Rust opus library
//
// Copyright (c) 2001-2011 the opus developers, and
// Copyright (c) 2017 est31 <MTest31@outlook.com>
// and contributors, All rights reserved.
// Licensed under the BSD 3 clause license.
// Please see the COPYING file attached to
// this source distribution for details.

#![no_main]

extern crate werk_test;

#[link(name="opus_decode", kind="static")]
extern {}
15 changes: 15 additions & 0 deletions werk_test/src/bin/test_opus_encode.rs
@@ -0,0 +1,15 @@
// Werk - a pure Rust opus library
//
// Copyright (c) 2001-2011 the opus developers, and
// Copyright (c) 2017 est31 <MTest31@outlook.com>
// and contributors, All rights reserved.
// Licensed under the BSD 3 clause license.
// Please see the COPYING file attached to
// this source distribution for details.

#![no_main]

extern crate werk_test;

#[link(name="opus_encode", kind="static")]
extern {}
10 changes: 10 additions & 0 deletions werk_test/src/lib.rs
@@ -0,0 +1,10 @@
// Werk - a pure Rust opus library
//
// Copyright (c) 2001-2011 the opus developers, and
// Copyright (c) 2017 est31 <MTest31@outlook.com>
// and contributors, All rights reserved.
// Licensed under the BSD 3 clause license.
// Please see the COPYING file attached to
// this source distribution for details.

extern crate werk;

0 comments on commit 713e22a

Please sign in to comment.