Skip to content

Commit cf1e648

Browse files
committed
[Frontend-Rust] Add test for recursive and triat implementation
Signed-off-by: Arthur Chan <[email protected]>
1 parent fbe77a0 commit cf1e648

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 Fuzz Introspector Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#![no_main]
16+
17+
pub mod recursive;
18+
19+
#[macro_use]
20+
extern crate libfuzzer_sys;
21+
22+
use crate::recursive::RecursiveStruct;
23+
24+
fuzz_target!(|data: &[u8]| {
25+
let mut instance = RecursiveStruct::new();
26+
if let Ok(s) = std::str::from_utf8(data) {
27+
let _ = unsafe { instance.process(s) };
28+
}
29+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
////////////////////////////////////////////////////////////////////////////////
16+
17+
pub trait RecursiveTrait {
18+
fn process(&mut self, input: &str) -> String;
19+
}
20+
21+
pub struct RecursiveStruct;
22+
23+
impl RecursiveStruct {
24+
pub fn new() -> Self {
25+
RecursiveStruct
26+
}
27+
}
28+
29+
impl RecursiveTrait for RecursiveStruct {
30+
fn process(&mut self, input: &str) -> String {
31+
if input.is_empty() {
32+
String::new()
33+
} else {
34+
self.process(&input[1..])
35+
}
36+
}
37+
}

src/test/test_frontends_rust.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,22 @@ def test_tree_sitter_rust_sample2():
5858
# Callsite check
5959
assert 'double_add' in functions_reached
6060
assert 'add' in functions_reached
61+
62+
63+
def test_tree_sitter_rust_sample5():
64+
project = oss_fuzz.analyse_folder(
65+
'rust',
66+
'src/test/data/source-code/rust/test-project-5',
67+
dump_output=False,
68+
)
69+
70+
# Project check
71+
harness = project.get_source_codes_with_harnesses()
72+
assert len(harness) == 1
73+
74+
functions_reached = project.get_reachable_functions(harness[0].source_file, harness[0])
75+
76+
# Callsite check
77+
assert '&str::is_empty' in functions_reached
78+
assert 'RecursiveStruct::new' in functions_reached
79+
assert 'RecursiveStruct::process' in functions_reached

0 commit comments

Comments
 (0)