From 5ce5102a37408e6b12fe10652371fb73078656c0 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Wed, 8 Jun 2022 14:06:25 -0700 Subject: [PATCH] the rest of the test-framework rework and clean up start --- Cargo.lock | 5 +- compiler/compiler/Cargo.toml | 9 -- compiler/compiler/benches/iteration.leo | 13 -- compiler/compiler/benches/leo_compiler.rs | 189 ---------------------- compiler/compiler/src/test.rs | 2 +- compiler/parser/src/test.rs | 2 +- tests/test-framework/src/runner.rs | 2 - 7 files changed, 6 insertions(+), 216 deletions(-) delete mode 100644 compiler/compiler/benches/iteration.leo delete mode 100644 compiler/compiler/benches/leo_compiler.rs diff --git a/Cargo.lock b/Cargo.lock index c201f7ae7e..f0b01bb8bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] diff --git a/compiler/compiler/Cargo.toml b/compiler/compiler/Cargo.toml index ec476ef504..7e396443e8 100644 --- a/compiler/compiler/Cargo.toml +++ b/compiler/compiler/Cargo.toml @@ -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" ] diff --git a/compiler/compiler/benches/iteration.leo b/compiler/compiler/benches/iteration.leo deleted file mode 100644 index 459b7b2738..0000000000 --- a/compiler/compiler/benches/iteration.leo +++ /dev/null @@ -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; -} diff --git a/compiler/compiler/benches/leo_compiler.rs b/compiler/compiler/benches/leo_compiler.rs deleted file mode 100644 index 58cf7988c2..0000000000 --- a/compiler/compiler/benches/leo_compiler.rs +++ /dev/null @@ -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 . - -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); diff --git a/compiler/compiler/src/test.rs b/compiler/compiler/src/test.rs index 8bdb4a0507..9c878005d8 100644 --- a/compiler/compiler/src/test.rs +++ b/compiler/compiler/src/test.rs @@ -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"); } diff --git a/compiler/parser/src/test.rs b/compiler/parser/src/test.rs index ccffde5bb1..1164e48565 100644 --- a/compiler/parser/src/test.rs +++ b/compiler/parser/src/test.rs @@ -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"); } diff --git a/tests/test-framework/src/runner.rs b/tests/test-framework/src/runner.rs index 486b7bf920..2d21c31e4e 100644 --- a/tests/test-framework/src/runner.rs +++ b/tests/test-framework/src/runner.rs @@ -287,8 +287,6 @@ impl TestCases { errors, }) } - - todo!() }, ); }