From 463eeae1144e5b8549e3c425f1497e04b7e8c173 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 22 Jan 2025 23:47:25 +0000 Subject: [PATCH] cleanup: Avoid clashing with global define `DEBUG`. Some systems define this, breaking our test code. --- testing/fuzzing/bootstrap_fuzz_test.cc | 2 +- testing/fuzzing/e2e_fuzz_test.cc | 2 +- testing/fuzzing/fuzz_support.cc | 14 +++++++------- testing/fuzzing/fuzz_support.hh | 16 ++++++++-------- testing/fuzzing/protodump.cc | 8 ++++---- testing/fuzzing/protodump_reduce.cc | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/testing/fuzzing/bootstrap_fuzz_test.cc b/testing/fuzzing/bootstrap_fuzz_test.cc index 4a784f846a..d127f0f1b9 100644 --- a/testing/fuzzing/bootstrap_fuzz_test.cc +++ b/testing/fuzzing/bootstrap_fuzz_test.cc @@ -109,7 +109,7 @@ void TestBootstrap(Fuzz_Data &input) [](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) { // Log to stdout. - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line, func, message); } diff --git a/testing/fuzzing/e2e_fuzz_test.cc b/testing/fuzzing/e2e_fuzz_test.cc index df4e03c698..5a6c55b198 100644 --- a/testing/fuzzing/e2e_fuzz_test.cc +++ b/testing/fuzzing/e2e_fuzz_test.cc @@ -144,7 +144,7 @@ void TestEndToEnd(Fuzz_Data &input) [](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) { // Log to stdout. - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line, func, message); } diff --git a/testing/fuzzing/fuzz_support.cc b/testing/fuzzing/fuzz_support.cc index 7f94970160..a031190e7d 100644 --- a/testing/fuzzing/fuzz_support.cc +++ b/testing/fuzzing/fuzz_support.cc @@ -57,13 +57,13 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len) if (fuzz_len == 0xffff) { errno = EWOULDBLOCK; - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("recvfrom: no data for tox1\n"); } return -1; } - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf( "recvfrom: %zu (%02x, %02x) for tox1\n", fuzz_len, input.data()[-2], input.data()[-1]); } @@ -77,7 +77,7 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len) static void *report_alloc(const char *name, const char *func, std::size_t size, void *ptr) { - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { printf("%s: %s(%zu): %s\n", name, func, size, ptr == nullptr ? "false" : "true"); } return ptr; @@ -181,7 +181,7 @@ static constexpr Random_Funcs fuzz_random_funcs = { std::memset(bytes, 0, length); CONSUME_OR_ABORT(const uint8_t *data, self->data, bytes_read); std::copy(data, data + bytes_read, bytes); - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { if (length == 1) { std::printf("rng: %d (0x%02x)\n", bytes[0], bytes[0]); } else { @@ -364,7 +364,7 @@ static constexpr Network_Funcs record_network_funcs = { if (self->recvq.empty()) { self->push("\xff\xff"); errno = EWOULDBLOCK; - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("%s: recvfrom: no data\n", self->name_); } return -1; @@ -387,7 +387,7 @@ static constexpr Network_Funcs record_network_funcs = { assert(recvlen > 0 && recvlen <= INT_MAX); self->push(uint8_t(recvlen >> 8)); self->push(uint8_t(recvlen & 0xff)); - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("%s: recvfrom: %zu (%02x, %02x)\n", self->name_, recvlen, self->recording().end()[-2], self->recording().end()[-1]); } @@ -428,7 +428,7 @@ static constexpr Random_Funcs record_random_funcs = { bytes[i] = simple_rng(self->seed_) & 0xff; self->push(bytes[i]); } - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf( "%s: rng: %02x..%02x[%zu]\n", self->name_, bytes[0], bytes[length - 1], length); } diff --git a/testing/fuzzing/fuzz_support.hh b/testing/fuzzing/fuzz_support.hh index c9eca0a0fb..2cba3f09b2 100644 --- a/testing/fuzzing/fuzz_support.hh +++ b/testing/fuzzing/fuzz_support.hh @@ -19,7 +19,7 @@ #include "../../toxcore/tox_private.h" struct Fuzz_Data { - static constexpr bool DEBUG = false; + static constexpr bool FUZZ_DEBUG = false; static constexpr std::size_t TRACE_TRAP = -1; // 579; private: @@ -47,7 +47,7 @@ public: // Special case because memcpy causes UB for bool (which can't be // anything other than 0 or 1). const bool val = fd.data_[0]; - if (DEBUG) { + if (FUZZ_DEBUG) { std::printf("consume@%zu(%s): bool %s\n", fd.pos(), func, val ? "true" : "false"); } ++fd.data_; @@ -74,7 +74,7 @@ public: const uint8_t *consume(const char *func, std::size_t count) { const uint8_t *val = data_; - if (DEBUG) { + if (FUZZ_DEBUG) { if (pos() == TRACE_TRAP) { __asm__("int $3"); } @@ -266,7 +266,7 @@ struct Null_System : System { * initialised with the same seed will be identical (same keys, etc.). */ struct Record_System : System { - static constexpr bool DEBUG = Fuzz_Data::DEBUG; + static constexpr bool FUZZ_DEBUG = Fuzz_Data::FUZZ_DEBUG; /** @brief State shared between all tox instances. */ struct Global { @@ -300,7 +300,7 @@ struct Record_System : System { void push(bool byte) { - if (DEBUG) { + if (FUZZ_DEBUG) { if (recording_.size() == Fuzz_Data::TRACE_TRAP) { __asm__("int $3"); } @@ -312,7 +312,7 @@ struct Record_System : System { void push(uint8_t byte) { - if (DEBUG) { + if (FUZZ_DEBUG) { if (recording_.size() == Fuzz_Data::TRACE_TRAP) { __asm__("int $3"); } @@ -323,7 +323,7 @@ struct Record_System : System { void push(const uint8_t *bytes, std::size_t size) { - if (DEBUG) { + if (FUZZ_DEBUG) { if (recording_.size() == Fuzz_Data::TRACE_TRAP) { __asm__("int $3"); } @@ -352,7 +352,7 @@ private: * everything down drastically. It's useful while developing the fuzzer and the * protodump program. */ -extern const bool DEBUG; +extern const bool FUZZ_DEBUG; inline constexpr char tox_log_level_name(Tox_Log_Level level) { diff --git a/testing/fuzzing/protodump.cc b/testing/fuzzing/protodump.cc index 28df05a02a..47db4999a8 100644 --- a/testing/fuzzing/protodump.cc +++ b/testing/fuzzing/protodump.cc @@ -266,7 +266,7 @@ void RecordBootstrap(const char *init, const char *bootstrap) sys1.clock += clock_increment; sys2.clock += clock_increment; - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { printf("tox1: rng: %d (for clock)\n", clock_increment); printf("tox2: rng: %d (for clock)\n", clock_increment); } @@ -276,7 +276,7 @@ void RecordBootstrap(const char *init, const char *bootstrap) while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("tox1: %d, tox2: %d\n", tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox2)); } @@ -291,7 +291,7 @@ void RecordBootstrap(const char *init, const char *bootstrap) while (tox_friend_get_connection_status(tox2, friend_number, nullptr) == TOX_CONNECTION_NONE || tox_friend_get_connection_status(tox1, 0, nullptr) == TOX_CONNECTION_NONE) { - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("tox1: %d, tox2: %d, tox1 -> tox2: %d, tox2 -> tox1: %d\n", tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox2), tox_friend_get_connection_status(tox1, 0, nullptr), @@ -305,7 +305,7 @@ void RecordBootstrap(const char *init, const char *bootstrap) dump(sys1.take_recording(), init); while (state1.done < MESSAGE_COUNT && state2.done < MESSAGE_COUNT) { - if (Fuzz_Data::DEBUG) { + if (Fuzz_Data::FUZZ_DEBUG) { std::printf("tox1: %d, tox2: %d, tox1 -> tox2: %d, tox2 -> tox1: %d\n", tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox2), tox_friend_get_connection_status(tox1, 0, nullptr), diff --git a/testing/fuzzing/protodump_reduce.cc b/testing/fuzzing/protodump_reduce.cc index 820a3fc7b8..53d39d0b24 100644 --- a/testing/fuzzing/protodump_reduce.cc +++ b/testing/fuzzing/protodump_reduce.cc @@ -11,7 +11,7 @@ namespace { -constexpr bool PROTODUMP_DEBUG = Fuzz_Data::DEBUG; +constexpr bool PROTODUMP_DEBUG = Fuzz_Data::FUZZ_DEBUG; void setup_callbacks(Tox_Dispatch *dispatch) {