diff --git a/test/hashtabletest.c b/test/hashtabletest.c index f748183e6..59c39b464 100644 --- a/test/hashtabletest.c +++ b/test/hashtabletest.c @@ -14,14 +14,14 @@ static void print_xid(void* ptr, void* v) { XID *x = v; - printf("%ld", (long)(*x)); + dbg("%ld", (long)(*x)); } static void print_int(void* ptr, void* v) { int *x = v; - printf("%d", *x); + dbg("%d", *x); } static void @@ -32,7 +32,7 @@ test1(void) int ok = 1; const int numKeys = 420; - printf("test1\n"); + dbg("test1\n"); h = ht_create(sizeof(XID), sizeof(int), ht_resourceid_hash, ht_resourceid_compare, NULL); for (c = 0; c < numKeys; ++c) { @@ -44,9 +44,11 @@ test1(void) } } - printf("Distribution after insertion\n"); - ht_dump_distribution(h); - ht_dump_contents(h, print_xid, print_int, NULL); + if (verbose) { + dbg("Distribution after insertion\n"); + ht_dump_distribution(h); + ht_dump_contents(h, print_xid, print_int, NULL); + } for (c = 0; c < numKeys; ++c) { XID id = c; @@ -55,26 +57,28 @@ test1(void) if (*v == 2 * c) { // ok } else { - printf("Key %d doesn't have expected value %d but has %d instead\n", + dbg("Key %d doesn't have expected value %d but has %d instead\n", c, 2 * c, *v); ok = 0; } } else { ok = 0; - printf("Cannot find key %d\n", c); + dbg("Cannot find key %d\n", c); } } if (ok) { - printf("%d keys inserted and found\n", c); + dbg("%d keys inserted and found\n", c); for (c = 0; c < numKeys; ++c) { XID id = c; ht_remove(h, &id); } - printf("Distribution after deletion\n"); - ht_dump_distribution(h); + if (verbose) { + dbg("Distribution after deletion\n"); + ht_dump_distribution(h); + } } ht_destroy(h); @@ -90,7 +94,7 @@ test2(void) int ok = 1; const int numKeys = 420; - printf("test2\n"); + dbg("test2\n"); h = ht_create(sizeof(XID), 0, ht_resourceid_hash, ht_resourceid_compare, NULL); for (c = 0; c < numKeys; ++c) { @@ -102,7 +106,7 @@ test2(void) XID id = c; if (!ht_find(h, &id)) { ok = 0; - printf("Cannot find key %d\n", c); + dbg("Cannot find key %d\n", c); } } @@ -110,16 +114,16 @@ test2(void) XID id = c + 1; if (ht_find(h, &id)) { ok = 0; - printf("Could find a key that shouldn't be there\n"); + dbg("Could find a key that shouldn't be there\n"); } } ht_destroy(h); if (ok) { - printf("Test with empty keys OK\n"); + dbg("Test with empty keys OK\n"); } else { - printf("Test with empty keys FAILED\n"); + dbg("Test with empty keys FAILED\n"); } assert(ok); @@ -133,22 +137,24 @@ test3(void) .keySize = 4 }; HashTable h; - printf("test3\n"); + dbg("test3\n"); h = ht_create(4, 0, ht_generic_hash, ht_generic_compare, &hashSetup); if (!ht_add(h, "helo") || !ht_add(h, "wrld")) { - printf("Could not insert keys\n"); + dbg("Could not insert keys\n"); } if (!ht_find(h, "helo") || !ht_find(h, "wrld")) { ok = 0; - printf("Could not find inserted keys\n"); + dbg("Could not find inserted keys\n"); } - printf("Hash distribution with two strings\n"); - ht_dump_distribution(h); + if (verbose) { + dbg("Hash distribution with two strings\n"); + ht_dump_distribution(h); + } ht_destroy(h); diff --git a/test/input.c b/test/input.c index c7d7cffdb..5ca8a97cd 100644 --- a/test/input.c +++ b/test/input.c @@ -997,7 +997,7 @@ test_padding_for_int32(int i) static void include_byte_padding_macros(void) { - printf("Testing bits_to_bytes()\n"); + dbg("Testing bits_to_bytes()\n"); /* the macros don't provide overflow protection */ test_bits_to_byte(0); @@ -1010,7 +1010,7 @@ include_byte_padding_macros(void) test_bits_to_byte(INT_MAX - 9); test_bits_to_byte(INT_MAX - 8); - printf("Testing bytes_to_int32()\n"); + dbg("Testing bytes_to_int32()\n"); test_bytes_to_int32(0); test_bytes_to_int32(1); @@ -1026,7 +1026,7 @@ include_byte_padding_macros(void) test_bytes_to_int32(INT_MAX - 4); test_bytes_to_int32(INT_MAX - 3); - printf("Testing pad_to_int32()\n"); + dbg("Testing pad_to_int32()\n"); test_pad_to_int32(0); test_pad_to_int32(1); @@ -1043,7 +1043,7 @@ include_byte_padding_macros(void) test_pad_to_int32(INT_MAX - 4); test_pad_to_int32(INT_MAX - 3); - printf("Testing padding_for_int32()\n"); + dbg("Testing padding_for_int32()\n"); test_padding_for_int32(0); test_padding_for_int32(1); @@ -1076,7 +1076,7 @@ xi_unregister_handlers(void) handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL); assert(handler == 3); - printf("Unlinking from front.\n"); + dbg("Unlinking from front.\n"); XIUnregisterPropertyHandler(&dev, 4); /* NOOP */ assert(dev.properties.handlers->id == 3); @@ -1565,7 +1565,7 @@ input_option_test(void) InputOption *opt; const char *val; - printf("Testing input_option list interface\n"); + dbg("Testing input_option list interface\n"); list = input_option_new(list, "key", "value"); assert(list); @@ -1654,7 +1654,7 @@ _test_double_fp16_values(double orig_d) double final_d; if (orig_d > 0x7FFF) { - printf("Test out of range\n"); + dbg("Test out of range\n"); assert(0); } @@ -1668,7 +1668,7 @@ _test_double_fp16_values(double orig_d) * snprintf(first_fp16_s, sizeof(first_fp16_s), "%d + %u * 2^-16", (first_fp16 & 0xffff0000) >> 16, first_fp16 & 0xffff); * snprintf(final_fp16_s, sizeof(final_fp16_s), "%d + %u * 2^-16", (final_fp16 & 0xffff0000) >> 16, final_fp16 & 0xffff); * - * printf("FP16: original double: %f first fp16: %s, re-encoded double: %f, final fp16: %s\n", orig_d, first_fp16_s, final_d, final_fp16_s); + * dbg("FP16: original double: %f first fp16: %s, re-encoded double: %f, final fp16: %s\n", orig_d, first_fp16_s, final_d, final_fp16_s); * } */ @@ -1689,7 +1689,7 @@ _test_double_fp32_values(double orig_d) double final_d; if (orig_d > 0x7FFFFFFF) { - printf("Test out of range\n"); + dbg("Test out of range\n"); assert(0); } @@ -1703,7 +1703,7 @@ _test_double_fp32_values(double orig_d) * snprintf(first_fp32_s, sizeof(first_fp32_s), "%d + %u * 2^-32", first_fp32.integral, first_fp32.frac); * snprintf(final_fp32_s, sizeof(final_fp32_s), "%d + %u * 2^-32", first_fp32.integral, final_fp32.frac); * - * printf("FP32: original double: %f first fp32: %s, re-encoded double: %f, final fp32: %s\n", orig_d, first_fp32_s, final_d, final_fp32_s); + * dbg("FP32: original double: %f first fp32: %s, re-encoded double: %f, final fp32: %s\n", orig_d, first_fp32_s, final_d, final_fp32_s); * } */ @@ -1722,7 +1722,7 @@ dix_double_fp_conversion(void) { uint32_t i; - printf("Testing double to FP1616/FP3232 conversions\n"); + dbg("Testing double to FP1616/FP3232 conversions\n"); _test_double_fp16_values(0); for (i = 1; i < 0x7FFF; i <<= 1) { diff --git a/test/tests.c b/test/tests.c index 97603822a..4ef0036a3 100644 --- a/test/tests.c +++ b/test/tests.c @@ -2,6 +2,8 @@ #include "tests.h" #include "tests-common.h" +int verbose = 0; + int main(int argc, char **argv) { diff --git a/test/tests.h b/test/tests.h index c41fa1184..d04d6ea63 100644 --- a/test/tests.h +++ b/test/tests.h @@ -1,6 +1,9 @@ #ifndef TESTS_H #define TESTS_H +extern int verbose; +#define dbg(...) if (verbose) printf("DBG" __VA_ARGS__); + #define DECLARE_WRAP_FUNCTION(f_, rval_, ...) \ extern rval_ (*wrapped_ ## f_)(__VA_ARGS__) \ diff --git a/test/xi1/protocol-xchangedevicecontrol.c b/test/xi1/protocol-xchangedevicecontrol.c index 20b125d35..4c1a1740a 100644 --- a/test/xi1/protocol-xchangedevicecontrol.c +++ b/test/xi1/protocol-xchangedevicecontrol.c @@ -98,18 +98,18 @@ test_ChangeDeviceControl(void) client_request = init_client(request->length, request); - printf("Testing invalid lengths:\n"); - printf(" -- no control struct\n"); + dbg("Testing invalid lengths:\n"); + dbg(" -- no control struct\n"); request_ChangeDeviceControl(&client_request, request, control, BadLength); - printf(" -- xDeviceResolutionCtl\n"); + dbg(" -- xDeviceResolutionCtl\n"); request_init(request, ChangeDeviceControl); request->control = DEVICE_RESOLUTION; control->length = (sizeof(xDeviceResolutionCtl) >> 2); request->length += control->length - 2; request_ChangeDeviceControl(&client_request, request, control, BadLength); - printf(" -- xDeviceEnableCtl\n"); + dbg(" -- xDeviceEnableCtl\n"); request_init(request, ChangeDeviceControl); request->control = DEVICE_ENABLE; control->length = (sizeof(xDeviceEnableCtl) >> 2); diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c index 5b4c34ac0..ed16b9498 100644 --- a/test/xi2/protocol-eventconvert.c +++ b/test/xi2/protocol-eventconvert.c @@ -742,7 +742,7 @@ test_values_XIDeviceChangedEvent(DeviceChangedEvent *in, flags & SCROLL_FLAG_PREFERRED); } default: - printf("Invalid class type.\n\n"); + dbg("Invalid class type.\n\n"); assert(1); break; } diff --git a/test/xi2/protocol-xigetclientpointer.c b/test/xi2/protocol-xigetclientpointer.c index e7c4ca4c3..0a916fef0 100644 --- a/test/xi2/protocol-xigetclientpointer.c +++ b/test/xi2/protocol-xigetclientpointer.c @@ -113,26 +113,26 @@ test_XIGetClientPointer(void) client_request = init_client(request.length, &request); - printf("Testing invalid window\n"); + dbg("Testing invalid window\n"); request.win = INVALID_WINDOW_ID; request_XIGetClientPointer(&client_request, &request, BadWindow); - printf("Testing invalid length\n"); + dbg("Testing invalid length\n"); client_request.req_len -= 4; request_XIGetClientPointer(&client_request, &request, BadLength); client_request.req_len += 4; test_data.cp_is_set = FALSE; - printf("Testing window None, unset ClientPointer.\n"); + dbg("Testing window None, unset ClientPointer.\n"); request.win = None; request_XIGetClientPointer(&client_request, &request, Success); - printf("Testing valid window, unset ClientPointer.\n"); + dbg("Testing valid window, unset ClientPointer.\n"); request.win = CLIENT_WINDOW_ID; request_XIGetClientPointer(&client_request, &request, Success); - printf("Testing valid window, set ClientPointer.\n"); + dbg("Testing valid window, set ClientPointer.\n"); client_window.clientPtr = devices.vcp; test_data.dev = devices.vcp; test_data.cp_is_set = TRUE; @@ -141,7 +141,7 @@ test_XIGetClientPointer(void) client_window.clientPtr = NULL; - printf("Testing window None, set ClientPointer.\n"); + dbg("Testing window None, set ClientPointer.\n"); client_request.clientPtr = devices.vcp; test_data.dev = devices.vcp; test_data.cp_is_set = TRUE; diff --git a/test/xi2/protocol-xigetselectedevents.c b/test/xi2/protocol-xigetselectedevents.c index 9471ca545..6b2f1f666 100644 --- a/test/xi2/protocol-xigetselectedevents.c +++ b/test/xi2/protocol-xigetselectedevents.c @@ -156,11 +156,11 @@ test_XIGetSelectedEvents(void) request_init(&request, XIGetSelectedEvents); - printf("Testing for BadWindow on invalid window.\n"); + dbg("Testing for BadWindow on invalid window.\n"); request.win = None; request_XIGetSelectedEvents(&request, BadWindow); - printf("Testing for zero-length (unset) masks.\n"); + dbg("Testing for zero-length (unset) masks.\n"); /* No masks set yet */ test_data.num_masks_expected = 0; request.win = ROOT_WINDOW_ID; @@ -171,7 +171,7 @@ test_XIGetSelectedEvents(void) memset(test_data.mask, 0, sizeof(test_data.mask)); - printf("Testing for valid masks\n"); + dbg("Testing for valid masks\n"); memset(&dev, 0, sizeof(dev)); /* dev->id is enough for XISetEventMask */ request.win = ROOT_WINDOW_ID; @@ -197,7 +197,7 @@ test_XIGetSelectedEvents(void) } } - printf("Testing removing all masks\n"); + dbg("Testing removing all masks\n"); /* Unset all masks one-by-one */ for (j = MAXDEVICES - 1; j >= 0; j--) { if (j < devices.num_devices + 2) diff --git a/test/xi2/protocol-xipassivegrabdevice.c b/test/xi2/protocol-xipassivegrabdevice.c index c7b5dc17d..b6ba65447 100644 --- a/test/xi2/protocol-xipassivegrabdevice.c +++ b/test/xi2/protocol-xipassivegrabdevice.c @@ -182,12 +182,12 @@ test_XIPassiveGrabDevice(void) wrapped_WriteToClient = reply_XIPassiveGrabDevice; client_request = init_client(request->length, request); - printf("Testing invalid device\n"); + dbg("Testing invalid device\n"); request->deviceid = 12; request_XIPassiveGrabDevice(&client_request, request, BadDevice, request->deviceid); - printf("Testing invalid length\n"); + dbg("Testing invalid length\n"); request->length -= 2; request_XIPassiveGrabDevice(&client_request, request, BadLength, client_request.errorValue); @@ -196,14 +196,14 @@ test_XIPassiveGrabDevice(void) request->grab_window = CLIENT_WINDOW_ID; request->deviceid = XIAllMasterDevices; - printf("Testing invalid grab types\n"); + dbg("Testing invalid grab types\n"); for (i = XIGrabtypeGestureSwipeBegin + 1; i < 0xFF; i++) { request->grab_type = i; request_XIPassiveGrabDevice(&client_request, request, BadValue, request->grab_type); } - printf("Testing invalid grab type + detail combinations\n"); + dbg("Testing invalid grab type + detail combinations\n"); request->grab_type = XIGrabtypeEnter; request->detail = 1; request_XIPassiveGrabDevice(&client_request, request, BadValue, @@ -215,7 +215,7 @@ test_XIPassiveGrabDevice(void) request->detail = 0; - printf("Testing invalid masks\n"); + dbg("Testing invalid masks\n"); mask = (unsigned char *) &request[1]; request->mask_len = bytes_to_int32(XI2LASTEVENT + 1); diff --git a/test/xi2/protocol-xiquerydevice.c b/test/xi2/protocol-xiquerydevice.c index e32e713c0..72b30052e 100644 --- a/test/xi2/protocol-xiquerydevice.c +++ b/test/xi2/protocol-xiquerydevice.c @@ -319,16 +319,16 @@ test_XIQueryDevice(void) wrapped_WriteToClient = reply_XIQueryDevice; request_init(&request, XIQueryDevice); - printf("Testing XIAllDevices.\n"); + dbg("Testing XIAllDevices.\n"); request_XIQueryDevice(&test_data, XIAllDevices, Success); - printf("Testing XIAllMasterDevices.\n"); + dbg("Testing XIAllMasterDevices.\n"); request_XIQueryDevice(&test_data, XIAllMasterDevices, Success); - printf("Testing existing device ids.\n"); + dbg("Testing existing device ids.\n"); for (i = 2; i < 6; i++) request_XIQueryDevice(&test_data, i, Success); - printf("Testing non-existing device ids.\n"); + dbg("Testing non-existing device ids.\n"); for (i = 6; i <= 0xFFFF; i++) request_XIQueryDevice(&test_data, i, BadDevice); } diff --git a/test/xi2/protocol-xiqueryversion.c b/test/xi2/protocol-xiqueryversion.c index cd1865fdb..528a02c5a 100644 --- a/test/xi2/protocol-xiqueryversion.c +++ b/test/xi2/protocol-xiqueryversion.c @@ -154,23 +154,23 @@ test_XIQueryVersion(void) wrapped_WriteToClient = reply_XIQueryVersion; - printf("Server version 2.0 - client versions [1..3].0\n"); + dbg("Server version 2.0 - client versions [1..3].0\n"); /* some simple tests to catch common errors quickly */ request_XIQueryVersion(2, 0, 1, 0, BadValue); request_XIQueryVersion(2, 0, 2, 0, Success); request_XIQueryVersion(2, 0, 3, 0, Success); - printf("Server version 3.0 - client versions [1..3].0\n"); + dbg("Server version 3.0 - client versions [1..3].0\n"); request_XIQueryVersion(3, 0, 1, 0, BadValue); request_XIQueryVersion(3, 0, 2, 0, Success); request_XIQueryVersion(3, 0, 3, 0, Success); - printf("Server version 2.0 - client versions [1..3].[1..3]\n"); + dbg("Server version 2.0 - client versions [1..3].[1..3]\n"); request_XIQueryVersion(2, 0, 1, 1, BadValue); request_XIQueryVersion(2, 0, 2, 2, Success); request_XIQueryVersion(2, 0, 3, 3, Success); - printf("Server version 2.2 - client versions [1..3].0\n"); + dbg("Server version 2.2 - client versions [1..3].0\n"); request_XIQueryVersion(2, 2, 1, 0, BadValue); request_XIQueryVersion(2, 2, 2, 0, Success); request_XIQueryVersion(2, 2, 3, 0, Success); @@ -179,7 +179,7 @@ test_XIQueryVersion(void) /* this one takes a while */ unsigned int cmin, cmaj, smin, smaj; - printf("Testing all combinations.\n"); + dbg("Testing all combinations.\n"); for (smaj = 2; smaj <= 0xFFFF; smaj++) for (smin = 0; smin <= 0xFFFF; smin++) for (cmin = 0; cmin <= 0xFFFF; cmin++) diff --git a/test/xi2/protocol-xiselectevents.c b/test/xi2/protocol-xiselectevents.c index 5dd4f9c36..9389bd27e 100644 --- a/test/xi2/protocol-xiselectevents.c +++ b/test/xi2/protocol-xiselectevents.c @@ -294,7 +294,7 @@ test_XISelectEvents(void) request_init(req, XISelectEvents); - printf("Testing for BadValue on zero-length masks\n"); + dbg("Testing for BadValue on zero-length masks\n"); /* zero masks are BadValue, regardless of the window */ req->num_masks = 0; @@ -307,7 +307,7 @@ test_XISelectEvents(void) req->win = CLIENT_WINDOW_ID; request_XISelectEvent(req, BadValue); - printf("Testing for BadWindow.\n"); + dbg("Testing for BadWindow.\n"); /* None window is BadWindow, regardless of the masks. * We don't actually need to set the masks here, BadWindow must occur * before checking the masks. @@ -327,7 +327,7 @@ test_XISelectEvents(void) req->num_masks = 0xFFFC; request_XISelectEvent(req, BadWindow); - printf("Triggering num_masks/length overflow\n"); + dbg("Triggering num_masks/length overflow\n"); req->win = ROOT_WINDOW_ID; /* Integer overflow - req->length can't hold that much */ req->num_masks = 0xFFFF; @@ -336,14 +336,14 @@ test_XISelectEvents(void) req->win = ROOT_WINDOW_ID; req->num_masks = 1; - printf("Triggering bogus mask length error\n"); + dbg("Triggering bogus mask length error\n"); mask = (xXIEventMask *) &req[1]; mask->deviceid = 0; mask->mask_len = 0xFFFF; request_XISelectEvent(req, BadLength); /* testing various device ids */ - printf("Testing existing device ids.\n"); + dbg("Testing existing device ids.\n"); for (i = 0; i < 6; i++) { mask = (xXIEventMask *) &req[1]; mask->deviceid = i; @@ -353,7 +353,7 @@ test_XISelectEvents(void) request_XISelectEvent(req, Success); } - printf("Testing non-existing device ids.\n"); + dbg("Testing non-existing device ids.\n"); for (i = 6; i <= 0xFFFF; i++) { req->win = ROOT_WINDOW_ID; req->num_masks = 1; diff --git a/test/xi2/protocol-xisetclientpointer.c b/test/xi2/protocol-xisetclientpointer.c index f6ddb72b5..881fcf3f1 100644 --- a/test/xi2/protocol-xisetclientpointer.c +++ b/test/xi2/protocol-xisetclientpointer.c @@ -92,14 +92,14 @@ test_XISetClientPointer(void) request.win = CLIENT_WINDOW_ID; - printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n"); + dbg("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n"); request.deviceid = XIAllDevices; request_XISetClientPointer(&request, BadDevice); request.deviceid = XIAllMasterDevices; request_XISetClientPointer(&request, BadDevice); - printf("Testing Success for VCP and VCK.\n"); + dbg("Testing Success for VCP and VCK.\n"); request.deviceid = devices.vcp->id; /* 2 */ request_XISetClientPointer(&request, Success); assert(client_window.clientPtr->id == 2); @@ -108,19 +108,19 @@ test_XISetClientPointer(void) request_XISetClientPointer(&request, Success); assert(client_window.clientPtr->id == 2); - printf("Testing BadDevice error for all other devices.\n"); + dbg("Testing BadDevice error for all other devices.\n"); for (i = 4; i <= 0xFFFF; i++) { request.deviceid = i; request_XISetClientPointer(&request, BadDevice); } - printf("Testing window None\n"); + dbg("Testing window None\n"); request.win = None; request.deviceid = devices.vcp->id; /* 2 */ request_XISetClientPointer(&request, Success); assert(client_request.clientPtr->id == 2); - printf("Testing invalid window\n"); + dbg("Testing invalid window\n"); request.win = INVALID_WINDOW_ID; request.deviceid = devices.vcp->id; request_XISetClientPointer(&request, BadWindow);