2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * test main and subroutines for nacl_cpuid
36 #include "native_client/include/portability.h"
40 #include "native_client/ncv/nacl_cpuid.h"
41 #include "native_client/ncv/nacl_cpuwhitelist.h"
43 #define dprint(args) printf args ;
45 #define sizeofA(array) (sizeof(array)/sizeof(array[0]))
46 static void CPUIDWhitelistUnitTests() {
47 extern bool xNaCl_CPUIsWhitelisted(const char *myid
);
51 for (i
= 0; i
< sizeofA(nacl_cpuwhitelist
); i
++) {
52 if (strlen(nacl_cpuwhitelist
[i
]) != kCPUWhitelistIDLength
- 1) {
53 fprintf(stderr
, "ERROR: whitelist entry %"PRIdS
" bad length\n", i
);
58 for (i
= 1; i
< sizeofA(nacl_cpuwhitelist
); i
++) {
59 if (strncmp(nacl_cpuwhitelist
[i
-1], nacl_cpuwhitelist
[i
],
60 kCPUWhitelistIDLength
) >= 0) {
61 fprintf(stderr
, "ERROR: whitelist order defect at index %"PRIdS
"\n", i
);
65 if (!xNaCl_CPUIsWhitelisted(" FakeEntry0000000000")) {
66 fprintf(stderr
, "ERROR: whitelist search 1 failed\n");
69 if (!xNaCl_CPUIsWhitelisted("GenuineIntel00000f43")) {
70 fprintf(stderr
, "ERROR: whitelist search 2 failed\n");
73 if (!xNaCl_CPUIsWhitelisted("zFakeEntry0000000000")) {
74 fprintf(stderr
, "ERROR: whitelist search 3 failed\n");
77 if (xNaCl_CPUIsWhitelisted("a")) {
78 fprintf(stderr
, "ERROR: whitelist search 4 didn't fail\n");
81 if (xNaCl_CPUIsWhitelisted("")) {
82 fprintf(stderr
, "ERROR: whitelist search 5 didn't fail\n");
85 if (xNaCl_CPUIsWhitelisted("zFakeEntry0000000001")) {
86 fprintf(stderr
, "ERROR: whitelist search 6 didn't fail\n");
89 if (xNaCl_CPUIsWhitelisted("zFakeEntry00000000000")) {
90 fprintf(stderr
, "ERROR: whitelist search 7 didn't fail\n");
93 printf("All whitelist unit tests passed\n");
96 int main(int argc
, char *argv
[]) {
98 extern char *GetCPUWhitelistID();
99 extern bool NaCl_CPUIsWhitelisted();
102 if (fv
.f_386
) dprint(("This is a 386 compatible computer\n"));
103 printf("white list ID: %s\n", GetCPUWhitelistID());
104 if (NaCl_CPUIsWhitelisted()) {
105 printf("this CPU is on the whitelist\n");
107 printf("this CPU is NOT on the whitelist\n");
110 CPUIDWhitelistUnitTests();