1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

run tests in thread with bigger stack

This commit is contained in:
schaeff 2021-01-26 12:55:41 +01:00
parent bf2fedb690
commit ef5ef9252e
3 changed files with 47 additions and 28 deletions

View file

@ -72,35 +72,41 @@ mod tests {
#[test]
fn compile_examples() {
for p in glob("./examples/**/*").expect("Failed to read glob pattern") {
let path = match p {
Ok(x) => x,
Err(why) => panic!("Error: {:?}", why),
};
let builder = std::thread::Builder::new().stack_size(8388608);
if !path.is_file() {
continue;
}
builder
.spawn(|| {
for p in glob("./examples/**/*").expect("Failed to read glob pattern") {
let path = match p {
Ok(x) => x,
Err(why) => panic!("Error: {:?}", why),
};
assert!(path.extension().expect("extension expected") == "zok");
if !path.is_file() {
continue;
}
let should_error = path.to_str().unwrap().contains("compile_errors");
assert!(path.extension().expect("extension expected") == "zok");
println!("Testing {:?}", path);
let should_error = path.to_str().unwrap().contains("compile_errors");
let file = File::open(path.clone()).unwrap();
println!("Testing {:?}", path);
let mut reader = BufReader::new(file);
let file = File::open(path.clone()).unwrap();
let mut source = String::new();
reader.read_to_string(&mut source).unwrap();
let mut reader = BufReader::new(file);
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap();
let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap());
let res = compile::<Bn128Field, _>(source, path, Some(&resolver));
let mut source = String::new();
reader.read_to_string(&mut source).unwrap();
assert_eq!(res.is_err(), should_error);
}
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap();
let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap());
let res = compile::<Bn128Field, _>(source, path, Some(&resolver));
assert_eq!(res.is_err(), should_error);
}
})
.unwrap();
}
#[test]

View file

@ -60,6 +60,7 @@ pub trait Field:
+ Ord
+ Display
+ Debug
+ Send
+ Add<Self, Output = Self>
+ for<'a> Add<&'a Self, Output = Self>
+ Sub<Self, Output = Self>
@ -151,6 +152,8 @@ mod prime_field {
value: BigInt,
}
unsafe impl Send for FieldPrime {}
impl Field for FieldPrime {
fn bits(&self) -> u32 {
self.value.bits() as u32

View file

@ -95,14 +95,24 @@ pub fn test_inner(test_path: &str) {
let curves = t.curves.clone().unwrap_or(vec![Curve::Bn128]);
for c in &curves {
match c {
Curve::Bn128 => compile_and_run::<Bn128Field>(t.clone()),
Curve::Bls12_381 => compile_and_run::<Bls12_381Field>(t.clone()),
Curve::Bls12_377 => compile_and_run::<Bls12_377Field>(t.clone()),
Curve::Bw6_761 => compile_and_run::<Bw6_761Field>(t.clone()),
}
}
// this function typically runs in a spawn thread whose stack size is small, leading to stack overflows
// to avoid that, run the stack-heavy bit in a thread with a larger stack (8M)
let builder = std::thread::Builder::new().stack_size(8388608);
builder
.spawn(move || {
for c in &curves {
match c {
Curve::Bn128 => compile_and_run::<Bn128Field>(t.clone()),
Curve::Bls12_381 => compile_and_run::<Bls12_381Field>(t.clone()),
Curve::Bls12_377 => compile_and_run::<Bls12_377Field>(t.clone()),
Curve::Bw6_761 => compile_and_run::<Bw6_761Field>(t.clone()),
}
}
})
.unwrap()
.join()
.unwrap();
}
fn compile_and_run<T: Field>(t: Tests) {