-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.h
More file actions
65 lines (49 loc) · 1.74 KB
/
Copy pathtest.h
File metadata and controls
65 lines (49 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-2.0
/* @author: gabriele */
#ifndef TEST_H
#define TEST_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "types.h"
struct kunit {
const char *name;
bool failed;
};
struct kunit_case {
const char *name;
void (*run_test)(struct kunit *);
};
struct kunit_suite {
const char *name;
struct kunit_case *test_cases;
};
#define GFP_KERNEL 0
#define UNUSED(x) (void)(x)
void *kmalloc(size_t size, int flags);
#define kfree(ptr) free(ptr)
#define kunit_info(test, fmt, ...) \
printf("# %s: " fmt "\n", (test)->name, ##__VA_ARGS__)
#define KUNIT_CASE(func) { .name = #func, .run_test = func }
uint64_t ktime_get_ns(void);
void get_random_bytes(void *buf, size_t nbytes);
int run_kunit_suite(struct kunit_suite *suite);
bool kunit_assert_ptr(struct kunit *t, const void *p, const char *f, int l);
void kunit_expect_eq(struct kunit *t, long long a, long long b, const char *f,
int l);
void kunit_expect_mem(struct kunit *t, const void *a, const void *b, size_t n,
const char *f, int l);
void kunit_expect_str(struct kunit *t, const char *a, const char *b,
const char *f, int l);
#define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p) \
if (!kunit_assert_ptr(test, p, __FILE__, __LINE__)) return
#define KUNIT_EXPECT_EQ(test, a, b) \
kunit_expect_eq(test, (long long)(a), (long long)(b), __FILE__, __LINE__)
#define KUNIT_EXPECT_MEMEQ(test, a, b, n) \
kunit_expect_mem(test, a, b, n, __FILE__, __LINE__)
#define KUNIT_EXPECT_STREQ(test, a, b) \
kunit_expect_str(test, a, b, __FILE__, __LINE__)
#define kunit_test_suite(suite) \
int main(void) { return run_kunit_suite(&(suite)); }
#endif /* TEST_H */