buffer_list_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #include <grpc/grpc.h>
22 
25 
26 #ifdef GRPC_LINUX_ERRQUEUE
27 
28 static void TestShutdownFlushesListVerifier(void* arg,
29  grpc_core::Timestamps* /*ts*/,
32  GPR_ASSERT(arg != nullptr);
33  gpr_atm* done = reinterpret_cast<gpr_atm*>(arg);
34  gpr_atm_rel_store(done, static_cast<gpr_atm>(1));
35 }
36 
41 static void TestShutdownFlushesList() {
43  TestShutdownFlushesListVerifier);
44  grpc_core::TracedBuffer* list = nullptr;
45 #define NUM_ELEM 5
46  gpr_atm verifier_called[NUM_ELEM];
47  for (auto i = 0; i < NUM_ELEM; i++) {
48  gpr_atm_rel_store(&verifier_called[i], static_cast<gpr_atm>(0));
49  grpc_core::TracedBuffer::AddNewEntry(
50  &list, i, 0, static_cast<void*>(&verifier_called[i]));
51  }
53  GPR_ASSERT(list == nullptr);
54  for (auto i = 0; i < NUM_ELEM; i++) {
55  GPR_ASSERT(gpr_atm_acq_load(&verifier_called[i]) ==
56  static_cast<gpr_atm>(1));
57  }
58 }
59 
60 static void TestVerifierCalledOnAckVerifier(void* arg,
64  GPR_ASSERT(arg != nullptr);
66  GPR_ASSERT(ts->acked_time.time.tv_sec == 123);
67  GPR_ASSERT(ts->acked_time.time.tv_nsec == 456);
68  GPR_ASSERT(ts->info.length > 0);
69  gpr_atm* done = reinterpret_cast<gpr_atm*>(arg);
70  gpr_atm_rel_store(done, static_cast<gpr_atm>(1));
71 }
72 
75 static void TestVerifierCalledOnAck() {
76  struct sock_extended_err serr;
77  serr.ee_data = 213;
78  serr.ee_info = grpc_core::SCM_TSTAMP_ACK;
79  struct grpc_core::scm_timestamping tss;
80  tss.ts[0].tv_sec = 123;
81  tss.ts[0].tv_nsec = 456;
83  TestVerifierCalledOnAckVerifier);
84  grpc_core::TracedBuffer* list = nullptr;
85  gpr_atm verifier_called;
86  gpr_atm_rel_store(&verifier_called, static_cast<gpr_atm>(0));
87  grpc_core::TracedBuffer::AddNewEntry(&list, 213, 0, &verifier_called);
88  grpc_core::TracedBuffer::ProcessTimestamp(&list, &serr, nullptr, &tss);
89  GPR_ASSERT(gpr_atm_acq_load(&verifier_called) == static_cast<gpr_atm>(1));
90  GPR_ASSERT(list == nullptr);
92 }
93 
96 static void TestRepeatedShutdown() {
97  struct sock_extended_err serr;
98  serr.ee_data = 213;
99  serr.ee_info = grpc_core::SCM_TSTAMP_ACK;
100  struct grpc_core::scm_timestamping tss;
101  tss.ts[0].tv_sec = 123;
102  tss.ts[0].tv_nsec = 456;
104  TestVerifierCalledOnAckVerifier);
105  grpc_core::TracedBuffer* list = nullptr;
106  gpr_atm verifier_called;
107  gpr_atm_rel_store(&verifier_called, static_cast<gpr_atm>(0));
108  grpc_core::TracedBuffer::AddNewEntry(&list, 213, 0, &verifier_called);
109  grpc_core::TracedBuffer::ProcessTimestamp(&list, &serr, nullptr, &tss);
110  GPR_ASSERT(gpr_atm_acq_load(&verifier_called) == static_cast<gpr_atm>(1));
111  GPR_ASSERT(list == nullptr);
115 }
116 
117 static void TestTcpBufferList() {
118  TestVerifierCalledOnAck();
119  TestShutdownFlushesList();
120  TestRepeatedShutdown();
121 }
122 
123 int main(int argc, char** argv) {
124  grpc::testing::TestEnvironment env(&argc, argv);
125  grpc_init();
126  TestTcpBufferList();
127  grpc_shutdown();
128  return 0;
129 }
130 
131 #else /* GRPC_LINUX_ERRQUEUE */
132 
133 int main(int /*argc*/, char** /*argv*/) { return 0; }
134 
135 #endif /* GRPC_LINUX_ERRQUEUE */
gpr_timespec::tv_nsec
int32_t tv_nsec
Definition: gpr_types.h:52
gpr_timespec::tv_sec
int64_t tv_sec
Definition: gpr_types.h:51
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
generate.env
env
Definition: generate.py:37
buffer_list.h
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::grpc_tcp_set_write_timestamps_callback
void grpc_tcp_set_write_timestamps_callback(void(*fn)(void *, Timestamps *, grpc_error_handle error))
Definition: buffer_list.cc:297
grpc_core::Timestamps
Definition: buffer_list.h:90
grpc_core::BufferTimestamp::time
gpr_timespec time
Definition: buffer_list.h:86
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::Timestamps::acked_time
BufferTimestamp acked_time
Definition: buffer_list.h:94
grpc.h
gpr_atm_acq_load
#define gpr_atm_acq_load(p)
Definition: impl/codegen/atm_gcc_atomic.h:52
done
struct tab * done
Definition: bloaty/third_party/zlib/examples/enough.c:176
arg
Definition: cmdline.cc:40
gpr_atm_rel_store
#define gpr_atm_rel_store(p, value)
Definition: impl/codegen/atm_gcc_atomic.h:54
gpr_timespec::clock_type
gpr_clock_type clock_type
Definition: gpr_types.h:55
test_config.h
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_atomic.h:32
grpc_core::TracedBuffer::Shutdown
static void Shutdown(TracedBuffer **, void *, grpc_error_handle shutdown_err)
Definition: buffer_list.h:149
port.h
main
int main(int, char **)
Definition: buffer_list_test.cc:133
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_core::TracedBuffer
Definition: buffer_list.h:146
arg
struct arg arg
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_error
Definition: error_internal.h:42
GPR_CLOCK_REALTIME
@ GPR_CLOCK_REALTIME
Definition: gpr_types.h:39
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
GRPC_ERROR_IS_NONE
#define GRPC_ERROR_IS_NONE(err)
Definition: error.h:241


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:41