Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix 'assert' disabled caused function_test failed bug #1080

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 6 additions & 2 deletions src/base/pegasus_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
*/

#include "pegasus_utils.h"

#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdlib.h>
#include <errno.h>

#include "dsn/c/api_utilities.h"
#include "dsn/dist/fmt_logging.h"

namespace pegasus {
namespace utils {

Expand Down Expand Up @@ -111,8 +115,8 @@ c_escape_string(const char *src, size_t src_len, char *dest, size_t dest_len, bo
inline unsigned int hex_digit_to_int(char c)
{
/* Assume ASCII. */
assert('0' == 0x30 && 'A' == 0x41 && 'a' == 0x61);
assert(isxdigit(c));
dassert_f('0' == 0x30 && 'A' == 0x41 && 'a' == 0x61, "");
dassert_f(isxdigit(c), "");
unsigned int x = static_cast<unsigned char>(c);
if (x > '9') {
x += 9;
Expand Down
2 changes: 1 addition & 1 deletion src/base/pegasus_value_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pegasus_extract_user_data(uint32_t version, std::string &&raw_value, ::dsn::blob
/// Extracts timetag from a v1 value.
inline uint64_t pegasus_extract_timetag(int version, dsn::string_view value)
{
dassert(version == 1, "data version(%d) must be v1", version);
dcheck_eq(version, 1);

dsn::data_input input(value);
input.skip(sizeof(uint32_t));
Expand Down
9 changes: 5 additions & 4 deletions src/geo/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
#include <rocksdb/statistics.h>
#include <rocksdb/env.h>

#include <dsn/utility/errors.h>
#include <dsn/utility/strings.h>
#include <dsn/utility/string_conv.h>
#include "dsn/dist/fmt_logging.h"
#include "dsn/utility/errors.h"
#include "dsn/utility/strings.h"
#include "dsn/utility/string_conv.h"

static const int data_count = 10000;

Expand Down Expand Up @@ -85,7 +86,7 @@ int main(int argc, char **argv)
std::string value;
S2LatLng latlng(S2Testing::SamplePoint(rect));
bool ok = codec.encode_to_value(latlng.lat().degrees(), latlng.lng().degrees(), value);
assert(ok);
dassert_f(ok, "");
int ret = my_geo.set(std::to_string(i), "", value, 1000);
if (ret != pegasus::PERR_OK) {
std::cerr << "set data failed. error=" << ret << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/geo/lib/latlng_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void extract_indices(const std::string &line,

bool latlng_codec::decode_from_value(const std::string &value, S2LatLng &latlng) const
{
assert(_sorted_indices.size() == 2);
dcheck_eq(_sorted_indices.size(), 2);
std::vector<std::string> data;
extract_indices(value, _sorted_indices, data, '|');
if (data.size() != 2) {
Expand All @@ -79,7 +79,7 @@ bool latlng_codec::decode_from_value(const std::string &value, S2LatLng &latlng)

bool latlng_codec::encode_to_value(double lat_degrees, double lng_degrees, std::string &value) const
{
assert(_sorted_indices.size() == 2);
dcheck_eq(_sorted_indices.size(), 2);
S2LatLng latlng = S2LatLng::FromDegrees(lat_degrees, lng_degrees);
if (!latlng.is_valid()) {
derror_f("latlng is invalid. lat_degrees={}, lng_degrees={}", lat_degrees, lng_degrees);
Expand Down
5 changes: 3 additions & 2 deletions src/rdsn/include/dsn/cpp/json_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <boost/lexical_cast.hpp>

#include <dsn/c/api_utilities.h>
#include <dsn/utility/autoref_ptr.h>
#include <dsn/utility/utils.h>
#include <dsn/tool-api/auto_codes.h>
Expand Down Expand Up @@ -495,7 +496,7 @@ inline void json_encode(JsonWriter &out, const dsn::ref_ptr<T> &t)
{
// when a smart ptr is encoded, caller should ensure the ptr is not nullptr
// TODO: encoded to null?
assert(t.get() != nullptr);
dassert_f(t.get(), "");
json_encode(out, *t);
}

Expand All @@ -511,7 +512,7 @@ inline void json_encode(JsonWriter &out, const std::shared_ptr<T> &t)
{
// when a smart ptr is encoded, caller should ensure the ptr is not nullptr
// TODO: encoded to null?
assert(t.get() != nullptr);
dassert(t.get(), "");
json_encode(out, *t);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rdsn/include/dsn/utility/casts.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline To down_cast(From *from)
// Use RTTI to do double-check, though in practice the unit tests are seldom built in debug
// mode. For example, the unit tests of github CI for both rDSN and Pegasus are built in
// release mode.
assert(from == NULL || dynamic_cast<To>(from) != NULL);
dassert_f(from == NULL || dynamic_cast<To>(from) != NULL, "");

return static_cast<To>(from);
}
Expand Down
5 changes: 4 additions & 1 deletion src/rdsn/include/dsn/utility/endians.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include <cstdint>
#include <cassert>

#include <dsn/c/api_utilities.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/utility/ports.h>
#include <dsn/utility/string_view.h>

Expand Down Expand Up @@ -145,7 +148,7 @@ class data_input
_size -= sz;
}

void ensure(size_t sz) { assert(_size >= sz); }
void ensure(size_t sz) { dcheck_ge(_size, sz); }

private:
const char *_p{nullptr};
Expand Down
11 changes: 4 additions & 7 deletions src/rdsn/src/aio/aio_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ aio_task::aio_task(dsn::task_code code, aio_handler &&cb, int hash, service_node
{
_is_null = (_cb == nullptr);

dassert(TASK_TYPE_AIO == spec().type,
"%s is not of AIO type, please use DEFINE_TASK_CODE_AIO to define the task code",
spec().name.c_str());
dassert_f(TASK_TYPE_AIO == spec().type,
"{} is not of AIO type, please use DEFINE_TASK_CODE_AIO to define the task code",
spec().name);
set_error_code(ERR_IO_PENDING);

_aio_ctx = file::prepare_aio_context(this);
Expand All @@ -51,10 +51,7 @@ void aio_task::collapse()
::memcpy(dest, b.buffer, b.size);
dest += b.size;
}
dassert(dest - buffer.get() == _aio_ctx->buffer_size,
"%u VS %u",
dest - buffer.get(),
_aio_ctx->buffer_size);
dcheck_eq(dest - buffer.get(), _aio_ctx->buffer_size);
_aio_ctx->buffer = buffer.get();
_merged_write_buffer_holder.assign(std::move(buffer), 0, _aio_ctx->buffer_size);
}
Expand Down
23 changes: 7 additions & 16 deletions src/rdsn/src/block_service/test/fds_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
#include <gtest/gtest.h>
#include <memory>

#include <dsn/utility/filesystem.h>
#include <dsn/utility/rand.h>
#include <dsn/dist/block_service.h>
#include "dsn/dist/block_service.h"
#include "dsn/dist/fmt_logging.h"
#include "dsn/utility/filesystem.h"
#include "dsn/utility/rand.h"
#include "dsn/utility/utils.h"

using namespace dsn;
using namespace dsn::dist::block_service;
Expand All @@ -39,17 +41,6 @@ static std::string access_key = "<access-key>";
static std::string access_secret = "<access-secret>";
static std::string bucket_name = "<test-bucket-name>";

static void pipe_execute(const char *command, std::stringstream &output)
{
std::array<char, 256> buffer;

std::shared_ptr<FILE> command_pipe(popen(command, "r"), pclose);
while (!feof(command_pipe.get())) {
if (fgets(buffer.data(), 256, command_pipe.get()) != NULL)
output << buffer.data();
}
}

static void file_eq_compare(const std::string &fname1, const std::string &fname2)
{
static const int length = 4096;
Expand Down Expand Up @@ -111,7 +102,7 @@ void FDSClientTest::SetUp()
fclose(fp);

std::stringstream ss;
pipe_execute((std::string("md5sum ") + f1.filename).c_str(), ss);
dcheck_eq(utils::pipe_execute((std::string("md5sum ") + f1.filename).c_str(), ss), 0);
ss >> f1.md5;
// well, the string of each line in _test_file is 32
f1.length = 32 * lines;
Expand All @@ -127,7 +118,7 @@ void FDSClientTest::SetUp()
fclose(fp);

std::stringstream ss;
pipe_execute((std::string("md5sum ") + f2.filename).c_str(), ss);
dcheck_eq(utils::pipe_execute((std::string("md5sum ") + f2.filename).c_str(), ss), 0);
ss >> f2.md5;
// well, the string of each line in _test_file is 32
f2.length = 32 * lines;
Expand Down
4 changes: 1 addition & 3 deletions src/rdsn/src/client/partition_resolver_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ void partition_resolver_simple::query_config_reply(error_code err,
if (!reqs2.empty()) {
if (_app_partition_count != -1) {
for (auto &req : reqs2) {
dassert(req->partition_index == -1,
"invalid partition_index, index = %d",
req->partition_index);
dcheck_eq(req->partition_index, -1);
req->partition_index =
get_partition_index(_app_partition_count, req->partition_hash);
}
Expand Down
10 changes: 4 additions & 6 deletions src/rdsn/src/client/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <iostream>

#include <boost/lexical_cast.hpp>
#include <dsn/dist/fmt_logging.h>
#include <dsn/dist/replication/duplication_common.h>
#include <dsn/dist/replication/replication_other_types.h>
#include <dsn/tool-api/group_address.h>
Expand Down Expand Up @@ -99,7 +100,7 @@ dsn::error_code replication_ddl_client::wait_app_ready(const std::string &app_na
<< std::endl;
return query_resp.err;
}
dassert(partition_count == query_resp.partition_count, "partition count not equal");
dcheck_eq(partition_count, query_resp.partition_count);
int ready_count = 0;
for (int i = 0; i < partition_count; i++) {
const partition_configuration &pc = query_resp.partitions[i];
Expand Down Expand Up @@ -384,11 +385,8 @@ dsn::error_code replication_ddl_client::list_apps(const dsn::app_status::type st
derror("list app(%s) failed, err = %s", info.app_name.c_str(), r.to_string());
return r;
}
dassert(info.app_id == app_id, "invalid app_id, %d VS %d", info.app_id, app_id);
dassert(info.partition_count == partition_count,
"invalid partition_count, %d VS %d",
info.partition_count,
partition_count);
dcheck_eq(info.app_id, app_id);
dcheck_eq(info.partition_count, partition_count);
int fully_healthy = 0;
int write_unhealthy = 0;
int read_unhealthy = 0;
Expand Down
5 changes: 1 addition & 4 deletions src/rdsn/src/common/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ dsn::error_code fs_manager::initialize(const std::vector<std::string> &data_dirs
bool for_test)
{
// create all dir_nodes
dassert(data_dirs.size() == tags.size(),
"data_dir size(%u) != tags size(%u)",
data_dirs.size(),
tags.size());
dcheck_eq(data_dirs.size(), tags.size());
for (unsigned i = 0; i < data_dirs.size(); ++i) {
std::string norm_path;
utils::filesystem::get_normalized_path(data_dirs[i], norm_path);
Expand Down
5 changes: 2 additions & 3 deletions src/rdsn/src/http/http_call_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <dsn/dist/fmt_logging.h>
#include <dsn/http/http_server.h>
#include <dsn/utility/errors.h>

Expand Down Expand Up @@ -46,9 +47,7 @@ class http_call_registry : public utils::singleton<http_call_registry>
{
auto call = std::shared_ptr<http_call>(call_uptr.release());
std::lock_guard<std::mutex> guard(_mu);
dassert(_call_map.find(call->path) == _call_map.end(),
"repeatedly register http call \"%s\"",
call->path.c_str());
dcheck_eq(_call_map.count(call->path), 0);
_call_map[call->path] = call;
}

Expand Down
3 changes: 2 additions & 1 deletion src/rdsn/src/http/http_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "http_message_parser.h"

#include <dsn/dist/fmt_logging.h>
#include <dsn/utility/ports.h>
#include <dsn/utility/crc.h>
#include <dsn/tool-api/rpc_message.h>
Expand Down Expand Up @@ -218,7 +219,7 @@ void http_message_parser::prepare_on_send(message_ex *msg)
dsn_size -= buf.length();
++dsn_buf_count;
}
dassert(dsn_size == 0, "dsn_size = %u", dsn_size);
dcheck_eq(dsn_size, 0);

buffers.resize(dsn_buf_count);
}
Expand Down
7 changes: 5 additions & 2 deletions src/rdsn/src/http/uri_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
// specific language governing permissions and limitations
// under the License.

#include <fmt/format.h>
#include "uri_decoder.h"

#include <fmt/format.h>

#include <dsn/dist/fmt_logging.h>

namespace dsn {
namespace uri {

Expand All @@ -37,7 +40,7 @@ error_with<char> from_hex(const char c)

error_with<char> decode_char(const string_view &hex)
{
assert(2 == hex.size());
dcheck_eq(2, hex.size());

auto high = from_hex(hex[0]);
auto low = from_hex(hex[1]);
Expand Down
6 changes: 1 addition & 5 deletions src/rdsn/src/meta/meta_backup_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ void policy_context::start_backup_app_meta_unlocked(int32_t app_id)
LPC_DEFAULT_CALLBACK,
[this, remote_file, buffer, app_id](const dist::block_service::write_response &resp) {
if (resp.err == dsn::ERR_OK) {
dassert(resp.written_size == buffer.length(),
"write %s length not match, source(%u), actual(%llu)",
remote_file->file_name().c_str(),
buffer.length(),
resp.written_size);
dcheck_eq(resp.written_size, buffer.length());
{
zauto_lock l(_lock);
ddebug("%s: successfully backup app metadata to %s",
Expand Down
2 changes: 1 addition & 1 deletion src/rdsn/src/runtime/rpc/thrift_message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ message_ex *thrift_message_parser::get_message_on_receive(message_reader *reader
case 1:
return parse_request_body_v1(reader, read_next);
default:
assert("invalid header version");
dassert_f(false, "invalid header version: {}", _header_version);
}

return nullptr;
Expand Down
14 changes: 8 additions & 6 deletions src/test/bench_test/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
* under the License.
*/

#include "benchmark.h"

#include <sstream>
#include <pegasus/client.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/c/app_model.h>

#include "benchmark.h"
#include "dsn/c/api_utilities.h"
#include "dsn/c/app_model.h"
#include "dsn/dist/fmt_logging.h"
#include "dsn/utility/ports.h"
#include "rand.h"

namespace pegasus {
Expand All @@ -31,7 +33,7 @@ benchmark::benchmark()
{
_client = pegasus_client_factory::get_client(config::instance().pegasus_cluster_name.c_str(),
config::instance().pegasus_app_name.c_str());
assert(nullptr != _client);
dassert_f(_client, "");

// init operation method map
_operation_method = {{kUnknown, nullptr},
Expand All @@ -58,7 +60,7 @@ void benchmark::run_benchmark(int thread_count, operation_type op_type)
{
// get method by operation type
bench_method method = _operation_method[op_type];
assert(method != nullptr);
dassert_f(method, "");

// create histogram statistic
std::shared_ptr<rocksdb::Statistics> hist_stats = rocksdb::CreateDBStatistics();
Expand Down
3 changes: 2 additions & 1 deletion src/test/bench_test/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include <unordered_map>

#include "statistics.h"
#include "config.h"
#include "pegasus/client.h"
#include "statistics.h"

namespace pegasus {
namespace test {
Expand Down
Loading