Skip to content

Commit 8e857c7

Browse files
bors[bot]japaric
andcommitted
132: add newlib support to the test generator r=japaric a=japaric Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 96e36ea + 9b26c6a commit 8e857c7

File tree

21 files changed

+1337
-817
lines changed

21 files changed

+1337
-817
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
**/*.rs.bk
22
.#*
3+
/bin
4+
/math/src
5+
/math/target
36
/target
47
/tests
58
Cargo.lock

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,37 @@ sudo: required
55
matrix:
66
include:
77
- env: TARGET=aarch64-unknown-linux-gnu
8+
rust: nightly
89
- env: TARGET=armv7-unknown-linux-gnueabihf
10+
rust: nightly
911
- env: TARGET=i686-unknown-linux-gnu
12+
rust: nightly
1013
- env: TARGET=mips-unknown-linux-gnu
14+
rust: nightly
1115
- env: TARGET=mips64-unknown-linux-gnuabi64
16+
rust: nightly
1217
- env: TARGET=mips64el-unknown-linux-gnuabi64
18+
rust: nightly
1319
- env: TARGET=mipsel-unknown-linux-gnu
20+
rust: nightly
1421
- env: TARGET=powerpc-unknown-linux-gnu
22+
rust: nightly
1523
- env: TARGET=powerpc64-unknown-linux-gnu
24+
rust: nightly
1625
- env: TARGET=powerpc64le-unknown-linux-gnu
26+
rust: nightly
1727
- env: TARGET=x86_64-unknown-linux-gnu
28+
rust: nightly
1829
- env: TARGET=cargo-fmt
1930
rust: beta
20-
# no-panic link test
21-
- env: TARGET=armv7-unknown-linux-gnueabihf
22-
rust: nightly
2331

2432
before_install: set -e
2533

2634
install:
2735
- bash ci/install.sh
2836

2937
script:
38+
- export PATH=$HOME/.local/bin:$PATH
3039
- bash ci/script.sh
3140

3241
after_script: set +e

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ version = "0.1.2"
1414
checked = []
1515

1616
[workspace]
17-
members = ["cb", "test-generator"]
17+
members = [
18+
"cb",
19+
"input-generator",
20+
"musl-generator",
21+
"newlib-generator",
22+
"shared",
23+
]
24+
25+
[dev-dependencies]
26+
shared = { path = "shared" }

ci/install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ main() {
1515
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
1616
rustup target add $TARGET
1717
fi
18+
19+
mkdir -p ~/.local/bin
20+
curl -L https://github.com/japaric/qemu-bin/raw/master/14.04/qemu-arm-2.12.0 > ~/.local/bin/qemu-arm
21+
chmod +x ~/.local/bin/qemu-arm
22+
qemu-arm --version
1823
}
1924

2025
main

ci/script.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@ main() {
66
return
77
fi
88

9-
# test that the functions don't contain invocations of `panic!`
10-
if [ $TRAVIS_RUST_VERSION = nightly ]; then
11-
cross build --release --target $TARGET --example no-panic
12-
return
13-
fi
14-
159
# quick check
1610
cargo check
1711

1812
# check that we can source import libm into compiler-builtins
1913
cargo check --package cb
2014

15+
# generate tests
16+
cargo run -p input-generator --target x86_64-unknown-linux-musl
17+
cargo run -p musl-generator --target x86_64-unknown-linux-musl
18+
cargo run -p newlib-generator
19+
20+
# test that the functions don't contain invocations of `panic!`
21+
case $TARGET in
22+
armv7-unknown-linux-gnueabihf)
23+
cross build --release --target $TARGET --example no-panic
24+
;;
25+
esac
26+
2127
# run unit tests
2228
cross test --lib --features checked --target $TARGET --release
2329

24-
# generate tests
25-
cargo run --package test-generator --target x86_64-unknown-linux-musl
26-
2730
# run generated tests
2831
cross test --tests --features checked --target $TARGET --release
2932

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[package]
2-
name = "test-generator"
2+
name = "input-generator"
33
version = "0.1.0"
44
authors = ["Jorge Aparicio <[email protected]>"]
5-
publish = false
65

76
[dependencies]
8-
rand = "0.5.3"
9-
itertools = "0.7.8"
7+
rand = "0.5.4"

input-generator/src/main.rs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
extern crate rand;
2+
3+
use std::collections::BTreeSet;
4+
use std::error::Error;
5+
use std::fs::{self, File};
6+
use std::io::Write;
7+
8+
use rand::{RngCore, SeedableRng, XorShiftRng};
9+
10+
const NTESTS: usize = 10_000;
11+
12+
fn main() -> Result<(), Box<Error>> {
13+
let mut rng = XorShiftRng::from_rng(&mut rand::thread_rng())?;
14+
15+
fs::remove_dir_all("bin").ok();
16+
fs::create_dir_all("bin/input")?;
17+
fs::create_dir_all("bin/output")?;
18+
19+
f32(&mut rng)?;
20+
f32f32(&mut rng)?;
21+
f32f32f32(&mut rng)?;
22+
f32i16(&mut rng)?;
23+
f64(&mut rng)?;
24+
f64f64(&mut rng)?;
25+
f64f64f64(&mut rng)?;
26+
f64i16(&mut rng)?;
27+
28+
Ok(())
29+
}
30+
31+
fn f32(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
32+
let mut set = BTreeSet::new();
33+
34+
while set.len() < NTESTS {
35+
let f = f32::from_bits(rng.next_u32());
36+
37+
if f.is_nan() {
38+
continue;
39+
}
40+
41+
set.insert(f.to_bits());
42+
}
43+
44+
let mut f = File::create("bin/input/f32")?;
45+
for i in set {
46+
f.write_all(&i.to_bytes())?;
47+
}
48+
49+
Ok(())
50+
}
51+
52+
fn f32f32(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
53+
let mut f = File::create("bin/input/f32f32")?;
54+
let mut i = 0;
55+
while i < NTESTS {
56+
let x0 = f32::from_bits(rng.next_u32());
57+
let x1 = f32::from_bits(rng.next_u32());
58+
59+
if x0.is_nan() || x1.is_nan() {
60+
continue;
61+
}
62+
63+
i += 1;
64+
f.write_all(&x0.to_bits().to_bytes())?;
65+
f.write_all(&x1.to_bits().to_bytes())?;
66+
}
67+
68+
Ok(())
69+
}
70+
71+
fn f32i16(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
72+
let mut f = File::create("bin/input/f32i16")?;
73+
let mut i = 0;
74+
while i < NTESTS {
75+
let x0 = f32::from_bits(rng.next_u32());
76+
let x1 = rng.next_u32() as i16;
77+
78+
if x0.is_nan() {
79+
continue;
80+
}
81+
82+
i += 1;
83+
f.write_all(&x0.to_bits().to_bytes())?;
84+
f.write_all(&x1.to_bytes())?;
85+
}
86+
87+
Ok(())
88+
}
89+
90+
fn f32f32f32(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
91+
let mut f = File::create("bin/input/f32f32f32")?;
92+
let mut i = 0;
93+
while i < NTESTS {
94+
let x0 = f32::from_bits(rng.next_u32());
95+
let x1 = f32::from_bits(rng.next_u32());
96+
let x2 = f32::from_bits(rng.next_u32());
97+
98+
if x0.is_nan() || x1.is_nan() || x2.is_nan() {
99+
continue;
100+
}
101+
102+
i += 1;
103+
f.write_all(&x0.to_bits().to_bytes())?;
104+
f.write_all(&x1.to_bits().to_bytes())?;
105+
f.write_all(&x2.to_bits().to_bytes())?;
106+
}
107+
108+
Ok(())
109+
}
110+
111+
fn f64(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
112+
let mut set = BTreeSet::new();
113+
114+
while set.len() < NTESTS {
115+
let f = f64::from_bits(rng.next_u64());
116+
117+
if f.is_nan() {
118+
continue;
119+
}
120+
121+
set.insert(f.to_bits());
122+
}
123+
124+
let mut f = File::create("bin/input/f64")?;
125+
for i in set {
126+
f.write_all(&i.to_bytes())?;
127+
}
128+
129+
Ok(())
130+
}
131+
132+
fn f64f64(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
133+
let mut f = File::create("bin/input/f64f64")?;
134+
let mut i = 0;
135+
while i < NTESTS {
136+
let x0 = f64::from_bits(rng.next_u64());
137+
let x1 = f64::from_bits(rng.next_u64());
138+
139+
if x0.is_nan() || x1.is_nan() {
140+
continue;
141+
}
142+
143+
i += 1;
144+
f.write_all(&x0.to_bits().to_bytes())?;
145+
f.write_all(&x1.to_bits().to_bytes())?;
146+
}
147+
148+
Ok(())
149+
}
150+
151+
fn f64f64f64(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
152+
let mut f = File::create("bin/input/f64f64f64")?;
153+
let mut i = 0;
154+
while i < NTESTS {
155+
let x0 = f64::from_bits(rng.next_u64());
156+
let x1 = f64::from_bits(rng.next_u64());
157+
let x2 = f64::from_bits(rng.next_u64());
158+
159+
if x0.is_nan() || x1.is_nan() || x2.is_nan() {
160+
continue;
161+
}
162+
163+
i += 1;
164+
f.write_all(&x0.to_bits().to_bytes())?;
165+
f.write_all(&x1.to_bits().to_bytes())?;
166+
f.write_all(&x2.to_bits().to_bytes())?;
167+
}
168+
169+
Ok(())
170+
}
171+
172+
fn f64i16(rng: &mut XorShiftRng) -> Result<(), Box<Error>> {
173+
let mut f = File::create("bin/input/f64i16")?;
174+
let mut i = 0;
175+
while i < NTESTS {
176+
let x0 = f64::from_bits(rng.next_u64());
177+
let x1 = rng.next_u32() as i16;
178+
179+
if x0.is_nan() {
180+
continue;
181+
}
182+
183+
i += 1;
184+
f.write_all(&x0.to_bits().to_bytes())?;
185+
f.write_all(&x1.to_bytes())?;
186+
}
187+
188+
Ok(())
189+
}

math/.cargo/config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.thumbv7em-none-eabi]
2+
rustflags = [
3+
"-C", "link-arg=-Wl,-Tlink.x",
4+
"-C", "link-arg=-nostartfiles",
5+
"-C", "link-arg=-mthumb",
6+
"-C", "link-arg=-march=armv7e-m",
7+
"-C", "link-arg=-mfloat-abi=soft",
8+
]
9+
10+
[build]
11+
target = "thumbv7em-none-eabi"

math/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "math"
3+
version = "0.0.0"
4+
5+
[dependencies]
6+
qemu-arm-rt = { git = "https://github.com/japaric/qemu-arm-rt" }
7+
8+
[workspace]

math/Cross.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.thumbv7em-none-eabi]
2+
xargo = false

musl-generator/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "musl-generator"
3+
version = "0.1.0"
4+
authors = ["Jorge Aparicio <[email protected]>"]
5+
6+
[dependencies]
7+
lazy_static = "1.0.2"
8+
shared = { path = "../shared" }
9+
libm = { path = ".." }

0 commit comments

Comments
 (0)