Skip to content

Commit

Permalink
port rpcgen to mercury for hg_proc_cb_t function generation
Browse files Browse the repository at this point in the history
Port sunrpc rpcgen to mercury to allow mercury users to generate
hg_proc_cb_t functions from .x files (as an additional alternative
to hand coding or using the boost preprocessor macros).  The
mercury version of rpcgen (hg_rpcgen) parses standard .x files
(though it ignores the 'program' section) and emits code that
uses the mercury proc API.

The port includes:
  - rpcgen itself, in util/rpc_gen (hg_info is moved to util/hg_info)
  - mercury proc versions of helper xdr functions like xdr_array()
    in src/proc_extra.  we update the legacy string functions in
    src/proc_extra to use hg_proc_string() for a backend.
  - a new unit test in Testing/unit/hg/test_hg_rpcgen.c

The unit test's input .x file (Testing/unit/hg/test_hg_rpcgen.x)
also documents the the .x file syntax.

Note that the hg_rpcgen reinitialize() code has been updated to
free() previously allocated parse tree memory rather than discard
(leak) it.  To do this, the char* strings in parse.h were changed
to tokens (since the token type/kind value can be used to determine
if the token string was allocated with malloc() or not).
  • Loading branch information
chuckcranor committed Jan 24, 2025
1 parent 7e411e1 commit f042d81
Show file tree
Hide file tree
Showing 33 changed files with 5,168 additions and 541 deletions.
22 changes: 20 additions & 2 deletions Testing/unit/hg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,30 @@ endif()
function(build_mercury_test test_name)
if(${CMAKE_VERSION} VERSION_GREATER 3.12)
add_executable(hg_test_${test_name} test_${test_name}.c)
target_link_libraries(hg_test_${test_name} mercury_unit)
target_link_libraries(hg_test_${test_name} mercury_unit ${ARGN})
else()
add_executable(hg_test_${test_name} test_${test_name}.c mercury_unit.c mercury_rpc_cb.c)
target_link_libraries(hg_test_${test_name} mercury_test_common)
target_link_libraries(hg_test_${test_name} mercury_test_common ${ARGN})
endif()
if(MERCURY_ENABLE_COVERAGE)
set_coverage_flags(hg_test_${test_name})
endif()
endfunction()

# add ${test_xname} lib target using hg_rpcgen on file ${test_xname}.x
function(build_mercury_rpcgen_procs test_xname)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${test_xname}.h
${CMAKE_CURRENT_BINARY_DIR}/${test_xname}_proc.c
COMMAND ${CMAKE_BINARY_DIR}/bin/hg_rpcgen
${CMAKE_CURRENT_SOURCE_DIR}/${test_xname}.x
DEPENDS ${test_xname}.x)
add_library(${test_xname} ${test_xname}_proc.c)
target_link_libraries(${test_xname} mercury)
target_include_directories(${test_xname}
PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
endfunction()

macro(add_mercury_test test_name comm protocol busy parallel self scalable
ignore_server_err)
# Set full test name
Expand Down Expand Up @@ -222,9 +236,13 @@ build_mercury_test(bulk)
build_mercury_test(lookup)
build_mercury_test(proc)

build_mercury_rpcgen_procs(test_hg_rpcgen)
build_mercury_test(hg_rpcgen test_hg_rpcgen)

build_mercury_test(kill)

add_mercury_test_standalone(proc)
add_mercury_test_standalone(hg_rpcgen)

add_mercury_test_comm_all(rpc)
add_mercury_test_comm_all(bulk)
Expand Down
8 changes: 3 additions & 5 deletions Testing/unit/hg/mercury_rpc_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,11 @@ HG_TEST_RPC_CB(hg_test_rpc_open, handle)
hg_size_t payload_size = HG_Get_input_payload_size(handle);
#ifdef HG_HAS_XDR
size_t expected_string_payload_size = /* note xdr rounding rules */
sizeof(uint64_t) + /* length */
RNDUP(strlen(HG_TEST_RPC_PATH) + 1) + /* string data, inc \0 at end */
RNDUP(sizeof(uint8_t)) + /* is_const */
RNDUP(sizeof(uint8_t)); /* is_owned */
sizeof(uint32_t) + /* length */
RNDUP(strlen(HG_TEST_RPC_PATH)); /* string data (no \0) */
#else
size_t expected_string_payload_size =
strlen(HG_TEST_RPC_PATH) + sizeof(uint64_t) + 3;
sizeof(uint32_t) + strlen(HG_TEST_RPC_PATH); /* len + data */
#endif

HG_TEST_CHECK_ERROR(
Expand Down
Loading

0 comments on commit f042d81

Please sign in to comment.