Skip to content

Commit

Permalink
cleanup: Avoid clashing with global define DEBUG.
Browse files Browse the repository at this point in the history
Some systems define this, breaking our test code.
  • Loading branch information
iphydf committed Jan 22, 2025
1 parent 92cc1e9 commit 463eeae
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion testing/fuzzing/bootstrap_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion testing/fuzzing/e2e_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions testing/fuzzing/fuzz_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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]);
}
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions testing/fuzzing/fuzz_support.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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_;
Expand All @@ -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");
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions testing/fuzzing/protodump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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));
}
Expand All @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion testing/fuzzing/protodump_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 463eeae

Please sign in to comment.