fuzzgen: Statistics framework (#4868)

* cranelift: Add non user trap codes function

* cranelift: Add Fuzzgen stats

* cranelift: Use `once_cell` and cleanup some stuff

* fuzzgen: Remove total_inputs metric

* fuzzgen: Filter empty trap codes
This commit is contained in:
Afonso Bordado
2022-09-27 17:04:57 +01:00
committed by GitHub
parent ee2ef5bdd0
commit 65a3af72c7
5 changed files with 125 additions and 20 deletions

View File

@@ -53,6 +53,25 @@ pub enum TrapCode {
User(u16),
}
impl TrapCode {
/// Returns a slice of all traps except `TrapCode::User` traps
pub const fn non_user_traps() -> &'static [TrapCode] {
&[
TrapCode::StackOverflow,
TrapCode::HeapOutOfBounds,
TrapCode::HeapMisaligned,
TrapCode::TableOutOfBounds,
TrapCode::IndirectCallToNull,
TrapCode::BadSignature,
TrapCode::IntegerOverflow,
TrapCode::IntegerDivisionByZero,
TrapCode::BadConversionToInteger,
TrapCode::UnreachableCodeReached,
TrapCode::Interrupt,
]
}
}
impl Display for TrapCode {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use self::TrapCode::*;
@@ -102,24 +121,9 @@ mod tests {
use super::*;
use alloc::string::ToString;
// Everything but user-defined codes.
const CODES: [TrapCode; 11] = [
TrapCode::StackOverflow,
TrapCode::HeapOutOfBounds,
TrapCode::HeapMisaligned,
TrapCode::TableOutOfBounds,
TrapCode::IndirectCallToNull,
TrapCode::BadSignature,
TrapCode::IntegerOverflow,
TrapCode::IntegerDivisionByZero,
TrapCode::BadConversionToInteger,
TrapCode::UnreachableCodeReached,
TrapCode::Interrupt,
];
#[test]
fn display() {
for r in &CODES {
for r in TrapCode::non_user_traps() {
let tc = *r;
assert_eq!(tc.to_string().parse(), Ok(tc));
}