Wed, 02 May 2018 20:55:23 +0200
minor formatting fix in modules.md
13 | 1 | /* |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
13 | 3 | * |
259 | 4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
13 | 27 | */ |
28 | ||
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
29 | #include "stack_tests.h" |
13 | 30 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
31 | #define test_ucx_stack_before \ |
187
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
32 | char space[99]; \ |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
33 | UcxStack stack; \ |
187
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
34 | ucx_stack_init(&stack, space, 99) \ |
13 | 35 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
36 | UCX_TEST(test_ucx_stack_init) { |
28 | 37 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
38 | test_ucx_stack_before; |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
39 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
40 | UCX_TEST_BEGIN |
28 | 41 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
42 | UCX_TEST_ASSERT( |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
43 | stack.allocator.malloc == (ucx_allocator_malloc) ucx_stack_malloc && |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
44 | stack.allocator.calloc == (ucx_allocator_calloc) ucx_stack_calloc && |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
45 | stack.allocator.realloc == (ucx_allocator_realloc) ucx_stack_realloc && |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
46 | stack.allocator.free == (ucx_allocator_free) ucx_stack_free && |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
47 | stack.allocator.pool == &stack, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
48 | "allocator not properly set"); |
28 | 49 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
50 | UCX_TEST_ASSERT(!stack.top && stack.space == space |
187
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
51 | && stack.size == 99 - 99 % sizeof(void*), |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
52 | "struct fields not properly set"); |
28 | 53 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
54 | UCX_TEST_END |
13 | 55 | } |
56 | ||
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
57 | UCX_TEST(test_ucx_stack_malloc) { |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
58 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
59 | test_ucx_stack_before; |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
60 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
61 | const size_t metasize = sizeof(struct ucx_stack_metadata); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
62 | |
28 | 63 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
64 | char* first = (char*) ucx_stack_malloc(&stack, 30); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
65 | char* second = (char*) ucx_stack_malloc(&stack, 30); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
66 | char* full = (char*) ucx_stack_malloc(&stack, 30); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
67 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
68 | memcpy(first, "012345678901234567890123456789", 30); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
69 | memcpy(second, "abcdefghijklmnopqrstuvwxyzABCD", 30); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
70 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
71 | UCX_TEST_BEGIN |
28 | 72 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
73 | UCX_TEST_ASSERT(!memcmp(space + metasize, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
74 | "012345678901234567890123456789", 30), "first element corrupted"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
75 | UCX_TEST_ASSERT(!memcmp(space + 32+2*metasize, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
76 | "abcdefghijklmnopqrstuvwxyzABCD", 30), "first element corrupted"); |
28 | 77 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
78 | UCX_TEST_ASSERT(!full, "stack can be overflowed"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
79 | UCX_TEST_ASSERT(stack.top == space + 32 + 2*metasize, "wrong top pointer"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
80 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
81 | if (3*metasize < 32) { |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
82 | UCX_TEST_ASSERT(ucx_stack_avail(&stack) == 32-3*metasize, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
83 | "wrong remaining available memory"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
84 | } else { |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
85 | UCX_TEST_ASSERT(ucx_stack_avail(&stack) == 0, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
86 | "wrong remaining available memory"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
87 | } |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
88 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
89 | UCX_TEST_END |
28 | 90 | } |
91 | ||
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
92 | UCX_TEST(test_ucx_stack_calloc) { |
28 | 93 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
94 | test_ucx_stack_before; |
113
8693d7874773
added mempool allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
95 | |
187
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
96 | char zeros[99]; |
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
97 | memset(zeros, 0, 99); |
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
98 | memset(space, 32, 99); |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
99 | ucx_stack_calloc(&stack, 4, sizeof(int)); |
113
8693d7874773
added mempool allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
100 | |
8693d7874773
added mempool allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
101 | UCX_TEST_BEGIN |
8693d7874773
added mempool allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
102 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
103 | UCX_TEST_ASSERT(!memcmp(space+sizeof(struct ucx_stack_metadata), |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
104 | zeros, 4*sizeof(int)), "memory not nulled"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
105 | UCX_TEST_ASSERT(!memcmp(space+sizeof(struct ucx_stack_metadata) |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
106 | +4*sizeof(int), " ", 10), "too much memory nulled"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
107 | |
113
8693d7874773
added mempool allocator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
108 | UCX_TEST_END |
28 | 109 | } |
110 | ||
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
111 | UCX_TEST(test_ucx_stack_free) { |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
112 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
113 | test_ucx_stack_before; |
28 | 114 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
115 | void *fst = ucx_stack_malloc(&stack, 10); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
116 | void *snd = ucx_stack_malloc(&stack, 10); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
117 | void *thrd = ucx_stack_malloc(&stack, 10); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
118 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
119 | UCX_TEST_BEGIN |
28 | 120 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
121 | UCX_TEST_ASSERT(stack.top == thrd, "wrong stack"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
122 | UCX_TEST_ASSERT(((struct ucx_stack_metadata*) thrd - 1)->prev == snd, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
123 | "wrong thrd prev pointer before free"); |
28 | 124 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
125 | ucx_stack_free(&stack, snd); |
28 | 126 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
127 | UCX_TEST_ASSERT(((struct ucx_stack_metadata*) thrd - 1)->prev == fst, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
128 | "wrong thrd prev pointer after freeing snd"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
129 | UCX_TEST_ASSERT(stack.top == thrd, "wrong top after freeing snd"); |
28 | 130 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
131 | ucx_stack_free(&stack, thrd); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
132 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
133 | UCX_TEST_ASSERT(stack.top == fst, "wrong top after freeing thrd"); |
28 | 134 | |
135 | UCX_TEST_END | |
136 | } | |
13 | 137 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
138 | UCX_TEST(test_ucx_stack_realloc) { |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
139 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
140 | test_ucx_stack_before; |
28 | 141 | |
187
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
142 | void *fst = ucx_stack_malloc(&stack, 14); |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
143 | void *snd = ucx_stack_malloc(&stack, 10); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
144 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
145 | UCX_TEST_BEGIN |
28 | 146 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
147 | void *nfst = ucx_stack_realloc(&stack, fst, 16); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
148 | UCX_TEST_ASSERT(nfst == fst, "unnecessary move on reallocation"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
149 | UCX_TEST_ASSERT(((struct ucx_stack_metadata*)fst - 1)->size == 16, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
150 | "wrong size after reallocation"); |
28 | 151 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
152 | void *nsnd = ucx_stack_realloc(&stack, snd, 30); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
153 | UCX_TEST_ASSERT(nsnd == snd, "unnecessary move on top reallocation"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
154 | UCX_TEST_ASSERT(ucx_stack_topsize(&stack) == 30, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
155 | "wrong size after top reallocation"); |
28 | 156 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
157 | nsnd = ucx_stack_realloc(&stack, snd, 5); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
158 | UCX_TEST_ASSERT(nsnd == snd, "unnecessary move on top shrink"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
159 | UCX_TEST_ASSERT(ucx_stack_topsize(&stack) == 5, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
160 | "wrong size after top shrink"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
161 | UCX_TEST_ASSERT(ucx_stack_avail(&stack) == |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
162 | 72-3*sizeof(struct ucx_stack_metadata), "wrong size after top shrink"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
163 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
164 | nfst = ucx_stack_realloc(&stack, fst, 24); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
165 | UCX_TEST_ASSERT(nfst != fst, "missing move on huge reallocation"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
166 | UCX_TEST_ASSERT(stack.top == nfst, "wrong top after huge reallocation"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
167 | UCX_TEST_ASSERT(ucx_stack_topsize(&stack) == 24, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
168 | "wrong size after huge reallocation"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
169 | UCX_TEST_ASSERT(!((struct ucx_stack_metadata*)snd - 1)->prev, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
170 | "element not freed after huge reallocation"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
171 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
172 | UCX_TEST_END |
28 | 173 | } |
13 | 174 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
175 | UCX_TEST(test_ucx_stack_pop) { |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
176 | |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
177 | test_ucx_stack_before; |
187
7d49f179cc25
fixed stack tests to work with 4-byte-alignment + fixed logging tests
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
178 | memset(space, 32, 99); |
28 | 179 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
180 | void *fst = ucx_stack_malloc(&stack, 10); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
181 | void *snd = ucx_stack_malloc(&stack, 10); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
182 | ucx_stack_malloc(&stack, 10); |
28 | 183 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
184 | char buf[16]; |
28 | 185 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
186 | UCX_TEST_BEGIN |
14 | 187 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
188 | memset(buf, '0', 16); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
189 | ucx_stack_pop(&stack, buf); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
190 | UCX_TEST_ASSERT(memcmp(buf, " 000000", 16) == 0, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
191 | "popped wrong content"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
192 | UCX_TEST_ASSERT(stack.top == snd, "wrong top after pop"); |
28 | 193 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
194 | memset(buf, '0', 16); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
195 | ucx_stack_popn(&stack, buf, 5); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
196 | UCX_TEST_ASSERT(memcmp(buf, " 00000000000", 16) == 0, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
197 | "n-popped wrong content"); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
198 | UCX_TEST_ASSERT(stack.top == fst, "wrong top after pop"); |
28 | 199 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
200 | ucx_stack_pop(&stack, buf); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
201 | UCX_TEST_ASSERT(!stack.top, "top not NULL after last pop"); |
28 | 202 | |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
203 | memset(buf, '0', 16); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
204 | ucx_stack_pop(&stack, buf); |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
205 | UCX_TEST_ASSERT(memcmp(buf, "0000000000000000", 16) == 0, |
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
206 | "content not unchanged after empty pop"); |
13 | 207 | |
28 | 208 | UCX_TEST_END |
13 | 209 | } |