Skip to content

Commit fc1c06d

Browse files
committed
auto merge of #12457 : alexcrichton/rust/fix-some-tests, r=brson
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
2 parents fd83b2b + 9cc26cf commit fc1c06d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+304
-1317
lines changed

src/libgreen/sched.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,6 @@ mod test {
13941394
});
13951395
}
13961396

1397-
// FIXME: #9407: ignore-test
1398-
#[ignore]
13991397
#[test]
14001398
fn dont_starve_1() {
14011399
let mut pool = SchedPool::new(PoolConfig {

src/test/auxiliary/private_variant_1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
mod super_sekrit {
1212
pub enum sooper_sekrit {
13-
pub quux, priv baz
13+
quux, priv baz
1414
}
1515
}

src/test/bench/shootout-fannkuch-redux.rs

+51-60
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-test reading from os::args()[1] - bogus!
12-
13-
use std::from_str::FromStr;
1411
use std::os;
15-
use std::vec::MutableVector;
1612
use std::vec;
1713

1814
fn max(a: i32, b: i32) -> i32 {
@@ -23,7 +19,6 @@ fn max(a: i32, b: i32) -> i32 {
2319
}
2420
}
2521

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

3530
let mut r = n;
3631
loop {
37-
unsafe {
38-
while r != 1 {
39-
count.unsafe_set((r-1) as uint, r);
40-
r -= 1;
41-
}
42-
43-
for (perm_i, perm1_i) in perm.mut_iter().zip(perm1.iter()) {
44-
*perm_i = *perm1_i;
45-
}
32+
while r != 1 {
33+
count[r - 1] = r;
34+
r -= 1;
35+
}
4636

47-
let mut flips_count: i32 = 0;
48-
let mut k: i32;
49-
loop {
50-
k = *perm.unsafe_ref(0);
51-
if k == 0 {
52-
break;
53-
}
37+
for (perm_i, perm1_i) in perm.mut_iter().zip(perm1.iter()) {
38+
*perm_i = *perm1_i;
39+
}
5440

55-
let k2 = (k+1) >> 1;
56-
for i in range(0i32, k2) {
57-
let (perm_i, perm_k_i) = {
58-
(*perm.unsafe_ref(i as uint),
59-
*perm.unsafe_ref((k-i) as uint))
60-
};
61-
perm.unsafe_set(i as uint, perm_k_i);
62-
perm.unsafe_set((k-i) as uint, perm_i);
63-
}
64-
flips_count += 1;
41+
let mut flips_count: i32 = 0;
42+
let mut k: i32;
43+
loop {
44+
k = perm[0];
45+
if k == 0 {
46+
break;
6547
}
6648

67-
max_flips_count = max(max_flips_count, flips_count);
68-
checksum += if perm_count % 2 == 0 {
69-
flips_count
70-
} else {
71-
-flips_count
72-
};
49+
let k2 = (k+1) >> 1;
50+
for i in range(0i32, k2) {
51+
perm.swap(i as uint, (k - i) as uint);
52+
}
53+
flips_count += 1;
54+
}
7355

74-
// Use incremental change to generate another permutation.
75-
loop {
76-
if r == n {
77-
println!("{}", checksum);
78-
return max_flips_count;
79-
}
56+
max_flips_count = max(max_flips_count, flips_count);
57+
checksum += if perm_count % 2 == 0 {
58+
flips_count
59+
} else {
60+
-flips_count
61+
};
8062

81-
let perm0 = perm1[0];
82-
let mut i: i32 = 0;
83-
while i < r {
84-
let j = i + 1;
85-
let perm1_j = { *perm1.unsafe_ref(j as uint) };
86-
perm1.unsafe_set(i as uint, perm1_j);
87-
i = j;
88-
}
89-
perm1.unsafe_set(r as uint, perm0);
63+
// Use incremental change to generate another permutation.
64+
loop {
65+
if r == n {
66+
println!("{}", checksum);
67+
return max_flips_count;
68+
}
9069

91-
let count_r = { *count.unsafe_ref(r as uint) };
92-
count.unsafe_set(r as uint, count_r - 1);
93-
if *count.unsafe_ref(r as uint) > 0 {
94-
break;
95-
}
96-
r += 1;
70+
let perm0 = perm1[0];
71+
let mut i: i32 = 0;
72+
while i < r {
73+
let j = i + 1;
74+
perm1[i] = perm1[j];
75+
i = j;
9776
}
77+
perm1[r] = perm0;
9878

99-
perm_count += 1;
79+
count[r] -= 1;
80+
if count[r] > 0 {
81+
break;
82+
}
83+
r += 1;
10084
}
85+
86+
perm_count += 1;
10187
}
10288
}
10389

10490
fn main() {
105-
let n: i32 = FromStr::from_str(os::args()[1]).unwrap();
91+
let args = os::args();
92+
let n = if args.len() > 1 {
93+
from_str::<i32>(args[1]).unwrap()
94+
} else {
95+
2
96+
};
10697
println!("Pfannkuchen({}) = {}", n as int, fannkuch_redux(n) as int);
10798
}

src/test/bench/shootout-fasta-redux.rs

+83-97
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-test reading from os::args()[1] - bogus!
12-
13-
use std::cast::transmute;
14-
use std::from_str::FromStr;
15-
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
11+
use std::cmp::min;
12+
use std::io::{stdout, BufferedWriter, IoResult};
1613
use std::os;
17-
use std::uint::min;
1814
use std::vec::bytes::copy_memory;
1915
use std::vec;
2016

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

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

40-
static MESSAGE_1: &'static str = ">ONE Homo sapiens alu\n";
41-
static MESSAGE_2: &'static str = ">TWO IUB ambiguity codes\n";
42-
static MESSAGE_3: &'static str = ">THREE Homo sapiens frequency\n";
43-
4436
static IUB: [AminoAcid, ..15] = [
4537
AminoAcid { c: 'a' as u8, p: 0.27 },
4638
AminoAcid { c: 'c' as u8, p: 0.12 },
@@ -85,73 +77,68 @@ struct AminoAcid {
8577
p: f32,
8678
}
8779

88-
struct RepeatFasta {
80+
struct RepeatFasta<'a, W> {
8981
alu: &'static str,
90-
stdout: *FILE,
82+
out: &'a mut W
9183
}
9284

93-
impl RepeatFasta {
94-
fn new(stdout: *FILE, alu: &'static str) -> RepeatFasta {
95-
RepeatFasta {
96-
alu: alu,
97-
stdout: stdout,
98-
}
85+
impl<'a, W: Writer> RepeatFasta<'a, W> {
86+
fn new(alu: &'static str, w: &'a mut W) -> RepeatFasta<'a, W> {
87+
RepeatFasta { alu: alu, out: w }
9988
}
10089

101-
fn make(&mut self, n: uint) {
102-
unsafe {
103-
let stdout = self.stdout;
104-
let alu_len = self.alu.len();
105-
let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8);
106-
let alu: &[u8] = self.alu.as_bytes();
107-
108-
copy_memory(buf, alu);
109-
let buf_len = buf.len();
110-
copy_memory(buf.mut_slice(alu_len, buf_len),
111-
alu.slice_to(LINE_LEN));
112-
113-
let mut pos = 0;
114-
let mut bytes;
115-
let mut n = n;
116-
while n > 0 {
117-
bytes = min(LINE_LEN, n);
118-
fwrite(transmute(&buf[pos]), bytes as size_t, 1, stdout);
119-
fputc('\n' as c_int, stdout);
120-
pos += bytes;
121-
if pos > alu_len {
122-
pos -= alu_len;
123-
}
124-
n -= bytes;
90+
fn make(&mut self, n: uint) -> IoResult<()> {
91+
let alu_len = self.alu.len();
92+
let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8);
93+
let alu: &[u8] = self.alu.as_bytes();
94+
95+
copy_memory(buf, alu);
96+
let buf_len = buf.len();
97+
copy_memory(buf.mut_slice(alu_len, buf_len),
98+
alu.slice_to(LINE_LEN));
99+
100+
let mut pos = 0;
101+
let mut bytes;
102+
let mut n = n;
103+
while n > 0 {
104+
bytes = min(LINE_LEN, n);
105+
try!(self.out.write(buf.slice(pos, pos + bytes)));
106+
try!(self.out.write_u8('\n' as u8));
107+
pos += bytes;
108+
if pos > alu_len {
109+
pos -= alu_len;
125110
}
111+
n -= bytes;
126112
}
113+
Ok(())
127114
}
128115
}
129116

130-
struct RandomFasta {
117+
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
118+
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
119+
let mut j = 0;
120+
for (i, slot) in lookup.mut_iter().enumerate() {
121+
while a[j].p < (i as f32) {
122+
j += 1;
123+
}
124+
*slot = a[j];
125+
}
126+
lookup
127+
}
128+
129+
struct RandomFasta<'a, W> {
131130
seed: u32,
132-
stdout: *FILE,
133131
lookup: [AminoAcid, ..LOOKUP_SIZE],
132+
out: &'a mut W,
134133
}
135134

136-
impl RandomFasta {
137-
fn new(stdout: *FILE, a: &[AminoAcid]) -> RandomFasta {
135+
impl<'a, W: Writer> RandomFasta<'a, W> {
136+
fn new(w: &'a mut W, a: &[AminoAcid]) -> RandomFasta<'a, W> {
138137
RandomFasta {
139138
seed: 42,
140-
stdout: stdout,
141-
lookup: RandomFasta::make_lookup(a),
142-
}
143-
}
144-
145-
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
146-
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
147-
let mut j = 0;
148-
for (i, slot) in lookup.mut_iter().enumerate() {
149-
while a[j].p < (i as f32) {
150-
j += 1;
151-
}
152-
*slot = a[j];
139+
out: w,
140+
lookup: make_lookup(a),
153141
}
154-
lookup
155142
}
156143

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

172-
fn make(&mut self, n: uint) {
173-
unsafe {
174-
let lines = n / LINE_LEN;
175-
let chars_left = n % LINE_LEN;
176-
let mut buf = [0, ..LINE_LEN + 1];
177-
178-
for _ in range(0, lines) {
179-
for i in range(0u, LINE_LEN) {
180-
buf[i] = self.nextc();
181-
}
182-
buf[LINE_LEN] = '\n' as u8;
183-
fwrite(transmute(&buf[0]),
184-
LINE_LEN as size_t + 1,
185-
1,
186-
self.stdout);
187-
}
188-
for i in range(0u, chars_left) {
159+
fn make(&mut self, n: uint) -> IoResult<()> {
160+
let lines = n / LINE_LEN;
161+
let chars_left = n % LINE_LEN;
162+
let mut buf = [0, ..LINE_LEN + 1];
163+
164+
for _ in range(0, lines) {
165+
for i in range(0u, LINE_LEN) {
189166
buf[i] = self.nextc();
190167
}
191-
fwrite(transmute(&buf[0]), chars_left as size_t, 1, self.stdout);
168+
buf[LINE_LEN] = '\n' as u8;
169+
try!(self.out.write(buf));
170+
}
171+
for i in range(0u, chars_left) {
172+
buf[i] = self.nextc();
192173
}
174+
self.out.write(buf.slice_to(chars_left))
193175
}
194176
}
195177

196178
fn main() {
197-
let n: uint = FromStr::from_str(os::args()[1]).unwrap();
198-
199-
unsafe {
200-
let mode = "w";
201-
let stdout = fdopen(STDOUT_FILENO as c_int, transmute(&mode[0]));
202-
203-
fputs(transmute(&MESSAGE_1[0]), stdout);
204-
let mut repeat = RepeatFasta::new(stdout, ALU);
205-
repeat.make(n * 2);
179+
let args = os::args();
180+
let n = if args.len() > 1 {
181+
from_str::<uint>(args[1]).unwrap()
182+
} else {
183+
5
184+
};
185+
186+
let mut out = BufferedWriter::new(stdout());
187+
188+
out.write_line(">ONE Homo sapiens alu").unwrap();
189+
{
190+
let mut repeat = RepeatFasta::new(ALU, &mut out);
191+
repeat.make(n * 2).unwrap();
192+
}
206193

207-
fputs(transmute(&MESSAGE_2[0]), stdout);
208-
let iub = sum_and_scale(IUB);
209-
let mut random = RandomFasta::new(stdout, iub);
210-
random.make(n * 3);
194+
out.write_line(">TWO IUB ambiguity codes").unwrap();
195+
let iub = sum_and_scale(IUB);
196+
let mut random = RandomFasta::new(&mut out, iub);
197+
random.make(n * 3).unwrap();
211198

212-
fputs(transmute(&MESSAGE_3[0]), stdout);
213-
let homo_sapiens = sum_and_scale(HOMO_SAPIENS);
214-
random.lookup = RandomFasta::make_lookup(homo_sapiens);
215-
random.make(n * 5);
199+
random.out.write_line(">THREE Homo sapiens frequency").unwrap();
200+
let homo_sapiens = sum_and_scale(HOMO_SAPIENS);
201+
random.lookup = make_lookup(homo_sapiens);
202+
random.make(n * 5).unwrap();
216203

217-
fputc('\n' as c_int, stdout);
218-
}
204+
random.out.write_str("\n").unwrap();
219205
}

0 commit comments

Comments
 (0)