Skip to content

Commit

Permalink
auto merge of #12457 : alexcrichton/rust/fix-some-tests, r=brson
Browse files Browse the repository at this point in the history
This updates a number of ignore-test tests, and removes a few completely
outdated tests due to the feature being tested no longer being supported.

This brings a number of bench/shootout tests up to date so they're compiling
again. I make no claims to the performance of these benchmarks, it's just nice
to not have bitrotted code.

Closes #2604
Closes #9407
  • Loading branch information
bors committed Feb 25, 2014
2 parents fd83b2b + 9cc26cf commit fc1c06d
Show file tree
Hide file tree
Showing 54 changed files with 304 additions and 1,317 deletions.
2 changes: 0 additions & 2 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,6 @@ mod test {
});
}

// FIXME: #9407: ignore-test
#[ignore]
#[test]
fn dont_starve_1() {
let mut pool = SchedPool::new(PoolConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/private_variant_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

mod super_sekrit {
pub enum sooper_sekrit {
pub quux, priv baz
quux, priv baz
}
}
111 changes: 51 additions & 60 deletions src/test/bench/shootout-fannkuch-redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-test reading from os::args()[1] - bogus!

use std::from_str::FromStr;
use std::os;
use std::vec::MutableVector;
use std::vec;

fn max(a: i32, b: i32) -> i32 {
Expand All @@ -23,7 +19,6 @@ fn max(a: i32, b: i32) -> i32 {
}
}

#[inline(never)]
fn fannkuch_redux(n: i32) -> i32 {
let mut perm = vec::from_elem(n as uint, 0i32);
let mut perm1 = vec::from_fn(n as uint, |i| i as i32);
Expand All @@ -34,74 +29,70 @@ fn fannkuch_redux(n: i32) -> i32 {

let mut r = n;
loop {
unsafe {
while r != 1 {
count.unsafe_set((r-1) as uint, r);
r -= 1;
}

for (perm_i, perm1_i) in perm.mut_iter().zip(perm1.iter()) {
*perm_i = *perm1_i;
}
while r != 1 {
count[r - 1] = r;
r -= 1;
}

let mut flips_count: i32 = 0;
let mut k: i32;
loop {
k = *perm.unsafe_ref(0);
if k == 0 {
break;
}
for (perm_i, perm1_i) in perm.mut_iter().zip(perm1.iter()) {
*perm_i = *perm1_i;
}

let k2 = (k+1) >> 1;
for i in range(0i32, k2) {
let (perm_i, perm_k_i) = {
(*perm.unsafe_ref(i as uint),
*perm.unsafe_ref((k-i) as uint))
};
perm.unsafe_set(i as uint, perm_k_i);
perm.unsafe_set((k-i) as uint, perm_i);
}
flips_count += 1;
let mut flips_count: i32 = 0;
let mut k: i32;
loop {
k = perm[0];
if k == 0 {
break;
}

max_flips_count = max(max_flips_count, flips_count);
checksum += if perm_count % 2 == 0 {
flips_count
} else {
-flips_count
};
let k2 = (k+1) >> 1;
for i in range(0i32, k2) {
perm.swap(i as uint, (k - i) as uint);
}
flips_count += 1;
}

// Use incremental change to generate another permutation.
loop {
if r == n {
println!("{}", checksum);
return max_flips_count;
}
max_flips_count = max(max_flips_count, flips_count);
checksum += if perm_count % 2 == 0 {
flips_count
} else {
-flips_count
};

let perm0 = perm1[0];
let mut i: i32 = 0;
while i < r {
let j = i + 1;
let perm1_j = { *perm1.unsafe_ref(j as uint) };
perm1.unsafe_set(i as uint, perm1_j);
i = j;
}
perm1.unsafe_set(r as uint, perm0);
// Use incremental change to generate another permutation.
loop {
if r == n {
println!("{}", checksum);
return max_flips_count;
}

let count_r = { *count.unsafe_ref(r as uint) };
count.unsafe_set(r as uint, count_r - 1);
if *count.unsafe_ref(r as uint) > 0 {
break;
}
r += 1;
let perm0 = perm1[0];
let mut i: i32 = 0;
while i < r {
let j = i + 1;
perm1[i] = perm1[j];
i = j;
}
perm1[r] = perm0;

perm_count += 1;
count[r] -= 1;
if count[r] > 0 {
break;
}
r += 1;
}

perm_count += 1;
}
}

fn main() {
let n: i32 = FromStr::from_str(os::args()[1]).unwrap();
let args = os::args();
let n = if args.len() > 1 {
from_str::<i32>(args[1]).unwrap()
} else {
2
};
println!("Pfannkuchen({}) = {}", n as int, fannkuch_redux(n) as int);
}
180 changes: 83 additions & 97 deletions src/test/bench/shootout-fasta-redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-test reading from os::args()[1] - bogus!

use std::cast::transmute;
use std::from_str::FromStr;
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
use std::cmp::min;
use std::io::{stdout, BufferedWriter, IoResult};
use std::os;
use std::uint::min;
use std::vec::bytes::copy_memory;
use std::vec;

Expand All @@ -37,10 +33,6 @@ static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\

static NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 };

static MESSAGE_1: &'static str = ">ONE Homo sapiens alu\n";
static MESSAGE_2: &'static str = ">TWO IUB ambiguity codes\n";
static MESSAGE_3: &'static str = ">THREE Homo sapiens frequency\n";

static IUB: [AminoAcid, ..15] = [
AminoAcid { c: 'a' as u8, p: 0.27 },
AminoAcid { c: 'c' as u8, p: 0.12 },
Expand Down Expand Up @@ -85,73 +77,68 @@ struct AminoAcid {
p: f32,
}

struct RepeatFasta {
struct RepeatFasta<'a, W> {
alu: &'static str,
stdout: *FILE,
out: &'a mut W
}

impl RepeatFasta {
fn new(stdout: *FILE, alu: &'static str) -> RepeatFasta {
RepeatFasta {
alu: alu,
stdout: stdout,
}
impl<'a, W: Writer> RepeatFasta<'a, W> {
fn new(alu: &'static str, w: &'a mut W) -> RepeatFasta<'a, W> {
RepeatFasta { alu: alu, out: w }
}

fn make(&mut self, n: uint) {
unsafe {
let stdout = self.stdout;
let alu_len = self.alu.len();
let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8);
let alu: &[u8] = self.alu.as_bytes();

copy_memory(buf, alu);
let buf_len = buf.len();
copy_memory(buf.mut_slice(alu_len, buf_len),
alu.slice_to(LINE_LEN));

let mut pos = 0;
let mut bytes;
let mut n = n;
while n > 0 {
bytes = min(LINE_LEN, n);
fwrite(transmute(&buf[pos]), bytes as size_t, 1, stdout);
fputc('\n' as c_int, stdout);
pos += bytes;
if pos > alu_len {
pos -= alu_len;
}
n -= bytes;
fn make(&mut self, n: uint) -> IoResult<()> {
let alu_len = self.alu.len();
let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8);
let alu: &[u8] = self.alu.as_bytes();

copy_memory(buf, alu);
let buf_len = buf.len();
copy_memory(buf.mut_slice(alu_len, buf_len),
alu.slice_to(LINE_LEN));

let mut pos = 0;
let mut bytes;
let mut n = n;
while n > 0 {
bytes = min(LINE_LEN, n);
try!(self.out.write(buf.slice(pos, pos + bytes)));
try!(self.out.write_u8('\n' as u8));
pos += bytes;
if pos > alu_len {
pos -= alu_len;
}
n -= bytes;
}
Ok(())
}
}

struct RandomFasta {
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
let mut j = 0;
for (i, slot) in lookup.mut_iter().enumerate() {
while a[j].p < (i as f32) {
j += 1;
}
*slot = a[j];
}
lookup
}

struct RandomFasta<'a, W> {
seed: u32,
stdout: *FILE,
lookup: [AminoAcid, ..LOOKUP_SIZE],
out: &'a mut W,
}

impl RandomFasta {
fn new(stdout: *FILE, a: &[AminoAcid]) -> RandomFasta {
impl<'a, W: Writer> RandomFasta<'a, W> {
fn new(w: &'a mut W, a: &[AminoAcid]) -> RandomFasta<'a, W> {
RandomFasta {
seed: 42,
stdout: stdout,
lookup: RandomFasta::make_lookup(a),
}
}

fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
let mut j = 0;
for (i, slot) in lookup.mut_iter().enumerate() {
while a[j].p < (i as f32) {
j += 1;
}
*slot = a[j];
out: w,
lookup: make_lookup(a),
}
lookup
}

fn rng(&mut self, max: f32) -> f32 {
Expand All @@ -169,51 +156,50 @@ impl RandomFasta {
0
}

fn make(&mut self, n: uint) {
unsafe {
let lines = n / LINE_LEN;
let chars_left = n % LINE_LEN;
let mut buf = [0, ..LINE_LEN + 1];

for _ in range(0, lines) {
for i in range(0u, LINE_LEN) {
buf[i] = self.nextc();
}
buf[LINE_LEN] = '\n' as u8;
fwrite(transmute(&buf[0]),
LINE_LEN as size_t + 1,
1,
self.stdout);
}
for i in range(0u, chars_left) {
fn make(&mut self, n: uint) -> IoResult<()> {
let lines = n / LINE_LEN;
let chars_left = n % LINE_LEN;
let mut buf = [0, ..LINE_LEN + 1];

for _ in range(0, lines) {
for i in range(0u, LINE_LEN) {
buf[i] = self.nextc();
}
fwrite(transmute(&buf[0]), chars_left as size_t, 1, self.stdout);
buf[LINE_LEN] = '\n' as u8;
try!(self.out.write(buf));
}
for i in range(0u, chars_left) {
buf[i] = self.nextc();
}
self.out.write(buf.slice_to(chars_left))
}
}

fn main() {
let n: uint = FromStr::from_str(os::args()[1]).unwrap();

unsafe {
let mode = "w";
let stdout = fdopen(STDOUT_FILENO as c_int, transmute(&mode[0]));

fputs(transmute(&MESSAGE_1[0]), stdout);
let mut repeat = RepeatFasta::new(stdout, ALU);
repeat.make(n * 2);
let args = os::args();
let n = if args.len() > 1 {
from_str::<uint>(args[1]).unwrap()
} else {
5
};

let mut out = BufferedWriter::new(stdout());

out.write_line(">ONE Homo sapiens alu").unwrap();
{
let mut repeat = RepeatFasta::new(ALU, &mut out);
repeat.make(n * 2).unwrap();
}

fputs(transmute(&MESSAGE_2[0]), stdout);
let iub = sum_and_scale(IUB);
let mut random = RandomFasta::new(stdout, iub);
random.make(n * 3);
out.write_line(">TWO IUB ambiguity codes").unwrap();
let iub = sum_and_scale(IUB);
let mut random = RandomFasta::new(&mut out, iub);
random.make(n * 3).unwrap();

fputs(transmute(&MESSAGE_3[0]), stdout);
let homo_sapiens = sum_and_scale(HOMO_SAPIENS);
random.lookup = RandomFasta::make_lookup(homo_sapiens);
random.make(n * 5);
random.out.write_line(">THREE Homo sapiens frequency").unwrap();
let homo_sapiens = sum_and_scale(HOMO_SAPIENS);
random.lookup = make_lookup(homo_sapiens);
random.make(n * 5).unwrap();

fputc('\n' as c_int, stdout);
}
random.out.write_str("\n").unwrap();
}
Loading

0 comments on commit fc1c06d

Please sign in to comment.