The Big Test Suite Overhaul
This replaces the make-based test runner with a set of Rust-based test
runners. I believe that all existing functionality has been
preserved. The primary objective is to dogfood the Rust test
framework.
A few main things happen here:
1) The run-pass/lib-* tests are all moved into src/test/stdtest. This
is a standalone test crate intended for all standard library tests. It
compiles to build/test/stdtest.stageN.
2) rustc now compiles into yet another build artifact, this one a test
runner that runs any tests contained directly in the rustc crate. This
allows much more fine-grained unit testing of the compiler. It
compiles to build/test/rustctest.stageN.
3) There is a new custom test runner crate at src/test/compiletest
that reproduces all the functionality for running the compile-fail,
run-fail, run-pass and bench tests while integrating with Rust's test
framework. It compiles to build/test/compiletest.stageN.
4) The build rules have been completely changed to use the new test
runners, while also being less redundant, following the example of the
recent stageN.mk rewrite.
It adds two new features to the cfail/rfail/rpass/bench tests:
1) Tests can specify multiple 'error-pattern' directives which must be
satisfied in order.
2) Tests can specify a 'compile-flags' directive which will make the
test runner provide additional command line arguments to rustc.
There are some downsides, the primary being that Rust has to be
functioning pretty well just to run _any_ tests, which I imagine will
be the source of some frustration when the entire test suite
breaks. Will also cause some headaches during porting.
Not having individual make rules, each rpass, etc test no longer
remembers between runs whether it completed successfully. As a result,
it's not possible to incrementally fix multiple tests by just running
'make check', fixing a test, and repeating without re-running all the
tests contained in the test runner. Instead you can filter just the
tests you want to run by using the TESTNAME environment variable.
This also dispenses with the ability to run stage0 tests, but they
tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
|
|
|
|
|
|
|
|
|
|
|
// -*- rust -*-
|
|
|
|
|
|
|
|
use std;
|
2011-07-08 20:52:26 -07:00
|
|
|
import std::sha1;
|
2011-08-15 16:38:23 -07:00
|
|
|
import std::vec;
|
2011-07-08 20:52:26 -07:00
|
|
|
import std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() {
|
2011-08-11 23:43:17 -07:00
|
|
|
type test = {input: str, output: [u8]};
|
2011-07-08 20:52:26 -07:00
|
|
|
|
|
|
|
fn a_million_letter_a() -> str {
|
2011-07-27 14:19:39 +02:00
|
|
|
let i = 0;
|
|
|
|
let rs = "";
|
|
|
|
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
|
2011-07-08 20:52:26 -07:00
|
|
|
ret rs;
|
|
|
|
}
|
|
|
|
// Test messages from FIPS 180-1
|
|
|
|
|
2011-08-11 23:43:17 -07:00
|
|
|
let fips_180_1_tests: [test] =
|
2011-08-19 15:16:48 -07:00
|
|
|
[{input: "abc",
|
2011-07-27 14:19:39 +02:00
|
|
|
output:
|
2011-08-19 15:16:48 -07:00
|
|
|
[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8, 0x6Au8,
|
|
|
|
0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8,
|
|
|
|
0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]},
|
2011-07-27 14:19:39 +02:00
|
|
|
{input:
|
|
|
|
"abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq",
|
|
|
|
output:
|
2011-08-19 15:16:48 -07:00
|
|
|
[0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8,
|
|
|
|
0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, 0x29u8, 0xE5u8,
|
|
|
|
0xE5u8, 0x46u8, 0x70u8, 0xF1u8]},
|
2011-07-27 14:19:39 +02:00
|
|
|
{input: a_million_letter_a(),
|
|
|
|
output:
|
2011-08-19 15:16:48 -07:00
|
|
|
[0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8, 0xC4u8, 0xDAu8, 0xA4u8,
|
|
|
|
0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8, 0x27u8, 0x31u8,
|
|
|
|
0x65u8, 0x34u8, 0x01u8, 0x6Fu8]}];
|
2011-07-08 20:52:26 -07:00
|
|
|
// Examples from wikipedia
|
|
|
|
|
2011-08-11 23:43:17 -07:00
|
|
|
let wikipedia_tests: [test] =
|
2011-08-19 15:16:48 -07:00
|
|
|
[{input: "The quick brown fox jumps over the lazy dog",
|
2011-07-27 14:19:39 +02:00
|
|
|
output:
|
2011-08-19 15:16:48 -07:00
|
|
|
[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8, 0xfcu8,
|
|
|
|
0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8, 0xe7u8, 0x39u8,
|
|
|
|
0x1bu8, 0x93u8, 0xebu8, 0x12u8]},
|
2011-07-27 14:19:39 +02:00
|
|
|
{input: "The quick brown fox jumps over the lazy cog",
|
|
|
|
output:
|
2011-08-19 15:16:48 -07:00
|
|
|
[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8, 0x3au8,
|
|
|
|
0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8,
|
|
|
|
0x10u8, 0x0du8, 0xb4u8, 0xb3u8]}];
|
2011-07-27 14:19:39 +02:00
|
|
|
let tests = fips_180_1_tests + wikipedia_tests;
|
2011-08-11 23:43:17 -07:00
|
|
|
fn check_vec_eq(v0: &[u8], v1: &[u8]) {
|
2011-08-13 00:10:18 -07:00
|
|
|
assert (vec::len::<u8>(v0) == vec::len::<u8>(v1));
|
|
|
|
let len = vec::len::<u8>(v0);
|
2011-07-27 14:19:39 +02:00
|
|
|
let i = 0u;
|
|
|
|
while i < len {
|
2011-08-19 15:16:48 -07:00
|
|
|
let a = v0[i];
|
|
|
|
let b = v1[i];
|
2011-07-08 20:52:26 -07:00
|
|
|
assert (a == b);
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Test that it works when accepting the message all at once
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
let sh = sha1::mk_sha1();
|
2011-08-15 21:54:52 -07:00
|
|
|
for t: test in tests {
|
2011-07-08 20:52:26 -07:00
|
|
|
sh.input_str(t.input);
|
2011-08-11 23:54:26 -07:00
|
|
|
let out = sh.result();
|
2011-07-08 20:52:26 -07:00
|
|
|
check_vec_eq(t.output, out);
|
|
|
|
sh.reset();
|
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
|
2011-07-08 20:52:26 -07:00
|
|
|
// Test that it works when accepting the message in pieces
|
2011-08-15 21:54:52 -07:00
|
|
|
for t: test in tests {
|
2011-07-27 14:19:39 +02:00
|
|
|
let len = str::byte_len(t.input);
|
|
|
|
let left = len;
|
|
|
|
while left > 0u {
|
|
|
|
let take = (left + 1u) / 2u;
|
2011-07-08 20:52:26 -07:00
|
|
|
sh.input_str(str::substr(t.input, len - left, take));
|
|
|
|
left = left - take;
|
|
|
|
}
|
2011-08-11 23:54:26 -07:00
|
|
|
let out = sh.result();
|
2011-07-08 20:52:26 -07:00
|
|
|
check_vec_eq(t.output, out);
|
|
|
|
sh.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|