imcplugin: Add launching sel_ldr
[nativeclient.git] / platform_qual_test / nacl_cpuwhitelist_test.c
blob7b6777bd599993b89096d4bf7d8ee0c15ac08f96
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
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
14 * distribution.
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.
33 * nacl_cpuwhitelist_test.c
35 #include "native_client/include/portability.h"
36 #include <stdio.h>
37 #include <string.h>
38 #include <assert.h>
39 #include <stdlib.h>
40 #include "native_client/ncv/nacl_cpuid.h"
41 #include "native_client/platform_qual_test/nacl_cpuwhitelist.h"
43 #define sizeofA(array) (sizeof(array) / sizeof(array[0]))
44 static void CPUIDWhitelistUnitTests() {
45 extern bool xNaCl_CPUIsWhitelisted(const char *myid);
46 size_t i;
48 /* check lengths */
49 for (i = 0; i < sizeofA(nacl_cpuwhitelist); i++) {
50 if (strlen(nacl_cpuwhitelist[i]) != kCPUWhitelistIDLength - 1) {
51 fprintf(stderr, "ERROR: whitelist entry %"PRIdS" bad length\n", i);
52 exit(-1);
55 /* check order */
56 for (i = 1; i < sizeofA(nacl_cpuwhitelist); i++) {
57 if (strncmp(nacl_cpuwhitelist[i-1], nacl_cpuwhitelist[i],
58 kCPUWhitelistIDLength) >= 0) {
59 fprintf(stderr, "ERROR: whitelist order defect at index %"PRIdS"\n", i);
60 exit(-1);
63 if (!xNaCl_CPUIsWhitelisted(" FakeEntry0000000000")) {
64 fprintf(stderr, "ERROR: whitelist search 1 failed\n");
65 exit(-1);
67 if (!xNaCl_CPUIsWhitelisted("GenuineIntel00000f43")) {
68 fprintf(stderr, "ERROR: whitelist search 2 failed\n");
69 exit(-1);
71 if (!xNaCl_CPUIsWhitelisted("zFakeEntry0000000000")) {
72 fprintf(stderr, "ERROR: whitelist search 3 failed\n");
73 exit(-1);
75 if (xNaCl_CPUIsWhitelisted("a")) {
76 fprintf(stderr, "ERROR: whitelist search 4 didn't fail\n");
77 exit(-1);
79 if (xNaCl_CPUIsWhitelisted("")) {
80 fprintf(stderr, "ERROR: whitelist search 5 didn't fail\n");
81 exit(-1);
83 if (xNaCl_CPUIsWhitelisted("zFakeEntry0000000001")) {
84 fprintf(stderr, "ERROR: whitelist search 6 didn't fail\n");
85 exit(-1);
87 if (xNaCl_CPUIsWhitelisted("zFakeEntry00000000000")) {
88 fprintf(stderr, "ERROR: whitelist search 7 didn't fail\n");
89 exit(-1);
91 printf("All whitelist unit tests passed\n");
94 int main(int argc, char *argv[]) {
95 extern char *GetCPUIDString();
96 extern bool NaCl_CPUIsWhitelisted();
97 extern bool NaCl_CPUIsBlacklisted();
99 printf("white list ID: %s\n", GetCPUIDString());
100 if (NaCl_CPUIsWhitelisted()) {
101 printf("this CPU is on the whitelist\n");
102 } else {
103 printf("this CPU is NOT on the whitelist\n");
105 if (NaCl_CPUIsBlacklisted()) {
106 printf("this CPU is on the blacklist\n");
107 } else {
108 printf("this CPU is NOT on the blacklist\n");
111 CPUIDWhitelistUnitTests();
112 return 0;