fuzzing_event_engine.h
Go to the documentation of this file.
1 // Copyright 2022 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 
15 #ifndef GRPC_TEST_CORE_EVENT_ENGINE_FUZZING_EVENT_ENGINE_H
16 #define GRPC_TEST_CORE_EVENT_ENGINE_FUZZING_EVENT_ENGINE_H
17 
18 #include <chrono>
19 #include <cstdint>
20 #include <map>
21 
23 #include <grpc/grpc.h>
24 
26 #include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h"
27 
28 namespace grpc_event_engine {
29 namespace experimental {
30 
31 // EventEngine implementation to be used by fuzzers.
33  public:
34  struct Options {
35  // After all scheduled tick lengths are completed, this is the amount of
36  // time Now() will be incremented each tick.
38  };
40  const fuzzing_event_engine::Actions& actions);
41  ~FuzzingEventEngine() override;
42 
43  void FuzzingDone();
44  void Tick();
45 
48  std::function<void(absl::Status)> on_shutdown,
49  const EndpointConfig& config,
50  std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory)
51  override;
52 
54  const ResolvedAddress& addr,
55  const EndpointConfig& args,
56  MemoryAllocator memory_allocator,
57  Duration timeout) override;
58 
59  bool CancelConnect(ConnectionHandle handle) override;
60 
61  bool IsWorkerThread() override;
62 
63  std::unique_ptr<DNSResolver> GetDNSResolver(
64  const DNSResolver::ResolverOptions& options) override;
65 
66  void Run(Closure* closure) override;
67  void Run(std::function<void()> closure) override;
68  TaskHandle RunAfter(Duration when, Closure* closure) override;
69  TaskHandle RunAfter(Duration when, std::function<void()> closure) override;
70  bool Cancel(TaskHandle handle) override;
71 
72  using Time = std::chrono::time_point<FuzzingEventEngine, Duration>;
73 
75 
76  private:
79  : id(id), closure(std::move(closure)) {}
82  };
83 
86  static gpr_timespec GlobalNowImpl(gpr_clock_type clock_type)
88 
90 
92 
93  intptr_t next_task_id_ ABSL_GUARDED_BY(mu_);
94  intptr_t current_tick_ ABSL_GUARDED_BY(mu_);
95  Time now_ ABSL_GUARDED_BY(mu_);
96  std::map<intptr_t, Duration> tick_increments_ ABSL_GUARDED_BY(mu_);
97  std::map<intptr_t, Duration> task_delays_ ABSL_GUARDED_BY(mu_);
98  std::map<intptr_t, std::shared_ptr<Task>> tasks_by_id_ ABSL_GUARDED_BY(mu_);
99  std::multimap<Time, std::shared_ptr<Task>> tasks_by_time_
101 };
102 
103 } // namespace experimental
104 } // namespace grpc_event_engine
105 
106 #endif
absl::time_internal::cctz::seconds
std::chrono::duration< std::int_fast64_t > seconds
Definition: abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h:40
grpc_event_engine::experimental::FuzzingEventEngine::CancelConnect
bool CancelConnect(ConnectionHandle handle) override
Definition: fuzzing_event_engine.cc:153
grpc_event_engine::experimental::FuzzingEventEngine::Cancel
bool Cancel(TaskHandle handle) override
Definition: fuzzing_event_engine.cc:192
grpc_event_engine::experimental::EventEngine::Listener::AcceptCallback
std::function< void(std::unique_ptr< Endpoint >, MemoryAllocator memory_allocator)> AcceptCallback
Called when the listener has accepted a new client connection.
Definition: event_engine.h:232
grpc_event_engine::experimental::MemoryAllocator
Definition: memory_allocator.h:35
grpc_event_engine::experimental::FuzzingEventEngine::GlobalNowImpl
static gpr_timespec GlobalNowImpl(gpr_clock_type clock_type) ABSL_LOCKS_EXCLUDED(mu_)
Definition: fuzzing_event_engine.cc:101
event_engine.h
options
double_dict options[]
Definition: capstone_test.c:55
grpc_event_engine::experimental::EventEngine
Definition: event_engine.h:74
grpc_event_engine::experimental::EventEngine::TaskHandle
Definition: event_engine.h:102
grpc_event_engine::experimental::FuzzingEventEngine::Task::closure
std::function< void()> closure
Definition: fuzzing_event_engine.h:81
gen_build_yaml.struct
def struct(**kwargs)
Definition: test/core/end2end/gen_build_yaml.py:30
grpc_event_engine::experimental::EndpointConfig
Definition: endpoint_config.h:31
grpc_event_engine::experimental::EventEngine::ResolvedAddress
Definition: event_engine.h:118
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
ABSL_EXCLUSIVE_LOCKS_REQUIRED
#define ABSL_EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:145
grpc_event_engine::experimental::FuzzingEventEngine::Time
std::chrono::time_point< FuzzingEventEngine, Duration > Time
Definition: fuzzing_event_engine.h:72
grpc.h
grpc_event_engine::experimental::FuzzingEventEngine::Options::final_tick_length
Duration final_tick_length
Definition: fuzzing_event_engine.h:37
grpc_event_engine::experimental::EventEngine::ConnectionHandle
Definition: event_engine.h:108
grpc_event_engine::experimental::FuzzingEventEngine::CreateListener
absl::StatusOr< std::unique_ptr< Listener > > CreateListener(Listener::AcceptCallback on_accept, std::function< void(absl::Status)> on_shutdown, const EndpointConfig &config, std::unique_ptr< MemoryAllocatorFactory > memory_allocator_factory) override
Definition: fuzzing_event_engine.cc:140
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
grpc_event_engine::experimental::FuzzingEventEngine::~FuzzingEventEngine
~FuzzingEventEngine() override
Definition: fuzzing_event_engine.cc:87
on_connect
void on_connect(uv_connect_t *req, int status)
Definition: libuv/docs/code/dns/main.c:32
grpc_event_engine::experimental::FuzzingEventEngine::Task::id
intptr_t id
Definition: fuzzing_event_engine.h:80
grpc_event_engine::experimental::EventEngine::OnConnectCallback
std::function< void(absl::StatusOr< std::unique_ptr< Endpoint > >)> OnConnectCallback
Definition: event_engine.h:224
grpc_event_engine::experimental::FuzzingEventEngine::Task::Task
Task(intptr_t id, std::function< void()> closure)
Definition: fuzzing_event_engine.h:78
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_event_engine::experimental::EventEngine::Closure
Definition: event_engine.h:87
grpc_event_engine::experimental::FuzzingEventEngine::final_tick_length_
const Duration final_tick_length_
Definition: fuzzing_event_engine.h:89
grpc_event_engine::experimental::FuzzingEventEngine::ABSL_GUARDED_BY
intptr_t next_task_id_ ABSL_GUARDED_BY(mu_)
ABSL_LOCKS_EXCLUDED
#define ABSL_LOCKS_EXCLUDED(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:163
grpc_event_engine::experimental::FuzzingEventEngine::Options
Definition: fuzzing_event_engine.h:34
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
grpc_event_engine::experimental::FuzzingEventEngine::IsWorkerThread
bool IsWorkerThread() override
Definition: fuzzing_event_engine.cc:155
grpc_event_engine::experimental::FuzzingEventEngine::NowAsTimespec
gpr_timespec NowAsTimespec(gpr_clock_type clock_type) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
Definition: fuzzing_event_engine.cc:92
on_accept
static void on_accept(void *arg, grpc_endpoint *endpoint, grpc_pollset *, grpc_tcp_server_acceptor *acceptor)
Definition: http_proxy_fixture.cc:567
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_event_engine::experimental::FuzzingEventEngine::GetDNSResolver
std::unique_ptr< DNSResolver > GetDNSResolver(const DNSResolver::ResolverOptions &options) override
Definition: fuzzing_event_engine.cc:157
grpc_event_engine
Definition: endpoint_config.h:24
grpc_event_engine::experimental::FuzzingEventEngine::Tick
void Tick()
Definition: fuzzing_event_engine.cc:107
closure
Definition: proxy.cc:59
config_s
Definition: bloaty/third_party/zlib/deflate.c:120
handle
static csh handle
Definition: test_arm_regression.c:16
Duration
Definition: bloaty/third_party/protobuf/src/google/protobuf/duration.pb.h:69
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
gpr_timespec
Definition: gpr_types.h:50
grpc_event_engine::experimental::FuzzingEventEngine::Connect
ConnectionHandle Connect(OnConnectCallback on_connect, const ResolvedAddress &addr, const EndpointConfig &args, MemoryAllocator memory_allocator, Duration timeout) override
Definition: fuzzing_event_engine.cc:147
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
grpc_event_engine::experimental::FuzzingEventEngine::mu_
grpc_core::Mutex mu_
Definition: fuzzing_event_engine.h:91
grpc_event_engine::experimental::FuzzingEventEngine::Run
void Run(Closure *closure) override
Definition: fuzzing_event_engine.cc:162
grpc_event_engine::experimental::FuzzingEventEngine::FuzzingDone
void FuzzingDone()
Definition: fuzzing_event_engine.cc:82
grpc_event_engine::experimental::FuzzingEventEngine
Definition: fuzzing_event_engine.h:32
grpc_event_engine::experimental::FuzzingEventEngine::Task
Definition: fuzzing_event_engine.h:77
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
timeout
uv_timer_t timeout
Definition: libuv/docs/code/uvwget/main.c:9
sync.h
grpc_event_engine::experimental::FuzzingEventEngine::Now
Time Now() ABSL_LOCKS_EXCLUDED(mu_)
Definition: fuzzing_event_engine.cc:134
grpc_event_engine::experimental::FuzzingEventEngine::FuzzingEventEngine
FuzzingEventEngine(Options options, const fuzzing_event_engine::Actions &actions)
Definition: fuzzing_event_engine.cc:36
id
uint32_t id
Definition: flow_control_fuzzer.cc:70
gpr_clock_type
gpr_clock_type
Definition: gpr_types.h:34
grpc_event_engine::experimental::FuzzingEventEngine::RunAfter
TaskHandle RunAfter(Duration when, Closure *closure) override
Definition: fuzzing_event_engine.cc:170


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