Skip to content

Commit

Permalink
Merge branch 'master' into shush
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Jan 23, 2024
2 parents 8212b8c + 19f1b39 commit 20d212d
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 64 deletions.
7 changes: 7 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# - bugprone-not-null-terminated-result
# - bugprone-signed-char-misuse
# - bugprone-sizeof-expression
# - bugprone-switch-missing-default-case
# - bugprone-too-small-loop-variable
# - bugprone-unchecked-optional-access
# - clang-diagnostic-deprecated-declarations
Expand All @@ -50,8 +51,10 @@
# - modernize-use-equals-default
# - modernize-use-equals-delete
# - modernize-use-using
# - performance-avoid-endl
# - performance-no-automatic-move
# - performance-no-int-to-ptr
# - performance-noexcept-swap
# - performance-unnecessary-copy-initialization
# - performance-unnecessary-value-param
# - readability-else-after-return
Expand All @@ -67,6 +70,7 @@ Checks: '-*,
-bugprone-assignment-in-if-condition,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-empty-catch,
-bugprone-exception-escape,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-infinite-loop,
Expand All @@ -75,15 +79,18 @@ Checks: '-*,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-sizeof-expression,
-bugprone-switch-missing-default-case,
-bugprone-too-small-loop-variable,
-bugprone-unchecked-optional-access,
google-*,
-google-readability-casting,
-google-runtime-int,
-google-runtime-references,
performance-*,
-performance-avoid-endl,
-performance-no-automatic-move,
-performance-no-int-to-ptr,
-performance-noexcept-swap,
-performance-unnecessary-copy-initialization,
-performance-unnecessary-value-param,
clang-diagnostic-deprecated-declarations,
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/gprpp/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
uint64_t now = grpc_core::Timestamp::FromTimespecRoundDown( \
gpr_now(GPR_CLOCK_MONOTONIC)) \
.milliseconds_after_process_epoch(); \
if (prev == 0 || now - prev > (n)*1000) { \
if (prev == 0 || now - prev > (n) * 1000) { \
prev = now; \
gpr_log(severity, format, __VA_ARGS__); \
} \
Expand All @@ -50,7 +50,7 @@
gpr_now(GPR_CLOCK_MONOTONIC)) \
.milliseconds_after_process_epoch(); \
uint64_t prev_tsamp = prev.exchange(now); \
if (now - prev_tsamp > (n)*1000) { \
if (now - prev_tsamp > (n) * 1000) { \
gpr_log(severity, format, __VA_ARGS__); \
} \
} while (0)
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/iomgr/combiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ bool grpc_combiner_continue_exec_ctx() {
// Define a macro to ease readability of the following switch statement.
#define OLD_STATE_WAS(orphaned, elem_count) \
(((orphaned) ? 0 : STATE_UNORPHANED) | \
((elem_count)*STATE_ELEM_COUNT_LOW_BIT))
((elem_count) * STATE_ELEM_COUNT_LOW_BIT))
// Depending on what the previous state was, we need to perform different
// actions.
switch (old_state) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/lib/iomgr/tcp_server_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ static grpc_error_handle CreateEventEngineListener(
} else {
EventEngine::Listener::AcceptCallback accept_cb =
[s](std::unique_ptr<EventEngine::Endpoint> ep, MemoryAllocator) {
grpc_core::ApplicationCallbackExecCtx app_ctx;
grpc_core::ExecCtx exec_ctx;
s->on_accept_cb(s->on_accept_cb_arg,
grpc_event_engine::experimental::
grpc_event_engine_endpoint_create(std::move(ep)),
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/json/json_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void JsonWriter::EscapeUtf16(uint16_t utf16) {
OutputChar(hex[(utf16 >> 12) & 0x0f]);
OutputChar(hex[(utf16 >> 8) & 0x0f]);
OutputChar(hex[(utf16 >> 4) & 0x0f]);
OutputChar(hex[(utf16)&0x0f]);
OutputChar(hex[(utf16) & 0x0f]);
}

void JsonWriter::EscapeString(const std::string& string) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/tsi/fake_transport_security.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static void store32_little_endian(uint32_t value, unsigned char* buf) {
buf[3] = static_cast<unsigned char>((value >> 24) & 0xFF);
buf[2] = static_cast<unsigned char>((value >> 16) & 0xFF);
buf[1] = static_cast<unsigned char>((value >> 8) & 0xFF);
buf[0] = static_cast<unsigned char>((value)&0xFF);
buf[0] = static_cast<unsigned char>((value) & 0xFF);
}

static uint32_t read_frame_size(const grpc_slice_buffer* sb) {
Expand Down
2 changes: 1 addition & 1 deletion src/objective-c/tests/InteropTests/InteropTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ - (void)concurrentRPCsWithErrors {
[call setResponseDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL)];
[call start];
}
while (completedCallCount<kNumRpcs && [waitUntil timeIntervalSinceNow]> 0) {
while (completedCallCount < kNumRpcs && [waitUntil timeIntervalSinceNow] > 0) {
[cv waitUntilDate:waitUntil];
}
[cv unlock];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM silkeh/clang:16-bullseye
FROM silkeh/clang:17-bullseye

ADD clang_format_all_the_things.sh /

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM silkeh/clang:16-bullseye
FROM silkeh/clang:17-bullseye

# Install prerequisites for the clang-tidy script
RUN apt-get update && apt-get install -y python3 jq git && apt-get clean
Expand Down
7 changes: 2 additions & 5 deletions templates/tools/dockerfile/test/sanity/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM silkeh/clang:16-bullseye
FROM silkeh/clang:17-bullseye

<%include file="../../apt_get_basic.include"/>

Expand Down Expand Up @@ -52,10 +52,7 @@
RUN python3 -m pip install --upgrade --ignore-installed PyYAML==5.4.1 --user

# Install prerequisites for the clang-tidy script
RUN apt-get update && apt-get install -y jq git

# Install prerequisites for the iwyu script
RUN apt-get update && apt-get install -y jq git cmake zlib1g-dev libtinfo-dev libclang-16-dev && apt-get clean
RUN apt-get update && apt-get install -y jq git && apt-get clean

<%include file="../../bazel.include"/>
<%include file="../../buildifier.include"/>
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/fuzzers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ grpc_cc_library(
"fuzzer_input_proto",
"//:chttp2_frame",
"//test/core/event_engine/fuzzing_event_engine",
"//test/core/util:fuzzing_channel_args",
"//test/core/util:grpc_test_util_base",
],
)
Expand Down Expand Up @@ -136,7 +137,6 @@ grpc_proto_fuzzer(
"//:grpc",
"//src/core:channel_args",
"//test/core/util:fuzz_config_vars",
"//test/core/util:fuzzing_channel_args",
"//test/core/util:grpc_test_util",
"//test/core/util:grpc_test_util_base",
],
Expand Down
3 changes: 3 additions & 0 deletions test/core/end2end/fuzzers/fuzzer_input.proto
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ message InputSegments {
}

message NetworkInput {
int32 connect_delay_ms = 3;
int32 connect_timeout_ms = 4;
grpc.testing.FuzzingChannelArgs endpoint_config = 5;
oneof value {
bytes single_read_bytes = 1;
InputSegments input_segments = 2;
Expand Down
145 changes: 145 additions & 0 deletions test/core/end2end/fuzzers/network_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@

#include "src/core/ext/transport/chttp2/transport/frame.h"
#include "src/core/ext/transport/chttp2/transport/varint.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_args_preconditioning.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/event_engine/channel_args_endpoint_config.h"
#include "src/core/lib/event_engine/tcp_socket_utils.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/slice/slice_buffer.h"
#include "test/core/end2end/fuzzers/fuzzer_input.pb.h"
#include "test/core/util/mock_endpoint.h"

using grpc_event_engine::experimental::EventEngine;

namespace grpc_core {

namespace {
Expand Down Expand Up @@ -307,4 +314,142 @@ Duration ScheduleReads(
});
return Duration::Milliseconds(delay + 2);
}

namespace {

void ReadForever(std::shared_ptr<EventEngine::Endpoint> ep) {
bool finished;
do {
auto buffer =
std::make_unique<grpc_event_engine::experimental::SliceBuffer>();
auto buffer_ptr = buffer.get();
finished = ep->Read(
[ep, buffer = std::move(buffer)](absl::Status status) mutable {
ExecCtx exec_ctx;
if (!status.ok()) return;
ReadForever(std::move(ep));
},
buffer_ptr, nullptr);
} while (finished);
}

void ScheduleWritesForReads(
std::shared_ptr<EventEngine::Endpoint> ep,
grpc_event_engine::experimental::FuzzingEventEngine* event_engine,
std::vector<QueuedRead> schedule) {
class Scheduler {
public:
Scheduler(std::shared_ptr<EventEngine::Endpoint> ep,
grpc_event_engine::experimental::FuzzingEventEngine* event_engine,
std::vector<QueuedRead> schedule)
: ep_(std::move(ep)),
event_engine_(event_engine),
schedule_(std::move(schedule)),
it_(schedule_.begin()) {
ScheduleNext();
}

private:
void ScheduleNext() {
if (it_ == schedule_.end()) {
delete this;
return;
}
event_engine_->RunAfterExactly(
Duration::Milliseconds(it_->delay_ms - delay_consumed_),
[this]() mutable {
ExecCtx exec_ctx;
delay_consumed_ = it_->delay_ms;
writing_.Clear();
writing_.Append(
grpc_event_engine::experimental::internal::SliceCast<
grpc_event_engine::experimental::Slice>(
it_->slices.JoinIntoSlice()));
if (ep_->Write(
[this](absl::Status status) {
ExecCtx exec_ctx;
FinishWrite(std::move(status));
},
&writing_, nullptr)) {
FinishWrite(absl::OkStatus());
}
});
}

void FinishWrite(absl::Status status) {
if (!status.ok()) {
it_ = schedule_.end();
} else {
++it_;
}
ScheduleNext();
}

std::shared_ptr<EventEngine::Endpoint> ep_;
grpc_event_engine::experimental::FuzzingEventEngine* event_engine_;
std::vector<QueuedRead> schedule_;
std::vector<QueuedRead>::iterator it_;
grpc_event_engine::experimental::SliceBuffer writing_;
int delay_consumed_ = 0;
};
new Scheduler(std::move(ep), event_engine, std::move(schedule));
}

} // namespace

Duration ScheduleConnection(
const fuzzer_input::NetworkInput& network_input,
grpc_event_engine::experimental::FuzzingEventEngine* event_engine,
testing::FuzzingEnvironment environment, int port) {
ChannelArgs channel_args =
CoreConfiguration::Get()
.channel_args_preconditioning()
.PreconditionChannelArgs(
CreateChannelArgsFromFuzzingConfiguration(
network_input.endpoint_config(), environment)
.ToC()
.get());
auto schedule = MakeSchedule(network_input);
Duration delay = Duration::Zero();
for (const auto& q : schedule) {
delay = std::max(
delay,
Duration::Milliseconds(q.delay_ms) +
Duration::NanosecondsRoundUp(
(q.slices.Length() * event_engine->max_delay_write()).count()));
}
delay += Duration::Milliseconds(network_input.connect_delay_ms() +
network_input.connect_timeout_ms());
event_engine->RunAfterExactly(
Duration::Milliseconds(network_input.connect_delay_ms()),
[event_engine, channel_args,
connect_timeout_ms = network_input.connect_timeout_ms(),
schedule = std::move(schedule), port]() mutable {
event_engine->Connect(
[event_engine, schedule = std::move(schedule)](
absl::StatusOr<std::unique_ptr<EventEngine::Endpoint>>
endpoint) mutable {
ExecCtx exec_ctx;
if (!endpoint.ok()) {
gpr_log(GPR_ERROR, "Failed to connect: %s",
endpoint.status().ToString().c_str());
return;
}
std::shared_ptr<EventEngine::Endpoint> ep =
std::move(endpoint.value());
ReadForever(ep);
ScheduleWritesForReads(std::move(ep), event_engine,
std::move(schedule));
},
grpc_event_engine::experimental::ResolvedAddressMakeWild4(port),
grpc_event_engine::experimental::ChannelArgsEndpointConfig(
channel_args),
channel_args.GetObject<ResourceQuota>()
->memory_quota()
->CreateMemoryAllocator("fuzzer"),
Duration::Milliseconds(connect_timeout_ms));
});
return delay;
}

} // namespace grpc_core
6 changes: 6 additions & 0 deletions test/core/end2end/fuzzers/network_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "src/core/lib/iomgr/endpoint.h"
#include "test/core/end2end/fuzzers/fuzzer_input.pb.h"
#include "test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h"
#include "test/core/util/fuzzing_channel_args.h"

namespace grpc_core {

Expand All @@ -27,6 +28,11 @@ Duration ScheduleReads(
grpc_endpoint* mock_endpoint,
grpc_event_engine::experimental::FuzzingEventEngine* event_engine);

Duration ScheduleConnection(
const fuzzer_input::NetworkInput& network_input,
grpc_event_engine::experimental::FuzzingEventEngine* event_engine,
testing::FuzzingEnvironment environment, int port);

} // namespace grpc_core

#endif // GRPC_TEST_CORE_END2END_FUZZERS_NETWORK_INPUT_H
Loading

0 comments on commit 20d212d

Please sign in to comment.