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
10 changes: 9 additions & 1 deletion cmake/libe3Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ if(LIBE3_BUILD_INTEGRATION_TESTS AND LIBE3_ENABLE_ASN1)
if(simple_name STREQUAL "bench_encoding_size")
target_link_libraries(${target_name} PRIVATE benchmark::benchmark)
endif()
add_test(NAME ${target_name} COMMAND ${target_name})
if(simple_name STREQUAL "bench_encoding_wire" AND TARGET libe3::e2sm_dapp)
target_link_libraries(${target_name} PRIVATE libe3::e2sm_dapp)
target_compile_definitions(${target_name} PRIVATE LIBE3_BENCH_E2SM_DAPP)
endif()
set(_test_args "")
if(simple_name STREQUAL "bench_encoding_wire")
set(_test_args --values)
endif()
add_test(NAME ${target_name} COMMAND ${target_name} ${_test_args})
set_tests_properties(${target_name} PROPERTIES LABELS "integration")
endforeach()
endif()
Expand Down
47 changes: 45 additions & 2 deletions tests/integration/bench_encoding_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
* encodings sit far above the baseline because field names and punctuation
* travel on the wire as text.
*
* With --sizes-only no benchmark is run and the CSV carries only the first
* four columns; each PDU is also decoded and re-encoded, and a mismatch is
* reported on stderr. --no-timestamp zeroes Pdu::timestamp so the optional
* E3-PDU envelope timestamp is left off the wire.
*
* Usage:
* ./bench_encoding_size
* ./bench_encoding_size --sizes-only
* taskset -c 2 ./bench_encoding_size | python scripts/collect_baseline.py \
* --type encoding --output data/baseline/encoding/encoding.csv
*
Expand Down Expand Up @@ -237,9 +243,10 @@ std::vector<Sample> make_samples(bool json_payloads) {
rep.dapp_identifier = 1;
rep.ran_function_identifier = 1;
rep.report_data = payload;
rep.sequence_id = 1;
s.pdu.choice = rep;
s.pdu.message_id = 8;
s.info_bytes = kMsgId + kU32 + kU32 + rep.report_data.size();
s.info_bytes = kMsgId + kU32 + kU32 + rep.report_data.size() + kU32;
samples.push_back(std::move(s));
}

Expand All @@ -250,9 +257,10 @@ std::vector<Sample> make_samples(bool json_payloads) {
xaction.dapp_identifier = 1;
xaction.ran_function_identifier = 1;
xaction.xapp_control_data = payload;
xaction.sequence_id = 1;
s.pdu.choice = xaction;
s.pdu.message_id = 9;
s.info_bytes = kMsgId + kU32 + kU32 + xaction.xapp_control_data.size();
s.info_bytes = kMsgId + kU32 + kU32 + xaction.xapp_control_data.size() + kU32;
samples.push_back(std::move(s));
}

Expand Down Expand Up @@ -370,6 +378,19 @@ void register_cell(Cell& cell) {
// ---------------------------------------------------------------------------

int main(int argc, char* argv[]) {
bool sizes_only = false;
bool no_timestamp = false;
for (int i = 1; i < argc; ++i) {
const bool so = std::strcmp(argv[i], "--sizes-only") == 0;
const bool nt = std::strcmp(argv[i], "--no-timestamp") == 0;
if (so || nt) {
sizes_only |= so;
no_timestamp |= nt;
for (int j = i; j < argc; ++j) argv[j] = argv[j + 1];
--argc;
--i;
}
}
benchmark::Initialize(&argc, argv);

struct EncoderCase {
Expand Down Expand Up @@ -397,12 +418,23 @@ int main(int argc, char* argv[]) {
continue;
}
for (auto& sample : make_samples(ec.json_payloads)) {
if (no_timestamp) sample.pdu.timestamp = 0;
auto result = enc->encode(sample.pdu);
if (!result.has_value()) {
std::fprintf(stderr, "WARN: encode failed for %s/%s\n",
ec.name, sample.name);
continue;
}
if (sizes_only) {
auto back = enc->decode(*result);
auto again = back ? enc->encode(*back)
: tl::expected<EncodedMessage, ErrorCode>(
tl::unexpected(back.error()));
if (!again || again->buffer != result->buffer) {
std::fprintf(stderr, "WARN: round trip mismatch for %s/%s\n",
ec.name, sample.name);
}
}
Cell cell;
cell.encoding = ec.name;
cell.message = sample.name;
Expand All @@ -418,6 +450,17 @@ int main(int argc, char* argv[]) {

// Register after `cells` is fully built: the benchmark lambdas capture
// pointers into the vector, which must not reallocate afterwards.
if (sizes_only) {
std::printf("encoding,message_type,encoded_bytes,info_bytes\n");
for (const auto& cell : cells) {
std::printf("%s,%s,%zu,%zu\n", cell.encoding.c_str(),
cell.message.c_str(), cell.encoded_bytes,
cell.info_bytes);
}
benchmark::Shutdown();
return 0;
}

for (auto& cell : cells) register_cell(cell);

CaptureReporter capture;
Expand Down
Loading
Loading