diff --git a/testing/config/tests.toml b/testing/config/tests.toml index 601e827..c6aa7de 100644 --- a/testing/config/tests.toml +++ b/testing/config/tests.toml @@ -1,796 +1,1672 @@ - -[[tests]] -test_name = "add1" -source_file = "cpp/simple/add.cpp" -expected_output = "7" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "add2" -source_file = "cpp/simple/add.cpp" -expected_output = "7" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "add3" -source_file = "cpp/simple/add.cpp" -expected_output = "7" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "add4" -source_file = "cpp/simple/add.cpp" -expected_output = "7" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "class_polymorphism1" -source_file = "cpp/simple/class.cpp" -expected_output = """ -12 -5, 7 -3, 6, 9 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "class_polymorphism2" -source_file = "cpp/simple/class.cpp" -expected_output = """ -12 -5, 7 -3, 6, 9 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "class_polymorphism3" -source_file = "cpp/simple/class.cpp" -expected_output = """ -12 -5, 7 -3, 6, 9 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "class_polymorphism4" -source_file = "cpp/simple/class.cpp" -expected_output = """ -12 -5, 7 -3, 6, 9 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "exception_handling1" -source_file = "cpp/simple/exceptions.cpp" -expected_output = """ -Exception caught: Test exception -Exception caught: Test exception -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "exception_handling2" -source_file = "cpp/simple/exceptions.cpp" -expected_output = """ -Exception caught: Test exception -Exception caught: Test exception -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "exception_handling3" -source_file = "cpp/simple/exceptions.cpp" -expected_output = """ -Exception caught: Test exception -Exception caught: Test exception -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "exception_handling4" -source_file = "cpp/simple/exceptions.cpp" -expected_output = """ -Exception caught: Test exception -Exception caught: Test exception -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "fact1" -source_file = "cpp/simple/fact.cpp" -expected_output = """ -3628800 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "fact2" -source_file = "cpp/simple/fact.cpp" -expected_output = """ -3628800 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "fact3" -source_file = "cpp/simple/fact.cpp" -expected_output = """ -3628800 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "fact4" -source_file = "cpp/simple/fact.cpp" -expected_output = """ -3628800 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "func1" -source_file = "cpp/simple/func.cpp" -expected_output = """ -Function f called (g incremented to 1) -Final value of g: 1 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "func2" -source_file = "cpp/simple/func.cpp" -expected_output = """ -Function f called (g incremented to 1) -Final value of g: 1 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "func3" -source_file = "cpp/simple/func.cpp" -expected_output = """ -Function f called (g incremented to 1) -Final value of g: 1 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "func4" -source_file = "cpp/simple/func.cpp" -expected_output = """ -Function f called (g incremented to 1) -Final value of g: 1 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "mul1" -source_file = "cpp/simple/mul.cpp" -expected_output = """ -42 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "mul2" -source_file = "cpp/simple/mul.cpp" -expected_output = """ -42 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "mul3" -source_file = "cpp/simple/mul.cpp" -expected_output = """ -42 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "mul4" -source_file = "cpp/simple/mul.cpp" -expected_output = """ -42 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "template1" -source_file = "cpp/simple/template.cpp" -expected_output = """ -Result: 42 -Result: 15 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "template2" -source_file = "cpp/simple/template.cpp" -expected_output = """ -Result: 42 -Result: 15 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "template3" -source_file = "cpp/simple/template.cpp" -expected_output = """ -Result: 42 -Result: 15 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "template4" -source_file = "cpp/simple/template.cpp" -expected_output = """ -Result: 42 -Result: 15 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "ptrsSharedUnique1" -source_file = "cpp/simple/ptr.cpp" -expected_output = """ -Value pointed by p1: 42, Value pointed by p2: 42 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "ptrsSharedUnique2" -source_file = "cpp/simple/ptr.cpp" -expected_output = """ -Value pointed by p1: 42, Value pointed by p2: 42 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "ptrsSharedUnique3" -source_file = "cpp/simple/ptr.cpp" -expected_output = """ -Value pointed by p1: 42, Value pointed by p2: 42 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "ptrsSharedUnique4" -source_file = "cpp/simple/ptr.cpp" -expected_output = """ -Value pointed by p1: 42, Value pointed by p2: 42 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "heap1" -source_file = "cpp/simple/heap.cpp" -expected_output = """ -Value: 10 -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "heap2" -source_file = "cpp/simple/heap.cpp" -expected_output = """ -Value: 10 -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "heap3" -source_file = "cpp/simple/heap.cpp" -expected_output = """ -Value: 10 -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "heap4" -source_file = "cpp/simple/heap.cpp" -expected_output = """ -Value: 10 -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "raii_filehandler1" -source_file = "cpp/simple/file_handler.cpp" -expected_output = """ -Handler created -File closed -""" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "raii_filehandler2" -source_file = "cpp/simple/file_handler.cpp" -expected_output = """ -Handler created -File closed -""" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "raii_filehandler3" -source_file = "cpp/simple/file_handler.cpp" -expected_output = """ -Handler created -File closed -""" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "raii_filehandler4" -source_file = "cpp/simple/file_handler.cpp" -expected_output = """ -Handler created -File closed -""" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "inline_constexpr1" -source_file = "cpp/simple/inline_constexpr.cpp" -aspis_options = "--eddi --cfcss" -expected_output = """ -9 -16 -5 -""" - -[[tests]] -test_name = "inline_constexpr2" -source_file = "cpp/simple/inline_constexpr.cpp" -aspis_options = "--seddi --rasm" -expected_output = """ -9 -16 -5 -""" - -[[tests]] -test_name = "inline_constexpr3" -source_file = "cpp/simple/inline_constexpr.cpp" -aspis_options = "--fdsc --rasm" -expected_output = """ -9 -16 -5 -""" - -[[tests]] -test_name = "inline_constexpr4" -source_file = "cpp/simple/inline_constexpr.cpp" -aspis_options = "--eddi --no-cfc" -expected_output = """ -9 -16 -5 -""" - -[[tests]] -test_name = "lambda_captures1" -source_file = "cpp/simple/lambda_captures.cpp" -aspis_options = "--eddi --cfcss" -expected_output = """ -x incremented by 5 -Value pointed by p: 11 -""" - -[[tests]] -test_name = "lambda_captures2" -source_file = "cpp/simple/lambda_captures.cpp" -aspis_options = "--seddi --rasm" -expected_output = """ -x incremented by 5 -Value pointed by p: 11 -""" - -[[tests]] -test_name = "lambda_captures3" -source_file = "cpp/simple/lambda_captures.cpp" -aspis_options = "--fdsc --rasm" -expected_output = """ -x incremented by 5 -Value pointed by p: 11 -""" - -[[tests]] -test_name = "lambda_captures4" -source_file = "cpp/simple/lambda_captures.cpp" -aspis_options = "--eddi --no-cfc" -expected_output = """ -x incremented by 5 -Value pointed by p: 11 -""" - -[[tests]] -test_name = "volatile_memory_order1" -source_file = "cpp/simple/volatile_memory_order.cpp" -aspis_options = "--eddi --cfcss" -expected_output = """ -42 -""" - -[[tests]] -test_name = "volatile_memory_order2" -source_file = "cpp/simple/volatile_memory_order.cpp" -aspis_options = "--seddi --rasm" -expected_output = """ -42 -""" - -[[tests]] -test_name = "volatile_memory_order3" -source_file = "cpp/simple/volatile_memory_order.cpp" -aspis_options = "--fdsc --rasm" -expected_output = """ -42 -""" - -[[tests]] -test_name = "volatile_memory_order4" -source_file = "cpp/simple/volatile_memory_order.cpp" -aspis_options = "--eddi --no-cfc" -expected_output = """ -42 -""" - -[[tests]] -test_name = "stl_containers_advanced1" -source_file = "cpp/simple/stl_containers_advanced.cpp" -aspis_options = "--eddi --cfcss" -expected_output = """ -0 1 2 3 4 -""" - -[[tests]] -test_name = "stl_containers_advanced2" -source_file = "cpp/simple/stl_containers_advanced.cpp" -aspis_options = "--seddi --rasm" -expected_output = """ -0 1 2 3 4 -""" - -[[tests]] -test_name = "stl_containers_advanced3" -source_file = "cpp/simple/stl_containers_advanced.cpp" -aspis_options = "--fdsc --rasm" -expected_output = """ -0 1 2 3 4 -""" - -[[tests]] -test_name = "stl_containers_advanced4" -source_file = "cpp/simple/stl_containers_advanced.cpp" -aspis_options = "--eddi --no-cfc" -expected_output = """ -0 1 2 3 4 -""" - -# [[tests]] -# test_name = "threads1" -# source_file = "cpp/simple/threads.cpp" -# aspis_options = "--eddi --cfcss" -# expected_output = """ -# 4000 -# """ -# -# [[tests]] -# test_name = "threads2" -# source_file = "cpp/simple/threads.cpp" -# aspis_options = "--seddi --rasm" -# expected_output = """ -# 4000 -# """ -# -# [[tests]] -# test_name = "threads3" -# source_file = "cpp/simple/threads.cpp" -# aspis_options = "--fdsc --rasm" -# expected_output = """ -# 4000 -# """ -# -# [[tests]] -# test_name = "threads4" -# source_file = "cpp/simple/threads.cpp" -# aspis_options = "--eddi --no-cfc" -# expected_output = """ -# 4000 -# """ - -[[tests]] -test_name = "function_pointer_v0" -source_file = "c/control_flow/function_pointer.c" -expected_output = "42" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "function_pointer_v1" -source_file = "c/control_flow/function_pointer.c" -expected_output = "42" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "function_pointer_v2" -source_file = "c/control_flow/function_pointer.c" -expected_output = "42" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "function_pointer_v3" -source_file = "c/control_flow/function_pointer.c" -expected_output = "42" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "loop_exit_v0" -source_file = "c/control_flow/loop_exit.c" -expected_output = "2" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "loop_exit_v1" -source_file = "c/control_flow/loop_exit.c" -expected_output = "2" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "loop_exit_v2" -source_file = "c/control_flow/loop_exit.c" -expected_output = "2" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "loop_exit_v3" -source_file = "c/control_flow/loop_exit.c" -expected_output = "2" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "nested-branch_v0" -source_file = "c/control_flow/nested-branch.c" -expected_output = "6" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "nested-branch_v1" -source_file = "c/control_flow/nested-branch.c" -expected_output = "6" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "nested-branch_v2" -source_file = "c/control_flow/nested-branch.c" -expected_output = "6" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "nested-branch_v3" -source_file = "c/control_flow/nested-branch.c" -expected_output = "6" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "simple-branch_v0" -source_file = "c/control_flow/simple-branch.c" -expected_output = "OK" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "simple-branch_v1" -source_file = "c/control_flow/simple-branch.c" -expected_output = "OK" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "simple-branch_v2" -source_file = "c/control_flow/simple-branch.c" -expected_output = "OK" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "simple-branch_v3" -source_file = "c/control_flow/simple-branch.c" -expected_output = "OK" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "switch-case_v0" -source_file = "c/control_flow/switch-case.c" -expected_output = "300" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "switch-case_v1" -source_file = "c/control_flow/switch-case.c" -expected_output = "300" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "switch-case_v2" -source_file = "c/control_flow/switch-case.c" -expected_output = "300" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "switch-case_v3" -source_file = "c/control_flow/switch-case.c" -expected_output = "300" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "data_dep_branches_v0" -source_file = "c/data_duplication_integrity/data_dep_branches.c" -expected_output = "7" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "data_dep_branches_v1" -source_file = "c/data_duplication_integrity/data_dep_branches.c" -expected_output = "7" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "data_dep_branches_v2" -source_file = "c/data_duplication_integrity/data_dep_branches.c" -expected_output = "7" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "data_dep_branches_v3" -source_file = "c/data_duplication_integrity/data_dep_branches.c" -expected_output = "7" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "global_var_across_functions_v0" -source_file = "c/data_duplication_integrity/global_var_across_functions.c" -expected_output = "2" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "global_var_across_functions_v1" -source_file = "c/data_duplication_integrity/global_var_across_functions.c" -expected_output = "2" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "global_var_across_functions_v2" -source_file = "c/data_duplication_integrity/global_var_across_functions.c" -expected_output = "2" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "global_var_across_functions_v3" -source_file = "c/data_duplication_integrity/global_var_across_functions.c" -expected_output = "2" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "misc_data_dup_v0" -source_file = "c/data_duplication_integrity/misc_data_dup.c" -expected_output = "OK" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "misc_data_dup_v1" -source_file = "c/data_duplication_integrity/misc_data_dup.c" -expected_output = "OK" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "misc_data_dup_v2" -source_file = "c/data_duplication_integrity/misc_data_dup.c" -expected_output = "OK" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "misc_data_dup_v3" -source_file = "c/data_duplication_integrity/misc_data_dup.c" -expected_output = "OK" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "volatile_io_v0" -source_file = "c/data_duplication_integrity/volatile_io.c" -expected_output = "42" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "volatile_io_v1" -source_file = "c/data_duplication_integrity/volatile_io.c" -expected_output = "42" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "volatile_io_v2" -source_file = "c/data_duplication_integrity/volatile_io.c" -expected_output = "42" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "volatile_io_v3" -source_file = "c/data_duplication_integrity/volatile_io.c" -expected_output = "42" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "arit_pipeline_v0" -source_file = "c/misc_math/arit_pipeline.c" -expected_output = "3" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "arit_pipeline_v1" -source_file = "c/misc_math/arit_pipeline.c" -expected_output = "3" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "arit_pipeline_v2" -source_file = "c/misc_math/arit_pipeline.c" -expected_output = "3" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "arit_pipeline_v3" -source_file = "c/misc_math/arit_pipeline.c" -expected_output = "3" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "mixed_ops_v0" -source_file = "c/misc_math/mixed_ops.c" -expected_output = "14.5" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "mixed_ops_v1" -source_file = "c/misc_math/mixed_ops.c" -expected_output = "14.5" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "mixed_ops_v2" -source_file = "c/misc_math/mixed_ops.c" -expected_output = "14.5" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "mixed_ops_v3" -source_file = "c/misc_math/mixed_ops.c" -expected_output = "14.5" -aspis_options = "--eddi --no-cfc" - -[[tests]] -test_name = "xor_cypher_v0" -source_file = "c/misc_math/xor_cypher.c" -expected_output = "SUCCESS" -aspis_options = "--eddi --cfcss" - -[[tests]] -test_name = "xor_cypher_v1" -source_file = "c/misc_math/xor_cypher.c" -expected_output = "SUCCESS" -aspis_options = "--seddi --rasm" - -[[tests]] -test_name = "xor_cypher_v2" -source_file = "c/misc_math/xor_cypher.c" -expected_output = "SUCCESS" -aspis_options = "--fdsc --rasm" - -[[tests]] -test_name = "xor_cypher_v3" -source_file = "c/misc_math/xor_cypher.c" -expected_output = "SUCCESS" -aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "add1" +source_file = "cpp/simple/add.cpp" +expected_output = "7" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "add2" +source_file = "cpp/simple/add.cpp" +expected_output = "7" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "add3" +source_file = "cpp/simple/add.cpp" +expected_output = "7" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "add4" +source_file = "cpp/simple/add.cpp" +expected_output = "7" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "class_polymorphism1" +source_file = "cpp/simple/class.cpp" +expected_output = """ +12 +5, 7 +3, 6, 9 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "class_polymorphism2" +source_file = "cpp/simple/class.cpp" +expected_output = """ +12 +5, 7 +3, 6, 9 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "class_polymorphism3" +source_file = "cpp/simple/class.cpp" +expected_output = """ +12 +5, 7 +3, 6, 9 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "class_polymorphism4" +source_file = "cpp/simple/class.cpp" +expected_output = """ +12 +5, 7 +3, 6, 9 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "exception_handling1" +source_file = "cpp/simple/exceptions.cpp" +expected_output = """ +Exception caught: Test exception +Exception caught: Test exception +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "exception_handling2" +source_file = "cpp/simple/exceptions.cpp" +expected_output = """ +Exception caught: Test exception +Exception caught: Test exception +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "exception_handling3" +source_file = "cpp/simple/exceptions.cpp" +expected_output = """ +Exception caught: Test exception +Exception caught: Test exception +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "exception_handling4" +source_file = "cpp/simple/exceptions.cpp" +expected_output = """ +Exception caught: Test exception +Exception caught: Test exception +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "fact1" +source_file = "cpp/simple/fact.cpp" +expected_output = """ +3628800 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "fact2" +source_file = "cpp/simple/fact.cpp" +expected_output = """ +3628800 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "fact3" +source_file = "cpp/simple/fact.cpp" +expected_output = """ +3628800 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "fact4" +source_file = "cpp/simple/fact.cpp" +expected_output = """ +3628800 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "func1" +source_file = "cpp/simple/func.cpp" +expected_output = """ +Function f called (g incremented to 1) +Final value of g: 1 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "func2" +source_file = "cpp/simple/func.cpp" +expected_output = """ +Function f called (g incremented to 1) +Final value of g: 1 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "func3" +source_file = "cpp/simple/func.cpp" +expected_output = """ +Function f called (g incremented to 1) +Final value of g: 1 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "func4" +source_file = "cpp/simple/func.cpp" +expected_output = """ +Function f called (g incremented to 1) +Final value of g: 1 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "mul1" +source_file = "cpp/simple/mul.cpp" +expected_output = """ +42 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "mul2" +source_file = "cpp/simple/mul.cpp" +expected_output = """ +42 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "mul3" +source_file = "cpp/simple/mul.cpp" +expected_output = """ +42 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "mul4" +source_file = "cpp/simple/mul.cpp" +expected_output = """ +42 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "template1" +source_file = "cpp/simple/template.cpp" +expected_output = """ +Result: 42 +Result: 15 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "template2" +source_file = "cpp/simple/template.cpp" +expected_output = """ +Result: 42 +Result: 15 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "template3" +source_file = "cpp/simple/template.cpp" +expected_output = """ +Result: 42 +Result: 15 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "template4" +source_file = "cpp/simple/template.cpp" +expected_output = """ +Result: 42 +Result: 15 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "ptrsSharedUnique1" +source_file = "cpp/simple/ptr.cpp" +expected_output = """ +Value pointed by p1: 42, Value pointed by p2: 42 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "ptrsSharedUnique2" +source_file = "cpp/simple/ptr.cpp" +expected_output = """ +Value pointed by p1: 42, Value pointed by p2: 42 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "ptrsSharedUnique3" +source_file = "cpp/simple/ptr.cpp" +expected_output = """ +Value pointed by p1: 42, Value pointed by p2: 42 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "ptrsSharedUnique4" +source_file = "cpp/simple/ptr.cpp" +expected_output = """ +Value pointed by p1: 42, Value pointed by p2: 42 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "heap1" +source_file = "cpp/simple/heap.cpp" +expected_output = """ +Value: 10 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "heap2" +source_file = "cpp/simple/heap.cpp" +expected_output = """ +Value: 10 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "heap3" +source_file = "cpp/simple/heap.cpp" +expected_output = """ +Value: 10 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "heap4" +source_file = "cpp/simple/heap.cpp" +expected_output = """ +Value: 10 +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "raii_filehandler1" +source_file = "cpp/simple/file_handler.cpp" +expected_output = """ +Handler created +File closed +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "raii_filehandler2" +source_file = "cpp/simple/file_handler.cpp" +expected_output = """ +Handler created +File closed +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "raii_filehandler3" +source_file = "cpp/simple/file_handler.cpp" +expected_output = """ +Handler created +File closed +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "raii_filehandler4" +source_file = "cpp/simple/file_handler.cpp" +expected_output = """ +Handler created +File closed +""" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "inline_constexpr1" +source_file = "cpp/simple/inline_constexpr.cpp" +aspis_options = "--eddi --cfcss" +expected_output = """ +9 +16 +5 +""" + +[[tests]] +test_name = "inline_constexpr2" +source_file = "cpp/simple/inline_constexpr.cpp" +aspis_options = "--seddi --rasm" +expected_output = """ +9 +16 +5 +""" + +[[tests]] +test_name = "inline_constexpr3" +source_file = "cpp/simple/inline_constexpr.cpp" +aspis_options = "--fdsc --rasm" +expected_output = """ +9 +16 +5 +""" + +[[tests]] +test_name = "inline_constexpr4" +source_file = "cpp/simple/inline_constexpr.cpp" +aspis_options = "--eddi --no-cfc" +expected_output = """ +9 +16 +5 +""" + +[[tests]] +test_name = "lambda_captures1" +source_file = "cpp/simple/lambda_captures.cpp" +aspis_options = "--eddi --cfcss" +expected_output = """ +x incremented by 5 +Value pointed by p: 11 +""" + +[[tests]] +test_name = "lambda_captures2" +source_file = "cpp/simple/lambda_captures.cpp" +aspis_options = "--seddi --rasm" +expected_output = """ +x incremented by 5 +Value pointed by p: 11 +""" + +[[tests]] +test_name = "lambda_captures3" +source_file = "cpp/simple/lambda_captures.cpp" +aspis_options = "--fdsc --rasm" +expected_output = """ +x incremented by 5 +Value pointed by p: 11 +""" + +[[tests]] +test_name = "lambda_captures4" +source_file = "cpp/simple/lambda_captures.cpp" +aspis_options = "--eddi --no-cfc" +expected_output = """ +x incremented by 5 +Value pointed by p: 11 +""" + +[[tests]] +test_name = "volatile_memory_order1" +source_file = "cpp/simple/volatile_memory_order.cpp" +aspis_options = "--eddi --cfcss" +expected_output = """ +42 +""" + +[[tests]] +test_name = "volatile_memory_order2" +source_file = "cpp/simple/volatile_memory_order.cpp" +aspis_options = "--seddi --rasm" +expected_output = """ +42 +""" + +[[tests]] +test_name = "volatile_memory_order3" +source_file = "cpp/simple/volatile_memory_order.cpp" +aspis_options = "--fdsc --rasm" +expected_output = """ +42 +""" + +[[tests]] +test_name = "volatile_memory_order4" +source_file = "cpp/simple/volatile_memory_order.cpp" +aspis_options = "--eddi --no-cfc" +expected_output = """ +42 +""" + +[[tests]] +test_name = "stl_containers_advanced1" +source_file = "cpp/simple/stl_containers_advanced.cpp" +aspis_options = "--eddi --cfcss" +expected_output = """ +0 1 2 3 4 +""" + +[[tests]] +test_name = "stl_containers_advanced2" +source_file = "cpp/simple/stl_containers_advanced.cpp" +aspis_options = "--seddi --rasm" +expected_output = """ +0 1 2 3 4 +""" + +[[tests]] +test_name = "stl_containers_advanced3" +source_file = "cpp/simple/stl_containers_advanced.cpp" +aspis_options = "--fdsc --rasm" +expected_output = """ +0 1 2 3 4 +""" + +[[tests]] +test_name = "stl_containers_advanced4" +source_file = "cpp/simple/stl_containers_advanced.cpp" +aspis_options = "--eddi --no-cfc" +expected_output = """ +0 1 2 3 4 +""" + +# [[tests]] +# test_name = "threads1" +# source_file = "cpp/simple/threads.cpp" +# aspis_options = "--eddi --cfcss" +# expected_output = """ +# 4000 +# """ +# +# [[tests]] +# test_name = "threads2" +# source_file = "cpp/simple/threads.cpp" +# aspis_options = "--seddi --rasm" +# expected_output = """ +# 4000 +# """ +# +# [[tests]] +# test_name = "threads3" +# source_file = "cpp/simple/threads.cpp" +# aspis_options = "--fdsc --rasm" +# expected_output = """ +# 4000 +# """ +# +# [[tests]] +# test_name = "threads4" +# source_file = "cpp/simple/threads.cpp" +# aspis_options = "--eddi --no-cfc" +# expected_output = """ +# 4000 +# """ + +[[tests]] +test_name = "function_pointer_v0" +source_file = "c/control_flow/function_pointer.c" +expected_output = "42" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "function_pointer_v1" +source_file = "c/control_flow/function_pointer.c" +expected_output = "42" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "function_pointer_v2" +source_file = "c/control_flow/function_pointer.c" +expected_output = "42" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "function_pointer_v3" +source_file = "c/control_flow/function_pointer.c" +expected_output = "42" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "loop_exit_v0" +source_file = "c/control_flow/loop_exit.c" +expected_output = "2" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "loop_exit_v1" +source_file = "c/control_flow/loop_exit.c" +expected_output = "2" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "loop_exit_v2" +source_file = "c/control_flow/loop_exit.c" +expected_output = "2" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "loop_exit_v3" +source_file = "c/control_flow/loop_exit.c" +expected_output = "2" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "nested-branch_v0" +source_file = "c/control_flow/nested-branch.c" +expected_output = "6" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "nested-branch_v1" +source_file = "c/control_flow/nested-branch.c" +expected_output = "6" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "nested-branch_v2" +source_file = "c/control_flow/nested-branch.c" +expected_output = "6" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "nested-branch_v3" +source_file = "c/control_flow/nested-branch.c" +expected_output = "6" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "simple-branch_v0" +source_file = "c/control_flow/simple-branch.c" +expected_output = "OK" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "simple-branch_v1" +source_file = "c/control_flow/simple-branch.c" +expected_output = "OK" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "simple-branch_v2" +source_file = "c/control_flow/simple-branch.c" +expected_output = "OK" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "simple-branch_v3" +source_file = "c/control_flow/simple-branch.c" +expected_output = "OK" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "switch-case_v0" +source_file = "c/control_flow/switch-case.c" +expected_output = "300" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "switch-case_v1" +source_file = "c/control_flow/switch-case.c" +expected_output = "300" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "switch-case_v2" +source_file = "c/control_flow/switch-case.c" +expected_output = "300" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "switch-case_v3" +source_file = "c/control_flow/switch-case.c" +expected_output = "300" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "data_dep_branches_v0" +source_file = "c/data_duplication_integrity/data_dep_branches.c" +expected_output = "7" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "data_dep_branches_v1" +source_file = "c/data_duplication_integrity/data_dep_branches.c" +expected_output = "7" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "data_dep_branches_v2" +source_file = "c/data_duplication_integrity/data_dep_branches.c" +expected_output = "7" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "data_dep_branches_v3" +source_file = "c/data_duplication_integrity/data_dep_branches.c" +expected_output = "7" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "global_var_across_functions_v0" +source_file = "c/data_duplication_integrity/global_var_across_functions.c" +expected_output = "2" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "global_var_across_functions_v1" +source_file = "c/data_duplication_integrity/global_var_across_functions.c" +expected_output = "2" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "global_var_across_functions_v2" +source_file = "c/data_duplication_integrity/global_var_across_functions.c" +expected_output = "2" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "global_var_across_functions_v3" +source_file = "c/data_duplication_integrity/global_var_across_functions.c" +expected_output = "2" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "misc_data_dup_v0" +source_file = "c/data_duplication_integrity/misc_data_dup.c" +expected_output = "OK" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "misc_data_dup_v1" +source_file = "c/data_duplication_integrity/misc_data_dup.c" +expected_output = "OK" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "misc_data_dup_v2" +source_file = "c/data_duplication_integrity/misc_data_dup.c" +expected_output = "OK" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "misc_data_dup_v3" +source_file = "c/data_duplication_integrity/misc_data_dup.c" +expected_output = "OK" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "volatile_io_v0" +source_file = "c/data_duplication_integrity/volatile_io.c" +expected_output = "42" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "volatile_io_v1" +source_file = "c/data_duplication_integrity/volatile_io.c" +expected_output = "42" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "volatile_io_v2" +source_file = "c/data_duplication_integrity/volatile_io.c" +expected_output = "42" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "volatile_io_v3" +source_file = "c/data_duplication_integrity/volatile_io.c" +expected_output = "42" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "arit_pipeline_v0" +source_file = "c/misc_math/arit_pipeline.c" +expected_output = "3" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "arit_pipeline_v1" +source_file = "c/misc_math/arit_pipeline.c" +expected_output = "3" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "arit_pipeline_v2" +source_file = "c/misc_math/arit_pipeline.c" +expected_output = "3" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "arit_pipeline_v3" +source_file = "c/misc_math/arit_pipeline.c" +expected_output = "3" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "mixed_ops_v0" +source_file = "c/misc_math/mixed_ops.c" +expected_output = "14.5" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "mixed_ops_v1" +source_file = "c/misc_math/mixed_ops.c" +expected_output = "14.5" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "mixed_ops_v2" +source_file = "c/misc_math/mixed_ops.c" +expected_output = "14.5" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "mixed_ops_v3" +source_file = "c/misc_math/mixed_ops.c" +expected_output = "14.5" +aspis_options = "--eddi --no-cfc" + +[[tests]] +test_name = "xor_cypher_v0" +source_file = "c/misc_math/xor_cypher.c" +expected_output = "SUCCESS" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "xor_cypher_v1" +source_file = "c/misc_math/xor_cypher.c" +expected_output = "SUCCESS" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "xor_cypher_v2" +source_file = "c/misc_math/xor_cypher.c" +expected_output = "SUCCESS" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "xor_cypher_v3" +source_file = "c/misc_math/xor_cypher.c" +expected_output = "SUCCESS" +aspis_options = "--eddi --no-cfc" + +# -------------------------------------------------------------------------------------------- +# The following tests have been developed for the project: 'Harden a C Application with ASPIS' +# All the codes tested here can be found in the repository: testing/tests/c/extended +# -------------------------------------------------------------------------------------------- + +# --------------------------------------------------------------------------- +# 1 - struct_player +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "struct_player_v0" +source_file = "c/extended/struct_player.c" +expected_output = """ +SCORE: 95 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "struct_player_v1" +source_file = "c/extended/struct_player.c" +expected_output = """ +SCORE: 95 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "struct_player_v2" +source_file = "c/extended/struct_player.c" +expected_output = """ +SCORE: 95 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "struct_player_v3" +source_file = "c/extended/struct_player.c" +expected_output = """ +SCORE: 95 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 2 - array2d_sum +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "array2d_sum_v0" +source_file = "c/extended/array2d_sum.c" +expected_output = """ +SUM: 45 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "array2d_sum_v1" +source_file = "c/extended/array2d_sum.c" +expected_output = """ +SUM: 45 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "array2d_sum_v2" +source_file = "c/extended/array2d_sum.c" +expected_output = """ +SUM: 45 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "array2d_sum_v3" +source_file = "c/extended/array2d_sum.c" +expected_output = """ +SUM: 45 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 3 - ptr_to_ptr +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "ptr_to_ptr_v0" +source_file = "c/extended/ptr_to_ptr.c" +expected_output = """ +VAL: 12 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "ptr_to_ptr_v1" +source_file = "c/extended/ptr_to_ptr.c" +expected_output = """ +VAL: 12 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "ptr_to_ptr_v2" +source_file = "c/extended/ptr_to_ptr.c" +expected_output = """ +VAL: 12 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "ptr_to_ptr_v3" +source_file = "c/extended/ptr_to_ptr.c" +expected_output = """ +VAL: 12 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 4 - recursion_factorial +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "recursion_factorial_v0" +source_file = "c/extended/recursion_factorial.c" +expected_output = """ +FACT: 120 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "recursion_factorial_v1" +source_file = "c/extended/recursion_factorial.c" +expected_output = """ +FACT: 120 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "recursion_factorial_v2" +source_file = "c/extended/recursion_factorial.c" +expected_output = """ +FACT: 120 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "recursion_factorial_v3" +source_file = "c/extended/recursion_factorial.c" +expected_output = """ +FACT: 120 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 5 - heap_dynamic +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "heap_dynamic_v0" +source_file = "c/extended/heap_dynamic.c" +expected_output = """ +SUM: 30 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "heap_dynamic_v1" +source_file = "c/extended/heap_dynamic.c" +expected_output = """ +SUM: 30 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "heap_dynamic_v2" +source_file = "c/extended/heap_dynamic.c" +expected_output = """ +SUM: 30 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "heap_dynamic_v3" +source_file = "c/extended/heap_dynamic.c" +expected_output = """ +SUM: 30 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 6 - funptr_static_map +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_static_map_v0" +source_file = "c/extended/funptr_static_map.c" +expected_output = """ +checksum=2113704757 +sentinels=-4 -3 10 11 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_static_map_v1" +source_file = "c/extended/funptr_static_map.c" +expected_output = """ +checksum=2113704757 +sentinels=-4 -3 10 11 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_static_map_v2" +source_file = "c/extended/funptr_static_map.c" +expected_output = """ +checksum=2113704757 +sentinels=-4 -3 10 11 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_static_map_v3" +source_file = "c/extended/funptr_static_map.c" +expected_output = """ +checksum=2113704757 +sentinels=-4 -3 10 11 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 7 - funptr_heap_minimal +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_heap_minimal_v0" +source_file = "c/extended/funptr_heap_minimal.c" +expected_output = """ +checksum=1649235461 +sentinels=-2 -88 62 112 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_heap_minimal_v1" +source_file = "c/extended/funptr_heap_minimal.c" +expected_output = """ +checksum=1649235461 +sentinels=-2 -88 62 112 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_heap_minimal_v2" +source_file = "c/extended/funptr_heap_minimal.c" +expected_output = """ +checksum=1649235461 +sentinels=-2 -88 62 112 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_heap_minimal_v3" +source_file = "c/extended/funptr_heap_minimal.c" +expected_output = """ +checksum=1649235461 +sentinels=-2 -88 62 112 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 8 - funptr_heap_alias +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_heap_alias_v0" +source_file = "c/extended/funptr_heap_alias.c" +expected_output = """ +checksum=1158918729 +sentinels=1 3 26 30 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_heap_alias_v1" +source_file = "c/extended/funptr_heap_alias.c" +expected_output = """ +checksum=1158918729 +sentinels=1 3 26 30 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_heap_alias_v2" +source_file = "c/extended/funptr_heap_alias.c" +expected_output = """ +checksum=1158918729 +sentinels=1 3 26 30 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_heap_alias_v3" +source_file = "c/extended/funptr_heap_alias.c" +expected_output = """ +checksum=1158918729 +sentinels=1 3 26 30 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 9 - funptr_table_runtime +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_table_runtime_v0" +source_file = "c/extended/funptr_table_runtime.c" +expected_output = """ +checksum=3171147141 +sentinels=1 2 8 9 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_table_runtime_v1" +source_file = "c/extended/funptr_table_runtime.c" +expected_output = """ +checksum=3171147141 +sentinels=1 2 8 9 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_table_runtime_v2" +source_file = "c/extended/funptr_table_runtime.c" +expected_output = """ +checksum=3171147141 +sentinels=1 2 8 9 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_table_runtime_v3" +source_file = "c/extended/funptr_table_runtime.c" +expected_output = """ +checksum=3171147141 +sentinels=1 2 8 9 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 10 - funptr_factory_return +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_factory_return_v0" +source_file = "c/extended/funptr_factory_return.c" +expected_output = """ +checksum=2249736000 +sentinels=-3 4 67 74 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_factory_return_v1" +source_file = "c/extended/funptr_factory_return.c" +expected_output = """ +checksum=2249736000 +sentinels=-3 4 67 74 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_factory_return_v2" +source_file = "c/extended/funptr_factory_return.c" +expected_output = """ +checksum=2249736000 +sentinels=-3 4 67 74 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_factory_return_v3" +source_file = "c/extended/funptr_factory_return.c" +expected_output = """ +checksum=2249736000 +sentinels=-3 4 67 74 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 11 - funptr_qsort_callback +# NOTE: data-flow protection crashes at runtime (segfault) when callback is +# invoked from external uninstrumented library code (qsort). +# -> control-flow-only variants are stable. +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_qsort_callback_v0" +source_file = "c/extended/funptr_qsort_callback.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +""" +aspis_options = "--no-dup --cfcss" + +[[tests]] +test_name = "funptr_qsort_callback_v1" +source_file = "c/extended/funptr_qsort_callback.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +""" +aspis_options = "--no-dup --rasm" + +# --------------------------------------------------------------------------- +# 11b - funptr_qsort_callback_mitigation +# NOTE: callback annotated exclude -> stable even with data-flow protection. +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_qsort_callback_mitigation_v0" +source_file = "c/extended/funptr_qsort_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_qsort_callback_mitigation_v1" +source_file = "c/extended/funptr_qsort_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_qsort_callback_mitigation_v2" +source_file = "c/extended/funptr_qsort_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_qsort_callback_mitigation_v3" +source_file = "c/extended/funptr_qsort_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 12 - funptr_bsearch_callback +# NOTE: same “external callback” boundary observed with bsearch. +# Only control-flow-only variants are stable. +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_bsearch_callback_v0" +source_file = "c/extended/funptr_bsearch_callback.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +found=6 idx=6 +""" +aspis_options = "--no-dup --cfcss" + +[[tests]] +test_name = "funptr_bsearch_callback_v1" +source_file = "c/extended/funptr_bsearch_callback.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +found=6 idx=6 +""" +aspis_options = "--no-dup --rasm" + +# --------------------------------------------------------------------------- +# 12b - funptr_bsearch_callback_mitigation +# NOTE: callback annotated exclude -> stable even with data-flow protection. +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "funptr_bsearch_callback_mitigation_v0" +source_file = "c/extended/funptr_bsearch_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +found=6 idx=6 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "funptr_bsearch_callback_mitigation_v1" +source_file = "c/extended/funptr_bsearch_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +found=6 idx=6 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "funptr_bsearch_callback_mitigation_v2" +source_file = "c/extended/funptr_bsearch_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +found=6 idx=6 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "funptr_bsearch_callback_mitigation_v3" +source_file = "c/extended/funptr_bsearch_callback_mitigation.c" +expected_output = """ +checksum=797261938 +sentinels=0 1 8 9 +found=6 idx=6 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 13 - pthread_entry_callback +# NOTE: entry-point invoked by external runtime (libpthread) -> segfault +# --------------------------------------------------------------------------- +# +# [[tests]] +# test_name = "pthread_entry_callback_v0" +# source_file = "c/extended/pthread_entry_callback.c" +# expected_output = "EXPECTED_FAIL: segfault at runtime (external entry-point + data-flow)" +# aspis_options = "--eddi --cfcss" +# +# [[tests]] +# test_name = "pthread_entry_callback_v1" +# source_file = "c/extended/pthread_entry_callback.c" +# expected_output = "EXPECTED_FAIL: segfault at runtime (external entry-point + data-flow)" +# aspis_options = "--seddi --rasm" +# +# [[tests]] +# test_name = "pthread_entry_callback_v2" +# source_file = "c/extended/pthread_entry_callback.c" +# expected_output = "EXPECTED_FAIL: segfault at runtime (external entry-point + data-flow)" +# aspis_options = "--fdsc --rasm" +# +# [[tests]] +# test_name = "pthread_entry_callback_v3" +# source_file = "c/extended/pthread_entry_callback.c" +# expected_output = "EXPECTED_FAIL: segfault at runtime (external entry-point + data-flow)" +# aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 13b - pthread_entry_callback_mitigation +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "pthread_entry_callback_mitigation_v0" +source_file = "c/extended/pthread_entry_callback_mitigation.c" +expected_output = """ +checksum=260243592 +sentinels=1 3 13 15 +""" +aspis_options = "--eddi --cfcss -pthread" + +[[tests]] +test_name = "pthread_entry_callback_mitigation_v1" +source_file = "c/extended/pthread_entry_callback_mitigation.c" +expected_output = """ +checksum=260243592 +sentinels=1 3 13 15 +""" +aspis_options = "--seddi --rasm -pthread" + +[[tests]] +test_name = "pthread_entry_callback_mitigation_v2" +source_file = "c/extended/pthread_entry_callback_mitigation.c" +expected_output = """ +checksum=260243592 +sentinels=1 3 13 15 +""" +aspis_options = "--fdsc --rasm -pthread" + +[[tests]] +test_name = "pthread_entry_callback_mitigation_v3" +source_file = "c/extended/pthread_entry_callback_mitigation.c" +expected_output = """ +checksum=260243592 +sentinels=1 3 13 15 +""" +aspis_options = "--eddi --no-cfc -pthread" + +# --------------------------------------------------------------------------- +# 14 - varargs_sum +# NOTE: hardening fails at compile-time (invalid LLVM IR) with data-flow passes. +# --------------------------------------------------------------------------- +# +# [[tests]] +# test_name = "varargs_sum_v0" +# source_file = "c/extended/varargs_sum.c" +# expected_output = "EXPECTED_FAIL: compile-time (LLVM verifier error on varargs signature)" +# aspis_options = "--eddi --cfcss" +# +# [[tests]] +# test_name = "varargs_sum_v1" +# source_file = "c/extended/varargs_sum.c" +# expected_output = "EXPECTED_FAIL: compile-time (LLVM verifier error on varargs signature)" +# aspis_options = "--seddi --rasm" +# +# [[tests]] +# test_name = "varargs_sum_v2" +# source_file = "c/extended/varargs_sum.c" +# expected_output = "EXPECTED_FAIL: compile-time (LLVM verifier error on varargs signature)" +# aspis_options = "--fdsc --rasm" +# +# [[tests]] +# test_name = "varargs_sum_v3" +# source_file = "c/extended/varargs_sum.c" +# expected_output = "EXPECTED_FAIL: compile-time (LLVM verifier error on varargs signature)" +# aspis_options = "--eddi --no-cfc" +# +# --------------------------------------------------------------------------- +# 15 - bitfield_packet +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "bitfield_packet_v0" +source_file = "c/extended/bitfield_packet.c" +expected_output = """ +checksum=3739283678 +sentinels=0 22 1215 1430 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "bitfield_packet_v1" +source_file = "c/extended/bitfield_packet.c" +expected_output = """ +checksum=3739283678 +sentinels=0 22 1215 1430 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "bitfield_packet_v2" +source_file = "c/extended/bitfield_packet.c" +expected_output = """ +checksum=3739283678 +sentinels=0 22 1215 1430 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "bitfield_packet_v3" +source_file = "c/extended/bitfield_packet.c" +expected_output = """ +checksum=3739283678 +sentinels=0 22 1215 1430 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 16 - memcpy_struct_bulk +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "memcpy_struct_bulk_v0" +source_file = "c/extended/memcpy_struct_bulk.c" +expected_output = """ +checksum=1467585440 +sentinels=3 10 89 81 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "memcpy_struct_bulk_v1" +source_file = "c/extended/memcpy_struct_bulk.c" +expected_output = """ +checksum=1467585440 +sentinels=3 10 89 81 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "memcpy_struct_bulk_v2" +source_file = "c/extended/memcpy_struct_bulk.c" +expected_output = """ +checksum=1467585440 +sentinels=3 10 89 81 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "memcpy_struct_bulk_v3" +source_file = "c/extended/memcpy_struct_bulk.c" +expected_output = """ +checksum=1467585440 +sentinels=3 10 89 81 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 17 - signal_flag_handler +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "signal_flag_handler_v0" +source_file = "c/extended/signal_flag_handler.c" +expected_output = """ +checksum=839387125 +sentinels=93 81 89 93 +got_signal=1 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "signal_flag_handler_v1" +source_file = "c/extended/signal_flag_handler.c" +expected_output = """ +checksum=839387125 +sentinels=93 81 89 93 +got_signal=1 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "signal_flag_handler_v2" +source_file = "c/extended/signal_flag_handler.c" +expected_output = """ +checksum=839387125 +sentinels=93 81 89 93 +got_signal=1 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "signal_flag_handler_v3" +source_file = "c/extended/signal_flag_handler.c" +expected_output = """ +checksum=839387125 +sentinels=93 81 89 93 +got_signal=1 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 18 - signal_loop_break_volatile +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "signal_loop_break_volatile_v0" +source_file = "c/extended/signal_loop_break_volatile.c" +expected_output = """ +checksum=2911428346 +sentinels=1592477752 4188842368 145946737 927160124 +stop_flag=1 iters=201 tick=579148290 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "signal_loop_break_volatile_v1" +source_file = "c/extended/signal_loop_break_volatile.c" +expected_output = """ +checksum=2911428346 +sentinels=1592477752 4188842368 145946737 927160124 +stop_flag=1 iters=201 tick=579148290 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "signal_loop_break_volatile_v2" +source_file = "c/extended/signal_loop_break_volatile.c" +expected_output = """ +checksum=2911428346 +sentinels=1592477752 4188842368 145946737 927160124 +stop_flag=1 iters=201 tick=579148290 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "signal_loop_break_volatile_v3" +source_file = "c/extended/signal_loop_break_volatile.c" +expected_output = """ +checksum=2911428346 +sentinels=1592477752 4188842368 145946737 927160124 +stop_flag=1 iters=201 tick=579148290 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 19 - atomic_fetch_add +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "atomic_fetch_add_v0" +source_file = "c/extended/atomic_fetch_add.c" +expected_output = """ +checksum=2887388389 +sentinels=2931447553 1951191220 2572826555 1131159742 +ctr=10000 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "atomic_fetch_add_v1" +source_file = "c/extended/atomic_fetch_add.c" +expected_output = """ +checksum=2887388389 +sentinels=2931447553 1951191220 2572826555 1131159742 +ctr=10000 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "atomic_fetch_add_v2" +source_file = "c/extended/atomic_fetch_add.c" +expected_output = """ +checksum=2887388389 +sentinels=2931447553 1951191220 2572826555 1131159742 +ctr=10000 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "atomic_fetch_add_v3" +source_file = "c/extended/atomic_fetch_add.c" +expected_output = """ +checksum=2887388389 +sentinels=2931447553 1951191220 2572826555 1131159742 +ctr=10000 +""" +aspis_options = "--eddi --no-cfc" + +# --------------------------------------------------------------------------- +# 20 - mega_ok_domain +# --------------------------------------------------------------------------- + +[[tests]] +test_name = "mega_ok_domain_v0" +source_file = "c/extended/mega_ok_domain.c" +expected_output = """ +checksum=3577851111 +sentinels=1 8 2654436132 2654436026 +facts=3628800 s2d=325 diag=15->25 got_signal=1 iters=201 +""" +aspis_options = "--eddi --cfcss" + +[[tests]] +test_name = "mega_ok_domain_v1" +source_file = "c/extended/mega_ok_domain.c" +expected_output = """ +checksum=3577851111 +sentinels=1 8 2654436132 2654436026 +facts=3628800 s2d=325 diag=15->25 got_signal=1 iters=201 +""" +aspis_options = "--seddi --rasm" + +[[tests]] +test_name = "mega_ok_domain_v2" +source_file = "c/extended/mega_ok_domain.c" +expected_output = """ +checksum=3577851111 +sentinels=1 8 2654436132 2654436026 +facts=3628800 s2d=325 diag=15->25 got_signal=1 iters=201 +""" +aspis_options = "--fdsc --rasm" + +[[tests]] +test_name = "mega_ok_domain_v3" +source_file = "c/extended/mega_ok_domain.c" +expected_output = """ +checksum=3577851111 +sentinels=1 8 2654436132 2654436026 +facts=3628800 s2d=325 diag=15->25 got_signal=1 iters=201 +""" +aspis_options = "--eddi --no-cfc" diff --git a/testing/tests/c/extended/array2d_sum.c b/testing/tests/c/extended/array2d_sum.c new file mode 100644 index 0000000..28cbab9 --- /dev/null +++ b/testing/tests/c/extended/array2d_sum.c @@ -0,0 +1,20 @@ +#include + +int sum2d(int m[3][3]) { + int s = 0; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + s += m[i][j]; + return s; +} + +int main(void) { + int m[3][3] = { + {1,2,3}, + {4,5,6}, + {7,8,9} + }; + int r = sum2d(m); + printf("SUM: %d\n", r); + return 0; +} diff --git a/testing/tests/c/extended/atomic_fetch_add.c b/testing/tests/c/extended/atomic_fetch_add.c new file mode 100644 index 0000000..40107ac --- /dev/null +++ b/testing/tests/c/extended/atomic_fetch_add.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +static uint32_t checksum_u32(const uint32_t *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= a[i]; + h *= 16777619u; + } + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const size_t N = 64; + + uint32_t *buf = (uint32_t *)dup_malloc(N * sizeof(uint32_t)); + if (!buf) return 1; + + for (size_t i = 0; i < N; i++) + buf[i] = (uint32_t)(i * 3u + 1u); + + _Atomic uint32_t ctr = 0; + + for (uint32_t i = 0; i < 10000; i++) { + uint32_t v = atomic_fetch_add_explicit(&ctr, 1u, memory_order_relaxed); + size_t idx = (size_t)(v % N); + buf[idx] ^= (v * 2654435761u) ^ (uint32_t)idx; + } + + uint32_t cs = checksum_u32(buf, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%u %u %u %u\n", buf[0], buf[1], buf[N-2], buf[N-1]); + printf("ctr=%u\n", atomic_load_explicit(&ctr, memory_order_relaxed)); + + dup_free(buf); + return 0; +} diff --git a/testing/tests/c/extended/bitfield_packet.c b/testing/tests/c/extended/bitfield_packet.c new file mode 100644 index 0000000..ecee22a --- /dev/null +++ b/testing/tests/c/extended/bitfield_packet.c @@ -0,0 +1,68 @@ +#include +#include +#include + +typedef enum { + MSG_DATA = 0, + MSG_ACK = 1, + MSG_ERR = 2 +} MsgType; + +typedef struct { + uint32_t type : 2; + uint32_t flags : 6; + uint32_t seq : 12; + uint32_t len : 12; +} PacketHdr; + +static void update(PacketHdr *h, int step) { + h->flags ^= (uint32_t)(1u << (step & 5)); + h->seq = (h->seq + 17u + (uint32_t)step) & 0xFFFu; + if (h->type == MSG_DATA && h->len < 3000u) { + h->len += 123u; + } else { + h->len = (h->len ^ 0x155u) & 0xFFFu; + } +} + +static uint32_t checksum_hdr(const PacketHdr *h) { + uint32_t x = 2166136261u; + x = (x ^ h->type) * 16777619u; + x = (x ^ h->flags) * 16777619u; + x = (x ^ h->seq) * 16777619u; + x = (x ^ h->len) * 16777619u; + return x; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + PacketHdr *h = (PacketHdr *)dup_malloc(sizeof(PacketHdr)); + if (!h) return 1; + + h->type = MSG_DATA; + h->flags = 0x15u; + h->seq = 1000u; + h->len = 200u; + + for (int i = 0; i < 10; i++) { + update(h, i); + } + + uint32_t cs = checksum_hdr(h); + + printf("checksum=%u\n", cs); + printf("sentinels=%u %u %u %u\n", + (unsigned)h->type, (unsigned)h->flags, (unsigned)h->seq, (unsigned)h->len); + + dup_free(h); + return 0; +} diff --git a/testing/tests/c/extended/funptr_bsearch_callback.c b/testing/tests/c/extended/funptr_bsearch_callback.c new file mode 100644 index 0000000..b3e7d71 --- /dev/null +++ b/testing/tests/c/extended/funptr_bsearch_callback.c @@ -0,0 +1,45 @@ +#include +#include +#include + +static int cmp_int(const void *a, const void *b) { + int x = *(const int *)a; + int y = *(const int *)b; + return (x > y) - (x < y); +} + +static uint32_t checksum_u32(const int *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +int main(void) { + const size_t N = 10; + int *arr = malloc(N * sizeof(int)); + if (!arr) return 1; + + /* Array già ordinato: evitiamo qsort apposta */ + for (size_t i = 0; i < N; i++) + arr[i] = (int)i; /* 0..9 */ + + int key = 6; + int *found = bsearch(&key, arr, N, sizeof(int), cmp_int); + + uint32_t cs = checksum_u32(arr, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", arr[0], arr[1], arr[N-2], arr[N-1]); + + if (found) { + printf("found=%d idx=%ld\n", *found, (long)(found - arr)); + } else { + printf("found=-1 idx=-1\n"); + } + + free(arr); + return 0; +} diff --git a/testing/tests/c/extended/funptr_bsearch_callback_mitigation.c b/testing/tests/c/extended/funptr_bsearch_callback_mitigation.c new file mode 100644 index 0000000..3652d57 --- /dev/null +++ b/testing/tests/c/extended/funptr_bsearch_callback_mitigation.c @@ -0,0 +1,45 @@ +#include +#include +#include + +__attribute__((annotate("exclude"))) +static int cmp_int(const void *a, const void *b) { + int x = *(const int *)a; + int y = *(const int *)b; + return (x > y) - (x < y); +} + +static uint32_t checksum_u32(const int *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +int main(void) { + const size_t N = 10; + int *arr = malloc(N * sizeof(int)); + if (!arr) return 1; + + for (size_t i = 0; i < N; i++) + arr[i] = (int)i; + + int key = 6; + int *found = bsearch(&key, arr, N, sizeof(int), cmp_int); + + uint32_t cs = checksum_u32(arr, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", arr[0], arr[1], arr[N-2], arr[N-1]); + + if (found) { + printf("found=%d idx=%ld\n", *found, (long)(found - arr)); + } else { + printf("found=-1 idx=-1\n"); + } + + free(arr); + return 0; +} diff --git a/testing/tests/c/extended/funptr_factory_return.c b/testing/tests/c/extended/funptr_factory_return.c new file mode 100644 index 0000000..f5cf0f1 --- /dev/null +++ b/testing/tests/c/extended/funptr_factory_return.c @@ -0,0 +1,66 @@ +#include +#include +#include + +typedef void (*op_t)(int *p, size_t n); + +static void op_add(int *p, size_t n) { + for(size_t i = 0; i < n; i++) p[i] += (int)(i + 1); +} +static void op_xor(int *p, size_t n) { + for(size_t i = 0; i < n; i++) p[i] ^= (int)(0x5A + (int)i); +} +static void op_mix(int *p, size_t n) { + for(size_t i = 0; i < n; i++) p[i] = (p[i] * 3) - (int)i; +} + +static op_t pick_op(uint32_t key) { + switch(key % 3u) { + case 0u: return &op_add; + case 1u: return &op_xor; + default: return &op_mix; + } +} + +static uint32_t checksum_u32(const int *a, size_t n) { + uint32_t h = 2166136261u; + for(size_t i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const size_t N = 12; + int *buf = (int*)dup_malloc(N * sizeof(int)); + if(!buf) return 1; + + for(size_t i = 0; i < N; i++) buf[i] = (int)(i * 7) - 3; + + int *alias = buf + 2; + const size_t M = 6; + + uint32_t key = (uint32_t)(buf[1] * 31 + buf[4] * 17 + (int)N); + + op_t f = pick_op(key); + f(alias, M); + + uint32_t cs = checksum_u32(buf, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", buf[0], buf[1], buf[N-2], buf[N-1]); + + dup_free(buf); + return 0; +} diff --git a/testing/tests/c/extended/funptr_heap_alias.c b/testing/tests/c/extended/funptr_heap_alias.c new file mode 100644 index 0000000..d18af41 --- /dev/null +++ b/testing/tests/c/extended/funptr_heap_alias.c @@ -0,0 +1,60 @@ +#include +#include +#include + +typedef void (*op_fn)(int *p, int n); + +void add_seq(int *p, int n) { + for (int i = 0; i < n; i++) + p[i] += i; +} + +void scale_seq(int *p, int n) { + for (int i = 0; i < n; i++) + p[i] *= 2; +} + +uint32_t checksum(int *p, int n) { + uint32_t h = 0; + for (int i = 0; i < n; i++) + h = (h * 33) ^ (uint32_t)p[i]; + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const int N = 8; + + int *buf = dup_malloc(N * sizeof(int)); + if (!buf) return 1; + + for (int i = 0; i < N; i++) + buf[i] = i + 1; + + int *alias1 = buf; + int *alias2 = buf + 3; + + op_fn f1 = add_seq; + op_fn f2 = scale_seq; + + f1(alias1, N); + f2(alias2, N - 3); + + uint32_t h = checksum(buf, N); + + printf("checksum=%u\n", h); + printf("sentinels=%d %d %d %d\n", + buf[0], buf[1], buf[6], buf[7]); + + dup_free(buf); + return 0; +} diff --git a/testing/tests/c/extended/funptr_heap_minimal.c b/testing/tests/c/extended/funptr_heap_minimal.c new file mode 100644 index 0000000..0d83278 --- /dev/null +++ b/testing/tests/c/extended/funptr_heap_minimal.c @@ -0,0 +1,60 @@ +#include +#include +#include + +typedef int (*op_fn)(int); + +static int op_add3(int x) { return x + 3; } +static int op_xor55(int x) { return x ^ 0x55; } +static int op_mul7(int x) { return x * 7; } +static int op_sub9(int x) { return x - 9; } + +static uint32_t mix_u32(uint32_t h, uint32_t x) { + h ^= x + 0x9e3779b9u + (h << 6) + (h >> 2); + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const size_t N = 64; + + int *a = (int*)dup_malloc(N * sizeof(int)); + if(!a) { + fprintf(stderr, "malloc failed\n"); + return 1; + } + + for(size_t i = 0; i < N; i++) { + a[i] = (int)(i * 2) - 5; + } + + op_fn ops[4] = { op_add3, op_xor55, op_mul7, op_sub9 }; + + uint32_t checksum = 0x12345678u; + + for(size_t i = 0; i < N; i++) { + op_fn f = ops[i & 3u]; + a[i] = f(a[i]); + checksum = mix_u32(checksum, (uint32_t)a[i]); + } + + int s0 = a[0]; + int s1 = a[1]; + int s2 = a[N/2]; + int s3 = a[N-1]; + + dup_free(a); + + printf("checksum=%u\n", checksum); + printf("sentinels=%d %d %d %d\n", s0, s1, s2, s3); + return 0; +} diff --git a/testing/tests/c/extended/funptr_qsort_callback.c b/testing/tests/c/extended/funptr_qsort_callback.c new file mode 100644 index 0000000..84d58fd --- /dev/null +++ b/testing/tests/c/extended/funptr_qsort_callback.c @@ -0,0 +1,41 @@ +#include +#include +#include + +static int cmp_int(const void *a, const void *b) { + int x = *(const int *)a; + int y = *(const int *)b; + return (x > y) - (x < y); +} + +static uint32_t checksum_u32(const int *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +int main(void) { + const size_t N = 10; + int *arr = malloc(N * sizeof(int)); + if (!arr) return 1; + + /* inizializzazione volutamente non ordinata */ + int init[10] = {7, 1, 9, 3, 5, 0, 8, 2, 6, 4}; + for (size_t i = 0; i < N; i++) + arr[i] = init[i]; + + /* NOVITÀ: callback a funzione di libreria */ + qsort(arr, N, sizeof(int), cmp_int); + + uint32_t cs = checksum_u32(arr, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", + arr[0], arr[1], arr[N-2], arr[N-1]); + + free(arr); + return 0; +} diff --git a/testing/tests/c/extended/funptr_qsort_callback_mitigation.c b/testing/tests/c/extended/funptr_qsort_callback_mitigation.c new file mode 100644 index 0000000..4b0fe4f --- /dev/null +++ b/testing/tests/c/extended/funptr_qsort_callback_mitigation.c @@ -0,0 +1,40 @@ +#include +#include +#include + +__attribute__((annotate("exclude"))) +static int cmp_int(const void *a, const void *b) { + int x = *(const int *)a; + int y = *(const int *)b; + return (x > y) - (x < y); +} + +static uint32_t checksum_u32(const int *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +int main(void) { + const size_t N = 10; + int *arr = malloc(N * sizeof(int)); + if (!arr) return 1; + + int init[10] = {7, 1, 9, 3, 5, 0, 8, 2, 6, 4}; + for (size_t i = 0; i < N; i++) + arr[i] = init[i]; + + qsort(arr, N, sizeof(int), cmp_int); + + uint32_t cs = checksum_u32(arr, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", + arr[0], arr[1], arr[N-2], arr[N-1]); + + free(arr); + return 0; +} diff --git a/testing/tests/c/extended/funptr_static_map.c b/testing/tests/c/extended/funptr_static_map.c new file mode 100644 index 0000000..0281b83 --- /dev/null +++ b/testing/tests/c/extended/funptr_static_map.c @@ -0,0 +1,41 @@ +// funptr_static_map.c +#include +#include + +static int inc(int x) { return x + 1; } +static int mul3(int x) { return x * 3; } + +static uint32_t checksum_ints(const int *a, int n) { + uint32_t h = 2166136261u; // FNV-ish semplice + for(int i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +static void apply(int *a, int n, int (*op)(int)) { + for(int i = 0; i < n; i++) { + a[i] = op(a[i]); // <-- NOVITÀ: chiamata indiretta via function pointer + } +} + +int main(void) { + const int N = 16; + int a[N]; + + // init deterministico + for(int i = 0; i < N; i++) a[i] = i - 5; + + // scegliamo l'operazione in modo deterministico (niente input, niente random) + int (*op)(int) = (N % 2 == 0) ? inc : mul3; + + apply(a, N, op); + + // output stabile: stampa checksum + 4 sentinelle + uint32_t h = checksum_ints(a, N); + printf("checksum=%u\n", h); + printf("sentinels=%d %d %d %d\n", a[0], a[1], a[N-2], a[N-1]); + + return 0; +} diff --git a/testing/tests/c/extended/funptr_table_runtime.c b/testing/tests/c/extended/funptr_table_runtime.c new file mode 100644 index 0000000..3646438 --- /dev/null +++ b/testing/tests/c/extended/funptr_table_runtime.c @@ -0,0 +1,61 @@ +#include +#include +#include + +typedef void (*op_fn)(int *p, int n); + +void op_add(int *p, int n) { + for (int i = 0; i < n; i++) p[i] += 1; +} + +void op_scale(int *p, int n) { + for (int i = 0; i < n; i++) p[i] *= 2; +} + +void op_xor(int *p, int n) { + for (int i = 0; i < n; i++) p[i] ^= 0x5A; +} + +static uint32_t checksum(const int *p, int n) { + uint32_t h = 2166136261u; + for (int i = 0; i < n; i++) { + h ^= (uint32_t)p[i]; + h *= 16777619u; + } + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const int N = 8; + int *buf = dup_malloc(N * sizeof(int)); + if (!buf) return 1; + + for (int i = 0; i < N; i++) buf[i] = i + 1; + + int *alias = buf + 2; + + op_fn table[3] = { op_add, op_scale, op_xor }; + + int idx = (buf[0] + buf[1]) % 3; + + op_fn f = table[idx]; + f(alias, N - 2); + + uint32_t h = checksum(buf, N); + + printf("checksum=%u\n", h); + printf("sentinels=%d %d %d %d\n", buf[0], buf[1], buf[N-2], buf[N-1]); + + dup_free(buf); + return 0; +} diff --git a/testing/tests/c/extended/heap_dynamic.c b/testing/tests/c/extended/heap_dynamic.c new file mode 100644 index 0000000..8a8d9ab --- /dev/null +++ b/testing/tests/c/extended/heap_dynamic.c @@ -0,0 +1,27 @@ +#include +#include + +__attribute__((annotate("to_duplicate"))) +static void *dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void *p) { + free(p); +} + +int main(void) { + int *v = dup_malloc(5 * sizeof(int)); + for (int i = 0; i < 5; i++) + v[i] = i * 3; + + int sum = 0; + for (int i = 0; i < 5; i++) + sum += v[i]; + + dup_free(v); + + printf("SUM: %d\n", sum); + return 0; +} diff --git a/testing/tests/c/extended/mega_ok_domain.c b/testing/tests/c/extended/mega_ok_domain.c new file mode 100644 index 0000000..e837e67 --- /dev/null +++ b/testing/tests/c/extended/mega_ok_domain.c @@ -0,0 +1,242 @@ +#include +#include +#include +#include +#include +#include + +/* ---------------- checksum helper (FNV-1a like) ---------------- */ +static uint32_t fnv1a_u32(uint32_t h, uint32_t x) { + h ^= x; + h *= 16777619u; + return h; +} +static uint32_t hash_mix_u32(uint32_t h, const uint32_t *a, size_t n) { + for(size_t i = 0; i < n; i++) h = fnv1a_u32(h, a[i]); + return h; +} + +/* ---------------- recursion (known OK) ---------------- */ +static int factorial(int n) { + if(n < 0) return -1; + if(n == 0 || n == 1) return 1; + return n * factorial(n - 1); +} + +/* ---------------- 2D array (known OK) ---------------- */ +static int sum2d_5(int a[5][5]) { + int s = 0; + for(int i = 0; i < 5; i++) + for(int j = 0; j < 5; j++) + s += a[i][j]; + return s; +} + +/* ---------------- ptr-to-ptr (known OK) ---------------- */ +static int diag_sum_pp(int **pp, int n) { + int s = 0; + for(int i = 0; i < n; i++) s += pp[i][i]; + return s; +} + +/* ---------------- bitfield packet (known OK) ---------------- */ +typedef struct { + unsigned type : 3; + unsigned flags: 5; + unsigned len : 12; + unsigned id : 12; +} PacketBits; + +static uint32_t pack_bits(PacketBits p) { + uint32_t x = 0; + x |= (p.type & 0x7u); + x |= (p.flags & 0x1Fu) << 3; + x |= (p.len & 0xFFFu) << 8; + x |= (p.id & 0xFFFu) << 20; + return x; +} +static PacketBits unpack_bits(uint32_t x) { + PacketBits p; + p.type = (x ) & 0x7u; + p.flags = (x >> 3) & 0x1Fu; + p.len = (x >> 8) & 0xFFFu; + p.id = (x >> 20) & 0xFFFu; + return p; +} + +/* ---------------- memcpy bulk on structs (known OK) ---------------- */ +typedef struct { + int32_t a; + int32_t b; + uint32_t tag; +} Rec; + +static uint32_t bulk_struct_op(void) { + Rec src[8]; + Rec dst[8]; + for(int i = 0; i < 8; i++) { + src[i].a = (int32_t)(i * 7 - 3); + src[i].b = (int32_t)(i * i + 11); + src[i].tag = 0xABC000u + (uint32_t)i; + } + memcpy(dst, src, sizeof(src)); + for(int i = 0; i < 8; i++) { + dst[i].a ^= (int32_t)dst[i].tag; + dst[i].b += dst[i].a; + } + uint32_t h = 2166136261u; + for(int i = 0; i < 8; i++) { + h = fnv1a_u32(h, (uint32_t)dst[i].a); + h = fnv1a_u32(h, (uint32_t)dst[i].b); + h = fnv1a_u32(h, dst[i].tag); + } + return h; +} + +/* ---------------- heap + alias + function pointer dispatch (known OK) ---------------- */ +typedef void (*op_fn)(uint32_t *buf, size_t n); + +static void op_add(uint32_t *buf, size_t n) { + for(size_t i = 0; i < n; i++) buf[i] += (uint32_t)i; +} +static void op_xor(uint32_t *buf, size_t n) { + for(size_t i = 0; i < n; i++) buf[i] ^= (0x9E3779B9u ^ (uint32_t)(i * 13u)); +} +static void op_mix(uint32_t *buf, size_t n) { + for(size_t i = 0; i < n; i++) buf[i] = (buf[i] * 33u) ^ (buf[i] >> 1); +} + +static op_fn pick_op(uint32_t key) { + switch(key % 3u) { + case 0: return op_add; + case 1: return op_xor; + default: return op_mix; + } +} + +/* ---------------- signals (known OK) ---------------- */ +static volatile sig_atomic_t got_signal = 0; +static volatile sig_atomic_t stop_flag = 0; + +static void on_sigusr1(int signum) { + (void)signum; + got_signal = 1; +} +static void on_sigusr2(int signum) { + (void)signum; + stop_flag = 1; +} + +/* ---------------- atomics (known OK) ---------------- */ +static uint32_t atomic_stress(void) { + _Atomic uint32_t ctr = 0; + const size_t N = 32; + uint32_t buf[N]; + for(size_t i = 0; i < N; i++) buf[i] = (uint32_t)(i * 3u + 1u); + + for(uint32_t i = 0; i < 2000; i++) { + uint32_t v = atomic_fetch_add_explicit(&ctr, 1u, memory_order_relaxed); + size_t idx = (size_t)(v % N); + buf[idx] ^= (v * 2654435761u) ^ (uint32_t)idx; + } + + uint32_t h = 2166136261u; + h = hash_mix_u32(h, buf, N); + h = fnv1a_u32(h, atomic_load_explicit(&ctr, memory_order_relaxed)); + return h; +} + +/* ---------------- malloc/free wrappers (README: to_duplicate) ---------------- */ +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +/* ---------------- main: glue everything ---------------- */ +int main(void) { + uint32_t H = 2166136261u; + + int f10 = factorial(10); + H = fnv1a_u32(H, (uint32_t)f10); + + int a[5][5]; + int v = 1; + for(int i = 0; i < 5; i++) + for(int j = 0; j < 5; j++) + a[i][j] = v++; + int s2d = sum2d_5(a); + H = fnv1a_u32(H, (uint32_t)s2d); + + int m[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; + int *rows[3] = { m[0], m[1], m[2] }; + int **pp = rows; + int d1 = diag_sum_pp(pp, 3); + m[1][1] += 10; + int d2 = diag_sum_pp(pp, 3); + H = fnv1a_u32(H, (uint32_t)d1); + H = fnv1a_u32(H, (uint32_t)d2); + + PacketBits p = { .type = 6, .flags = 22, .len = 1215, .id = 1430 }; + uint32_t packed = pack_bits(p); + PacketBits q = unpack_bits(packed); + H = fnv1a_u32(H, packed); + H = fnv1a_u32(H, (uint32_t)(q.type | (q.flags<<8) | (q.len<<16))); + + uint32_t h_bulk = bulk_struct_op(); + H = fnv1a_u32(H, h_bulk); + + const size_t N = 64; + uint32_t *buf = (uint32_t*)dup_malloc(N * sizeof(uint32_t)); + if(!buf) return 1; + for(size_t i = 0; i < N; i++) buf[i] = (uint32_t)(i * 7u + 1u); + + uint32_t *alias = buf + 8; + op_fn table[3] = { op_add, op_xor, op_mix }; + + table[0](alias, N - 8); + table[1](alias, N - 8); + + uint32_t key = buf[0] ^ buf[1] ^ buf[2]; + op_fn f = pick_op(key); + f(alias, N - 8); + + signal(SIGUSR1, on_sigusr1); + signal(SIGUSR2, on_sigusr2); + + raise(SIGUSR1); + H = fnv1a_u32(H, (uint32_t)got_signal); + + uint32_t tick = 0x12345678u; + uint32_t iters = 0; + while(!stop_flag) { + tick = tick * 1103515245u + 12345u; + iters++; + if(iters == 201) raise(SIGUSR2); + } + H = fnv1a_u32(H, iters); + H = fnv1a_u32(H, tick); + + uint32_t h_atomic = atomic_stress(); + H = fnv1a_u32(H, h_atomic); + + H = hash_mix_u32(H, buf, N); + + uint32_t s0 = buf[0]; + uint32_t s1 = buf[1]; + uint32_t s2 = buf[N-2]; + uint32_t s3 = buf[N-1]; + + dup_free(buf); + + printf("checksum=%u\n", H); + printf("sentinels=%u %u %u %u\n", s0, s1, s2, s3); + printf("facts=%d s2d=%d diag=%d->%d got_signal=%d iters=%u\n", + f10, s2d, d1, d2, (int)got_signal, iters); + + return 0; +} diff --git a/testing/tests/c/extended/memcpy_struct_bulk.c b/testing/tests/c/extended/memcpy_struct_bulk.c new file mode 100644 index 0000000..841b9be --- /dev/null +++ b/testing/tests/c/extended/memcpy_struct_bulk.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +typedef struct { + uint32_t tag; + uint32_t len; + uint8_t payload[64]; + uint32_t crc; +} Msg; + +static uint32_t checksum_u32(const uint8_t *p, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= (uint32_t)p[i]; + h *= 16777619u; + } + return h; +} + +static void init_msg(Msg *m) { + m->tag = 0xAABBCCDDu; + m->len = 64u; + for (uint32_t i = 0; i < m->len; i++) { + m->payload[i] = (uint8_t)((i * 7u + 3u) & 0xFFu); + } + m->crc = checksum_u32(m->payload, m->len); +} + +static void mutate_overlap(Msg *m) { + memmove(&m->payload[5], &m->payload[0], 40); + + for (int i = 0; i < 10; i++) { + m->payload[i] ^= (uint8_t)(0x5Au + (uint8_t)i); + } + + m->crc = checksum_u32(m->payload, m->len); +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + Msg *a = (Msg *)dup_malloc(sizeof(Msg)); + Msg *b = (Msg *)dup_malloc(sizeof(Msg)); + if (!a || !b) return 1; + + init_msg(a); + + memcpy(b, a, sizeof(Msg)); + + mutate_overlap(b); + + uint32_t ca = checksum_u32(a->payload, a->len) ^ a->crc ^ a->tag ^ a->len; + uint32_t cb = checksum_u32(b->payload, b->len) ^ b->crc ^ b->tag ^ b->len; + + printf("checksum=%u\n", (uint32_t)(ca * 31u + cb)); + printf("sentinels=%u %u %u %u\n", + (unsigned)a->payload[0], (unsigned)a->payload[1], + (unsigned)b->payload[0], (unsigned)b->payload[1]); + + dup_free(a); + dup_free(b); + return 0; +} diff --git a/testing/tests/c/extended/pthread_entry_callback.c b/testing/tests/c/extended/pthread_entry_callback.c new file mode 100644 index 0000000..eec20c6 --- /dev/null +++ b/testing/tests/c/extended/pthread_entry_callback.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +typedef struct { + int *buf; + int n; +} Task; + +static void op_add(int *buf, int n) { + for (int i = 0; i < n; i++) + buf[i] += i; +} + +static uint32_t checksum(int *buf, int n) { + uint32_t c = 0; + for (int i = 0; i < n; i++) + c = c * 31u + (uint32_t)buf[i]; + return c; +} + +/* Start routine: chiamata da libpthread (codice non strumentato) */ +static void *worker(void *arg) { + Task *t = (Task *)arg; + op_add(t->buf, t->n); + return NULL; +} + +int main(void) { + const int n = 8; + int *buf = malloc(n * sizeof(int)); + if (!buf) return 1; + + for (int i = 0; i < n; i++) + buf[i] = i + 1; /* 1..8 */ + + Task t = { buf, n }; + + pthread_t th; + if (pthread_create(&th, NULL, worker, &t) != 0) { + free(buf); + return 2; + } + pthread_join(th, NULL); + + uint32_t cs = checksum(buf, n); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", buf[0], buf[1], buf[n-2], buf[n-1]); + + free(buf); + return 0; +} diff --git a/testing/tests/c/extended/pthread_entry_callback_mitigation.c b/testing/tests/c/extended/pthread_entry_callback_mitigation.c new file mode 100644 index 0000000..cac7f71 --- /dev/null +++ b/testing/tests/c/extended/pthread_entry_callback_mitigation.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +typedef struct { + int *buf; + int n; +} Task; + +static void op_add(int *buf, int n) { + for (int i = 0; i < n; i++) + buf[i] += i; +} + +static uint32_t checksum(int *buf, int n) { + uint32_t c = 0; + for (int i = 0; i < n; i++) + c = c * 31u + (uint32_t)buf[i]; + return c; +} + +__attribute__((annotate("exclude"))) +static void *worker(void *arg) { + Task *t = (Task *)arg; + op_add(t->buf, t->n); + return NULL; +} + +int main(void) { + const int n = 8; + int *buf = malloc(n * sizeof(int)); + if (!buf) return 1; + + for (int i = 0; i < n; i++) + buf[i] = i + 1; + + Task t = { buf, n }; + + pthread_t th; + if (pthread_create(&th, NULL, worker, &t) != 0) { + free(buf); + return 2; + } + pthread_join(th, NULL); + + uint32_t cs = checksum(buf, n); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", buf[0], buf[1], buf[n-2], buf[n-1]); + + free(buf); + return 0; +} diff --git a/testing/tests/c/extended/ptr_to_ptr.c b/testing/tests/c/extended/ptr_to_ptr.c new file mode 100644 index 0000000..d219dfd --- /dev/null +++ b/testing/tests/c/extended/ptr_to_ptr.c @@ -0,0 +1,21 @@ +#include + +void add(int *x, int v) { + *x += v; +} + +void add_ptr(int **pp, int v) { + **pp += v; +} + +int main(void) { + int a = 5; + int *p = &a; + int **pp = &p; + + add(&a, 3); + add_ptr(pp, 4); + + printf("VAL: %d\n", a); + return 0; +} diff --git a/testing/tests/c/extended/recursion_factorial.c b/testing/tests/c/extended/recursion_factorial.c new file mode 100644 index 0000000..66cd808 --- /dev/null +++ b/testing/tests/c/extended/recursion_factorial.c @@ -0,0 +1,12 @@ +#include + +int fact(int n) { + if (n <= 1) return 1; + return n * fact(n - 1); +} + +int main(void) { + int r = fact(5); + printf("FACT: %d\n", r); + return 0; +} diff --git a/testing/tests/c/extended/signal_flag_handler.c b/testing/tests/c/extended/signal_flag_handler.c new file mode 100644 index 0000000..7062df8 --- /dev/null +++ b/testing/tests/c/extended/signal_flag_handler.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +static volatile sig_atomic_t got_signal = 0; + +static void handler(int signum) { + (void)signum; + got_signal = 1; +} + +static uint32_t checksum_u32(const int *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const size_t N = 16; + int *buf = (int *)dup_malloc(N * sizeof(int)); + if (!buf) return 1; + + for (size_t i = 0; i < N; i++) + buf[i] = (int)(i * 3 + 7); + + if (signal(SIGUSR1, handler) == SIG_ERR) { + dup_free(buf); + return 2; + } + + raise(SIGUSR1); + + if (got_signal) { + for (size_t i = 0; i < N; i++) + buf[i] ^= (int)(0x5A + (int)i); + } else { + for (size_t i = 0; i < N; i++) + buf[i] += 11; + } + + uint32_t cs = checksum_u32(buf, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", buf[0], buf[1], buf[N-2], buf[N-1]); + printf("got_signal=%d\n", (int)got_signal); + + dup_free(buf); + return 0; +} diff --git a/testing/tests/c/extended/signal_loop_break_volatile.c b/testing/tests/c/extended/signal_loop_break_volatile.c new file mode 100644 index 0000000..c25a16c --- /dev/null +++ b/testing/tests/c/extended/signal_loop_break_volatile.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +static volatile sig_atomic_t stop_flag = 0; +static volatile uint32_t tick = 0; + +static void handler(int signum) { + (void)signum; + stop_flag = 1; + tick ^= 0xA5A5A5A5u; +} + +static uint32_t checksum_u32(const uint32_t *a, size_t n) { + uint32_t h = 2166136261u; + for (size_t i = 0; i < n; i++) { + h ^= a[i]; + h *= 16777619u; + } + return h; +} + +__attribute__((annotate("to_duplicate"))) +static void* dup_malloc(size_t n) { + return malloc(n); +} + +__attribute__((annotate("to_duplicate"))) +static void dup_free(void* p) { + free(p); +} + +int main(void) { + const size_t N = 32; + uint32_t *buf = (uint32_t *)dup_malloc(N * sizeof(uint32_t)); + if (!buf) return 1; + + for (size_t i = 0; i < N; i++) + buf[i] = (uint32_t)(i * 11u + 7u); + + if (signal(SIGUSR1, handler) == SIG_ERR) { + dup_free(buf); + return 2; + } + + int iters = 0; + for (int i = 0; i < 100000; i++) { + iters++; + + tick = (tick * 1664525u) + 1013904223u; + buf[(size_t)i % N] ^= tick; + + if (i == 200) { + raise(SIGUSR1); + } + + if (stop_flag) { + break; + } + } + + uint32_t cs = checksum_u32(buf, N); + + printf("checksum=%u\n", cs); + printf("sentinels=%u %u %u %u\n", buf[0], buf[1], buf[N-2], buf[N-1]); + printf("stop_flag=%d iters=%d tick=%u\n", (int)stop_flag, iters, (uint32_t)tick); + + dup_free(buf); + return 0; +} diff --git a/testing/tests/c/extended/struct_player.c b/testing/tests/c/extended/struct_player.c new file mode 100644 index 0000000..7f748a6 --- /dev/null +++ b/testing/tests/c/extended/struct_player.c @@ -0,0 +1,35 @@ +#include + +typedef struct { + int x; + int y; +} Vec2D; + +typedef struct { + Vec2D position; + int health; +} Player; + +void move_player(Player *p, int dx, int dy) { + p->position.x += dx; + p->position.y += dy; +} + +void hit_player(Player *p, int damage) { + p->health -= damage; + if (p->health < 0) p->health = 0; +} + +int compute_score(Player p) { + int dist = p.position.x * p.position.x + p.position.y * p.position.y; + return dist + p.health; +} + +int main(void) { + Player p = {{0,0}, 100}; + move_player(&p, 3, 4); + hit_player(&p, 30); + int score = compute_score(p); + printf("SCORE: %d\n", score); + return 0; +} diff --git a/testing/tests/c/extended/varargs_sum.c b/testing/tests/c/extended/varargs_sum.c new file mode 100644 index 0000000..4085840 --- /dev/null +++ b/testing/tests/c/extended/varargs_sum.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +static int v_sum(int count, ...) { + va_list ap; + va_start(ap, count); + + int s = 0; + for (int i = 0; i < count; i++) { + s += va_arg(ap, int); + } + + va_end(ap); + return s; +} + +static uint32_t checksum_u32(const int *a, int n) { + uint32_t h = 2166136261u; + for (int i = 0; i < n; i++) { + h ^= (uint32_t)a[i]; + h *= 16777619u; + } + return h; +} + +int main(void) { + const int n = 8; + int *buf = malloc(n * sizeof(int)); + if (!buf) return 1; + + for (int i = 0; i < n; i++) + buf[i] = i + 1; /* 1..8 */ + + /* usiamo varargs per calcolare un offset deterministico */ + int off = v_sum(4, buf[0], buf[1], buf[2], buf[3]); /* 1+2+3+4 = 10 */ + + for (int i = 0; i < n; i++) + buf[i] += off; /* +10 su tutti */ + + uint32_t cs = checksum_u32(buf, n); + + printf("checksum=%u\n", cs); + printf("sentinels=%d %d %d %d\n", buf[0], buf[1], buf[n-2], buf[n-1]); + + free(buf); + return 0; +}