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