Skip to content

Commit da91e3d

Browse files
committed
[Frontend-JVM] Add unit test for multiple entry points
Signed-off-by: Arthur Chan <[email protected]>
1 parent a82c4f6 commit da91e3d

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed

src/fuzz_introspector/frontends/frontend_jvm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ def post_process_full_qualified_name(self):
303303
# Refine name
304304
class_name = self.parent_source.get_full_qualified_name(
305305
self.class_interface.name)
306-
self.name = f'[{class_name}].{self.name}({",".join(self.arg_types)})'
306+
if '[' not in self.name and '].' not in self.name:
307+
self.name = f'[{class_name}].{self.name}({",".join(self.arg_types)})'
307308

308309
# Refine variable map
309310
for key in self.var_map:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
package multiple;
18+
19+
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
20+
21+
public class FuzzerOne {
22+
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
23+
SimpleClass sc = new SimpleClass(data.consumeRemainingAsString());
24+
sc.simpleMethodOne();
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
package multiple;
18+
19+
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
20+
21+
public class FuzzerTwo {
22+
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
23+
SimpleClass sc = new SimpleClass();
24+
sc.simpleMethodTwo();
25+
}
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
package multiple
18+
19+
public class SimpleClass {
20+
public SimpleClass() {
21+
System.out.println("Default Constructor Called");
22+
}
23+
24+
public SimpleClass(String param) {
25+
System.out.println("Constructor with parameter called: " + param.toUpperCase());
26+
}
27+
28+
public void simpleMethodOne() {
29+
System.out.println("Simple Method One Called");
30+
}
31+
32+
public void simpleMethodTwo() {
33+
System.out.println("Simple Method Two Called");
34+
}
35+
36+
public void unreachableMethod() {
37+
System.out.println("Unreachable Method in SimpleClass");
38+
}
39+
}

src/test/test_frontends_jvm.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,39 @@ def test_tree_sitter_jvm_sample8():
211211
assert '[variable.B].callInstanceMethod(variable.test.A)' in functions_reached
212212
assert '[variable.test.A].instanceMethod()' in functions_reached
213213
assert 'System.out.println(String)' in functions_reached
214+
215+
216+
def test_tree_sitter_jvm_sample9():
217+
project = oss_fuzz.analyse_folder(
218+
'jvm',
219+
'src/test/data/source-code/jvm/test-project-9',
220+
'fuzzerTestOneInput',
221+
dump_output=False,
222+
)
223+
224+
# Project check
225+
harness = project.get_source_codes_with_harnesses()
226+
assert len(harness) == 2
227+
228+
result_one = project.get_reachable_methods(harness[0].source_file, harness[0])
229+
result_two = project.get_reachable_methods(harness[1].source_file, harness[1])
230+
231+
# Callsite check
232+
if 'FuzzerOne' in harness[0].source_file:
233+
functions_reached_one = result_one
234+
functions_reached_two = result_two
235+
else:
236+
functions_reached_one = result_two
237+
functions_reached_two = result_one
238+
239+
assert '[multiple.SimpleClass].<init>(String)' in functions_reached_one
240+
assert '[multiple.SimpleClass].simpleMethodOne()' in functions_reached_one
241+
assert '[multiple.SimpleClass].<init>()' not in functions_reached_one
242+
assert '[multiple.SimpleClass].simpleMethodTwo()' not in functions_reached_one
243+
assert '[multiple.SimpleClass].unreachableMethod()' not in functions_reached_one
244+
245+
assert '[multiple.SimpleClass].<init>()' in functions_reached_two
246+
assert '[multiple.SimpleClass].simpleMethodTwo()' in functions_reached_two
247+
assert '[multiple.SimpleClass].<init>(String)' not in functions_reached_two
248+
assert '[multiple.SimpleClass].simpleMethodOne()' not in functions_reached_two
249+
assert '[multiple.SimpleClass].unreachableMethod()' not in functions_reached_two

0 commit comments

Comments
 (0)