2 * Copyright (c) 2014-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.
32 #include "pt_opcodes.h"
37 /* A test fixture for sync tests. */
39 /* The trace buffer. */
42 /* A trace configuration. */
43 struct pt_config config;
45 /* The test fixture initialization and finalization functions. */
46 struct ptunit_result (*init)(struct sync_fixture *);
47 struct ptunit_result (*fini)(struct sync_fixture *);
50 static struct ptunit_result sfix_init(struct sync_fixture *sfix)
52 memset(sfix->buffer, 0xcd, sizeof(sfix->buffer));
54 memset(&sfix->config, 0, sizeof(sfix->config));
55 sfix->config.size = sizeof(sfix->config);
56 sfix->config.begin = sfix->buffer;
57 sfix->config.end = sfix->buffer + sizeof(sfix->buffer);
62 static void sfix_encode_psb(uint8_t *pos)
69 for (i = 0; i < pt_psb_repeat_count; ++i) {
76 static struct ptunit_result sync_fwd_null(struct sync_fixture *sfix)
81 errcode = pt_sync_forward(NULL, sfix->config.begin, &sfix->config);
82 ptu_int_eq(errcode, -pte_internal);
84 errcode = pt_sync_forward(&sync, NULL, &sfix->config);
85 ptu_int_eq(errcode, -pte_internal);
87 errcode = pt_sync_forward(&sync, sfix->config.begin, NULL);
88 ptu_int_eq(errcode, -pte_internal);
93 static struct ptunit_result sync_bwd_null(struct sync_fixture *sfix)
98 errcode = pt_sync_backward(NULL, sfix->config.begin, &sfix->config);
99 ptu_int_eq(errcode, -pte_internal);
101 errcode = pt_sync_backward(&sync, NULL, &sfix->config);
102 ptu_int_eq(errcode, -pte_internal);
104 errcode = pt_sync_backward(&sync, sfix->config.begin, NULL);
105 ptu_int_eq(errcode, -pte_internal);
110 static struct ptunit_result sync_fwd_empty(struct sync_fixture *sfix)
115 sfix->config.end = sfix->config.begin;
117 errcode = pt_sync_forward(&sync, sfix->config.begin, &sfix->config);
118 ptu_int_eq(errcode, -pte_eos);
123 static struct ptunit_result sync_bwd_empty(struct sync_fixture *sfix)
128 sfix->config.end = sfix->config.begin;
130 errcode = pt_sync_backward(&sync, sfix->config.end, &sfix->config);
131 ptu_int_eq(errcode, -pte_eos);
136 static struct ptunit_result sync_fwd_none(struct sync_fixture *sfix)
141 errcode = pt_sync_forward(&sync, sfix->config.begin, &sfix->config);
142 ptu_int_eq(errcode, -pte_eos);
147 static struct ptunit_result sync_bwd_none(struct sync_fixture *sfix)
152 errcode = pt_sync_backward(&sync, sfix->config.end, &sfix->config);
153 ptu_int_eq(errcode, -pte_eos);
158 static struct ptunit_result sync_fwd_here(struct sync_fixture *sfix)
163 sfix_encode_psb(sfix->config.begin);
165 errcode = pt_sync_forward(&sync, sfix->config.begin, &sfix->config);
166 ptu_int_eq(errcode, 0);
167 ptu_ptr_eq(sync, sfix->config.begin);
172 static struct ptunit_result sync_bwd_here(struct sync_fixture *sfix)
177 sfix_encode_psb(sfix->config.end - ptps_psb);
179 errcode = pt_sync_backward(&sync, sfix->config.end, &sfix->config);
180 ptu_int_eq(errcode, 0);
181 ptu_ptr_eq(sync, sfix->config.end - ptps_psb);
186 static struct ptunit_result sync_fwd(struct sync_fixture *sfix)
191 sfix_encode_psb(sfix->config.begin + 0x23);
193 errcode = pt_sync_forward(&sync, sfix->config.begin, &sfix->config);
194 ptu_int_eq(errcode, 0);
195 ptu_ptr_eq(sync, sfix->config.begin + 0x23);
200 static struct ptunit_result sync_bwd(struct sync_fixture *sfix)
205 sfix_encode_psb(sfix->config.begin + 0x23);
207 errcode = pt_sync_backward(&sync, sfix->config.end, &sfix->config);
208 ptu_int_eq(errcode, 0);
209 ptu_ptr_eq(sync, sfix->config.begin + 0x23);
214 static struct ptunit_result sync_fwd_past(struct sync_fixture *sfix)
219 sfix_encode_psb(sfix->config.begin);
221 errcode = pt_sync_forward(&sync, sfix->config.begin + ptps_psb,
223 ptu_int_eq(errcode, -pte_eos);
228 static struct ptunit_result sync_bwd_past(struct sync_fixture *sfix)
233 sfix_encode_psb(sfix->config.end - ptps_psb);
235 errcode = pt_sync_backward(&sync, sfix->config.end - ptps_psb,
237 ptu_int_eq(errcode, -pte_eos);
242 static struct ptunit_result sync_fwd_cutoff(struct sync_fixture *sfix)
247 sfix_encode_psb(sfix->config.begin);
248 sfix_encode_psb(sfix->config.end - ptps_psb);
249 sfix->config.begin += 1;
250 sfix->config.end -= 1;
252 errcode = pt_sync_forward(&sync, sfix->config.begin, &sfix->config);
253 ptu_int_eq(errcode, -pte_eos);
258 static struct ptunit_result sync_bwd_cutoff(struct sync_fixture *sfix)
263 sfix_encode_psb(sfix->config.begin);
264 sfix_encode_psb(sfix->config.end - ptps_psb);
265 sfix->config.begin += 1;
266 sfix->config.end -= 1;
268 errcode = pt_sync_backward(&sync, sfix->config.end, &sfix->config);
269 ptu_int_eq(errcode, -pte_eos);
274 int main(int argc, char **argv)
276 struct sync_fixture sfix;
277 struct ptunit_suite suite;
279 sfix.init = sfix_init;
282 suite = ptunit_mk_suite(argc, argv);
284 ptu_run_f(suite, sync_fwd_null, sfix);
285 ptu_run_f(suite, sync_bwd_null, sfix);
287 ptu_run_f(suite, sync_fwd_empty, sfix);
288 ptu_run_f(suite, sync_bwd_empty, sfix);
290 ptu_run_f(suite, sync_fwd_none, sfix);
291 ptu_run_f(suite, sync_bwd_none, sfix);
293 ptu_run_f(suite, sync_fwd_here, sfix);
294 ptu_run_f(suite, sync_bwd_here, sfix);
296 ptu_run_f(suite, sync_fwd, sfix);
297 ptu_run_f(suite, sync_bwd, sfix);
299 ptu_run_f(suite, sync_fwd_past, sfix);
300 ptu_run_f(suite, sync_bwd_past, sfix);
302 ptu_run_f(suite, sync_fwd_cutoff, sfix);
303 ptu_run_f(suite, sync_bwd_cutoff, sfix);
305 return ptunit_report(&suite);