hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/tools/testing/selftests/kvm/include/test_util.h
....@@ -1,14 +1,12 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * tools/testing/selftests/kvm/include/test_util.h
34 *
45 * Copyright (C) 2018, Google LLC.
5
- *
6
- * This work is licensed under the terms of the GNU GPL, version 2.
7
- *
86 */
97
10
-#ifndef TEST_UTIL_H
11
-#define TEST_UTIL_H 1
8
+#ifndef SELFTEST_KVM_TEST_UTIL_H
9
+#define SELFTEST_KVM_TEST_UTIL_H
1210
1311 #include <stdlib.h>
1412 #include <stdarg.h>
....@@ -21,12 +19,28 @@
2119 #include <fcntl.h>
2220 #include "kselftest.h"
2321
22
+static inline int _no_printf(const char *format, ...) { return 0; }
23
+
24
+#ifdef DEBUG
25
+#define pr_debug(...) printf(__VA_ARGS__)
26
+#else
27
+#define pr_debug(...) _no_printf(__VA_ARGS__)
28
+#endif
29
+#ifndef QUIET
30
+#define pr_info(...) printf(__VA_ARGS__)
31
+#else
32
+#define pr_info(...) _no_printf(__VA_ARGS__)
33
+#endif
34
+
35
+void print_skip(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
36
+
2437 ssize_t test_write(int fd, const void *buf, size_t count);
2538 ssize_t test_read(int fd, void *buf, size_t count);
2639 int test_seq_read(const char *path, char **bufp, size_t *sizep);
2740
2841 void test_assert(bool exp, const char *exp_str,
29
- const char *file, unsigned int line, const char *fmt, ...);
42
+ const char *file, unsigned int line, const char *fmt, ...)
43
+ __attribute__((format(printf, 5, 6)));
3044
3145 #define TEST_ASSERT(e, fmt, ...) \
3246 test_assert((e), #e, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
....@@ -41,4 +55,16 @@
4155 #a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
4256 } while (0)
4357
44
-#endif /* TEST_UTIL_H */
58
+#define TEST_FAIL(fmt, ...) \
59
+ TEST_ASSERT(false, fmt, ##__VA_ARGS__)
60
+
61
+size_t parse_size(const char *size);
62
+
63
+int64_t timespec_to_ns(struct timespec ts);
64
+struct timespec timespec_add_ns(struct timespec ts, int64_t ns);
65
+struct timespec timespec_add(struct timespec ts1, struct timespec ts2);
66
+struct timespec timespec_sub(struct timespec ts1, struct timespec ts2);
67
+struct timespec timespec_diff_now(struct timespec start);
68
+struct timespec timespec_div(struct timespec ts, int divisor);
69
+
70
+#endif /* SELFTEST_KVM_TEST_UTIL_H */