-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.h
More file actions
108 lines (86 loc) · 3.18 KB
/
test.h
File metadata and controls
108 lines (86 loc) · 3.18 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Copyright (c) 2016 Peter Cannici
* Licensed under the MIT (X11) license. See LICENSE.
*/
#pragma once
#include "yu_common.h"
#include "internal_alloc.h"
#include "sys_alloc.h"
#include "ned_alloc.h"
#include "ptest.h"
#define ASSERT_YU_STR_EQ(expr, expect) do{ \
yu_str _actual = (expr), _hope = (expect); \
char *_msg; \
asprintf(&_msg, "%s yu_str_eq %s: Expected '%.*s', got '%.*s'.", \
#expr, #expect, \
(int)yu_str_len(_hope), _hope, \
(int)yu_str_len(_actual), _actual); \
pt_assert_run(yu_str_cmp(_actual,_hope)==0, _msg, __func__, __FILE__, __LINE__); \
free(_msg); \
}while(0)
#define SUITE_NAME(name) YU_NAME(suite, name)
#define TEST_NAME(name) YU_NAME(test, name)
#define SUITE_ENUMERATE_ADD_TESTS(name, desc) \
pt_add_test(TEST_NAME(name), desc, sname);
#define TEST_USE_SYS_ALLOC 1
#define TEST_USE_BUMP_ALLOC 2
#define TEST_USE_DEBUG_ALLOC 3
#define TEST_USE_NEDMALLOC 4
#ifndef TEST_ALLOC
#define TEST_ALLOC TEST_USE_SYS_ALLOC
#endif
#ifndef BUMP_ALLOC_SIZE
#define BUMP_ALLOC_SIZE (64 * 1024 * 1024)
#endif
#if TEST_ALLOC == TEST_USE_BUMP_ALLOC
#error Bump allocator is deprecated
#elif TEST_ALLOC == TEST_USE_DEBUG_ALLOC
#error Debug allocator not yet ported to new API
#elif TEST_ALLOC == TEST_USE_NEDMALLOC
#define TEST_GET_ALLOCATOR(ctx) \
ned_allocator ctx; \
do{ \
yu_err _allocerr = ned_alloc_ctx_init(&ctx, 1*1024*1024); \
assert(_allocerr == YU_OK); \
}while(0)
#define TEST_GET_INTERNAL_ALLOCATOR(ctx) \
ned_allocator ctx; \
do{ \
yu_err _allocerr = ned_alloc_ctx_init(&ctx, 1*1024*1024); \
assert(_allocerr == YU_OK); \
}while(0)
#else
#define TEST_GET_ALLOCATOR(ctx) \
sys_allocator ctx; \
do{ \
yu_err _allocerr = sys_alloc_ctx_init(&ctx); \
assert(_allocerr == YU_OK); \
}while(0)
#define TEST_GET_INTERNAL_ALLOCATOR(ctx) \
internal_allocator ctx; \
do{ \
yu_err _allocerr = internal_alloc_ctx_init(&ctx); \
assert(_allocerr == YU_OK); \
}while(0)
#endif
/* See http://stackoverflow.com/a/4152185 for what this is doing.
* In addition to __section__ we also need __attribute__(used) or
* the suites generally get compiled out (they're never referenced
* explicitly.
* See also: test/test.ld (the linker script that makes this all work).
* Note: We also have to insert some padding (done in the linker script)
* or GDB refuses to accept the file as executable even though it
* is a fully valid ELF file.
* TODO: Test suite doesn't need to run on Windows, does it? :(
*/
#define SUITE(name, list) \
void SUITE_NAME(name)(void) { \
const char *sname = #name; \
list(SUITE_ENUMERATE_ADD_TESTS) \
} \
static void (*EXPAND(DEFER(PASTE)(registered, SUITE_NAME(name))))(void) \
__attribute__((used,__section__(".suite_registry"))) = SUITE_NAME(name);
#define TEST(name) static void TEST_NAME(name)(void) { SETUP
#define END(name) TEARDOWN }
extern void (*suite_registry_begin[])(void);
extern void (*suite_registry_end[])(void);