libdpf/test/CMakeLists.txt
Ryan Henry 0d22946a0e Checkpoint the party/runtime stack before share-program and malicious-mode work.
Ship the TLS mesh, composer, Beaver/Yao/leaf MPC, prep/online paths, apps, and docs so the tree is pushable before elevating share_expr, security_mode, and prep resume.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 05:59:19 -06:00

443 lines
20 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

cmake_minimum_required(VERSION 3.10)
project(libdpf_test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(BUILD_GMOCK "Builds the googlemock subproject" OFF)
option(INSTALL_GTEST "Enable installation of googletest" OFF)
add_subdirectory(googletest)
enable_testing()
include_directories(../include ../thirdparty ../thirdparty/asio/asio/include)
link_libraries(gtest_main bsd)
# The run log's `ev=build rev=` names the tree this build was configured from.
execute_process(
COMMAND git -C "${CMAKE_CURRENT_SOURCE_DIR}/.." describe --always --dirty --abbrev=12
OUTPUT_VARIABLE LIBDPF_GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(LIBDPF_GIT_REV)
add_compile_definitions(LIBDPF_GIT_REV="${LIBDPF_GIT_REV}")
endif()
# The async SCTP backend (dpf::net::async_sctp_stream_array) auto-enables on
# Linux when <netinet/sctp.h> is present and needs libsctp (-lsctp). Most
# targets reach it through dpf.hpp, so link it everywhere; if the library is
# missing, force the header's stub path so the build still links.
if(UNIX AND NOT APPLE)
find_library(SCTP_LIB sctp)
if(SCTP_LIB)
link_libraries(${SCTP_LIB})
else()
add_compile_definitions(DPF_HAS_LIBSCTP=0)
endif()
endif()
# Party and client links run TLS 1.3 through OpenSSL (dpf/net/tls.hpp). The
# headers auto-enable it when <openssl/ssl.h> exists; without it, encrypted
# links fail at setup and `encryption=off` keeps plaintext links working.
find_package(OpenSSL)
if(OPENSSL_FOUND)
link_libraries(OpenSSL::SSL OpenSSL::Crypto)
else()
add_compile_definitions(DPF_HAS_OPENSSL=0)
endif()
add_compile_options(-march=native)
add_compile_options(-Wall -Wextra -Wpedantic)
# `__int128` is the 128-bit limb. `-Wpedantic` reports that GNU extension
# at every use; the rest of `-Wall` and `-Wextra` stay on.
add_compile_options(-Wno-pedantic)
# `if constexpr` followed by a runtime `if`/`else` is the comparison-leaf
# dispatch. The `else` binds to the runtime `if`.
add_compile_options(-Wno-dangling-else)
# SIMD block types (`__m128i` / simde) carry alignment attributes that GCC
# cannot preserve on template arguments; the warning is noise for this codebase.
add_compile_options(-Wno-ignored-attributes)
# Third-party and leaf-lane memcpy patterns trigger GCC's false-positive
# stringop-overflow diagnostics under aggressive inlining.
add_compile_options(-Wno-stringop-overflow)
# `HEDLEY_WARN_UNUSED_RESULT` / `[[nodiscard]]` are not silenced by `(void)`
# casts on this GCC; tests intentionally discard values inside EXPECT_THROW.
add_compile_options(-Wno-unused-result)
option(COVERAGE "Compile with coverage instrumentation" OFF)
if(COVERAGE)
add_compile_options(-g -O0 -fno-inline -fno-inline-small-functions -fno-default-inline -fprofile-arcs -ftest-coverage)
link_libraries(gcov)
endif()
# Profile harnesses (profile_eval, profile_grotto, profile_party) and the
# party binaries that those harnesses execute. OFF leaves them as normal
# optimized drivers. generate instruments; use consumes the .gcda files.
set(LIBDPF_PGO "OFF" CACHE STRING
"PGO for profile harnesses and party binaries: OFF, generate, or use")
set_property(CACHE LIBDPF_PGO PROPERTY STRINGS OFF generate use)
set(LIBDPF_PGO_DIR "${CMAKE_BINARY_DIR}/pgo" CACHE PATH
"Directory for GCC .gcda profile data")
if(COVERAGE AND NOT LIBDPF_PGO STREQUAL "OFF")
message(FATAL_ERROR
"COVERAGE and LIBDPF_PGO cannot be combined; configure a separate build directory")
endif()
if(NOT LIBDPF_PGO STREQUAL "OFF" AND NOT LIBDPF_PGO STREQUAL "generate" AND NOT LIBDPF_PGO STREQUAL "use")
message(FATAL_ERROR "LIBDPF_PGO must be OFF, generate, or use (got '${LIBDPF_PGO}')")
endif()
function(libdpf_apply_pgo target)
if(LIBDPF_PGO STREQUAL "OFF")
return()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
file(MAKE_DIRECTORY "${LIBDPF_PGO_DIR}")
target_compile_options(${target} PRIVATE
-O3 -fno-omit-frame-pointer
"-fprofile-dir=${LIBDPF_PGO_DIR}")
get_target_property(_kind ${target} TYPE)
if(LIBDPF_PGO STREQUAL "generate")
target_compile_options(${target} PRIVATE -fprofile-generate)
if(_kind STREQUAL "EXECUTABLE")
target_link_options(${target} PRIVATE -fprofile-generate)
endif()
else()
target_compile_options(${target} PRIVATE
-fprofile-use -fprofile-correction -Wno-missing-profile)
if(_kind STREQUAL "EXECUTABLE")
target_link_options(${target} PRIVATE -fprofile-use -fprofile-correction)
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR
"LIBDPF_PGO is implemented for GCC (-fprofile-generate/use). This compiler is ${CMAKE_CXX_COMPILER_ID}.")
else()
message(FATAL_ERROR
"LIBDPF_PGO is implemented for GCC. This compiler is ${CMAKE_CXX_COMPILER_ID}.")
endif()
endfunction()
add_executable(all_test tests/all_test.cpp)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
add_executable(dpf_key_test tests/dpf_key_test.cpp)
add_executable(wildcard_test tests/wildcard_test.cpp)
add_executable(eval_point_test tests/eval_point_test.cpp)
add_executable(eval_interval_test tests/eval_interval_test.cpp)
add_executable(eval_full_test tests/eval_full_test.cpp)
add_executable(eval_sequence_test tests/eval_sequence_test.cpp)
add_executable(eval_point_multi_test tests/eval_point_multi_test.cpp)
add_executable(eval_interval_multi_test tests/eval_interval_multi_test.cpp)
add_executable(eval_full_multi_test tests/eval_full_multi_test.cpp)
add_executable(eval_sequence_multi_test tests/eval_sequence_multi_test.cpp)
add_executable(advice_bit_iterable_test tests/advice_bit_iterable_test.cpp)
add_executable(bit_array_test tests/bit_array_test.cpp)
add_executable(parallel_bit_iterable_test tests/parallel_bit_iterable_test.cpp)
add_executable(setbit_index_iterable_test tests/setbit_index_iterable_test.cpp)
add_executable(incremental_test tests/incremental_test.cpp)
add_executable(path_recipe_test tests/path_recipe_test.cpp)
add_executable(blocked_dcf_test tests/blocked_dcf_test.cpp)
target_compile_definitions(blocked_dcf_test PRIVATE LIBDPF_HAS_NLOHMANN_JSON)
target_include_directories(blocked_dcf_test PRIVATE ../thirdparty/json/include)
add_executable(geneval_test tests/geneval_test.cpp)
add_executable(stress_scenarios_test tests/stress_scenarios_test.cpp)
add_executable(incremental_json_test tests/incremental_json_test.cpp)
target_compile_definitions(incremental_json_test PRIVATE LIBDPF_HAS_NLOHMANN_JSON)
target_include_directories(incremental_json_test PRIVATE ../thirdparty/json/include)
add_executable(keyword2_test tests/keyword2_test.cpp)
# Patterns are compiled as constexpr automata. Length, state, and 256-bit
# boundaries exceed the default constexpr operation budget.
target_compile_options(keyword2_test PRIVATE -fconstexpr-ops-limit=100000000)
add_executable(types_test tests/types_test.cpp)
add_executable(packed_lane_test tests/packed_lane_test.cpp)
add_executable(bitmore_mod_test tests/bitmore_mod_test.cpp)
add_executable(lane_blast_test tests/lane_blast_test.cpp)
add_executable(context_blast_test tests/context_blast_test.cpp)
add_executable(random_test tests/random_test.cpp tests/random_odr_tu.cpp)
target_compile_options(random_test PRIVATE -ftrapv)
find_package(Threads REQUIRED)
target_link_libraries(random_test Threads::Threads)
add_executable(prg_lowmc_test tests/prg_lowmc_test.cpp)
add_executable(prg_chacha_test tests/prg_chacha_test.cpp)
add_executable(prg_aes_ccr_test tests/prg_aes_ccr_test.cpp)
add_executable(half_tree_test tests/half_tree_test.cpp)
add_executable(constrained_cmp_test tests/constrained_cmp_test.cpp)
add_executable(fp61_test tests/fp61_test.cpp)
add_executable(field_output_test tests/field_output_test.cpp)
add_executable(gf2_test tests/gf2_test.cpp)
add_executable(gf2_adversarial_test tests/gf2_adversarial_test.cpp)
add_executable(arith_payload_test tests/arith_payload_test.cpp)
add_executable(verifiable_test tests/verifiable_test.cpp)
add_executable(vdpf_adversarial_test tests/vdpf_adversarial_test.cpp)
add_executable(shamir_adversarial_test tests/shamir_adversarial_test.cpp)
add_executable(vdpf_regression_test tests/vdpf_regression_test.cpp)
add_executable(opt_in_malicious_test tests/opt_in_malicious_test.cpp)
add_executable(multipoint_test tests/multipoint_test.cpp)
add_executable(dpf3_test tests/dpf3_test.cpp)
add_executable(eval_inner_product_test tests/eval_inner_product_test.cpp)
add_executable(shared_and_test tests/shared_and_test.cpp)
target_include_directories(shared_and_test PRIVATE ../party)
add_executable(cohort_test tests/cohort_test.cpp)
add_executable(interleave_leaves_test tests/interleave_leaves_test.cpp)
add_executable(secret_share_test tests/secret_share_test.cpp)
add_executable(beaver_test tests/beaver_test.cpp)
add_executable(share_runtime_test tests/share_runtime_test.cpp)
add_executable(net_control_test tests/net_control_test.cpp)
add_executable(security_test tests/security_test.cpp)
add_executable(protocol_batch_test tests/protocol_batch_test.cpp)
target_include_directories(protocol_batch_test PRIVATE ../party)
add_executable(compose_test tests/compose_test.cpp)
target_include_directories(compose_test PRIVATE ../party)
add_executable(experiment_test tests/experiment_test.cpp)
add_executable(log_test tests/log_test.cpp)
add_executable(constant_lut_test tests/constant_lut_test.cpp)
add_executable(signed_prefix_test tests/signed_prefix_test.cpp)
add_executable(easy_lut_test tests/easy_lut_test.cpp)
add_executable(dyadic_lut_test tests/dyadic_lut_test.cpp)
add_executable(nmod_test tests/nmod_test.cpp)
add_executable(exact_steps_test tests/exact_steps_test.cpp)
add_executable(closed_form_test tests/closed_form_test.cpp)
add_executable(principal_lut_test tests/principal_lut_test.cpp)
add_executable(range_lut_test tests/range_lut_test.cpp)
add_executable(window_lut_test tests/window_lut_test.cpp)
add_executable(dwt_lut_test tests/dwt_lut_test.cpp)
add_executable(offset_horner_test tests/offset_horner_test.cpp)
add_executable(offset_poly_test tests/offset_poly_test.cpp)
add_executable(lut_union_test tests/lut_union_test.cpp)
add_executable(offset_jet_test tests/offset_jet_test.cpp)
add_executable(offset_repr_test tests/offset_repr_test.cpp)
add_executable(offset_twist_test tests/offset_twist_test.cpp)
add_executable(ring_switch_test tests/ring_switch_test.cpp)
add_executable(corner_gaps_test tests/corner_gaps_test.cpp)
add_executable(carry_test tests/carry_test.cpp)
add_executable(fixedpoint_beaver_test tests/fixedpoint_beaver_test.cpp)
add_executable(class_sweep_test tests/class_sweep_test.cpp)
add_executable(extractable_full_test tests/extractable_full_test.cpp)
add_executable(walk_helpers_test tests/walk_helpers_test.cpp)
add_executable(domain128_point_test tests/domain128_point_test.cpp)
add_executable(blob_leaf_test tests/blob_leaf_test.cpp)
add_executable(growing_idpf_test tests/growing_idpf_test.cpp)
add_executable(pprf_test tests/pprf_test.cpp)
add_executable(ppvc_test tests/ppvc_test.cpp)
add_executable(leaf_later_test tests/leaf_later_test.cpp)
add_executable(caller_fold_test tests/caller_fold_test.cpp)
add_executable(defer_eval_test tests/defer_eval_test.cpp)
add_executable(wrap_and_rotate_test tests/wrap_and_rotate_test.cpp)
add_executable(sfss_test tests/sfss_test.cpp)
add_executable(path_sketch_test tests/path_sketch_test.cpp)
add_executable(eval_until_test tests/eval_until_test.cpp)
add_executable(idpf_agg_test tests/idpf_agg_test.cpp)
add_executable(it_dpf3_test tests/it_dpf3_test.cpp)
# (2+1) party processes over local sockets
add_library(party_flows STATIC
../party/registry.cpp
../party/run.cpp
)
# flows_bulk.cpp is #included from run.cpp (single TU; avoids dpf.hpp ODR).
target_include_directories(party_flows PUBLIC
../include ../thirdparty ../thirdparty/asio/asio/include ../party
../thirdparty/json/include)
target_compile_definitions(party_flows PUBLIC LIBDPF_HAS_ASIO LIBDPF_HAS_NLOHMANN_JSON)
target_link_libraries(party_flows PUBLIC bsd pthread)
add_executable(p0 ../party/p0.cpp)
add_executable(p1 ../party/p1.cpp)
add_executable(p2 ../party/p2.cpp)
add_executable(party_bench ../party/party_bench.cpp)
foreach(party_target p0 p1 p2 party_bench)
target_link_libraries(${party_target} PRIVATE party_flows)
target_compile_definitions(${party_target} PRIVATE
"LIBDPF_PARTY_BIN_DIR=\"${CMAKE_BINARY_DIR}/bin\"")
set_target_properties(${party_target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endforeach()
add_dependencies(party_bench p0 p1 p2)
# In-process and (2+1) workloads for cost measurement and profile-guided
# optimization. Not gtest: run the binaries directly. See each file's header.
add_executable(profile_eval profile/eval_profile.cpp)
add_executable(profile_grotto profile/grotto_profile.cpp)
add_executable(profile_party profile/party_profile.cpp)
foreach(profile_target profile_eval profile_grotto profile_party)
target_compile_options(${profile_target} PRIVATE -O3 -fno-omit-frame-pointer)
set_target_properties(${profile_target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endforeach()
target_link_libraries(profile_party PRIVATE party_flows)
target_compile_definitions(profile_party PRIVATE
"LIBDPF_PARTY_BIN_DIR=\"${CMAKE_BINARY_DIR}/bin\"")
add_dependencies(profile_party p0 p1 p2)
foreach(pgo_target profile_eval profile_grotto profile_party party_flows p0 p1 p2 party_bench)
libdpf_apply_pgo(${pgo_target})
endforeach()
add_executable(yao_share_test tests/yao_share_test.cpp)
add_executable(yao_test tests/yao_test.cpp)
add_executable(yao_stack_test tests/yao_stack_test.cpp)
add_executable(arith_garble_test tests/arith_garble_test.cpp)
add_executable(flute_test tests/flute_test.cpp)
add_executable(shuffle_hidden_test tests/shuffle_hidden_test.cpp)
add_executable(bench_cell_test tests/bench_cell_test.cpp)
target_link_libraries(bench_cell_test PRIVATE pthread)
target_include_directories(yao_test PRIVATE ../party)
target_link_libraries(yao_test PRIVATE pthread)
# Half-gates are fine at -O0. The session test's Chou–Orlandi base OT is not.
target_compile_options(yao_test PRIVATE -O2)
add_executable(iknp_party_test tests/iknp_party_test.cpp)
target_include_directories(iknp_party_test PRIVATE ../party)
target_link_libraries(iknp_party_test PRIVATE pthread)
# Base OTs are P-256 scalar multiplications. The default test flags leave this
# TU unoptimized, which makes those scalars take minutes.
target_compile_options(iknp_party_test PRIVATE -O2)
add_executable(beaver_party_test tests/beaver_party_test.cpp)
target_include_directories(beaver_party_test PRIVATE ../party)
target_compile_definitions(beaver_party_test PRIVATE
"LIBDPF_PARTY_BIN_DIR=\"${CMAKE_BINARY_DIR}/bin\"")
target_link_libraries(beaver_party_test PRIVATE party_flows)
add_dependencies(beaver_party_test p0 p1 p2)
include(GoogleTest)
gtest_discover_tests(yao_share_test)
gtest_discover_tests(yao_test)
gtest_discover_tests(yao_stack_test)
gtest_discover_tests(arith_garble_test)
gtest_discover_tests(flute_test)
gtest_discover_tests(shuffle_hidden_test)
gtest_discover_tests(bench_cell_test)
gtest_discover_tests(iknp_party_test)
gtest_discover_tests(dpf_key_test)
gtest_discover_tests(wildcard_test)
gtest_discover_tests(eval_point_test)
gtest_discover_tests(eval_interval_test)
gtest_discover_tests(eval_full_test)
gtest_discover_tests(eval_sequence_test)
gtest_discover_tests(eval_point_multi_test)
gtest_discover_tests(eval_interval_multi_test)
gtest_discover_tests(eval_full_multi_test)
gtest_discover_tests(eval_sequence_multi_test)
gtest_discover_tests(advice_bit_iterable_test)
gtest_discover_tests(bit_array_test)
gtest_discover_tests(parallel_bit_iterable_test)
gtest_discover_tests(setbit_index_iterable_test)
gtest_discover_tests(incremental_test)
gtest_discover_tests(path_recipe_test)
gtest_discover_tests(blocked_dcf_test)
gtest_discover_tests(geneval_test)
gtest_discover_tests(stress_scenarios_test)
gtest_discover_tests(incremental_json_test)
gtest_discover_tests(keyword2_test)
gtest_discover_tests(types_test)
gtest_discover_tests(packed_lane_test)
gtest_discover_tests(bitmore_mod_test)
gtest_discover_tests(lane_blast_test)
gtest_discover_tests(context_blast_test)
gtest_discover_tests(random_test)
gtest_discover_tests(prg_lowmc_test)
gtest_discover_tests(prg_chacha_test)
gtest_discover_tests(prg_aes_ccr_test)
gtest_discover_tests(half_tree_test)
gtest_discover_tests(constrained_cmp_test)
gtest_discover_tests(fp61_test)
gtest_discover_tests(field_output_test)
gtest_discover_tests(gf2_test)
gtest_discover_tests(gf2_adversarial_test)
gtest_discover_tests(arith_payload_test)
gtest_discover_tests(verifiable_test)
gtest_discover_tests(vdpf_adversarial_test)
gtest_discover_tests(shamir_adversarial_test)
gtest_discover_tests(vdpf_regression_test)
gtest_discover_tests(opt_in_malicious_test)
gtest_discover_tests(multipoint_test)
gtest_discover_tests(dpf3_test)
gtest_discover_tests(eval_inner_product_test)
gtest_discover_tests(shared_and_test)
gtest_discover_tests(cohort_test)
gtest_discover_tests(interleave_leaves_test)
gtest_discover_tests(secret_share_test)
gtest_discover_tests(beaver_test)
gtest_discover_tests(share_runtime_test)
gtest_discover_tests(net_control_test)
gtest_discover_tests(security_test)
gtest_discover_tests(protocol_batch_test)
gtest_discover_tests(compose_test)
gtest_discover_tests(experiment_test)
gtest_discover_tests(log_test)
gtest_discover_tests(beaver_party_test)
gtest_discover_tests(constant_lut_test)
gtest_discover_tests(signed_prefix_test)
gtest_discover_tests(easy_lut_test)
gtest_discover_tests(dyadic_lut_test)
gtest_discover_tests(nmod_test)
gtest_discover_tests(exact_steps_test)
gtest_discover_tests(closed_form_test)
gtest_discover_tests(principal_lut_test)
gtest_discover_tests(range_lut_test)
gtest_discover_tests(window_lut_test)
gtest_discover_tests(dwt_lut_test)
gtest_discover_tests(offset_horner_test)
gtest_discover_tests(offset_poly_test)
gtest_discover_tests(lut_union_test)
gtest_discover_tests(offset_jet_test)
gtest_discover_tests(offset_repr_test)
gtest_discover_tests(offset_twist_test)
gtest_discover_tests(ring_switch_test)
add_executable(ic_test tests/ic_test.cpp)
gtest_discover_tests(ic_test)
add_executable(wide_payload_test tests/wide_payload_test.cpp)
gtest_discover_tests(wide_payload_test)
gtest_discover_tests(corner_gaps_test)
gtest_discover_tests(carry_test)
gtest_discover_tests(fixedpoint_beaver_test)
gtest_discover_tests(class_sweep_test)
gtest_discover_tests(extractable_full_test)
gtest_discover_tests(walk_helpers_test)
gtest_discover_tests(domain128_point_test)
gtest_discover_tests(blob_leaf_test)
gtest_discover_tests(growing_idpf_test)
gtest_discover_tests(pprf_test)
gtest_discover_tests(ppvc_test)
gtest_discover_tests(leaf_later_test)
gtest_discover_tests(caller_fold_test)
gtest_discover_tests(defer_eval_test)
gtest_discover_tests(wrap_and_rotate_test)
gtest_discover_tests(sfss_test)
gtest_discover_tests(path_sketch_test)
gtest_discover_tests(eval_until_test)
gtest_discover_tests(idpf_agg_test)
gtest_discover_tests(it_dpf3_test)
# Optional Python module (keys stay opaque capsules).
option(LIBDPF_PYTHON "Build the optional pybind11 pydpf module" OFF)
if(LIBDPF_PYTHON)
set(PYBIND11_FINDPYTHON ON)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
# Prefer the FindPython result over a stale classic PYTHON_EXECUTABLE
# (this tree previously cached 3.7).
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}" CACHE FILEPATH
"Python interpreter for pybind11" FORCE)
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.13.6
)
FetchContent_MakeAvailable(pybind11)
pybind11_add_module(pydpf ../python/pydpf.cpp)
target_include_directories(pydpf PRIVATE ../include ../thirdparty ../python)
target_compile_options(pydpf PRIVATE -march=native -Wno-pedantic
-Wno-ignored-attributes -Wno-dangling-else)
target_link_libraries(pydpf PRIVATE bsd)
set_target_properties(pydpf PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python")
add_custom_target(pydpf_pytest
COMMAND ${CMAKE_COMMAND} -E env
"PYTHONPATH=${CMAKE_BINARY_DIR}/python"
${Python3_EXECUTABLE}
"${CMAKE_CURRENT_SOURCE_DIR}/../python/tests/test_pydpf.py"
DEPENDS pydpf
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../python"
COMMENT "Run pydpf smoke tests")
endif()