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.
31 #include "pt_mapped_section.h"
36 static struct ptunit_result begin(void)
38 struct pt_mapped_section msec;
39 struct pt_section sec;
42 pt_msec_init(&msec, &sec, NULL, 0x2000ull, 0x100ull, 0x1000ull);
44 begin = pt_msec_begin(&msec);
45 ptu_uint_eq(begin, 0x2000);
50 static struct ptunit_result end(void)
52 struct pt_mapped_section msec;
53 struct pt_section sec;
56 pt_msec_init(&msec, &sec, NULL, 0x2000ull, 0x100ull, 0x1000ull);
58 end = pt_msec_end(&msec);
59 ptu_uint_eq(end, 0x3000);
64 static struct ptunit_result offset(void)
66 struct pt_mapped_section msec;
67 struct pt_section sec;
70 pt_msec_init(&msec, &sec, NULL, 0x2000ull, 0x100ull, 0x1000ull);
72 offset = pt_msec_offset(&msec);
73 ptu_uint_eq(offset, 0x100ull);
78 static struct ptunit_result size(void)
80 struct pt_mapped_section msec;
81 struct pt_section sec;
84 pt_msec_init(&msec, &sec, NULL, 0x2000ull, 0x100ull, 0x1000ull);
86 size = pt_msec_size(&msec);
87 ptu_uint_eq(size, 0x1000ull);
92 static struct ptunit_result asid(void)
94 struct pt_mapped_section msec;
96 const struct pt_asid *pasid;
99 asid.cr3 = 0xa00000ull;
100 asid.vmcs = 0xb00000ull;
102 pt_msec_init(&msec, NULL, &asid, 0x2000ull, 0x100ull, 0x1000ull);
104 pasid = pt_msec_asid(&msec);
106 ptu_uint_eq(pasid->cr3, asid.cr3);
107 ptu_uint_eq(pasid->vmcs, asid.vmcs);
112 static struct ptunit_result asid_null(void)
114 struct pt_mapped_section msec;
115 const struct pt_asid *pasid;
117 pt_msec_init(&msec, NULL, NULL, 0x2000ull, 0x100ull, 0x1000ull);
119 pasid = pt_msec_asid(&msec);
121 ptu_uint_eq(pasid->cr3, pt_asid_no_cr3);
122 ptu_uint_eq(pasid->vmcs, pt_asid_no_vmcs);
127 static struct ptunit_result map(void)
129 struct pt_mapped_section msec;
132 pt_msec_init(&msec, NULL, NULL, 0x2000ull, 0x100ull, 0x1000ull);
134 mapped = pt_msec_map(&msec, 0x900);
135 ptu_uint_eq(mapped, 0x2800);
140 static struct ptunit_result unmap(void)
142 struct pt_mapped_section msec;
145 pt_msec_init(&msec, NULL, NULL, 0x2000ull, 0x100ull, 0x1000ull);
147 offset = pt_msec_unmap(&msec, 0x3000);
148 ptu_uint_eq(offset, 0x1100);
153 static struct ptunit_result section(void)
155 static struct pt_section section;
156 struct pt_mapped_section msec;
157 struct pt_section *psection;
159 pt_msec_init(&msec, §ion, NULL, 0x2000ull, 0x100ull, 0x1000ull);
161 psection = pt_msec_section(&msec);
162 ptu_ptr_eq(psection, §ion);
167 static struct ptunit_result section_null(void)
169 struct pt_mapped_section msec;
170 struct pt_section *psection;
172 pt_msec_init(&msec, NULL, NULL, 0x2000ull, 0x100ull, 0x1000ull);
174 psection = pt_msec_section(&msec);
175 ptu_ptr_eq(psection, NULL);
180 int main(int argc, char **argv)
182 struct ptunit_suite suite;
184 suite = ptunit_mk_suite(argc, argv);
186 ptu_run(suite, begin);
188 ptu_run(suite, offset);
189 ptu_run(suite, size);
190 ptu_run(suite, asid);
191 ptu_run(suite, asid_null);
193 ptu_run(suite, unmap);
194 ptu_run(suite, section);
195 ptu_run(suite, section_null);
197 return ptunit_report(&suite);