mirror of
https://github.com/trailofbits/buttercup
synced 2026-06-21 14:11:39 +00:00
42691e50b4
* style: apply ruff auto-fixes and formatting across entire codebase Applied safe auto-fixes from ruff v0.12.9 with --select ALL to improve code quality: - Reorder imports (stdlib → third-party → local) - Use modern type hints (collections.abc.Generator instead of typing.Generator) - Add trailing commas for better diffs - Format multi-line function parameters for readability - Add strict=False to zip() calls for explicit behavior - Simplify redundant elif to if after return statements - Consistent code formatting with ruff format These are all mechanical, non-controversial changes that improve code consistency without altering functionality. Changes affect 180 files across all modules: common, fuzzer, orchestrator, patcher, program-model, and seed-gen. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * re-applt ruff after merge --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Michael D Brown <michael.brown@trailofbits.com>
107 lines
3.0 KiB
Python
107 lines
3.0 KiB
Python
"""Macros testing"""
|
|
|
|
import pytest
|
|
|
|
from buttercup.common.challenge_task import ChallengeTask
|
|
from buttercup.program_model.codequery import CodeQuery
|
|
|
|
from .common import (
|
|
TestFunctionInfo,
|
|
TestTypeDefinitionInfo,
|
|
TypeDefinitionType,
|
|
common_test_get_functions,
|
|
common_test_get_type_definitions,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"function_name,file_path,function_info",
|
|
[
|
|
(
|
|
"png_create_read_struct",
|
|
"/src/libpng/pngread.c",
|
|
TestFunctionInfo(
|
|
num_bodies=1,
|
|
body_excerpts=[
|
|
"""#ifndef PNG_USER_MEM_SUPPORTED
|
|
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
|
|
error_fn, warn_fn, NULL, NULL, NULL);
|
|
#else
|
|
return png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
|
|
warn_fn, NULL, NULL, NULL);
|
|
""",
|
|
],
|
|
),
|
|
),
|
|
(
|
|
"png_create_info_struct",
|
|
"/src/libpng/png.c",
|
|
TestFunctionInfo(
|
|
num_bodies=1,
|
|
body_excerpts=["""info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr,"""],
|
|
),
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_libpng_get_functions(
|
|
libpng_oss_fuzz_task: ChallengeTask,
|
|
libpng_oss_fuzz_cq: CodeQuery,
|
|
function_name,
|
|
file_path,
|
|
function_info,
|
|
):
|
|
"""Test that we can get functions in challenge task code"""
|
|
common_test_get_functions(libpng_oss_fuzz_cq, function_name, file_path, function_info)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"type_name,file_path,fuzzy,type_definition_info",
|
|
[
|
|
(
|
|
"PNG_CHUNK_FROM_STRING",
|
|
"/src/libpng/pngpriv.h",
|
|
False,
|
|
TestTypeDefinitionInfo(
|
|
name="PNG_CHUNK_FROM_STRING",
|
|
type=TypeDefinitionType.PREPROC_FUNCTION,
|
|
definition="PNG_U32(0xff & (s)[0], 0xff & (s)[1], 0xff & (s)[2], 0xff & (s)[3])",
|
|
definition_line=863,
|
|
file_path="/src/libpng/pngpriv.h",
|
|
),
|
|
),
|
|
(
|
|
"PNG_ROWBYTES",
|
|
"/src/libpng/pngpriv.h",
|
|
False,
|
|
TestTypeDefinitionInfo(
|
|
name="PNG_ROWBYTES",
|
|
type=TypeDefinitionType.PREPROC_FUNCTION,
|
|
definition="""((pixel_bits) >= 8 ? \\
|
|
((size_t)(width) * (((size_t)(pixel_bits)) >> 3)) : \\
|
|
(( ((size_t)(width) * ((size_t)(pixel_bits))) + 7) >> 3) )""",
|
|
definition_line=721,
|
|
file_path="/src/libpng/pngpriv.h",
|
|
),
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_get_type_definitions(
|
|
libpng_oss_fuzz_task: ChallengeTask,
|
|
libpng_oss_fuzz_cq: CodeQuery,
|
|
type_name,
|
|
file_path,
|
|
fuzzy,
|
|
type_definition_info,
|
|
):
|
|
"""Test that we can get type defs"""
|
|
common_test_get_type_definitions(
|
|
libpng_oss_fuzz_task,
|
|
libpng_oss_fuzz_cq,
|
|
type_name,
|
|
file_path,
|
|
fuzzy,
|
|
type_definition_info,
|
|
)
|