Home | History | Annotate | Line # | Download | only in hpc
      1 /*	$NetBSD: platid_test.c,v 1.4 2009/03/18 16:00:11 cegger Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999
      5  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the PocketBSD project
     18  *	and its contributors.
     19  * 4. Neither the name of the project nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  */
     36 #include <stdio.h>
     37 #include <machine/platid.h>
     38 #define PLATID_DEFINE_MASK_NICKNAME
     39 #include <machine/platid_mask.h>
     40 
     41 platid_bit_test(void)
     42 {
     43 	platid_t pid;
     44 	int err_count = 0;
     45 	int verbose = 0;
     46 
     47 	memset((char*)&pid, 0, sizeof(pid));
     48 	pid.s.cpu_arch = ~0;
     49 	if (pid.dw.dw0 != PLATID_CPU_ARCH_MASK && err_count++ || verbose) {
     50 		platid_hton(&pid);
     51 		platid_dump("cpu_arch", &pid);
     52 		printf("%14s: %08lx00000000\n", "", PLATID_CPU_ARCH_MASK);
     53 	}
     54 
     55 	memset((char*)&pid, 0, sizeof(pid));
     56 	pid.s.cpu_series = ~0;
     57 	if (pid.dw.dw0 != PLATID_CPU_SERIES_MASK && err_count++ || verbose) {
     58 		platid_hton(&pid);
     59 		platid_dump("cpu_series", &pid);
     60 		printf("%14s: %08lx00000000\n", "", PLATID_CPU_SERIES_MASK);
     61 	}
     62 
     63 	memset((char*)&pid, 0, sizeof(pid));
     64 	pid.s.cpu_model = ~0;
     65 	if (pid.dw.dw0 != PLATID_CPU_MODEL_MASK && err_count++ || verbose) {
     66 		platid_hton(&pid);
     67 		platid_dump("cpu_model", &pid);
     68 		printf("%14s: %08lx00000000\n", "", PLATID_CPU_MODEL_MASK);
     69 	}
     70 
     71 	memset((char*)&pid, 0, sizeof(pid));
     72 	pid.s.cpu_submodel = ~0;
     73 	if (pid.dw.dw0 != PLATID_CPU_SUBMODEL_MASK && err_count++ || verbose) {
     74 		platid_hton(&pid);
     75 		platid_dump("cpu_submodel", &pid);
     76 		printf("%14s: %08lx00000000\n", "", PLATID_CPU_SUBMODEL_MASK);
     77 	}
     78 
     79 	memset((char*)&pid, 0, sizeof(pid));
     80 	pid.s.flags = ~0;
     81 	if (pid.dw.dw0 != PLATID_FLAGS_MASK && err_count++ || verbose) {
     82 		platid_hton(&pid);
     83 		platid_dump("flags", &pid);
     84 		printf("%14s: %08lx00000000\n", "", PLATID_FLAGS_MASK);
     85 	}
     86 
     87 	memset((char*)&pid, 0, sizeof(pid));
     88 	pid.s.vendor = ~0;
     89 	if (pid.dw.dw1 != PLATID_VENDOR_MASK && err_count++ || verbose) {
     90 		platid_hton(&pid);
     91 		platid_dump("vendor", &pid);
     92 		printf("%14s: 00000000%08lx\n", "", PLATID_VENDOR_MASK);
     93 	}
     94 
     95 	memset((char*)&pid, 0, sizeof(pid));
     96 	pid.s.series = ~0;
     97 	if (pid.dw.dw1 != PLATID_SERIES_MASK && err_count++ || verbose) {
     98 		platid_hton(&pid);
     99 		platid_dump("series", &pid);
    100 		printf("%14s: 00000000%08lx\n", "", PLATID_SERIES_MASK);
    101 	}
    102 
    103 	memset((char*)&pid, 0, sizeof(pid));
    104 	pid.s.model = ~0;
    105 	if (pid.dw.dw1 != PLATID_MODEL_MASK && err_count++ || verbose) {
    106 		platid_hton(&pid);
    107 		platid_dump("model", &pid);
    108 		printf("%14s: 00000000%08lx\n", "", PLATID_MODEL_MASK);
    109 	}
    110 
    111 	memset((char*)&pid, 0, sizeof(pid));
    112 	pid.s.submodel = ~0;
    113 	if (pid.dw.dw1 != PLATID_SUBMODEL_MASK && err_count++ || verbose) {
    114 		platid_hton(&pid);
    115 		platid_dump("submodel", &pid);
    116 		printf("%14s: 00000000%08lx\n", "", PLATID_SUBMODEL_MASK);
    117 	}
    118 
    119 	if (err_count) {
    120 		printf("error!\n");
    121 	}
    122 }
    123 
    124 void
    125 platid_search_data_test(void)
    126 {
    127 	char *mcr700str = "MC-R700";
    128 	char *mcr500str = "MC-R500";
    129 	char *mcr530str = "MC/R530";
    130 	char *defstr = "default";
    131 
    132 	struct platid_data d_null[] = {
    133 		{ &platid_mask_MACH_NEC_MCR_700A, mcr700str },
    134 		{ &platid_mask_MACH_NEC_MCR_500, mcr500str },
    135 		{ &platid_mask_MACH_NEC_MCR_530, mcr530str },
    136 		{ NULL, NULL }
    137 	};
    138 
    139 	struct platid_data d_default[] = {
    140 		{ &platid_mask_MACH_NEC_MCR_700A, mcr700str },
    141 		{ &platid_mask_MACH_NEC_MCR_500, mcr500str },
    142 		{ &platid_mask_MACH_NEC_MCR_530, mcr530str },
    143 		{ NULL, defstr }
    144 	};
    145 
    146 	printf("#\n");
    147 	printf("# platid_search_data() test\n");
    148 	printf("#\n");
    149 
    150 	printf("search MC-R700 in no default table: %s\n",
    151 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_700A, d_null)->data);
    152 	printf("search MC-R500 in no default table: %s\n",
    153 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_500, d_null)->data);
    154 	printf("search MC/R530 in no default table: %s\n",
    155 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_530, d_null)->data);
    156 	printf("search non exist MC-R300 in no default table: %s\n",
    157 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_300, d_null) == NULL?"NULL":"any!!bug!");
    158 	printf("search MC-R700 in default table: %s\n",
    159 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_700A, d_default)->data);
    160 	printf("search MC-R500 in default table: %s\n",
    161 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_500, d_default)->data);
    162 	printf("search MC/R530 in default table: %s\n",
    163 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_530, d_default)->data);
    164 	printf("search non exist MC-R300 in default table: %s\n",
    165 		(char *)platid_search_data(&platid_mask_MACH_NEC_MCR_300, d_default)->data);
    166 }
    167 
    168 void
    169 platid_search_test(void)
    170 {
    171 	struct platid_name *res;
    172 	struct platid_name tab[] = {
    173 		{ &platid_mask_MACH_NEC_MCR,
    174 		  TEXT("MC-R") },
    175 		{ &platid_mask_MACH_NEC_MCR_3XX,
    176 		  TEXT("MC-R300 series") },
    177 		{ &platid_mask_MACH_NEC_MCR_300,
    178 		  TEXT("MC-R300") },
    179 		{ &platid_mask_MACH_NEC_MCR_330,
    180 		  TEXT("MC-R330") },
    181 	};
    182 	int i, nmemb = sizeof(tab)/sizeof(*tab);
    183 
    184 	printf("#\n");
    185 	printf("# platid_search() test\n");
    186 	printf("#\n");
    187 	printf("# table contains: ");
    188 	for (i = 0; i < nmemb; i++)
    189 		printf(" %s%s", tab[i].name, i < nmemb - 1 ? "," : "");
    190 	printf("\n");
    191 
    192 	res = platid_search(&platid_mask_MACH_NEC_MCR_300,
    193 	    tab, nmemb, sizeof(struct platid_name));
    194 	printf("search MC-R300: %s\n",
    195 	    (res == NULL) ? "not found" : res->name);
    196 
    197 	res = platid_search(&platid_mask_MACH_NEC_MCR,
    198 	    tab, nmemb, sizeof(struct platid_name));
    199 	printf("search MC-R: %s\n",
    200 	    (res == NULL) ? "not found" : res->name);
    201 
    202 	res = platid_search(&platid_mask_MACH_NEC_MCR_700,
    203 	    tab, nmemb, sizeof(struct platid_name));
    204 	printf("search MC-R700: %s\n",
    205 	    (res == NULL) ? "not found" : res->name);
    206 
    207 	res = platid_search(&platid_mask_MACH_NEC_MCR_320,
    208 	    tab, nmemb, sizeof(struct platid_name));
    209 	printf("search MC-R320: %s\n",
    210 	    (res == NULL) ? "not found" : res->name);
    211 
    212 	res = platid_search(&platid_mask_MACH_NEC_MCCS_12,
    213 	    tab, nmemb, sizeof(struct platid_name));
    214 	printf("search MC-CS12: %s\n",
    215 	    (res == NULL) ? "not found" : res->name);
    216 }
    217 
    218 
    219 void
    220 platid_name_test(void)
    221 {
    222 	int i, err;
    223 
    224 	printf("#\n");
    225 	printf("# platid_name() test\n");
    226 	printf("#\n");
    227 	err = 0;
    228 	for (i = 0; i < platid_name_table_size; i++) {
    229 		if (strcmp(platid_name(platid_name_table[i].mask),
    230 		    platid_name_table[i].name) != 0) {
    231 			printf("%s mismatch\n", platid_name_table[i].name);
    232 			err++;
    233 		}
    234 	}
    235 	printf("%s\n", err ? "ERROR" : "ok");
    236 }
    237 
    238 #define __PP(p)	PLATID_DEREFP(p)
    239 
    240 void
    241 main(void)
    242 {
    243 	platid_t pid = platid_unknown;
    244 
    245 	platid_bit_test();
    246 
    247 	pid.dw.dw0 =	PLATID_CPU_MIPS_VR_4111;
    248 	pid.dw.dw1 =	PLATID_MACH_NEC_MCR_500;
    249 
    250 	printf("CPU_MIPS:\t%s\n",
    251 	       platid_match(&pid, __PP(GENERIC_MIPS)) ? "O" : "X");
    252 	printf("CPU_MIPS_VR:\t%s\n",
    253 	       platid_match(&pid, __PP(GENERIC_MIPS_VR)) ? "O" : "X");
    254 	printf("CPU_MIPS_VR41XX:\t%s\n",
    255 	       platid_match(&pid, __PP(GENERIC_MIPS_VR_41XX)) ? "O" : "X");
    256 	printf("CPU_MIPS_VR4102:\t%s\n",
    257 	       platid_match(&pid, __PP(GENERIC_MIPS_VR_4102)) ? "O" : "X");
    258 	printf("CPU_MIPS_VR4111:\t%s\n",
    259 	       platid_match(&pid, __PP(GENERIC_MIPS_VR_4111)) ? "O" : "X");
    260 	printf("CPU_MIPS_VR4121:\t%s\n",
    261 	       platid_match(&pid, __PP(GENERIC_MIPS_VR_4121)) ? "O" : "X");
    262 	printf("NEC_MCR:\t%s\n",
    263 	       platid_match(&pid, __PP(NEC_MCR)) ? "O" : "X");
    264 	printf("NEC_MCR_5XX:\t%s\n",
    265 	       platid_match(&pid, __PP(NEC_MCR_5XX)) ? "O" : "X");
    266 	printf("NEC_MCR_500:\t%s\n",
    267 	       platid_match(&pid, __PP(NEC_MCR_500)) ? "O" : "X");
    268 	printf("NEC_MCR_510:\t%s\n",
    269 	       platid_match(&pid, __PP(NEC_MCR_510)) ? "O" : "X");
    270 
    271 	platid_search_data_test();
    272 	platid_search_test();
    273 	platid_name_test();
    274 	exit(0);
    275 }
    276