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>
}
ok(value == expected_value,
- "Expected unsigned integer value %u, got %" PRIu64,
+ "Expected unsigned integer value %" PRIu64 ", got %" PRIu64,
expected_value, value);
ret = 0;
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;
}
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");
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);
}
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);
}
if (result != NULL) {
free(result);
}
- ok(result == NULL, name);
+ ok(result == NULL, "%s", name);
}
}
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 */
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);
}
}
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 */
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);
}
}
-/*-
- * 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"
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.
*
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;
}
* Note that the plan is to skip all tests
*/
int
-plan_skip_all(char *reason)
+plan_skip_all(const char *reason)
{
LOCK;
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)
{
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);
}
void
-todo_start(char *fmt, ...)
+todo_start(const char *fmt, ...)
{
va_list ap;
-/*-
- * 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
#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);
_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