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.
39 void pt_cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx,
50 static struct ptunit_result cpu_valid(void)
55 error = pt_cpu_parse(&cpu, "6/44/2");
57 ptu_int_eq(cpu.vendor, pcv_intel);
58 ptu_uint_eq(cpu.family, 6);
59 ptu_uint_eq(cpu.model, 44);
60 ptu_uint_eq(cpu.stepping, 2);
62 error = pt_cpu_parse(&cpu, "0xf/0x2c/0xf");
64 ptu_int_eq(cpu.vendor, pcv_intel);
65 ptu_uint_eq(cpu.family, 0xf);
66 ptu_uint_eq(cpu.model, 0x2c);
67 ptu_uint_eq(cpu.stepping, 0xf);
69 error = pt_cpu_parse(&cpu, "022/054/017");
71 ptu_int_eq(cpu.vendor, pcv_intel);
72 ptu_uint_eq(cpu.family, 022);
73 ptu_uint_eq(cpu.model, 054);
74 ptu_uint_eq(cpu.stepping, 017);
76 error = pt_cpu_parse(&cpu, "6/44");
78 ptu_int_eq(cpu.vendor, pcv_intel);
79 ptu_uint_eq(cpu.family, 6);
80 ptu_uint_eq(cpu.model, 44);
81 ptu_uint_eq(cpu.stepping, 0);
86 static struct ptunit_result cpu_null(void)
91 error = pt_cpu_parse(&cpu, NULL);
92 ptu_int_eq(error, -pte_invalid);
94 error = pt_cpu_parse(NULL, "");
95 ptu_int_eq(error, -pte_invalid);
97 error = pt_cpu_parse(NULL, NULL);
98 ptu_int_eq(error, -pte_invalid);
103 static struct ptunit_result cpu_incomplete(void)
108 error = pt_cpu_parse(&cpu, "");
109 ptu_int_eq(error, -pte_invalid);
111 error = pt_cpu_parse(&cpu, "6");
112 ptu_int_eq(error, -pte_invalid);
114 error = pt_cpu_parse(&cpu, "6/");
115 ptu_int_eq(error, -pte_invalid);
117 error = pt_cpu_parse(&cpu, "6//2");
118 ptu_int_eq(error, -pte_invalid);
120 error = pt_cpu_parse(&cpu, "//");
121 ptu_int_eq(error, -pte_invalid);
126 static struct ptunit_result cpu_invalid(void)
131 error = pt_cpu_parse(&cpu, "e/44/2");
132 ptu_int_eq(error, -pte_invalid);
134 error = pt_cpu_parse(&cpu, "6/e/2");
135 ptu_int_eq(error, -pte_invalid);
137 error = pt_cpu_parse(&cpu, "6/44/e");
138 ptu_int_eq(error, -pte_invalid);
140 error = pt_cpu_parse(&cpu, "65536/44/2");
141 ptu_int_eq(error, -pte_invalid);
143 error = pt_cpu_parse(&cpu, "6/256/2");
144 ptu_int_eq(error, -pte_invalid);
146 error = pt_cpu_parse(&cpu, "6/44/256");
147 ptu_int_eq(error, -pte_invalid);
149 error = pt_cpu_parse(&cpu, "-1/44/2");
150 ptu_int_eq(error, -pte_invalid);
152 error = pt_cpu_parse(&cpu, "6/-1/2");
153 ptu_int_eq(error, -pte_invalid);
155 error = pt_cpu_parse(&cpu, "6/44/-1");
156 ptu_int_eq(error, -pte_invalid);
161 int main(int argc, char **argv)
163 struct ptunit_suite suite;
165 suite = ptunit_mk_suite(argc, argv);
167 ptu_run(suite, cpu_valid);
168 ptu_run(suite, cpu_null);
169 ptu_run(suite, cpu_incomplete);
170 ptu_run(suite, cpu_invalid);
172 return ptunit_report(&suite);