Branch data Line data Source code
1 : : /*
2 : : * Copyright 2025 Jinwoo Sung
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.apache.org/licenses/LICENSE-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : #pragma once
18 : :
19 : : #include <atomic>
20 : : #include <chrono>
21 : : #include <functional>
22 : :
23 : : namespace boost::system {
24 : : class error_code;
25 : : }
26 : :
27 : : namespace wirestead::wrapper {
28 : : class SendResult;
29 : : }
30 : :
31 : : namespace wirestead::transport::detail {
32 : : // Internal scheduling seam. Tests can stop immediately before the completion
33 : : // signal or observe callers reaching its wait; production leaves this null.
34 : : inline std::atomic<void (*)()> g_tcp_io_completion_hook{nullptr};
35 : : // Inject an initiation failure after handoff; tests must not call channel APIs here.
36 : : inline std::atomic<void (*)()> g_tcp_write_initiation_hook{nullptr};
37 : : // After write initiation, before completion; no admission lock held.
38 : : inline std::atomic<void (*)()> g_tcp_write_started_hook{nullptr};
39 : : // Pauses a TCP write after its state check, before reservation/submission.
40 : : inline std::atomic<void (*)()> g_tcp_write_admission_hook{nullptr};
41 : : // Pauses a connection-pinned write before acquiring the admission mutex.
42 : : inline std::atomic<void (*)()> g_tcp_pinned_write_hook{nullptr};
43 : : // Observe native admission outcomes after the submission lock is released.
44 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_tcp_write_result_hook{nullptr};
45 : : inline std::atomic<void (*)()> g_uds_write_admission_hook{nullptr};
46 : : inline std::atomic<void (*)()> g_uds_pinned_write_hook{nullptr};
47 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_uds_write_result_hook{nullptr};
48 : : inline std::atomic<void (*)()> g_uds_io_completion_hook{nullptr};
49 : : // Controlled virtual-session time for expiry boundary tests.
50 : : inline std::atomic<std::chrono::steady_clock::time_point (*)()> g_udp_session_clock_hook{nullptr};
51 : : inline std::atomic<void (*)()> g_udp_pinned_write_hook{nullptr};
52 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_udp_write_result_hook{nullptr};
53 : : inline std::atomic<void (*)()> g_udp_io_completion_hook{nullptr};
54 : : // Handoff failure injection; do not call channel APIs under the admission lock.
55 : : inline std::atomic<void (*)()> g_udp_write_initiation_hook{nullptr};
56 : : // After initiation and before completion, with no admission lock held.
57 : : inline std::atomic<void (*)()> g_udp_write_started_hook{nullptr};
58 : : // Hold a completion while allowing the strand to process timers. Tests must
59 : : // resume the closure on the channel executor before waiting for shutdown.
60 : : inline std::atomic<void (*)(std::function<void()>)> g_udp_defer_write_completion_hook{nullptr};
61 : : // Before classifying a write completion, outside the admission lock.
62 : : inline std::atomic<void (*)()> g_udp_write_completion_hook{nullptr};
63 : : // Override a live receive completion for terminal-read accounting regressions.
64 : : inline std::atomic<void (*)(boost::system::error_code&)> g_udp_receive_result_hook{nullptr};
65 : : inline std::atomic<void (*)()> g_serial_write_admission_hook{nullptr};
66 : : inline std::atomic<void (*)()> g_serial_pinned_write_hook{nullptr};
67 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_serial_write_result_hook{nullptr};
68 : : inline std::atomic<void (*)()> g_serial_io_completion_hook{nullptr};
69 : : // Snapshot taken, before any per-target fanout admission; no native locks held.
70 : : inline std::atomic<void (*)()> g_tcp_fanout_snapshot_hook{nullptr};
71 : : inline std::atomic<void (*)()> g_uds_fanout_snapshot_hook{nullptr};
72 : : // After targets move to retirement, before asynchronous session cleanup.
73 : : inline std::atomic<void (*)()> g_server_sessions_retiring_hook{nullptr};
74 : : using StopTestHook = void (*)(const void*, bool);
75 : : inline std::atomic<StopTestHook> g_stop_test_hook{nullptr};
76 : 8778 : inline void stop_test_hook(const void* object, bool completing) {
77 [ + + ]: 8778 : if (auto hook = g_stop_test_hook.load(std::memory_order_acquire)) hook(object, completing);
78 : 8778 : }
79 : : inline std::atomic<void (*)()> g_tcp_session_write_admission_hook{nullptr};
80 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_tcp_session_write_result_hook{nullptr};
81 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_tcp_server_write_result_hook{nullptr};
82 : : inline std::atomic<void (*)()> g_uds_session_write_admission_hook{nullptr};
83 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_uds_session_write_result_hook{nullptr};
84 : : inline std::atomic<void (*)(const wrapper::SendResult&)> g_uds_server_write_result_hook{nullptr};
85 : : inline std::atomic<void (*)()> g_tcp_server_pinned_write_hook{nullptr};
86 : : inline std::atomic<void (*)()> g_uds_server_pinned_write_hook{nullptr};
87 : : } // namespace wirestead::transport::detail
|