2 * Copyright (c) 2013-2018, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
31 #include "pt_retstack.h"
36 static struct ptunit_result init(void)
38 struct pt_retstack retstack;
41 memset(&retstack, 0xcd, sizeof(retstack));
43 pt_retstack_init(&retstack);
45 status = pt_retstack_is_empty(&retstack);
46 ptu_int_ne(status, 0);
51 static struct ptunit_result init_null(void)
53 pt_retstack_init(NULL);
58 static struct ptunit_result query(void)
60 struct pt_retstack retstack;
64 pt_retstack_init(&retstack);
66 status = pt_retstack_push(&retstack, 0x42ull);
67 ptu_int_eq(status, 0);
69 status = pt_retstack_is_empty(&retstack);
70 ptu_int_eq(status, 0);
72 status = pt_retstack_pop(&retstack, &ip);
73 ptu_int_eq(status, 0);
74 ptu_uint_eq(ip, 0x42ull);
76 status = pt_retstack_is_empty(&retstack);
77 ptu_int_ne(status, 0);
82 static struct ptunit_result query_empty(void)
84 struct pt_retstack retstack;
88 pt_retstack_init(&retstack);
91 status = pt_retstack_pop(&retstack, &ip);
92 ptu_int_eq(status, -pte_retstack_empty);
93 ptu_uint_eq(ip, 0x42ull);
98 static struct ptunit_result query_null(void)
104 status = pt_retstack_pop(NULL, &ip);
105 ptu_int_eq(status, -pte_invalid);
106 ptu_uint_eq(ip, 0x42ull);
111 static struct ptunit_result pop(void)
113 struct pt_retstack retstack;
116 pt_retstack_init(&retstack);
118 status = pt_retstack_push(&retstack, 0x42ull);
119 ptu_int_eq(status, 0);
121 status = pt_retstack_is_empty(&retstack);
122 ptu_int_eq(status, 0);
124 status = pt_retstack_pop(&retstack, NULL);
125 ptu_int_eq(status, 0);
127 status = pt_retstack_is_empty(&retstack);
128 ptu_int_ne(status, 0);
133 static struct ptunit_result pop_empty(void)
135 struct pt_retstack retstack;
138 pt_retstack_init(&retstack);
140 status = pt_retstack_pop(&retstack, NULL);
141 ptu_int_eq(status, -pte_retstack_empty);
146 static struct ptunit_result pop_null(void)
150 status = pt_retstack_pop(NULL, NULL);
151 ptu_int_eq(status, -pte_invalid);
156 static struct ptunit_result full(void)
158 struct pt_retstack retstack;
162 pt_retstack_init(&retstack);
164 for (idx = 0; idx < pt_retstack_size; ++idx) {
165 status = pt_retstack_push(&retstack, idx);
166 ptu_int_eq(status, 0);
169 status = pt_retstack_is_empty(&retstack);
170 ptu_int_eq(status, 0);
172 for (idx = pt_retstack_size; idx > 0;) {
175 status = pt_retstack_pop(&retstack, &ip);
176 ptu_int_eq(status, 0);
177 ptu_uint_eq(ip, idx);
180 status = pt_retstack_is_empty(&retstack);
181 ptu_int_ne(status, 0);
186 static struct ptunit_result overflow(void)
188 struct pt_retstack retstack;
192 pt_retstack_init(&retstack);
194 for (idx = 0; idx <= pt_retstack_size; ++idx) {
195 status = pt_retstack_push(&retstack, idx);
196 ptu_int_eq(status, 0);
199 status = pt_retstack_is_empty(&retstack);
200 ptu_int_eq(status, 0);
202 for (idx = pt_retstack_size; idx > 0; --idx) {
203 status = pt_retstack_pop(&retstack, &ip);
204 ptu_int_eq(status, 0);
205 ptu_uint_eq(ip, idx);
208 status = pt_retstack_is_empty(&retstack);
209 ptu_int_ne(status, 0);
214 int main(int argc, char **argv)
216 struct ptunit_suite suite;
218 suite = ptunit_mk_suite(argc, argv);
220 ptu_run(suite, init);
221 ptu_run(suite, init_null);
222 ptu_run(suite, query);
223 ptu_run(suite, query_empty);
224 ptu_run(suite, query_null);
226 ptu_run(suite, pop_empty);
227 ptu_run(suite, pop_null);
228 ptu_run(suite, full);
229 ptu_run(suite, overflow);
231 return ptunit_report(&suite);