blob: 73c3933436ecc1206b8f90f2e4991ac4ddcf7bea [file] [log] [blame]
Paolo Bonzini783e9e52018-03-27 11:49:19 +02001/*
2 * tools/testing/selftests/kvm/include/test_util.h
3 *
4 * Copyright (C) 2018, Google LLC.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2.
7 *
8 */
9
10#ifndef TEST_UTIL_H
11#define TEST_UTIL_H 1
12
13#include <stdlib.h>
14#include <stdarg.h>
15#include <stdbool.h>
16#include <stdio.h>
17#include <string.h>
18#include <inttypes.h>
19#include <errno.h>
20#include <unistd.h>
21#include <fcntl.h>
Paolo Bonzinibcb2b942018-04-18 18:26:45 +020022#include "kselftest.h"
Paolo Bonzini783e9e52018-03-27 11:49:19 +020023
24ssize_t test_write(int fd, const void *buf, size_t count);
25ssize_t test_read(int fd, void *buf, size_t count);
26int test_seq_read(const char *path, char **bufp, size_t *sizep);
27
28void test_assert(bool exp, const char *exp_str,
29 const char *file, unsigned int line, const char *fmt, ...);
30
Paolo Bonzini783e9e52018-03-27 11:49:19 +020031#define TEST_ASSERT(e, fmt, ...) \
32 test_assert((e), #e, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
33
34#define ASSERT_EQ(a, b) do { \
35 typeof(a) __a = (a); \
36 typeof(b) __b = (b); \
37 TEST_ASSERT(__a == __b, \
38 "ASSERT_EQ(%s, %s) failed.\n" \
39 "\t%s is %#lx\n" \
40 "\t%s is %#lx", \
41 #a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
42} while (0)
43
44#endif /* TEST_UTIL_H */