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
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ test:valgrind --run_under='valgrind --leak-check=full --show-leak-kinds=definite

build --enable_platform_specific_config

# Treat third-party (external repo) headers as system headers so the aggressive
# warning set used for our own code (see phaser/copts.bzl) does not flood the
# build with diagnostics from abseil/protobuf/googletest/toolbelt.
build --features=external_include_paths

# For all builds, use C++17
build --cxxopt="-std=c++17"
build --cxxopt='-Wno-sign-compare'
Expand Down
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Google
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "phaser",
version = "1.1.0"
version = "1.1.1"
)

bazel_dep(name = "bazel_skylib", version = "1.9.0")
Expand Down
19 changes: 19 additions & 0 deletions phaser/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ package(default_visibility = ["//visibility:public"])

exports_files(["valgrind.supp"])

# True when building with clang, which gates the clang-only -Weverything set in
# PHASER_COPTS (GCC does not understand -Weverything).
config_setting(
name = "is_clang",
flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"},
)

cc_library(
name = "test_helpers",
hdrs = ["test_helpers.h"],
Expand All @@ -31,6 +38,18 @@ cc_test(
],
)

cc_test(
name = "active_message_test",
srcs = ["active_message_test.cc"],
copts = PHASER_COPTS,
data = ["valgrind.supp"],
deps = [
"//phaser/runtime:phaser_runtime",
"//phaser/testdata:foo_active_message_phaser",
"@com_google_googletest//:gtest",
],
)

cc_test(
name = "all_types_test",
srcs = ["all_types_test.cc"],
Expand Down
45 changes: 45 additions & 0 deletions phaser/active_message_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024-2026 David Allison
// All Rights Reserved
// See LICENSE file for licensing information.

#include <gtest/gtest.h>

#include <any>
#include <string>

#include "phaser/runtime/runtime.h"
#include "phaser/testdata/Foo.phaser.h"

// Verifies the optional `std::any active_message` field that is emitted when a
// phaser_library is built with enable_active_message = True (which passes the
// active_message=true plugin command-line option).
TEST(ActiveMessage, DefaultsToEmpty) {
char* buffer = static_cast<char*>(calloc(4096, 1));
foo::bar::phaser::Foo msg =
foo::bar::phaser::Foo::CreateMutable(buffer, 4096);
EXPECT_FALSE(msg.active_message.has_value());
free(buffer);
}

TEST(ActiveMessage, HoldsArbitraryPayload) {
char* buffer = static_cast<char*>(calloc(4096, 1));
foo::bar::phaser::Foo msg =
foo::bar::phaser::Foo::CreateMutable(buffer, 4096);

// The field is a public std::any, independent of the wire-format fields.
msg.set_a(42);
msg.active_message = std::string("attached-payload");

ASSERT_TRUE(msg.active_message.has_value());
EXPECT_EQ("attached-payload", std::any_cast<std::string>(msg.active_message));
EXPECT_EQ(42, msg.a());

msg.active_message.reset();
EXPECT_FALSE(msg.active_message.has_value());
free(buffer);
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading
Loading