From: Simon Marchi Date: Fri, 20 Aug 2021 19:22:16 +0000 (-0400) Subject: tests: sync tests/utils/tap with Babeltrace repository X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9f4a25d35d037cbb5d8aeb50f9e8fa10748a4d14;p=lttng-tools.git tests: sync tests/utils/tap with Babeltrace repository There are a few fixes / improvements in the Babeltrace version of the tap library, bring them here. The Babeltrace commit used is 0022a87819b0 ("Fix: clear_string_field(): set first character to 0") In particular, I'm looking for the TAP_PRINTF_FORMAT fixes, to be able to enable -Wsuggest-attribute=format. But I think it's easier to keep them in sync, so bring in all changes, instead of just the TAP_PRINTF_FORMAT ones. The only diff not brought are the semicolons in the pass / fail definitions, which were removed in the previous patch. Those changes should be brought to the Babeltrace repository. Bringing in the TAP_PRINTF_FORMAT changes finds a few format string mistakes in the tests, fix them. Change-Id: I0d125b313265e72303be8d704ba40554bca87cd1 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/tests/regression/tools/notification/notification.cpp b/tests/regression/tools/notification/notification.cpp index 7a0b5dc91..6d3e46ea3 100644 --- a/tests/regression/tools/notification/notification.cpp +++ b/tests/regression/tools/notification/notification.cpp @@ -272,7 +272,7 @@ static int validate_array_unsigned_int_field_at_index( } ok(value == expected_value, - "Expected unsigned integer value %u, got %" PRIu64, + "Expected unsigned integer value %" PRIu64 ", got %" PRIu64, expected_value, value); ret = 0; diff --git a/tests/regression/tools/trigger/name/trigger_name.cpp b/tests/regression/tools/trigger/name/trigger_name.cpp index 3bb3099ce..1c9aae32c 100644 --- a/tests/regression/tools/trigger/name/trigger_name.cpp +++ b/tests/regression/tools/trigger/name/trigger_name.cpp @@ -102,7 +102,14 @@ int unregister_all_triggers(void) ret = lttng_unregister_trigger(trigger); if (ret) { - fail("Failed to unregister trigger: trigger name = '%s'"); + const char *name; + enum lttng_trigger_status get_name_status = + lttng_trigger_get_name(trigger, &name); + if (get_name_status == LTTNG_TRIGGER_STATUS_OK) { + fail("Failed to unregister trigger: trigger name = '%s'", name); + } else { + fail("Failed to unregister trigger"); + } goto end; } diff --git a/tests/unit/test_notification.cpp b/tests/unit/test_notification.cpp index a44c8ef67..5a2bac14d 100644 --- a/tests/unit/test_notification.cpp +++ b/tests/unit/test_notification.cpp @@ -193,7 +193,7 @@ static void test_condition_buffer_usage( ok(status == LTTNG_CONDITION_STATUS_OK, "Set threshold > 0"); status = lttng_condition_buffer_usage_get_threshold(buffer_usage_condition, &threshold_bytes); ok(status == LTTNG_CONDITION_STATUS_OK, "Threshold is set"); - ok(threshold_bytes == 100000, "Threshold is %" PRIu64 , 100000); + ok(threshold_bytes == 100000, "Threshold is 100000"); status = lttng_condition_buffer_usage_set_threshold(buffer_usage_condition, UINT64_MAX); ok(status == LTTNG_CONDITION_STATUS_OK, "Set threshold UINT64_MAX"); diff --git a/tests/unit/test_utils_expand_path.cpp b/tests/unit/test_utils_expand_path.cpp index 428acad22..85c8a5428 100644 --- a/tests/unit/test_utils_expand_path.cpp +++ b/tests/unit/test_utils_expand_path.cpp @@ -271,7 +271,7 @@ static void test_utils_expand_path(void) result = utils_expand_path(valid_tests_inputs[i].input); ok(result != NULL && - strcmp(result, valid_tests_expected_results[i]) == 0, name); + strcmp(result, valid_tests_expected_results[i]) == 0, "%s", name); free(result); } @@ -301,12 +301,12 @@ static void test_utils_expand_path(void) PRINT_ERR("truncation occurred while concatenating paths \"%s\" and \"%s\"", real_tree_origin, symlink_tests_inputs[i].input); - fail(name); + fail("%s", name); continue; } result = utils_expand_path(tmppath); ok(result != NULL && strcmp(result + treelen, - symlink_tests_inputs[i].expected_result) == 0, name); + symlink_tests_inputs[i].expected_result) == 0, "%s", name); free(result); } @@ -322,7 +322,7 @@ static void test_utils_expand_path(void) if (result != NULL) { free(result); } - ok(result == NULL, name); + ok(result == NULL, "%s", name); } } diff --git a/tests/unit/test_utils_parse_size_suffix.cpp b/tests/unit/test_utils_parse_size_suffix.cpp index 04f2fffe1..ac6efa251 100644 --- a/tests/unit/test_utils_parse_size_suffix.cpp +++ b/tests/unit/test_utils_parse_size_suffix.cpp @@ -104,7 +104,7 @@ static void test_utils_parse_size_suffix(void) sprintf(name, "valid test case: %s", valid_tests_inputs[i].input); ret = utils_parse_size_suffix(valid_tests_inputs[i].input, &result); - ok(ret == 0 && result == valid_tests_inputs[i].expected_result, name); + ok(ret == 0 && result == valid_tests_inputs[i].expected_result, "%s", name); } /* Test invalid cases */ @@ -113,7 +113,7 @@ static void test_utils_parse_size_suffix(void) sprintf(name, "invalid test case: %s", invalid_tests_inputs[i]); ret = utils_parse_size_suffix(invalid_tests_inputs[i], &result); - ok(ret != 0, name); + ok(ret != 0, "%s", name); } } diff --git a/tests/unit/test_utils_parse_time_suffix.cpp b/tests/unit/test_utils_parse_time_suffix.cpp index 95aac5561..89fab12eb 100644 --- a/tests/unit/test_utils_parse_time_suffix.cpp +++ b/tests/unit/test_utils_parse_time_suffix.cpp @@ -101,7 +101,7 @@ static void test_utils_parse_time_suffix(void) ret = utils_parse_time_suffix(valid_tests_inputs[i].input, &result); sprintf(name, "valid test case: %s expected %" PRIu64, valid_tests_inputs[i].input, result); - ok(ret == 0 && result == valid_tests_inputs[i].expected_result, name); + ok(ret == 0 && result == valid_tests_inputs[i].expected_result, "%s", name); } /* Test invalid cases */ @@ -111,7 +111,7 @@ static void test_utils_parse_time_suffix(void) sprintf(name, "invalid test case: %s", invalid_tests_inputs[i]); ret = utils_parse_time_suffix(invalid_tests_inputs[i], &result); - ok(ret != 0, name); + ok(ret != 0, "%s", name); } } diff --git a/tests/utils/tap/tap.c b/tests/utils/tap/tap.c index 7395f6fc5..9f41408bd 100644 --- a/tests/utils/tap/tap.c +++ b/tests/utils/tap/tap.c @@ -1,35 +1,17 @@ -/*- - * Copyright (C) 2004 Nik Clayton - * All rights reserved. - * +/* * SPDX-License-Identifier: BSD-2-Clause * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * Copyright (C) 2004 Nik Clayton + * Copyright (C) 2017 Jérémie Galarneau */ #include #include #include #include +#include +#include +#include #include "tap.h" @@ -60,6 +42,18 @@ static void _expected_tests(unsigned int); static void _tap_init(void); static void _cleanup(void); +#ifdef __MINGW32__ +static inline +void flockfile (FILE * filehandle) { + return; +} + +static inline +void funlockfile(FILE * filehandle) { + return; +} +#endif + /* * Generate a test result. * @@ -95,7 +89,7 @@ _gen_result(int ok, const char *func, const char *file, unsigned int line, if(local_test_name) { name_is_digits = 1; for(c = local_test_name; *c != '\0'; c++) { - if(!isdigit(*c) && !isspace(*c)) { + if(!isdigit((unsigned char) *c) && !isspace((unsigned char) *c)) { name_is_digits = 0; break; } @@ -214,7 +208,7 @@ plan_no_plan(void) * Note that the plan is to skip all tests */ int -plan_skip_all(char *reason) +plan_skip_all(const char *reason) { LOCK; @@ -285,6 +279,28 @@ diag(const char *fmt, ...) return 0; } +void +diag_multiline(const char *val) +{ + size_t len, i, line_start_idx = 0; + + assert(val); + len = strlen(val); + + for (i = 0; i < len; i++) { + int line_length; + + if (val[i] != '\n') { + continue; + } + + assert((i - line_start_idx + 1) <= INT_MAX); + line_length = i - line_start_idx + 1; + fprintf(stderr, "# %.*s", line_length, &val[line_start_idx]); + line_start_idx = i + 1; + } +} + void _expected_tests(unsigned int tests) { @@ -302,7 +318,7 @@ skip(unsigned int n, const char *fmt, ...) LOCK; va_start(ap, fmt); - if (asprintf(&skip_msg, fmt, ap) == -1) { + if (vasprintf(&skip_msg, fmt, ap) == -1) { skip_msg = NULL; } va_end(ap); @@ -322,7 +338,7 @@ skip(unsigned int n, const char *fmt, ...) } void -todo_start(char *fmt, ...) +todo_start(const char *fmt, ...) { va_list ap; diff --git a/tests/utils/tap/tap.h b/tests/utils/tap/tap.h index 84288f038..bba1ceadc 100644 --- a/tests/utils/tap/tap.h +++ b/tests/utils/tap/tap.h @@ -1,29 +1,8 @@ -/*- - * Copyright (C) 2004 Nik Clayton - * All rights reserved. - * +/* * SPDX-License-Identifier: BSD-2-Clause * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * Copyright (C) 2004 Nik Clayton + * Copyright (C) 2017 Jérémie Galarneau */ #ifdef __cplusplus @@ -79,17 +58,29 @@ extern "C" { #define skip_end() } while(0); +#ifdef __MINGW_PRINTF_FORMAT +# define TAP_PRINTF_FORMAT __MINGW_PRINTF_FORMAT +#else +# define TAP_PRINTF_FORMAT printf +#endif + +__attribute__((format(TAP_PRINTF_FORMAT, 5, 6))) unsigned int _gen_result(int, const char *, const char *, unsigned int, const char *, ...); int plan_no_plan(void); -int plan_skip_all(char *); +__attribute__((noreturn)) +int plan_skip_all(const char *); int plan_tests(unsigned int); +__attribute__((format(TAP_PRINTF_FORMAT, 1, 2))) unsigned int diag(const char *, ...); +void diag_multiline(const char *); +__attribute__((format(TAP_PRINTF_FORMAT, 2, 3))) int skip(unsigned int, const char *, ...); -void todo_start(char *, ...); +__attribute__((format(TAP_PRINTF_FORMAT, 1, 2))) +void todo_start(const char *, ...); void todo_end(void); int exit_status(void); diff --git a/tests/utils/tap/tap.sh b/tests/utils/tap/tap.sh index 109cc8e4c..4b51106c0 100755 --- a/tests/utils/tap/tap.sh +++ b/tests/utils/tap/tap.sh @@ -381,6 +381,11 @@ BAIL_OUT(){ _cleanup(){ local rc=0 + if (( _plan_set == 0 )) ; then + diag "Looks like your test died before it could output anything." + return $rc + fi + if (( _test_died != 0 )) ; then diag "Looks like your test died just after $_executed_tests." return $rc