From 8175b09e465028fae1a413228a01eed5e18384fc Mon Sep 17 00:00:00 2001 From: desbma-s1n Date: Wed, 29 May 2024 18:58:19 +0200 Subject: [PATCH] feat: more tests & fixes --- src/strace/parser/mod.rs | 55 ++++++++++++++++++++++++++++++++++++++ src/strace/parser/peg.pest | 9 ++++--- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/strace/parser/mod.rs b/src/strace/parser/mod.rs index 5a9cc6f..913f2ae 100644 --- a/src/strace/parser/mod.rs +++ b/src/strace/parser/mod.rs @@ -1354,6 +1354,61 @@ mod tests { ] ); } + + #[test] + fn test_getpid() { + let _ = simple_logger::SimpleLogger::new().init(); + + assert_eq!( + parse_line("641342 0.000022 getpid() = 641314", &[]).unwrap(), + ParseResult::Syscall(Syscall { + pid: 641342, + rel_ts: 0.000022, + name: "getpid".to_owned(), + args: vec![], + ret_val: 641314 + }) + ); + } + + #[test] + fn test_execve() { + let _ = simple_logger::SimpleLogger::new().init(); + + assert_eq!( + parse_line( + "1234 0.000000 execve(\"\\x12\", [\"\\x34\"], [\"\\x56\"]) = 0", + &[] + ) + .unwrap(), + ParseResult::Syscall(Syscall { + pid: 1234, + rel_ts: 0.000000, + name: "execve".to_owned(), + args: vec![ + Expression::Buffer(BufferExpression { + value: vec![18], + type_: BufferType::Unknown + }), + Expression::Collection { + complement: false, + values: vec![Expression::Buffer(BufferExpression { + value: vec![0x34], + type_: BufferType::Unknown + })] + }, + Expression::Collection { + complement: false, + values: vec![Expression::Buffer(BufferExpression { + value: vec![0x56], + type_: BufferType::Unknown + })] + }, + ], + ret_val: 0 + }) + ); + } } #[cfg(all(feature = "nightly", test))] diff --git a/src/strace/parser/peg.pest b/src/strace/parser/peg.pest index 7009c65..2c590f8 100644 --- a/src/strace/parser/peg.pest +++ b/src/strace/parser/peg.pest @@ -7,7 +7,7 @@ syscall_line = { #start = syscall_line_start | #end = syscall_line_end } -syscall_line_complete = { SOI ~ pid ~ " "+ ~ rel_ts ~ " " ~ name ~ "(" ~ arguments ~ ")" ~ " = " ~ ret_val ~ EOI } +syscall_line_complete = { SOI ~ pid ~ " "+ ~ rel_ts ~ " " ~ name ~ "(" ~ arguments ~ ") " ~ " "* ~ "= " ~ ret_val ~ EOI } syscall_line_start = { SOI ~ pid ~ " "+ ~ rel_ts ~ " " ~ name ~ "(" ~ arguments ~ " " ~ EOI } syscall_line_end = { SOI ~ pid ~ " "+ ~ rel_ts ~ " <... " ~ name ~ " resumed> ) " ~ " "* ~ "= " ~ ret_val ~ EOI } @@ -83,15 +83,16 @@ buffer = { ( buffer_byte+ | buffer_char+ - ) ~ - "\"" + )? ~ + "\"" ~ + "..."? } buffer_char = { !"\"" ~ ANY } buffer_byte = { "\\x" ~ ASCII_HEX_DIGIT{2} } macro = { symbol_name ~ "(" ~ arguments ~ ")" } -array = { "[" ~ (expression ~ (", " ~ expression)+)? ~ "]" } +array = { "[" ~ (expression ~ (", " ~ expression)*)? ~ "]" } set = { "~"? ~