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