Skip to content

Commit

Permalink
Merge a08c478 into 7e09f07
Browse files Browse the repository at this point in the history
  • Loading branch information
yperess authored Aug 3, 2022
2 parents 7e09f07 + a08c478 commit 3f7be50
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 1,497 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/verify_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Check PR

on:
pull_request:
branches:
- master

jobs:
check-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: ./buildandtest
2 changes: 2 additions & 0 deletions buildandtest
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ make clean
make all
build/fff_test_c
build/fff_test_cpp --gtest_output=xml:build/test_results.xml
build/fff_test_cpp_custom_fn --gtest_output=xml:build/test_results_custom_fn.xml
build/ui_test_ansic
build/ui_test_cpp --gtest_output=xml:build/example_results.xml
build/fff_test_glob_c
build/fff_test_glob_cpp --gtest_output=xml:build/test_global_results.xml
build/fff_test_glob_cpp_custom_fn --gtest_output=xml:build/test_global_results_custom_fn.xml
build/driver_testing --gtest_output=xml:build/driver_testing.xml
build/driver_testing_fff --gtest_output=xml:build/driver_testing_fff.xml
build/weak_linking/test_display
Expand Down
36 changes: 28 additions & 8 deletions fakegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ def output_constants
end


def output_default_function_pointer_macro(has_calling_conventions)
name = has_calling_conventions ? "(CALLING_CONVENTION *FUNCNAME)" : "(*FUNCNAME)"
calling_conv = has_calling_conventions ? ", CALLING_CONVENTION" : ""
putd "#ifndef CUSTOM_FFF_FUNCTION_TEMPLATE"
putd_backslash "#define CUSTOM_FFF_FUNCTION_TEMPLATE(RETURN#{calling_conv}, FUNCNAME, ...)"
indent {
putd "RETURN#{name}(__VA_ARGS__)"
}
putd "#endif /* CUSTOM_FFF_FUNCTION_TEMPLATE */"
end




Expand Down Expand Up @@ -231,7 +242,9 @@ def define_reset_fake_helper
indent {
putd_backslash "void FUNCNAME##_reset(void){"
indent {
putd_backslash "memset(&FUNCNAME##_fake, 0, sizeof(FUNCNAME##_fake));"
putd_backslash "memset((void*)&FUNCNAME##_fake, 0, sizeof(FUNCNAME##_fake) - sizeof(FUNCNAME##_fake.custom_fake) - sizeof(FUNCNAME##_fake.custom_fake_seq));"
putd_backslash "FUNCNAME##_fake.custom_fake = NULL;"
putd_backslash "FUNCNAME##_fake.custom_fake_seq = NULL;"
putd_backslash "FUNCNAME##_fake.arg_history_len = FFF_ARG_HISTORY_LEN;"
}
putd "}"
Expand Down Expand Up @@ -355,6 +368,14 @@ def arg_val_list(args_count)
arguments.join(", ")
end

#example: ARG0_TYPE, ARG1_TYPE
def arg_type_list(args_count)
return "void" if (args_count == 0)
arguments = []
args_count.times { |i| arguments << "ARG#{i}_TYPE" }
arguments.join(", ")
end

#example: arg0, arg1
def arg_list(args_count)
arguments = []
Expand All @@ -370,17 +391,15 @@ def arg_list(args_count)
def output_custom_function_signature(arg_count, has_varargs, has_calling_conventions, is_value_function)
return_type = is_value_function ? "RETURN_TYPE" : "void"
ap_list = has_varargs ? ", va_list ap" : ""
signature = has_calling_conventions ? "(CALLING_CONVENTION *custom_fake)" : "(*custom_fake)"
signature += "(#{arg_val_list(arg_count)}#{ap_list});"
putd_backslash return_type + signature
calling_conv = has_calling_conventions ? ", CALLING_CONVENTION" : ""
putd_backslash "CUSTOM_FFF_FUNCTION_TEMPLATE(#{return_type}#{calling_conv}, custom_fake, #{arg_type_list(arg_count)}#{ap_list});"
end

def output_custom_function_array(arg_count, has_varargs, has_calling_conventions, is_value_function)
return_type = is_value_function ? "RETURN_TYPE" : "void"
ap_list = has_varargs ? ", va_list ap" : ""
custom_array = has_calling_conventions ? "(CALLING_CONVENTION **custom_fake_seq)" : "(**custom_fake_seq)"
custom_array += "(#{arg_val_list(arg_count)}#{ap_list});"
putd_backslash return_type + custom_array
calling_conv = has_calling_conventions ? ", CALLING_CONVENTION" : ""
putd_backslash "CUSTOM_FFF_FUNCTION_TEMPLATE(#{return_type}#{calling_conv}, *custom_fake_seq, #{arg_type_list(arg_count)}#{ap_list});"
end

# example: RETURN_TYPE FUNCNAME(ARG0_TYPE arg0, ARG1_TYPE arg1)
Expand Down Expand Up @@ -479,7 +498,7 @@ def output_function_body(arg_count, has_varargs, is_value_function)
putd_backslash "}"
}
putd_backslash "}"
putd_backslash "if (FUNCNAME##_fake.custom_fake){ "
putd_backslash "if (FUNCNAME##_fake.custom_fake != NULL){ "
indent {
putd_backslash "RETURN_TYPE ret = FUNCNAME##_fake.custom_fake(#{arg_list(arg_count)});" unless not is_value_function
putd_backslash "SAVE_RET_HISTORY(FUNCNAME, ret);" unless not is_value_function
Expand Down Expand Up @@ -639,6 +658,7 @@ def output_c_and_cpp(has_calling_conventions)
include_guard {
include_dependencies
output_constants
output_default_function_pointer_macro(has_calling_conventions)
output_internal_helper_macros
yield
output_macro_counting_shortcuts(has_calling_conventions)
Expand Down
Loading

0 comments on commit 3f7be50

Please sign in to comment.