tests: sync tests/utils/tap with Babeltrace repository
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 20 Aug 2021 19:22:16 +0000 (15:22 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 9 Dec 2021 19:46:17 +0000 (14:46 -0500)
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 <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/tools/notification/notification.cpp
tests/regression/tools/trigger/name/trigger_name.cpp
tests/unit/test_notification.cpp
tests/unit/test_utils_expand_path.cpp
tests/unit/test_utils_parse_size_suffix.cpp
tests/unit/test_utils_parse_time_suffix.cpp
tests/utils/tap/tap.c
tests/utils/tap/tap.h
tests/utils/tap/tap.sh

index 7a0b5dc91d65a4c9f41651bcf627510a86b92840..6d3e46ea32bb319ea9f0cb153daf17f88bba403f 100644 (file)
@@ -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;
index 3bb3099ce860659749979250ed9184476fda678b..1c9aae32c23afbba93b3f5b674380f08dea30caa 100644 (file)
@@ -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;
                }
 
index a44c8ef6718b9ba4808e1387565617eb060c48d6..5a2bac14d2159d678d01b717fe658d6a357ce450 100644 (file)
@@ -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");
index 428acad2285191827a65232ce6bf1bc6e7e94bf7..85c8a54282fc947aa7591c4476368fef62032d3b 100644 (file)
@@ -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);
        }
 }
 
index 04f2fffe1ea0cfad74def9db809eec1075e8c74f..ac6efa251f3041e371a5c338c9af8d55986c37f6 100644 (file)
@@ -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);
        }
 }
 
index 95aac5561d13edca8091359357c723c24db6a9d7..89fab12eb1ed72e3d7235543fa83acb6fbfe8bf6 100644 (file)
@@ -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);
        }
 }
 
index 7395f6fc59b80c14ce5a710ff8018e45d025f861..9f41408bd4c4dd25a729b607b4c276bb115ab27b 100644 (file)
@@ -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 <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <assert.h>
 
 #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;
 
index 84288f03848831f8f148c4612d9cd73608af8c75..bba1ceadc0889f1ab886081207e7414e65f5a5e6 100644 (file)
@@ -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);
index 109cc8e4ce5bc4ebba3af6f8f9c669b2c26f8365..4b51106c013273aee268342734446f5c43f2aabe 100755 (executable)
@@ -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
This page took 0.032211 seconds and 4 git commands to generate.