Skip to content

Internal change #22308

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 10 additions & 0 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1505,8 +1505,12 @@ cc_test(
":port",
":protobuf",
"//src/google/protobuf/stubs",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/log:log_streamer",
"@abseil-cpp//absl/numeric:bits",
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/random:seed_sequences",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/time",
Expand Down Expand Up @@ -1879,6 +1883,7 @@ cc_test(
}),
data = [":testdata"],
deps = [
":arena",
":cc_test_protos",
":internal_visibility_for_testing",
":lite_test_util",
Expand All @@ -1895,13 +1900,18 @@ cc_test(
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:time_util",
"@abseil-cpp//absl/base",
"@abseil-cpp//absl/base:log_severity",
"@abseil-cpp//absl/cleanup",
"@abseil-cpp//absl/container:btree",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/log:absl_log",
"@abseil-cpp//absl/log:globals",
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/random:distributions",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
"@googletest//:gtest",
"@googletest//:gtest_main",
Expand Down
29 changes: 21 additions & 8 deletions src/google/protobuf/arenaz_sampler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#include <cstdint>
#include <limits>
#include <memory>
#include <random>
#include <utility>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/base/optimization.h"
#include "absl/log/absl_check.h"
#include "absl/log/log_streamer.h"
#include "absl/random/random.h"
#include "absl/random/seed_sequences.h"
#include "absl/strings/str_cat.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
Expand Down Expand Up @@ -330,37 +333,47 @@ TEST(ThreadSafeArenazSamplerTest, Unregistration) {
EXPECT_THAT(GetBytesAllocated(&sampler), IsEmpty());
}

// This will log the following:
// ```
// Tagged seed sequence (ABSL_RANDOM_SALT_OVERRIDE=fBAY_g): SEED_MT_0=XVKmv...
// Tagged seed sequence (ABSL_RANDOM_SALT_OVERRIDE=fBAY_g): SEED_MT_1=5wvqx...
// ...
// ```
// To try to reproduce a run using the same random sequence, do this:
// $ export SEED_MT_0=XVKmv... SEED_MT_1=5wvqx... ... bazel test <this test>
TEST(ThreadSafeArenazSamplerTest, MultiThreaded) {
ThreadSafeArenazSampler sampler;
absl::Notification stop;
ThreadPool pool(10);

for (int i = 0; i < 10; ++i) {
const int64_t sampling_stride = 11 + i % 3;
pool.Schedule([&sampler, &stop, sampling_stride]() {
std::random_device rd;
std::mt19937 gen(rd());

pool.Schedule([i, &sampler, &stop, sampling_stride]() {
absl::BitGen bitgen{absl::MakeTaggedSeedSeq(
/*env_var=*/absl::StrCat("SEED_", test_info_->name(), "_", i).c_str(),
/*stream=*/absl::LogInfoStreamer().stream())};
std::vector<ThreadSafeArenaStats*> infoz;
while (!stop.HasBeenNotified()) {
if (infoz.empty()) {
infoz.push_back(sampler.Register(sampling_stride));
}
switch (std::uniform_int_distribution<>(0, 1)(gen)) {
switch (absl::Uniform(absl::IntervalClosedClosed, bitgen, 0, 1)) {
case 0: {
infoz.push_back(sampler.Register(sampling_stride));
break;
}
case 1: {
size_t p =
std::uniform_int_distribution<>(0, infoz.size() - 1)(gen);
size_t p = absl::Uniform<size_t>(bitgen, 0, infoz.size());
ThreadSafeArenaStats* info = infoz[p];
infoz[p] = infoz.back();
infoz.pop_back();
EXPECT_EQ(info->weight, sampling_stride);
sampler.Unregister(info);
break;
}
default:
ABSL_UNREACHABLE();
break;
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/google/protobuf/descriptor_database_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#include "google/protobuf/descriptor_database.h"

#include <algorithm>
#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "google/protobuf/descriptor.pb.h"
#include <gmock/gmock.h>
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/generated_message_tctable_lite_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ TEST(GeneratedMessageTctableLiteTest,
}



} // namespace internal
} // namespace protobuf
} // namespace google
Expand Down
6 changes: 2 additions & 4 deletions src/google/protobuf/map_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <random>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/container/flat_hash_set.h"
#include "absl/random/distributions.h"
#include "absl/random/random.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/arena_test_util.h"
#include "google/protobuf/internal_visibility_for_testing.h"
#include "google/protobuf/map_field.h"
#include "google/protobuf/map_proto2_unittest.pb.h"
#include "google/protobuf/map_test_util.h"
#include "google/protobuf/map_unittest.pb.h"
#include "google/protobuf/reflection_tester.h"
#include "google/protobuf/unittest.pb.h"
Expand Down
30 changes: 20 additions & 10 deletions src/google/protobuf/map_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,55 @@

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <random>
#include <ostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "google/protobuf/testing/file.h"
#include "google/protobuf/testing/file.h" // IWYU pragma: keep
#include "google/protobuf/descriptor.pb.h"
#include <gmock/gmock.h>
#include "google/protobuf/testing/googletest.h"
#include "google/protobuf/testing/googletest.h" // IWYU pragma: keep
#include <gtest/gtest.h>
#include "absl/base/casts.h"
#include "absl/base/log_severity.h"
#include "absl/cleanup/cleanup.h"
#include "absl/container/btree_set.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/strings/substitute.h"
#include "absl/time/time.h"
#include "google/protobuf/arena_test_util.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/arena_test_util.h" // IWYU pragma: keep
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor_database.h"
#include "google/protobuf/dynamic_message.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/tokenizer.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "google/protobuf/map.h"
#include "google/protobuf/map_entry.h"
#include "google/protobuf/map_proto2_unittest.pb.h"
#include "google/protobuf/map_proto3_unittest.pb.h"
#include "google/protobuf/map_test_util.h"
#include "google/protobuf/message.h"
#include "google/protobuf/message_lite.h"
#include "google/protobuf/port.h"
#include "google/protobuf/reflection.h"
#include "google/protobuf/reflection_ops.h"
#include "google/protobuf/reflection_tester.h"
#include "google/protobuf/test_textproto.h"
#include "google/protobuf/test_util.h"
#include "google/protobuf/test_util2.h"
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/message_differencer.h"
#include "google/protobuf/wire_format.h"
#include "google/protobuf/wire_format_lite.h"


// Must be included last.
Expand Down
Loading