mirror of
https://github.com/trailofbits/buttercup
synced 2026-06-21 14:11:39 +00:00
93f55a274b
* Change cscope call to compress database and improve lookup speed. Update tests. * Fix log4j2 source paths * Add private version of cscope
120 lines
3.0 KiB
Python
120 lines
3.0 KiB
Python
"""CodeQuery primitives testing"""
|
|
|
|
import pytest
|
|
|
|
from buttercup.common.challenge_task import ChallengeTask
|
|
from ..conftest import oss_fuzz_task
|
|
from ..common import (
|
|
common_test_get_functions,
|
|
common_test_get_callers,
|
|
common_test_get_callees,
|
|
TestFunctionInfo,
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def graphql_oss_fuzz_task(tmp_path_factory: pytest.TempPathFactory):
|
|
return oss_fuzz_task(
|
|
tmp_path_factory.mktemp("task_dir"),
|
|
"graphql-java",
|
|
"graphql-java",
|
|
"https://github.com/graphql-java/graphql-java",
|
|
"f52305325593dcec70aba9c4a5717b18b6543fa0",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"function_name,file_path,function_info",
|
|
[
|
|
(
|
|
"simplePrint",
|
|
"/src/graphql-java/src/main/java/graphql/schema/GraphQLTypeUtil.java",
|
|
TestFunctionInfo(
|
|
num_bodies=2,
|
|
body_excerpts=[
|
|
"""return "[" + simplePrint(unwrapOne(type)) + "]";""",
|
|
"""return ((GraphQLNamedSchemaElement) schemaElement).getName();""",
|
|
],
|
|
),
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_graphql_get_functions(
|
|
graphql_oss_fuzz_task: ChallengeTask, function_name, file_path, function_info
|
|
):
|
|
"""Test that we can get functions in challenge task code"""
|
|
common_test_get_functions(
|
|
graphql_oss_fuzz_task, function_name, file_path, function_info
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"function_name,file_path,line_number,fuzzy,expected_callers,num_callers",
|
|
[
|
|
(
|
|
"simplePrint",
|
|
"/src/graphql-java/src/main/java/graphql/schema/GraphQLTypeUtil.java",
|
|
28,
|
|
False,
|
|
[],
|
|
None, # FIXME(Evan): Too many to verify. Need to add a test for this.
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_get_callers(
|
|
graphql_oss_fuzz_task: ChallengeTask,
|
|
function_name,
|
|
file_path,
|
|
line_number,
|
|
fuzzy,
|
|
expected_callers,
|
|
num_callers,
|
|
):
|
|
"""Test that we can get function callers"""
|
|
common_test_get_callers(
|
|
graphql_oss_fuzz_task,
|
|
function_name,
|
|
file_path,
|
|
line_number,
|
|
fuzzy,
|
|
expected_callers,
|
|
num_callers,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"function_name,file_path,line_number,fuzzy,expected_callees,num_callees",
|
|
[
|
|
(
|
|
"simplePrint",
|
|
"/src/graphql-java/src/main/java/graphql/schema/GraphQLTypeUtil.java",
|
|
28,
|
|
False,
|
|
[],
|
|
None, # FIXME(Evan): Too many to verify. Need to add a test for this.
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_graphql_get_callees(
|
|
graphql_oss_fuzz_task: ChallengeTask,
|
|
function_name,
|
|
file_path,
|
|
line_number,
|
|
fuzzy,
|
|
expected_callees,
|
|
num_callees,
|
|
):
|
|
"""Test that we can get function callees."""
|
|
common_test_get_callees(
|
|
graphql_oss_fuzz_task,
|
|
function_name,
|
|
file_path,
|
|
line_number,
|
|
fuzzy,
|
|
expected_callees,
|
|
num_callees,
|
|
)
|