Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix: fail_point is failed when use FAIL_POINT_INJECT_VOID_F #1047

Merged
merged 7 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/dsn/utility/fail_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
} \
} while (0)

/// The only entry to define a fail point with `void` function: lambda function must be
/// The only entry to define a fail point with `no return` function: lambda function usually is
/// return void type. When a fail point is defined, it's referenced via the name.
#define FAIL_POINT_INJECT_VOID_F(name, lambda) \
#define FAIL_POINT_INJECT_NOT_RETURN_F(name, lambda) \
do { \
if (dsn_likely(!::dsn::fail::_S_FAIL_POINT_ENABLED)) \
break; \
auto __Func = lambda; \
auto __Res = ::dsn::fail::eval(name); \
if (__Res == nullptr) { \
__Func(); \
if (__Res != nullptr) { \
__Func(*__Res); \
} \
} while (0)

Expand Down
2 changes: 1 addition & 1 deletion src/aio/native_linux_aio_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ error_code native_linux_aio_provider::write(const aio_context &aio_ctx,
}

// mock the `ret` to reproduce the `write incomplete` case in the first write
FAIL_POINT_INJECT_VOID_F("aio_pwrite_incomplete", [&]() -> void {
FAIL_POINT_INJECT_NOT_RETURN_F("aio_pwrite_incomplete", [&](string_view s) -> void {
if (dsn_unlikely(buffer_offset == 0)) {
--ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/aio/test/aio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DEFINE_TASK_CODE_AIO(LPC_AIO_TEST, TASK_PRIORITY_COMMON, THREAD_POOL_TEST_SERVER
TEST(core, aio)
{
fail::setup();
fail::cfg("aio_pwrite_incomplete", "off()");
fail::cfg("aio_pwrite_incomplete", "void()");
const char *buffer = "hello, world";
int len = (int)strlen(buffer);

Expand Down Expand Up @@ -148,7 +148,7 @@ TEST(core, aio_share)
TEST(core, operation_failed)
{
fail::setup();
fail::cfg("aio_pwrite_incomplete", "off()");
fail::cfg("aio_pwrite_incomplete", "void()");

auto fp = file::open("tmp_test_file", O_WRONLY, 0600);
EXPECT_TRUE(fp == nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/replica/duplication/load_from_private_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void load_from_private_log::run()
_duplicator->progress().confirmed_decree);
repeat(1_s);

FAIL_POINT_INJECT_VOID_F("duplication_sync_complete", [&]() -> void {
FAIL_POINT_INJECT_NOT_RETURN_F("duplication_sync_complete", [&](string_view s) -> void {
if (_duplicator->progress().confirmed_decree == invalid_decree) {
// set_confirmed_decree(9), the value must be equal (decree_start of
// `test_start_duplication` in `load_from_private_log_test.cpp`) -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class load_from_private_log_test : public duplication_test_base
fail::setup();
fail::cfg("open_read", "25%1*return()");
fail::cfg("mutation_log_read_log_block", "25%1*return()");
fail::cfg("duplication_sync_complete", "off()");
fail::cfg("duplication_sync_complete", "void()");
duplicator->run_pipeline();
duplicator->wait_all();
fail::teardown();
Expand Down
5 changes: 5 additions & 0 deletions src/utils/fail_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ inline const char *task_type_to_string(fail_point::task_type t)
return "Return";
case fail_point::Print:
return "Print";
case fail_point::Void:
return "Void";
default:
dfatal("unexpected type: %d", t);
__builtin_unreachable();
Expand Down Expand Up @@ -123,6 +125,8 @@ bool fail_point::parse_from_string(string_view action)
_task = Return;
} else if (task_type.compare("print") == 0) {
_task = Print;
} else if (task_type.compare("void") == 0) {
_task = Void;
} else {
return false;
}
Expand Down Expand Up @@ -153,6 +157,7 @@ const std::string *fail_point::eval()
switch (_task) {
case Off:
break;
case Void:
case Return:
return &_arg;
case Print:
Expand Down
1 change: 1 addition & 0 deletions src/utils/fail_point_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct fail_point
Off,
Return,
Print,
Void,
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
};

void set_action(string_view action);
Expand Down