Skip to content

Commit 463eeae

Browse files
committed
cleanup: Avoid clashing with global define DEBUG.
Some systems define this, breaking our test code.
1 parent 92cc1e9 commit 463eeae

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

testing/fuzzing/bootstrap_fuzz_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void TestBootstrap(Fuzz_Data &input)
109109
[](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func,
110110
const char *message, void *user_data) {
111111
// Log to stdout.
112-
if (Fuzz_Data::DEBUG) {
112+
if (Fuzz_Data::FUZZ_DEBUG) {
113113
std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line,
114114
func, message);
115115
}

testing/fuzzing/e2e_fuzz_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void TestEndToEnd(Fuzz_Data &input)
144144
[](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func,
145145
const char *message, void *user_data) {
146146
// Log to stdout.
147-
if (Fuzz_Data::DEBUG) {
147+
if (Fuzz_Data::FUZZ_DEBUG) {
148148
std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line,
149149
func, message);
150150
}

testing/fuzzing/fuzz_support.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
5757

5858
if (fuzz_len == 0xffff) {
5959
errno = EWOULDBLOCK;
60-
if (Fuzz_Data::DEBUG) {
60+
if (Fuzz_Data::FUZZ_DEBUG) {
6161
std::printf("recvfrom: no data for tox1\n");
6262
}
6363
return -1;
6464
}
6565

66-
if (Fuzz_Data::DEBUG) {
66+
if (Fuzz_Data::FUZZ_DEBUG) {
6767
std::printf(
6868
"recvfrom: %zu (%02x, %02x) for tox1\n", fuzz_len, input.data()[-2], input.data()[-1]);
6969
}
@@ -77,7 +77,7 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
7777

7878
static void *report_alloc(const char *name, const char *func, std::size_t size, void *ptr)
7979
{
80-
if (Fuzz_Data::DEBUG) {
80+
if (Fuzz_Data::FUZZ_DEBUG) {
8181
printf("%s: %s(%zu): %s\n", name, func, size, ptr == nullptr ? "false" : "true");
8282
}
8383
return ptr;
@@ -181,7 +181,7 @@ static constexpr Random_Funcs fuzz_random_funcs = {
181181
std::memset(bytes, 0, length);
182182
CONSUME_OR_ABORT(const uint8_t *data, self->data, bytes_read);
183183
std::copy(data, data + bytes_read, bytes);
184-
if (Fuzz_Data::DEBUG) {
184+
if (Fuzz_Data::FUZZ_DEBUG) {
185185
if (length == 1) {
186186
std::printf("rng: %d (0x%02x)\n", bytes[0], bytes[0]);
187187
} else {
@@ -364,7 +364,7 @@ static constexpr Network_Funcs record_network_funcs = {
364364
if (self->recvq.empty()) {
365365
self->push("\xff\xff");
366366
errno = EWOULDBLOCK;
367-
if (Fuzz_Data::DEBUG) {
367+
if (Fuzz_Data::FUZZ_DEBUG) {
368368
std::printf("%s: recvfrom: no data\n", self->name_);
369369
}
370370
return -1;
@@ -387,7 +387,7 @@ static constexpr Network_Funcs record_network_funcs = {
387387
assert(recvlen > 0 && recvlen <= INT_MAX);
388388
self->push(uint8_t(recvlen >> 8));
389389
self->push(uint8_t(recvlen & 0xff));
390-
if (Fuzz_Data::DEBUG) {
390+
if (Fuzz_Data::FUZZ_DEBUG) {
391391
std::printf("%s: recvfrom: %zu (%02x, %02x)\n", self->name_, recvlen,
392392
self->recording().end()[-2], self->recording().end()[-1]);
393393
}
@@ -428,7 +428,7 @@ static constexpr Random_Funcs record_random_funcs = {
428428
bytes[i] = simple_rng(self->seed_) & 0xff;
429429
self->push(bytes[i]);
430430
}
431-
if (Fuzz_Data::DEBUG) {
431+
if (Fuzz_Data::FUZZ_DEBUG) {
432432
std::printf(
433433
"%s: rng: %02x..%02x[%zu]\n", self->name_, bytes[0], bytes[length - 1], length);
434434
}

testing/fuzzing/fuzz_support.hh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "../../toxcore/tox_private.h"
2020

2121
struct Fuzz_Data {
22-
static constexpr bool DEBUG = false;
22+
static constexpr bool FUZZ_DEBUG = false;
2323
static constexpr std::size_t TRACE_TRAP = -1; // 579;
2424

2525
private:
@@ -47,7 +47,7 @@ public:
4747
// Special case because memcpy causes UB for bool (which can't be
4848
// anything other than 0 or 1).
4949
const bool val = fd.data_[0];
50-
if (DEBUG) {
50+
if (FUZZ_DEBUG) {
5151
std::printf("consume@%zu(%s): bool %s\n", fd.pos(), func, val ? "true" : "false");
5252
}
5353
++fd.data_;
@@ -74,7 +74,7 @@ public:
7474
const uint8_t *consume(const char *func, std::size_t count)
7575
{
7676
const uint8_t *val = data_;
77-
if (DEBUG) {
77+
if (FUZZ_DEBUG) {
7878
if (pos() == TRACE_TRAP) {
7979
__asm__("int $3");
8080
}
@@ -266,7 +266,7 @@ struct Null_System : System {
266266
* initialised with the same seed will be identical (same keys, etc.).
267267
*/
268268
struct Record_System : System {
269-
static constexpr bool DEBUG = Fuzz_Data::DEBUG;
269+
static constexpr bool FUZZ_DEBUG = Fuzz_Data::FUZZ_DEBUG;
270270

271271
/** @brief State shared between all tox instances. */
272272
struct Global {
@@ -300,7 +300,7 @@ struct Record_System : System {
300300

301301
void push(bool byte)
302302
{
303-
if (DEBUG) {
303+
if (FUZZ_DEBUG) {
304304
if (recording_.size() == Fuzz_Data::TRACE_TRAP) {
305305
__asm__("int $3");
306306
}
@@ -312,7 +312,7 @@ struct Record_System : System {
312312

313313
void push(uint8_t byte)
314314
{
315-
if (DEBUG) {
315+
if (FUZZ_DEBUG) {
316316
if (recording_.size() == Fuzz_Data::TRACE_TRAP) {
317317
__asm__("int $3");
318318
}
@@ -323,7 +323,7 @@ struct Record_System : System {
323323

324324
void push(const uint8_t *bytes, std::size_t size)
325325
{
326-
if (DEBUG) {
326+
if (FUZZ_DEBUG) {
327327
if (recording_.size() == Fuzz_Data::TRACE_TRAP) {
328328
__asm__("int $3");
329329
}
@@ -352,7 +352,7 @@ private:
352352
* everything down drastically. It's useful while developing the fuzzer and the
353353
* protodump program.
354354
*/
355-
extern const bool DEBUG;
355+
extern const bool FUZZ_DEBUG;
356356

357357
inline constexpr char tox_log_level_name(Tox_Log_Level level)
358358
{

testing/fuzzing/protodump.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void RecordBootstrap(const char *init, const char *bootstrap)
266266
sys1.clock += clock_increment;
267267
sys2.clock += clock_increment;
268268

269-
if (Fuzz_Data::DEBUG) {
269+
if (Fuzz_Data::FUZZ_DEBUG) {
270270
printf("tox1: rng: %d (for clock)\n", clock_increment);
271271
printf("tox2: rng: %d (for clock)\n", clock_increment);
272272
}
@@ -276,7 +276,7 @@ void RecordBootstrap(const char *init, const char *bootstrap)
276276

277277
while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE
278278
|| tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) {
279-
if (Fuzz_Data::DEBUG) {
279+
if (Fuzz_Data::FUZZ_DEBUG) {
280280
std::printf("tox1: %d, tox2: %d\n", tox_self_get_connection_status(tox1),
281281
tox_self_get_connection_status(tox2));
282282
}
@@ -291,7 +291,7 @@ void RecordBootstrap(const char *init, const char *bootstrap)
291291

292292
while (tox_friend_get_connection_status(tox2, friend_number, nullptr) == TOX_CONNECTION_NONE
293293
|| tox_friend_get_connection_status(tox1, 0, nullptr) == TOX_CONNECTION_NONE) {
294-
if (Fuzz_Data::DEBUG) {
294+
if (Fuzz_Data::FUZZ_DEBUG) {
295295
std::printf("tox1: %d, tox2: %d, tox1 -> tox2: %d, tox2 -> tox1: %d\n",
296296
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox2),
297297
tox_friend_get_connection_status(tox1, 0, nullptr),
@@ -305,7 +305,7 @@ void RecordBootstrap(const char *init, const char *bootstrap)
305305
dump(sys1.take_recording(), init);
306306

307307
while (state1.done < MESSAGE_COUNT && state2.done < MESSAGE_COUNT) {
308-
if (Fuzz_Data::DEBUG) {
308+
if (Fuzz_Data::FUZZ_DEBUG) {
309309
std::printf("tox1: %d, tox2: %d, tox1 -> tox2: %d, tox2 -> tox1: %d\n",
310310
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox2),
311311
tox_friend_get_connection_status(tox1, 0, nullptr),

testing/fuzzing/protodump_reduce.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace {
1313

14-
constexpr bool PROTODUMP_DEBUG = Fuzz_Data::DEBUG;
14+
constexpr bool PROTODUMP_DEBUG = Fuzz_Data::FUZZ_DEBUG;
1515

1616
void setup_callbacks(Tox_Dispatch *dispatch)
1717
{

0 commit comments

Comments
 (0)