Skip to content

Commit

Permalink
feat: more tests & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma-s1n committed May 29, 2024
1 parent 66d4a3e commit 8175b09
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
55 changes: 55 additions & 0 deletions src/strace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
9 changes: 5 additions & 4 deletions src/strace/parser/peg.pest
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~ " <unfinished ...>" ~ EOI }
syscall_line_end = { SOI ~ pid ~ " "+ ~ rel_ts ~ " <... " ~ name ~ " resumed> ) " ~ " "* ~ "= " ~ ret_val ~ EOI }

Expand Down Expand Up @@ -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 = {
"~"? ~
Expand Down

0 comments on commit 8175b09

Please sign in to comment.