mirror of
https://github.com/raspberrypi/linux.git
synced 2026-01-03 08:14:12 +00:00
There were a few problems with the way we output "debug" messages. The first is that we used DEBUG() which is defined when NDEBUG is not defined, but NDEBUG will never be defined for kselftests because it relies too much on assert(). The next is that most of the DEBUG() messages were actually "info" messages, which users may want to turn off if they just want a silent test that either completes or asserts. Finally, a debug message output from a library function, and thus for all tests, was annoying when its information wasn't interesting for a test. Rework these messages so debug messages only output when DEBUG is defined and info messages output unless QUIET is defined. Also name the functions pr_debug and pr_info and make sure that when they're disabled we eat all the inputs. The later avoids unused variable warnings when the variables were only defined for the purpose of printing. Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* tools/testing/selftests/kvm/include/test_util.h
|
|
*
|
|
* Copyright (C) 2018, Google LLC.
|
|
*/
|
|
|
|
#ifndef SELFTEST_KVM_TEST_UTIL_H
|
|
#define SELFTEST_KVM_TEST_UTIL_H
|
|
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <inttypes.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include "kselftest.h"
|
|
|
|
static inline int _no_printf(const char *format, ...) { return 0; }
|
|
|
|
#ifdef DEBUG
|
|
#define pr_debug(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define pr_debug(...) _no_printf(__VA_ARGS__)
|
|
#endif
|
|
#ifndef QUIET
|
|
#define pr_info(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define pr_info(...) _no_printf(__VA_ARGS__)
|
|
#endif
|
|
|
|
ssize_t test_write(int fd, const void *buf, size_t count);
|
|
ssize_t test_read(int fd, void *buf, size_t count);
|
|
int test_seq_read(const char *path, char **bufp, size_t *sizep);
|
|
|
|
void test_assert(bool exp, const char *exp_str,
|
|
const char *file, unsigned int line, const char *fmt, ...);
|
|
|
|
#define TEST_ASSERT(e, fmt, ...) \
|
|
test_assert((e), #e, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
|
|
|
#define ASSERT_EQ(a, b) do { \
|
|
typeof(a) __a = (a); \
|
|
typeof(b) __b = (b); \
|
|
TEST_ASSERT(__a == __b, \
|
|
"ASSERT_EQ(%s, %s) failed.\n" \
|
|
"\t%s is %#lx\n" \
|
|
"\t%s is %#lx", \
|
|
#a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
|
|
} while (0)
|
|
|
|
size_t parse_size(const char *size);
|
|
|
|
int64_t timespec_to_ns(struct timespec ts);
|
|
struct timespec timespec_diff(struct timespec start, struct timespec end);
|
|
|
|
#endif /* SELFTEST_KVM_TEST_UTIL_H */
|