Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert designated initializer usages for C++17 compliance. #1584

Merged
merged 1 commit into from
Mar 1, 2025
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: 1 addition & 4 deletions centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ cc_library(
name = "reverse_pc_table",
hdrs = ["reverse_pc_table.h"],
# Avoid non-trivial dependencies here, as this library will be linked to target binaries.
deps = [
":pc_info",
"@com_google_absl//absl/types:span",
],
deps = [":pc_info"],
)

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion centipede/mutation_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ inline std::vector<MutationInputRef> GetMutationInputRefsFromDataInputs(
const std::vector<ByteArray> &inputs) {
std::vector<MutationInputRef> results;
results.reserve(inputs.size());
for (const auto &input : inputs) results.push_back({.data = input});
for (const auto &input : inputs) results.push_back({/*data=*/input});
return results;
}

Expand Down
2 changes: 1 addition & 1 deletion centipede/pc_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace centipede {
namespace {

TEST(PCTableTest, SerializesAndDeserializesPCInfoSuccessfully) {
PCTable input = {{.pc = 0, .flags = 1}, {.pc = 2, .flags = 3}};
PCTable input = {{/*pc=*/0, /*flags=*/1}, {/*pc=*/2, /*flags=*/3}};

std::stringstream stream;
WritePcTable(input, stream);
Expand Down
10 changes: 5 additions & 5 deletions centipede/periodic_action_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ TEST(PeriodicActionTest, OnlyNudgedInvocations) {
constexpr absl::Duration kDuration = absl::Seconds(3);
constexpr absl::Duration kNudgeInterval = absl::Milliseconds(100);
int count = 0;
PeriodicAction::Options options;
// Effectively disable periodic invocations: only `Nudge()` calls
// below will trigger them.
options.sleep_before_each = [](size_t) { return absl::InfiniteDuration(); };
PeriodicAction action{
[&count]() { ++count; },
{
// Effectively disable periodic invocations: only `Nudge()` calls
// below will trigger them.
.sleep_before_each = [](size_t) { return absl::InfiniteDuration(); },
},
std::move(options),
};
int expected_count = 0;
const absl::Time end_time = absl::Now() + kDuration;
Expand Down
2 changes: 1 addition & 1 deletion centipede/puzzles/pthread_exit_uint32_cmp_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
struct ThreadArg {
const uint8_t *data;
size_t size;
} arg = {.data = data, .size = size};
} arg = {data, size};
auto pt_entry = +[](const ThreadArg *thread_arg) {
uint32_t value, expected_value;
if (thread_arg->size == sizeof(value)) {
Expand Down
60 changes: 38 additions & 22 deletions centipede/resource_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cstddef>
#include <string>
#include <string_view>
#include <utility>

#include "gtest/gtest.h"
#include "absl/log/log.h"
Expand All @@ -31,28 +32,40 @@
namespace centipede::perf {
namespace {

constexpr RUsageMemory MakeMemRss(MemSize mem_rss) {
return RUsageMemory{/*mem_vsize=*/0, /*mem_vpeak=*/0, mem_rss};
}

TEST(ResourcePoolTest, InvalidLeaseRequests) {
const RUsageMemory kQuota = {.mem_rss = 1000};
const RUsageMemory kZero = {.mem_rss = 0};
const RUsageMemory kEpsilon = {.mem_rss = 1};
constexpr RUsageMemory kQuota = MakeMemRss(1000);
constexpr RUsageMemory kZero = MakeMemRss(0);
constexpr RUsageMemory kEpsilon = MakeMemRss(1);
ResourcePool pool{kQuota};
{
const auto lease = pool.AcquireLeaseBlocking({.amount = kZero});
ResourcePool<RUsageMemory>::LeaseRequest request;
request.amount = kZero;
const auto lease = pool.AcquireLeaseBlocking(std::move(request));
EXPECT_EQ(lease.status().code(), absl::StatusCode::kInvalidArgument)
<< VV(lease.status());
}
{
const auto lease = pool.AcquireLeaseBlocking({.amount = kQuota - kEpsilon});
ResourcePool<RUsageMemory>::LeaseRequest request;
request.amount = kQuota - kEpsilon;
const auto lease = pool.AcquireLeaseBlocking(std::move(request));
EXPECT_EQ(lease.status().code(), absl::StatusCode::kOk)
<< VV(lease.status());
}
{
const auto lease = pool.AcquireLeaseBlocking({.amount = kQuota});
ResourcePool<RUsageMemory>::LeaseRequest request;
request.amount = kQuota;
const auto lease = pool.AcquireLeaseBlocking(std::move(request));
EXPECT_EQ(lease.status().code(), absl::StatusCode::kOk)
<< VV(lease.status());
}
{
const auto lease = pool.AcquireLeaseBlocking({.amount = kQuota + kEpsilon});
ResourcePool<RUsageMemory>::LeaseRequest request;
request.amount = kQuota + kEpsilon;
const auto lease = pool.AcquireLeaseBlocking(std::move(request));
EXPECT_EQ(lease.status().code(), absl::StatusCode::kResourceExhausted)
<< VV(lease.status());
}
Expand All @@ -69,37 +82,40 @@ TEST(ResourcePoolTest, Dynamic) {
absl::StatusCode expected_lease_status;
};

constexpr RUsageMemory kRssQuota = {.mem_rss = 5};
constexpr RUsageMemory kRssQuota = MakeMemRss(5);
constexpr int kNumTasks = 9;
constexpr std::array<TaskSpec, kNumTasks> kTaskSpecs = {{
// Can't request 0 amount.
{"0", {.mem_rss = 0}, 0, 1, 3, absl::StatusCode::kInvalidArgument},
{"0", /*ram_chunk=*/MakeMemRss(0), 0, 1, 3,
absl::StatusCode::kInvalidArgument},
// Exceeds the initial pool capacity.
{"1", {.mem_rss = 10}, 0, 1, 3, absl::StatusCode::kResourceExhausted},
{"1", /*ram_chunk=*/MakeMemRss(10), 0, 1, 3,
absl::StatusCode::kResourceExhausted},
// "2" gets the resource first.
{"2", {.mem_rss = 2}, 0, 0, 2, absl::StatusCode::kOk},
{"2", /*ram_chunk=*/MakeMemRss(2), 0, 0, 2, absl::StatusCode::kOk},
// "1" gets the resource immediately after "2" and runs concurrently.
{"3", {.mem_rss = 2}, 0, 0, 4, absl::StatusCode::kOk},
{"3", /*ram_chunk=*/MakeMemRss(2), 0, 0, 4, absl::StatusCode::kOk},
// "4" can't get the resource right away - 1 sec later than "2" and "3" -
// because they almost exhaust the pool; but it waits long enough for "2"
// to finish (while "3" is still running) and free up enough of the pool;
// then "4" gets the resource and runs fine.
{"4", {.mem_rss = 1}, 1, 3, 4, absl::StatusCode::kOk},
{"4", /*ram_chunk=*/MakeMemRss(1), 1, 3, 4, absl::StatusCode::kOk},
// "5" starts while "2" and "3", and later on "3" and "4", are still
// running. They all continuously hold enough of the pool to prevent "5"
// from ever getting its resource. Eventually, "5" runs out of time.
{"5", {.mem_rss = 4}, 2, 3, 5, absl::StatusCode::kDeadlineExceeded},
{"5", /*ram_chunk=*/MakeMemRss(4), 2, 3, 5,
absl::StatusCode::kDeadlineExceeded},
// "6" is like "5", but it waits long enough for "3" and "4" to free up
// the pool; then "6" gets the resource and runs fine.
{"6", {.mem_rss = 4}, 2, 5, 6, absl::StatusCode::kOk},
{"6", /*ram_chunk=*/MakeMemRss(4), 2, 5, 6, absl::StatusCode::kOk},
// "7" is also like "5", but is less greedy, so although it starts 1 sec
// later, it is allowed in front of "5" and "6" and runs fine, partially
// sharing the pool with "3" and "4".
{"7", {.mem_rss = 1}, 3, 3, 5, absl::StatusCode::kOk},
{"7", /*ram_chunk=*/MakeMemRss(1), 3, 3, 5, absl::StatusCode::kOk},
// "8" starts waiting for the maximum available amount when other
// consumers already use some of the pool. It waits long enough for all of
// them to finish, then finally grabs the entire quota and runs.
{"8", {.mem_rss = 5}, 2, 9, 10, absl::StatusCode::kOk},
{"8", /*ram_chunk=*/MakeMemRss(5), 2, 9, 10, absl::StatusCode::kOk},
}};
std::array<absl::Status, kNumTasks> task_lease_statuses;

Expand All @@ -114,11 +130,11 @@ TEST(ResourcePoolTest, Dynamic) {
// as many threads, and scheduling is fast), so they are on roughly the
// same relative timetable.
absl::SleepFor(absl::Seconds(t.request_at_secs));
const auto lease = pool.AcquireLeaseBlocking({
.id = std::string(t.id),
.amount = t.ram_chunk,
.timeout = absl::Seconds(t.timeout_at_secs - t.request_at_secs),
});
ResourcePool<RUsageMemory>::LeaseRequest request;
request.id = std::string(t.id);
request.amount = t.ram_chunk;
request.timeout = absl::Seconds(t.timeout_at_secs - t.request_at_secs);
const auto lease = pool.AcquireLeaseBlocking(std::move(request));
lease_status = lease.status();
if (lease_status.ok()) {
absl::SleepFor(absl::Seconds(t.release_at_secs - t.request_at_secs));
Expand Down
7 changes: 3 additions & 4 deletions centipede/reverse_pc_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class ReversePCTable {
const auto &pc_info = pc_table[idx];
if (pc_info.pc >= size_) __builtin_trap(); // TODO(kcc): use RunnerCheck.
table_[pc_info.pc] = {
.is_function_entry = pc_info.has_flag(PCInfo::kFuncEntry),
.pc_index = static_cast<uint32_t>(idx)};
/*is_function_entry=*/pc_info.has_flag(PCInfo::kFuncEntry),
/*pc_index=*/static_cast<uint32_t>(idx)};
}
}

Expand All @@ -80,8 +80,7 @@ class ReversePCTable {

private:
// A PCGuard object, such that IsValid() will return false.
static constexpr PCGuard kInvalidPCGuard = {
.is_function_entry = 0, .pc_index = PCGuard::kInvalidPcIndex};
static constexpr PCGuard kInvalidPCGuard = {0, PCGuard::kInvalidPcIndex};

// We use size_ and table_ pointer instead of std::vector<> because
// (1) we need ReversePCTable object to be accessible even after the
Expand Down
Loading