the rest of the test-framework rework and clean up start

This commit is contained in:
gluax 2022-06-08 14:06:25 -07:00
parent 8972674dec
commit 5ce5102a37
7 changed files with 6 additions and 216 deletions

5
Cargo.lock generated
View File

@ -1224,7 +1224,6 @@ dependencies = [
name = "leo-compiler"
version = "1.5.3"
dependencies = [
"criterion",
"leo-ast",
"leo-errors",
"leo-parser",
@ -1356,12 +1355,16 @@ name = "leo-test-framework"
version = "1.5.3"
dependencies = [
"backtrace",
"criterion",
"leo-compiler",
"leo-errors",
"leo-span",
"regex",
"serde",
"serde_json",
"serde_yaml",
"structopt",
"walkdir",
]
[[package]]

View File

@ -18,11 +18,6 @@ license = "GPL-3.0"
edition = "2021"
rust-version = "1.56.1"
[[bench]]
name = "leo_compiler"
path = "benches/leo_compiler.rs"
harness = false
[dependencies.leo-ast]
path = "../ast"
version = "1.5.3"
@ -46,9 +41,6 @@ version = "0.10"
path = "../../leo/span"
version = "1.5.3"
[dev-dependencies.criterion]
version = "0.3"
[dev-dependencies.leo-test-framework]
path = "../../tests/test-framework"
version = "1.4.0"
@ -60,7 +52,6 @@ features = ["derive"]
[dev-dependencies.serde_yaml]
version = "0.8.24"
[features]
default = [ ]
ci_skip = [ "leo-ast/ci_skip" ]

View File

@ -1,13 +0,0 @@
function one() -> u32 {
return 1u32;
}
function main(y: bool) -> bool {
let a: u32 = 0u32;
for i: u32 in 0u32..10u32 {
a = a + one();
}
return (a == 10u32) == y;
}

View File

@ -1,189 +0,0 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_compiler::Compiler;
use leo_errors::emitter::Handler;
use leo_span::{
source_map::FileName,
symbol::{SessionGlobals, SESSION_GLOBALS},
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::{
path::PathBuf,
time::{Duration, Instant},
};
macro_rules! sample {
($name:expr) => {
Sample {
name: $name,
input: include_str!(concat!("./", $name, ".leo")),
path: concat!("./", $name, ".leo"),
}
};
}
#[derive(Clone, Copy)]
struct Sample {
name: &'static str,
input: &'static str,
path: &'static str,
}
fn new_compiler<'a>(handler: &'a Handler, main_file_path: &str) -> Compiler<'a> {
Compiler::new(
handler,
PathBuf::from(main_file_path),
PathBuf::from("/tmp/output/"),
None,
)
}
impl Sample {
const SAMPLES: &'static [Sample] = &[sample!("big"), sample!("iteration")];
fn data(&self) -> (&str, FileName) {
black_box((self.input, FileName::Custom(self.path.into())))
}
fn bench_parse(&self, c: &mut Criterion) {
c.bench_function(&format!("parse {}", self.name), |b| {
b.iter_custom(|iters| {
let mut time = Duration::default();
for _ in 0..iters {
SESSION_GLOBALS.set(&SessionGlobals::default(), || {
let handler = Handler::default();
let mut compiler = new_compiler(&handler, self.path);
let (input, name) = self.data();
let start = Instant::now();
let out = compiler.parse_program_from_string(input, name);
time += start.elapsed();
out.expect("Failed to parse program")
});
}
time
})
});
}
fn bench_symbol_table(&self, c: &mut Criterion) {
c.bench_function(&format!("symbol table pass {}", self.name), |b| {
b.iter_custom(|iters| {
let mut time = Duration::default();
for _ in 0..iters {
SESSION_GLOBALS.set(&SessionGlobals::default(), || {
let handler = Handler::default();
let mut compiler = new_compiler(&handler, self.path);
let (input, name) = self.data();
compiler
.parse_program_from_string(input, name)
.expect("Failed to parse program");
let start = Instant::now();
let out = compiler.symbol_table_pass();
time += start.elapsed();
out.expect("failed to generate symbol table");
});
}
time
})
});
}
fn bench_type_checker(&self, c: &mut Criterion) {
c.bench_function(&format!("type checker pass {}", self.name), |b| {
b.iter_custom(|iters| {
let mut time = Duration::default();
for _ in 0..iters {
SESSION_GLOBALS.set(&SessionGlobals::default(), || {
let handler = Handler::default();
let mut compiler = new_compiler(&handler, self.path);
let (input, name) = self.data();
compiler
.parse_program_from_string(input, name)
.expect("Failed to parse program");
let mut symbol_table = compiler.symbol_table_pass().expect("failed to generate symbol table");
let start = Instant::now();
let out = compiler.type_checker_pass(&mut symbol_table);
time += start.elapsed();
out.expect("failed to run type check pass")
});
}
time
})
});
}
fn bench_full(&self, c: &mut Criterion) {
c.bench_function(&format!("full {}", self.name), |b| {
b.iter_custom(|iters| {
let mut time = Duration::default();
for _ in 0..iters {
SESSION_GLOBALS.set(&SessionGlobals::default(), || {
let handler = Handler::default();
let mut compiler = new_compiler(&handler, self.path);
let (input, name) = self.data();
let start = Instant::now();
compiler
.parse_program_from_string(input, name)
.expect("Failed to parse program");
let mut symbol_table = compiler.symbol_table_pass().expect("failed to generate symbol table");
compiler
.type_checker_pass(&mut symbol_table)
.expect("failed to run type check pass");
time += start.elapsed();
});
}
time
})
});
}
}
fn bench_parse(c: &mut Criterion) {
for sample in Sample::SAMPLES {
sample.bench_parse(c);
}
}
fn bench_symbol_table(c: &mut Criterion) {
for sample in Sample::SAMPLES {
sample.bench_symbol_table(c);
}
}
fn bench_type_checker(c: &mut Criterion) {
for sample in Sample::SAMPLES {
sample.bench_type_checker(c);
}
}
fn bench_full(c: &mut Criterion) {
for sample in Sample::SAMPLES {
sample.bench_full(c);
}
}
criterion_group!(
name = benches;
config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(30)).nresamples(200_000);
targets =
bench_parse,
bench_symbol_table,
bench_type_checker,
bench_full
);
criterion_main!(benches);

View File

@ -240,5 +240,5 @@ impl Runner for TestRunner {
#[test]
pub fn compiler_tests() {
leo_test_framework::run_tests(&TestRunner, "compiler");
leo_test_framework::TestCases::run_tests(&TestRunner, "compiler");
}

View File

@ -236,5 +236,5 @@ impl Runner for TestRunner {
#[test]
pub fn parser_tests() {
leo_test_framework::run_tests(&TestRunner, "parser");
leo_test_framework::TestCases::run_tests(&TestRunner, "parser");
}

View File

@ -287,8 +287,6 @@ impl TestCases {
errors,
})
}
todo!()
},
);
}