fuzzing_event_engine_test.cc
Go to the documentation of this file.
1 // Copyright 2022 The gRPC Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <chrono>
18 #include <thread>
19 
20 #include "absl/time/clock.h"
21 
22 #include <grpc/grpc.h>
23 
24 #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h"
26 
27 namespace grpc_event_engine {
28 namespace experimental {
29 namespace {
30 
31 class ThreadedFuzzingEventEngine : public FuzzingEventEngine {
32  public:
33  ThreadedFuzzingEventEngine()
34  : FuzzingEventEngine(
35  []() {
36  Options options;
37  options.final_tick_length = std::chrono::milliseconds(10);
38  return options;
39  }(),
40  fuzzing_event_engine::Actions()),
41  main_([this]() {
42  while (!done_.load()) {
43  auto tick_start = absl::Now();
44  while (absl::Now() - tick_start < absl::Milliseconds(10)) {
46  }
47  Tick();
48  }
49  }) {}
50 
51  ~ThreadedFuzzingEventEngine() override {
52  done_.store(true);
53  main_.join();
54  }
55 
56  private:
57  std::atomic<bool> done_{false};
59 };
60 
61 } // namespace
62 } // namespace experimental
63 } // namespace grpc_event_engine
64 
65 int main(int argc, char** argv) {
66  testing::InitGoogleTest(&argc, argv);
68  []() {
69  return absl::make_unique<
70  grpc_event_engine::experimental::ThreadedFuzzingEventEngine>();
71  },
72  nullptr);
73  return RUN_ALL_TESTS();
74 }
SetEventEngineFactories
void SetEventEngineFactories(std::function< std::unique_ptr< grpc_event_engine::experimental::EventEngine >()> factory, std::function< std::unique_ptr< grpc_event_engine::experimental::EventEngine >()> oracle_ee_factory)
Definition: event_engine_test.cc:26
options
double_dict options[]
Definition: capstone_test.c:55
main_
std::thread main_
Definition: fuzzing_event_engine_test.cc:58
absl::make_unique
memory_internal::MakeUniqueResult< T >::scalar make_unique(Args &&... args)
Definition: third_party/abseil-cpp/absl/memory/memory.h:168
absl::SleepFor
void SleepFor(absl::Duration duration)
Definition: abseil-cpp/absl/time/clock.h:70
done_
std::atomic< bool > done_
Definition: fuzzing_event_engine_test.cc:57
main
int main(int argc, char **argv)
Definition: fuzzing_event_engine_test.cc:65
absl::Milliseconds
constexpr Duration Milliseconds(T n)
Definition: third_party/abseil-cpp/absl/time/time.h:415
fuzzing_event_engine.h
grpc.h
event_engine_test.h
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
absl::Now
ABSL_NAMESPACE_BEGIN Time Now()
Definition: abseil-cpp/absl/time/clock.cc:39
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_event_engine
Definition: endpoint_config.h:24
thread
static uv_thread_t thread
Definition: test-async-null-cb.c:29


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:23