Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 147 additions & 1 deletion smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(protocyte_smoke LANGUAGES CXX)
option(PROTOCYTE_SMOKE_REGENERATE "Regenerate checked protocyte output with protoc." OFF)
option(PROTOCYTE_SMOKE_FETCH_PROTOBUF "Fetch and build protobuf when protoc is not installed." ON)
option(PROTOCYTE_SMOKE_BUILD_DRIVER "Build the WDK kernel driver smoke test." OFF)
option(PROTOCYTE_SMOKE_BUILD_BENCHMARKS "Build Protocyte marshalling benchmarks." OFF)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -17,6 +18,7 @@ set(PROTOCYTE_SMOKE_PROTO_DIR "${CMAKE_CURRENT_LIST_DIR}/proto")
set(PROTOCYTE_EXAMPLE_PROTO "${PROTOCYTE_SMOKE_PROTO_DIR}/example.proto")
set(PROTOCYTE_COMPAT_PROTO "${PROTOCYTE_SMOKE_PROTO_DIR}/compat.proto")
set(PROTOCYTE_CROSS_PACKAGE_PROTO "${PROTOCYTE_SMOKE_PROTO_DIR}/cross_package.proto")
set(PROTOCYTE_BENCHMARK_PROTO "${PROTOCYTE_SMOKE_PROTO_DIR}/benchmark.proto")
set(PROTOCYTE_GENERATED_DIR "${CMAKE_CURRENT_LIST_DIR}/generated")
set(
PROTOCYTE_SMOKE_CLANG_FORMAT
Expand All @@ -40,7 +42,7 @@ set(PROTOCYTE_GENERATED_FILES
"${PROTOCYTE_GENERATED_DIR}/protocyte/runtime/runtime.hpp"
)

if(PROTOCYTE_SMOKE_REGENERATE)
if(PROTOCYTE_SMOKE_REGENERATE OR PROTOCYTE_SMOKE_BUILD_BENCHMARKS)
set(PROTOCYTE_FETCH_PROTOBUF "${PROTOCYTE_SMOKE_FETCH_PROTOBUF}")
else()
set(PROTOCYTE_FETCH_PROTOBUF OFF)
Expand Down Expand Up @@ -115,6 +117,87 @@ FetchContent_Declare(
GIT_TAG v3.7.1
)
FetchContent_MakeAvailable(Catch2)
FetchContent_GetProperties(Catch2 SOURCE_DIR protocyte_smoke_catch2_source_dir)
list(APPEND CMAKE_MODULE_PATH "${protocyte_smoke_catch2_source_dir}/extras")

if(PROTOCYTE_SMOKE_BUILD_BENCHMARKS)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
set(BENCHMARK_INSTALL_DOCS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_INSTALL_TOOLS OFF CACHE BOOL "" FORCE)
if(WIN32)
set(CMAKE_USE_WIN32_THREADS_INIT ON CACHE BOOL "" FORCE)
set(CMAKE_USE_PTHREADS_INIT OFF CACHE BOOL "" FORCE)
set(CMAKE_THREAD_LIBS_INIT "" CACHE STRING "" FORCE)
set(HAVE_LIB_RT OFF CACHE BOOL "" FORCE)
endif()
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.9.5
)
FetchContent_MakeAvailable(benchmark)

set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "" FORCE)
protocyte_setup_codegen()
if(NOT TARGET protobuf::libprotobuf AND NOT TARGET libprotobuf)
find_package(Protobuf CONFIG QUIET)
endif()
if(NOT TARGET protobuf::libprotobuf AND NOT TARGET libprotobuf)
find_package(Protobuf MODULE QUIET)
endif()
if(NOT TARGET protobuf::libprotobuf AND NOT TARGET libprotobuf AND PROTOCYTE_SMOKE_FETCH_PROTOBUF)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_CONFORMANCE OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_PROTOBUF_BINARIES ON CACHE BOOL "" FORCE)
FetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG "${PROTOCYTE_PROTOBUF_GIT_TAG}"
)
FetchContent_MakeAvailable(protobuf)
set(PROTOCYTE_PROTOC_EXECUTABLE "$<TARGET_FILE:protobuf::protoc>" CACHE INTERNAL "protoc executable for protocyte")
endif()
set(PROTOCYTE_PROTOBUF_BENCHMARK_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/protobuf")
set(PROTOCYTE_PROTOBUF_BENCHMARK_HEADER "${PROTOCYTE_PROTOBUF_BENCHMARK_GENERATED_DIR}/benchmark.pb.h")
set(PROTOCYTE_PROTOBUF_BENCHMARK_SOURCE "${PROTOCYTE_PROTOBUF_BENCHMARK_GENERATED_DIR}/benchmark.pb.cc")
add_custom_command(
OUTPUT
"${PROTOCYTE_PROTOBUF_BENCHMARK_HEADER}"
"${PROTOCYTE_PROTOBUF_BENCHMARK_SOURCE}"
COMMAND
"${CMAKE_COMMAND}" -E make_directory "${PROTOCYTE_PROTOBUF_BENCHMARK_GENERATED_DIR}"
COMMAND
${PROTOCYTE_PROTOC_EXECUTABLE}
"--proto_path=${PROTOCYTE_SMOKE_PROTO_DIR}"
"--cpp_out=${PROTOCYTE_PROTOBUF_BENCHMARK_GENERATED_DIR}"
"${PROTOCYTE_BENCHMARK_PROTO}"
DEPENDS "${PROTOCYTE_BENCHMARK_PROTO}"
COMMENT "Generating protobuf benchmark C++ sources"
VERBATIM
)
add_custom_target(
protocyte_smoke_protobuf_benchmark_codegen
DEPENDS
"${PROTOCYTE_PROTOBUF_BENCHMARK_HEADER}"
"${PROTOCYTE_PROTOBUF_BENCHMARK_SOURCE}"
)
set_source_files_properties(
"${PROTOCYTE_PROTOBUF_BENCHMARK_SOURCE}"
PROPERTIES
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:Clang>:-Wno-invalid-offsetof>"
)

if(TARGET protobuf::libprotobuf)
set(protocyte_smoke_libprotobuf_target protobuf::libprotobuf)
elseif(TARGET libprotobuf)
set(protocyte_smoke_libprotobuf_target libprotobuf)
else()
message(FATAL_ERROR "protobuf benchmark requires a libprotobuf CMake target")
endif()
endif()

add_executable(protocyte_host_smoke
src/host_smoke.cpp
Expand Down Expand Up @@ -142,6 +225,69 @@ else()
target_compile_options(protocyte_host_smoke PRIVATE -Wall -Wextra -Wpedantic)
endif()

if(PROTOCYTE_SMOKE_BUILD_BENCHMARKS)
add_executable(protocyte_host_benchmark
src/host_benchmark.cpp
"${PROTOCYTE_GENERATED_DIR}/example.protocyte.cpp"
"${PROTOCYTE_GENERATED_DIR}/compat.protocyte.cpp"
"${PROTOCYTE_GENERATED_DIR}/cross_package.protocyte.cpp"
)
target_include_directories(protocyte_host_benchmark PRIVATE "${PROTOCYTE_GENERATED_DIR}")
target_compile_definitions(
protocyte_host_benchmark
PRIVATE
PROTOCYTE_ENABLE_HOSTED_ALLOCATOR=1
PROTOCYTE_ENABLE_STD_STRING_VIEW=1
)
target_compile_features(protocyte_host_benchmark PRIVATE cxx_std_20)
target_link_libraries(protocyte_host_benchmark PRIVATE benchmark::benchmark_main)

if(PROTOCYTE_SMOKE_REGENERATE)
add_dependencies(protocyte_host_benchmark protocyte_smoke_regenerate)
endif()

if(MSVC)
target_compile_options(protocyte_host_benchmark PRIVATE /W4 /permissive-)
else()
target_compile_options(protocyte_host_benchmark PRIVATE -Wall -Wextra -Wpedantic)
endif()

add_executable(protocyte_host_protobuf_benchmark
src/protobuf_benchmark.cpp
"${PROTOCYTE_PROTOBUF_BENCHMARK_SOURCE}"
)
target_include_directories(
protocyte_host_protobuf_benchmark
PRIVATE
"${PROTOCYTE_GENERATED_DIR}"
"${PROTOCYTE_PROTOBUF_BENCHMARK_GENERATED_DIR}"
)
target_compile_definitions(
protocyte_host_protobuf_benchmark
PRIVATE
PROTOCYTE_ENABLE_HOSTED_ALLOCATOR=1
PROTOCYTE_ENABLE_STD_STRING_VIEW=1
)
target_compile_features(protocyte_host_protobuf_benchmark PRIVATE cxx_std_20)
target_link_libraries(
protocyte_host_protobuf_benchmark
PRIVATE
benchmark::benchmark_main
"${protocyte_smoke_libprotobuf_target}"
)
add_dependencies(protocyte_host_protobuf_benchmark protocyte_smoke_protobuf_benchmark_codegen)

if(PROTOCYTE_SMOKE_REGENERATE)
add_dependencies(protocyte_host_protobuf_benchmark protocyte_smoke_regenerate)
endif()

if(MSVC)
target_compile_options(protocyte_host_protobuf_benchmark PRIVATE /W4 /permissive-)
else()
target_compile_options(protocyte_host_protobuf_benchmark PRIVATE -Wall -Wextra -Wpedantic)
endif()
endif()

enable_testing()
include(Catch)
catch_discover_tests(protocyte_host_smoke)
Expand Down
28 changes: 28 additions & 0 deletions smoke/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"PATH": "$env{VCINSTALLDIR}Tools/Llvm/x64/bin;$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja;$env{WindowsSdkVerBinPath}x64;$penv{PATH}"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"CMAKE_RC_COMPILER": "rc",
"CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY"
Expand All @@ -22,6 +23,7 @@
"PATH": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja;$env{WindowsSdkVerBinPath}x64;$penv{PATH}"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_RC_COMPILER": "rc",
"CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY"
Expand All @@ -39,6 +41,24 @@
"displayName": "Windows MSVC + Ninja",
"binaryDir": "${sourceDir}/build/msvc"
},
{
"name": "windows-clangcl-ninja-benchmarks",
"inherits": "windows-clangcl-ninja",
"displayName": "Windows clang-cl + Ninja + benchmarks",
"binaryDir": "${sourceDir}/build/clangcl-benchmarks",
"cacheVariables": {
"PROTOCYTE_SMOKE_BUILD_BENCHMARKS": "ON"
}
},
{
"name": "windows-msvc-ninja-benchmarks",
"inherits": "windows-msvc-ninja",
"displayName": "Windows MSVC + Ninja + benchmarks",
"binaryDir": "${sourceDir}/build/msvc-benchmarks",
"cacheVariables": {
"PROTOCYTE_SMOKE_BUILD_BENCHMARKS": "ON"
}
},
{
"name": "windows-clangcl-ninja-driver",
"inherits": "windows-clangcl-ninja",
Expand Down Expand Up @@ -67,6 +87,14 @@
"name": "windows-msvc-ninja",
"configurePreset": "windows-msvc-ninja"
},
{
"name": "windows-clangcl-ninja-benchmarks",
"configurePreset": "windows-clangcl-ninja-benchmarks"
},
{
"name": "windows-msvc-ninja-benchmarks",
"configurePreset": "windows-msvc-ninja-benchmarks"
},
{
"name": "windows-clangcl-ninja-driver",
"configurePreset": "windows-clangcl-ninja-driver"
Expand Down
125 changes: 125 additions & 0 deletions smoke/proto/benchmark.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
syntax = "proto3";

package test.benchmark;

message BenchmarkMessage {
double f_double = 1;
float f_float = 2;
int32 f_int32 = 4;
int64 f_int64 = 8;
uint32 f_uint32 = 9;
uint64 f_uint64 = 10;
sint32 f_sint32 = 11;
sint64 f_sint64 = 12;
fixed32 f_fixed32 = 13;
fixed64 f_fixed64 = 14;
sfixed32 f_sfixed32 = 15;
sfixed64 f_sfixed64 = 16;
bool f_bool = 17;
string f_string = 18;
bytes f_bytes = 19;

repeated int32 r_int32_unpacked = 21 [packed = false];
repeated int32 r_int32_packed = 22 [packed = true];
repeated double r_double = 23;

enum Color {
COLOR_UNSPECIFIED = 0;
RED = 1;
GREEN = 2;
BLUE = 3;
}

Color color = 24;

message NestedLevel1 {
string name = 1;
int32 id = 2;

message NestedLevel2 {
string description = 1;
repeated float values = 2;

enum InnerEnum {
INNER_UNSPECIFIED = 0;
A = 1;
B = 2;
C = 3;
}

InnerEnum mode = 3;
}

NestedLevel2 inner = 3;
}

NestedLevel1 nested1 = 25;

oneof special_oneof {
string oneof_string = 26;
int32 oneof_int32 = 27;
NestedLevel1 oneof_msg = 28;
bytes oneof_bytes = 29;
}

message RepeatedBytesHolder {
repeated bytes values = 1;
}

message BoundedRepeatedBytesHolder {
repeated bytes values = 1;
}

message FixedRepeatedBytesHolder {
repeated bytes values = 1;
}

oneof crazy_bytes_oneof {
bytes crazy_plain_bytes = 49;
bytes crazy_bounded_bytes = 50;
bytes crazy_fixed_bytes = 51;
RepeatedBytesHolder crazy_repeated_bytes = 52;
BoundedRepeatedBytesHolder crazy_bounded_repeated_bytes = 53;
FixedRepeatedBytesHolder crazy_fixed_repeated_bytes = 54;
}

map<string, int32> map_str_int32 = 30;
map<int32, string> map_int32_str = 31;
map<bool, bytes> map_bool_bytes = 32;
map<uint64, NestedLevel1> map_uint64_msg = 33;
map<string, NestedLevel1.NestedLevel2> very_nested_map = 34;

BenchmarkMessage recursive_self = 35;
repeated NestedLevel1.NestedLevel2 lots_of_nested = 36;
repeated Color colors = 37;
optional int32 opt_int32 = 38;
optional string opt_string = 39;

message LevelA {
message LevelB {
message LevelC {
message LevelD {
message LevelE {
string extreme = 1;
map<int32, string> weird_map = 2;
oneof deep_oneof {
int64 val = 3;
string text = 4;
}
}
}
}
}
}

LevelA.LevelB.LevelC.LevelD.LevelE extreme_nesting = 40;

bytes sha256 = 41;
repeated int32 integer_array = 42;
bytes byte_array = 43;
repeated uint32 fixed_integer_array = 44;
bytes float_expr_array = 45;
repeated bytes repeated_byte_array = 46;
repeated bytes bounded_repeated_byte_array = 47;
repeated bytes fixed_repeated_byte_array = 48;
}
Loading
Loading