Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 10 additions & 39 deletions compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ impl CrateDefMap {
match attributes.function().map(|attr| &attr.kind) {
Some(FunctionAttributeKind::Test(scope)) => {
let location = interner.function_meta(&func_id).name.location;
Some(TestFunction::new(func_id, scope.clone(), location, has_arguments))
let scope = scope.clone();
Some(TestFunction { id: func_id, scope, location, has_arguments })
}
_ => None,
}
Expand All @@ -230,7 +231,7 @@ impl CrateDefMap {
match attributes.function().map(|attr| &attr.kind) {
Some(FunctionAttributeKind::FuzzingHarness(scope)) => {
let location = interner.function_meta(&func_id).name.location;
Some(FuzzingHarness::new(func_id, scope.clone(), location))
Some(FuzzingHarness { id: func_id, scope: scope.clone(), location })
}
_ => None,
}
Expand Down Expand Up @@ -373,30 +374,13 @@ pub fn parse_file(fm: &FileManager, file_id: FileId) -> (ParsedModule, Vec<Parse
}

pub struct TestFunction {
id: FuncId,
scope: TestScope,
location: Location,
has_arguments: bool,
pub id: FuncId,
pub scope: TestScope,
pub location: Location,
pub has_arguments: bool,
}

impl TestFunction {
fn new(id: FuncId, scope: TestScope, location: Location, has_arguments: bool) -> Self {
TestFunction { id, scope, location, has_arguments }
}

/// Returns the function id of the test function
pub fn get_id(&self) -> FuncId {
self.id
}

pub fn file_id(&self) -> FileId {
self.location.file
}

pub fn has_arguments(&self) -> bool {
self.has_arguments
}

/// Returns true if the test function has been specified to fail
/// This is done by annotating the function with `#[test(should_fail)]`
/// or `#[test(should_fail_with = "reason")]`
Expand All @@ -418,25 +402,12 @@ impl TestFunction {
}

pub struct FuzzingHarness {
id: FuncId,
scope: FuzzingScope,
location: Location,
pub id: FuncId,
pub scope: FuzzingScope,
pub location: Location,
}

impl FuzzingHarness {
fn new(id: FuncId, scope: FuzzingScope, location: Location) -> Self {
FuzzingHarness { id, scope, location }
}

/// Returns the function id of the test function
pub fn get_id(&self) -> FuncId {
self.id
}

pub fn file_id(&self) -> FileId {
self.location.file
}

/// Returns true if the fuzzing harness has been specified to fail only under specific reason
/// This is done by annotating the function with
/// `#[fuzz(only_fail_with = "reason")]`
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Context<'_, '_> {
.get_all_test_functions(interner)
.filter_map(|test_function| {
let fully_qualified_name =
self.fully_qualified_function_name(crate_id, &test_function.get_id());
self.fully_qualified_function_name(crate_id, &test_function.id);
match &pattern {
FunctionNameMatch::Anything => Some((fully_qualified_name, test_function)),
FunctionNameMatch::Exact(patterns) => patterns
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Context<'_, '_> {
.get_all_fuzzing_harnesses(interner)
.filter_map(|fuzzing_harness| {
let fully_qualified_name =
self.fully_qualified_function_name(crate_id, &fuzzing_harness.get_id());
self.fully_qualified_function_name(crate_id, &fuzzing_harness.id);
match &pattern {
FunctionNameMatch::Anything => Some((fully_qualified_name, fuzzing_harness)),
FunctionNameMatch::Exact(patterns) => patterns
Expand Down
42 changes: 28 additions & 14 deletions tooling/greybox_fuzzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

use noirc_artifacts::program::ProgramArtifact;
use rand::prelude::*;
use rand::{Rng, SeedableRng};

Check warning on line 38 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Seedable)
use rand_xorshift::XorShiftRng;

Check warning on line 39 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (xorshift)

use rayon::prelude::IntoParallelIterator;
use std::io::Write;
Expand All @@ -44,14 +44,14 @@

const FOREIGN_CALL_FAILURE_SUBSTRING: &str = "Failed calling external resolver.";

/// We aim the number of testcases per round so one round takes these many microseconds

Check warning on line 47 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (testcases)
const SINGLE_FUZZING_ROUND_TARGET_TIME: u128 = 100_000u128;

/// Minimum pulse interval in milliseconds for printing metrics
const MINIMUM_PULSE_INTERVAL_MILLIS: u64 = 1000u64;

/// A seed for the XorShift RNG for use during mutation
type SimpleXorShiftRNGSeed = <XorShiftRng as SeedableRng>::Seed;

Check warning on line 54 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Seedable)

/// Information collected from testcase execution on success
pub type WitnessAndCoverage = (WitnessStack<FieldElement>, Option<Vec<u32>>);
Expand All @@ -68,7 +68,7 @@
main_testcase_id: TestCaseId,
/// An optional id of a second testcase that will be used for splicing
additional_testcase_id: Option<TestCaseId>,
/// A seed for the PRNG that will be used for mutating/splicing

Check warning on line 71 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (PRNG)
seed: SimpleXorShiftRNGSeed,
}

Expand All @@ -83,7 +83,7 @@
}

/// Create a task for executing a testcase without mutation
pub fn mutationless(main_testcase_id: TestCaseId) -> Self {

Check warning on line 86 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (mutationless)
Self {
main_testcase_id,
additional_testcase_id: None,
Expand All @@ -91,7 +91,7 @@
}
}

pub fn prng_seed(&self) -> SimpleXorShiftRNGSeed {

Check warning on line 94 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (prng)
self.seed
}
pub fn main_id(&self) -> TestCaseId {
Expand All @@ -102,7 +102,7 @@
}
}

/// Contains information from parallel execution of testcases for quick single-threaded processing

Check warning on line 105 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (testcases)
/// If no new coverage is detected, the fuzzer can simply quickly update the timing metrics without parsing the outcome
#[derive(Debug)]
struct FastParallelFuzzResult {
Expand Down Expand Up @@ -174,9 +174,9 @@
total_acir_execution_time: u128,
/// Total time spent executing Brillig programs in microseconds
total_brillig_execution_time: u128,
/// Total time spent mutating testcases

Check warning on line 177 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (testcases)
total_mutation_time: u128,
/// The number of unique testcases run

Check warning on line 179 in tooling/greybox_fuzzer/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (testcases)
processed_testcase_count: usize,
/// Number of testcases removed from the corpus
removed_testcase_count: usize,
Expand Down Expand Up @@ -271,6 +271,8 @@
pub num_threads: usize,
/// Maximum time in seconds to spend fuzzing (default: no timeout)
pub timeout: u64,
/// Whether to output progress to stdout or not.
pub show_progress: bool,
}

pub enum FuzzedExecutorFailureConfiguration {
Expand Down Expand Up @@ -321,6 +323,9 @@
/// Number of threads to use
num_threads: usize,

/// Whether to output progress to stdout or not.
show_progress: bool,

/// Determines what is considered a failure during execution
failure_configuration: FuzzedExecutorFailureConfiguration,

Expand Down Expand Up @@ -391,6 +396,7 @@
package_name: package_name.to_string(),
function_name: function_name.to_string(),
num_threads: fuzz_execution_config.num_threads,
show_progress: fuzz_execution_config.show_progress,
failure_configuration,
corpus_dir: PathBuf::from(
folder_configuration.corpus_dir.unwrap_or(DEFAULT_CORPUS_FOLDER.to_string()),
Expand Down Expand Up @@ -530,17 +536,19 @@
minimized_corpus_path =
minimized_corpus.as_ref().unwrap().get_corpus_storage_path().to_path_buf();
}
let _ = display_starting_info(
self.minimize_corpus,
seed,
starting_corpus_ids.len(),
self.num_threads,
&self.package_name,
&self.function_name,
corpus.get_corpus_storage_path(),
&minimized_corpus_path,
abi_change_detected,
);
if self.show_progress {
let _ = display_starting_info(
self.minimize_corpus,
seed,
starting_corpus_ids.len(),
self.num_threads,
&self.package_name,
&self.function_name,
corpus.get_corpus_storage_path(),
&minimized_corpus_path,
abi_change_detected,
);
}

// Generate the default input (it is needed if the corpus is empty)
let default_map = self.mutator.generate_default_input_map();
Expand Down Expand Up @@ -745,7 +753,9 @@
all_fuzzing_results.iter().find(|fast_result| fast_result.failed())
{
self.metrics.set_active_corpus_size(corpus.get_testcase_count());
let _ = display_metrics(&self.metrics);
if self.show_progress {
let _ = display_metrics(&self.metrics);
}
break individual_failing_result.outcome().clone();
}

Expand Down Expand Up @@ -934,7 +944,9 @@
// If we've found something, return
if let Some(result) = failing_result {
self.metrics.set_active_corpus_size(corpus.get_testcase_count());
let _ = display_metrics(&self.metrics);
if self.show_progress {
let _ = display_metrics(&self.metrics);
}
break result;
}
if time_tracker.elapsed() - last_metric_check
Expand All @@ -943,7 +955,9 @@
// Update and display metrics
self.metrics.set_active_corpus_size(corpus.get_testcase_count());
self.metrics.set_last_round_update_time(updating_time);
let _ = display_metrics(&self.metrics);
if self.show_progress {
let _ = display_metrics(&self.metrics);
}
self.metrics.refresh_round();
last_metric_check = time_tracker.elapsed();
// Check if we've exceeded the timeout
Expand Down
2 changes: 1 addition & 1 deletion tooling/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn get_package_tests_in_crate(
let package_tests: Vec<_> = tests
.into_iter()
.map(|(func_name, test_function)| {
let location = context.function_meta(&test_function.get_id()).name.location;
let location = context.function_meta(&test_function.id).name.location;
let file_id = location.file;
let file_path = fm.path(file_id).expect("file must exist to contain tests");
let range =
Expand Down
2 changes: 1 addition & 1 deletion tooling/lsp/src/requests/code_lens_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub(crate) fn collect_lenses_for_package(
let tests =
context.get_all_test_functions_in_crate_matching(&crate_id, &FunctionNameMatch::Anything);
for (func_name, test_function) in tests {
let location = context.function_meta(&test_function.get_id()).name.location;
let location = context.function_meta(&test_function.id).name.location;
let file_id = location.file;

// Ignore diagnostics for any file that wasn't the file we saved
Expand Down
2 changes: 0 additions & 2 deletions tooling/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ tracing.workspace = true
serde.workspace = true
serde_json.workspace = true
walkdir = "2.5.0"
noir_fuzzer = { workspace = true }
proptest = { workspace = true }
noir_greybox_fuzzer = { workspace = true }

# Some dependencies are optional so we can compile to Wasm.
Expand Down
10 changes: 3 additions & 7 deletions tooling/nargo/src/ops/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ pub fn get_test_function_for_debug(
}
};

let test_function_has_arguments = !context
.def_interner
.function_meta(&test_function.get_id())
.function_signature()
.0
.is_empty();
let test_function_has_arguments =
!context.def_interner.function_meta(&test_function.id).function_signature().0.is_empty();

if test_function_has_arguments {
return Err(String::from("Cannot debug tests with arguments"));
Expand All @@ -78,7 +74,7 @@ pub fn compile_test_fn_for_debugging(
compile_options: CompileOptions,
) -> Result<CompiledProgram, noirc_driver::CompileError> {
let compiled_program =
compile_no_check(context, &compile_options, test_def.function.get_id(), None, false)?;
compile_no_check(context, &compile_options, test_def.function.id, None, false)?;
let expression_width =
get_target_width(package.expression_width, compile_options.expression_width);
let compiled_program = transform_program(compiled_program, expression_width);
Expand Down
Loading
Loading