xref: /titanic_52/usr/src/test/util-tests/tests/libjedec/libjedec_test.c (revision 174bc6499d233e329ecd3d98a880a7b07df16bfa)
1*174bc649SRobert Mustacchi /*
2*174bc649SRobert Mustacchi  * This file and its contents are supplied under the terms of the
3*174bc649SRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4*174bc649SRobert Mustacchi  * You may only use this file in accordance with the terms of version
5*174bc649SRobert Mustacchi  * 1.0 of the CDDL.
6*174bc649SRobert Mustacchi  *
7*174bc649SRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8*174bc649SRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9*174bc649SRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10*174bc649SRobert Mustacchi  */
11*174bc649SRobert Mustacchi 
12*174bc649SRobert Mustacchi /*
13*174bc649SRobert Mustacchi  * Copyright (c) 2018, Joyent, Inc.
14*174bc649SRobert Mustacchi  */
15*174bc649SRobert Mustacchi 
16*174bc649SRobert Mustacchi /*
17*174bc649SRobert Mustacchi  * Test basic functionality of libjedec.
18*174bc649SRobert Mustacchi  */
19*174bc649SRobert Mustacchi 
20*174bc649SRobert Mustacchi #include <sys/types.h>
21*174bc649SRobert Mustacchi #include <sys/sysmacros.h>
22*174bc649SRobert Mustacchi #include <libjedec.h>
23*174bc649SRobert Mustacchi #include <stdio.h>
24*174bc649SRobert Mustacchi #include <strings.h>
25*174bc649SRobert Mustacchi 
26*174bc649SRobert Mustacchi /*
27*174bc649SRobert Mustacchi  * Table of various values and expected vendors.
28*174bc649SRobert Mustacchi  */
29*174bc649SRobert Mustacchi typedef struct {
30*174bc649SRobert Mustacchi 	uint_t		ljtt_cont;
31*174bc649SRobert Mustacchi 	uint_t		ljtt_vendor;
32*174bc649SRobert Mustacchi 	const char	*ljtt_exp;
33*174bc649SRobert Mustacchi } libjedec_test_t;
34*174bc649SRobert Mustacchi 
35*174bc649SRobert Mustacchi static const libjedec_test_t libjedec_expects[] = {
36*174bc649SRobert Mustacchi 	{ 0x00, 0x01, "AMD" },
37*174bc649SRobert Mustacchi 	{ 0x00, 0x19, "Xicor" },
38*174bc649SRobert Mustacchi 	{ 0x00, 0x89, "Intel" },
39*174bc649SRobert Mustacchi 	{ 0x00, 0xFE, "Numonyx Corporation" },
40*174bc649SRobert Mustacchi 	{ 0x01, 0x15, "Hughes Aircraft" },
41*174bc649SRobert Mustacchi 	{ 0x01, 0xF2, "Yamaha Corporation" },
42*174bc649SRobert Mustacchi 	{ 0x02, 0x9E, "Corsair" },
43*174bc649SRobert Mustacchi 	{ 0x02, 0x3E, "West Bay Semiconductor" },
44*174bc649SRobert Mustacchi 	{ 0x02, 0xF8, "Galaxy Power" },
45*174bc649SRobert Mustacchi 	{ 0x03, 0x26, "BOPS" },
46*174bc649SRobert Mustacchi 	{ 0x03, 0x6B, "NVIDIA" },
47*174bc649SRobert Mustacchi 	{ 0x03, 0x7A, "Astec International" },
48*174bc649SRobert Mustacchi 	{ 0x04, 0x07, "Dotcast" },
49*174bc649SRobert Mustacchi 	{ 0x04, 0x40, "Bandspeed" },
50*174bc649SRobert Mustacchi 	{ 0x04, 0x6D, "Supreme Top Technology Ltd." },
51*174bc649SRobert Mustacchi 	{ 0x05, 0x2A, "Atrua Technologies, Inc." },
52*174bc649SRobert Mustacchi 	{ 0x05, 0x52, "New Japan Radio Co. Ltd." },
53*174bc649SRobert Mustacchi 	{ 0x05, 0xEF, "MetaRAM" },
54*174bc649SRobert Mustacchi 	{ 0x06, 0x0B, "Netxen" },
55*174bc649SRobert Mustacchi 	{ 0x06, 0xF2, "Muscle Power" },
56*174bc649SRobert Mustacchi 	{ 0x07, 0x9E, "Teikon" },
57*174bc649SRobert Mustacchi 	{ 0x07, 0xCE, "Mustang" },
58*174bc649SRobert Mustacchi 	{ 0x08, 0x1F, "Shenzhen City Gcai Electronics" },
59*174bc649SRobert Mustacchi 	{ 0x08, 0xF1, "Asgard" },
60*174bc649SRobert Mustacchi 	{ 0x09, 0x13, "Raspberry Pi Trading Ltd." },
61*174bc649SRobert Mustacchi 	/* Various Failure cases */
62*174bc649SRobert Mustacchi 	{ 0x00, 0x05, NULL },
63*174bc649SRobert Mustacchi 	{ 0x09, 0xFE, NULL },
64*174bc649SRobert Mustacchi 	{ 0x20, 0x01, NULL }
65*174bc649SRobert Mustacchi };
66*174bc649SRobert Mustacchi 
67*174bc649SRobert Mustacchi int
68*174bc649SRobert Mustacchi main(void)
69*174bc649SRobert Mustacchi {
70*174bc649SRobert Mustacchi 	uint_t i, errs = 0;
71*174bc649SRobert Mustacchi 
72*174bc649SRobert Mustacchi 	for (i = 0; i < ARRAY_SIZE(libjedec_expects); i++) {
73*174bc649SRobert Mustacchi 		const char *out;
74*174bc649SRobert Mustacchi 
75*174bc649SRobert Mustacchi 		out = libjedec_vendor_string(libjedec_expects[i].ljtt_cont,
76*174bc649SRobert Mustacchi 		    libjedec_expects[i].ljtt_vendor);
77*174bc649SRobert Mustacchi 		if (out == NULL && libjedec_expects[i].ljtt_exp != NULL) {
78*174bc649SRobert Mustacchi 			errs++;
79*174bc649SRobert Mustacchi 			(void) fprintf(stderr, "test %u failed, expected %s, "
80*174bc649SRobert Mustacchi 			    "but lookup failed\n", i,
81*174bc649SRobert Mustacchi 			    libjedec_expects[i].ljtt_vendor);
82*174bc649SRobert Mustacchi 		} else if (out != NULL && libjedec_expects[i].ljtt_exp ==
83*174bc649SRobert Mustacchi 		    NULL) {
84*174bc649SRobert Mustacchi 			errs++;
85*174bc649SRobert Mustacchi 			(void) fprintf(stderr, "test %u failed, expected "
86*174bc649SRobert Mustacchi 			    "lookup failure, but it succeeded with %s\n", i,
87*174bc649SRobert Mustacchi 			    out);
88*174bc649SRobert Mustacchi 		} else if (strcmp(out, libjedec_expects[i].ljtt_exp) != 0) {
89*174bc649SRobert Mustacchi 			errs++;
90*174bc649SRobert Mustacchi 			(void) fprintf(stderr, "test %u failed, expected %s, "
91*174bc649SRobert Mustacchi 			    "found %s\n", i, libjedec_expects[i].ljtt_exp,
92*174bc649SRobert Mustacchi 			    out);
93*174bc649SRobert Mustacchi 		}
94*174bc649SRobert Mustacchi 	}
95*174bc649SRobert Mustacchi 
96*174bc649SRobert Mustacchi 	return (errs);
97*174bc649SRobert Mustacchi }
98