xref: /titanic_50/usr/src/test/util-tests/tests/libsff/libsff_lengths.c (revision 59596c01ca1b980a016d25670874f53e64c27ec0)
1*59596c01SRobert Mustacchi /*
2*59596c01SRobert Mustacchi  * This file and its contents are supplied under the terms of the
3*59596c01SRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4*59596c01SRobert Mustacchi  * You may only use this file in accordance with the terms of version
5*59596c01SRobert Mustacchi  * 1.0 of the CDDL.
6*59596c01SRobert Mustacchi  *
7*59596c01SRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8*59596c01SRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9*59596c01SRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10*59596c01SRobert Mustacchi  */
11*59596c01SRobert Mustacchi 
12*59596c01SRobert Mustacchi /*
13*59596c01SRobert Mustacchi  * Copyright (c) 2017, Joyent, Inc.
14*59596c01SRobert Mustacchi  */
15*59596c01SRobert Mustacchi 
16*59596c01SRobert Mustacchi /*
17*59596c01SRobert Mustacchi  * Print and tests SFF length values.
18*59596c01SRobert Mustacchi  */
19*59596c01SRobert Mustacchi 
20*59596c01SRobert Mustacchi #include <stdio.h>
21*59596c01SRobert Mustacchi #include <errno.h>
22*59596c01SRobert Mustacchi #include <strings.h>
23*59596c01SRobert Mustacchi #include <err.h>
24*59596c01SRobert Mustacchi #include <libsff.h>
25*59596c01SRobert Mustacchi 
26*59596c01SRobert Mustacchi /*
27*59596c01SRobert Mustacchi  * Pick up private sff header file with offsets from lib/libsff.
28*59596c01SRobert Mustacchi  */
29*59596c01SRobert Mustacchi #include "sff.h"
30*59596c01SRobert Mustacchi 
31*59596c01SRobert Mustacchi int
main(void)32*59596c01SRobert Mustacchi main(void)
33*59596c01SRobert Mustacchi {
34*59596c01SRobert Mustacchi 	int ret;
35*59596c01SRobert Mustacchi 	uint8_t buf[256];
36*59596c01SRobert Mustacchi 	nvlist_t *nvl;
37*59596c01SRobert Mustacchi 	char *val;
38*59596c01SRobert Mustacchi 	uint_t i;
39*59596c01SRobert Mustacchi 	const char *lengths_8472[] = { LIBSFF_KEY_LENGTH_SMF_KM,
40*59596c01SRobert Mustacchi 	    LIBSFF_KEY_LENGTH_SMF, LIBSFF_KEY_LENGTH_OM2, LIBSFF_KEY_LENGTH_OM1,
41*59596c01SRobert Mustacchi 	    LIBSFF_KEY_LENGTH_COPPER, LIBSFF_KEY_LENGTH_OM3, NULL };
42*59596c01SRobert Mustacchi 	const char *lengths_8636[] = { LIBSFF_KEY_LENGTH_SMF_KM,
43*59596c01SRobert Mustacchi 	    LIBSFF_KEY_LENGTH_OM2, LIBSFF_KEY_LENGTH_OM1,
44*59596c01SRobert Mustacchi 	    LIBSFF_KEY_LENGTH_COPPER, LIBSFF_KEY_LENGTH_OM3, NULL };
45*59596c01SRobert Mustacchi 
46*59596c01SRobert Mustacchi 	/*
47*59596c01SRobert Mustacchi 	 * Make sure if lengths are zero that they don't show up.
48*59596c01SRobert Mustacchi 	 */
49*59596c01SRobert Mustacchi 	bzero(buf, sizeof (buf));
50*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
51*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to parse SFP length "
52*59596c01SRobert Mustacchi 		    "values: %s\n", strerror(ret));
53*59596c01SRobert Mustacchi 	}
54*59596c01SRobert Mustacchi 
55*59596c01SRobert Mustacchi 	for (i = 0; lengths_8472[i] != NULL; i++) {
56*59596c01SRobert Mustacchi 		if ((ret = nvlist_lookup_string(nvl, lengths_8472[i], &val)) !=
57*59596c01SRobert Mustacchi 		    ENOENT) {
58*59596c01SRobert Mustacchi 			errx(1, "TEST FALIED: found unexpected return value "
59*59596c01SRobert Mustacchi 			    "for key %s: %d\n", lengths_8472[i], ret);
60*59596c01SRobert Mustacchi 		}
61*59596c01SRobert Mustacchi 	}
62*59596c01SRobert Mustacchi 
63*59596c01SRobert Mustacchi 	nvlist_free(nvl);
64*59596c01SRobert Mustacchi 
65*59596c01SRobert Mustacchi 	buf[SFF_8472_LENGTH_SMF_KM] = 0x23;
66*59596c01SRobert Mustacchi 	buf[SFF_8472_LENGTH_SMF] = 0x24;
67*59596c01SRobert Mustacchi 	buf[SFF_8472_LENGTH_50UM] = 0x25;
68*59596c01SRobert Mustacchi 	buf[SFF_8472_LENGTH_62UM] = 0x26;
69*59596c01SRobert Mustacchi 	buf[SFF_8472_LENGTH_COPPER] = 0x27;
70*59596c01SRobert Mustacchi 	buf[SFF_8472_LENGTH_OM3] = 0x28;
71*59596c01SRobert Mustacchi 
72*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
73*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to parse SFP length "
74*59596c01SRobert Mustacchi 		    "values: %s\n", strerror(ret));
75*59596c01SRobert Mustacchi 	}
76*59596c01SRobert Mustacchi 
77*59596c01SRobert Mustacchi 	for (i = 0; lengths_8472[i] != NULL; i++) {
78*59596c01SRobert Mustacchi 		if ((ret = nvlist_lookup_string(nvl, lengths_8472[i], &val)) !=
79*59596c01SRobert Mustacchi 		    0) {
80*59596c01SRobert Mustacchi 			errx(1, "TEST FALIED: failed to find length for key "
81*59596c01SRobert Mustacchi 			    "%s: %d\n", lengths_8472[i], ret);
82*59596c01SRobert Mustacchi 		}
83*59596c01SRobert Mustacchi 		(void) printf("%s: %s\n", lengths_8472[i], val);
84*59596c01SRobert Mustacchi 	}
85*59596c01SRobert Mustacchi 
86*59596c01SRobert Mustacchi 	nvlist_free(nvl);
87*59596c01SRobert Mustacchi 
88*59596c01SRobert Mustacchi 	/*
89*59596c01SRobert Mustacchi 	 * Now for QSFP+
90*59596c01SRobert Mustacchi 	 */
91*59596c01SRobert Mustacchi 	(void) puts("\n\nQSFP\n");
92*59596c01SRobert Mustacchi 	bzero(buf, sizeof (buf));
93*59596c01SRobert Mustacchi 	buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
94*59596c01SRobert Mustacchi 
95*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
96*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to parse QSFP length "
97*59596c01SRobert Mustacchi 		    "values: %s\n", strerror(ret));
98*59596c01SRobert Mustacchi 	}
99*59596c01SRobert Mustacchi 
100*59596c01SRobert Mustacchi 	for (i = 0; lengths_8472[i] != NULL; i++) {
101*59596c01SRobert Mustacchi 		if ((ret = nvlist_lookup_string(nvl, lengths_8472[i], &val)) !=
102*59596c01SRobert Mustacchi 		    ENOENT) {
103*59596c01SRobert Mustacchi 			errx(1, "TEST FALIED: found unexpected return value "
104*59596c01SRobert Mustacchi 			    "for key %s: %d\n", lengths_8472[i], ret);
105*59596c01SRobert Mustacchi 		}
106*59596c01SRobert Mustacchi 	}
107*59596c01SRobert Mustacchi 
108*59596c01SRobert Mustacchi 	nvlist_free(nvl);
109*59596c01SRobert Mustacchi 
110*59596c01SRobert Mustacchi 	buf[SFF_8636_LENGTH_SMF] = 0x23;
111*59596c01SRobert Mustacchi 	buf[SFF_8636_LENGTH_OM3] = 0x24;
112*59596c01SRobert Mustacchi 	buf[SFF_8636_LENGTH_OM2] = 0x25;
113*59596c01SRobert Mustacchi 	buf[SFF_8636_LENGTH_OM1] = 0x26;
114*59596c01SRobert Mustacchi 	buf[SFF_8636_LENGTH_COPPER] = 0x27;
115*59596c01SRobert Mustacchi 
116*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
117*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to parse QSFP length "
118*59596c01SRobert Mustacchi 		    "values: %s\n", strerror(ret));
119*59596c01SRobert Mustacchi 	}
120*59596c01SRobert Mustacchi 
121*59596c01SRobert Mustacchi 	for (i = 0; lengths_8636[i] != NULL; i++) {
122*59596c01SRobert Mustacchi 		if ((ret = nvlist_lookup_string(nvl, lengths_8636[i], &val)) !=
123*59596c01SRobert Mustacchi 		    0) {
124*59596c01SRobert Mustacchi 			errx(1, "TEST FALIED: failed to find length for key "
125*59596c01SRobert Mustacchi 			    "%s: %d\n", lengths_8472[i], ret);
126*59596c01SRobert Mustacchi 		}
127*59596c01SRobert Mustacchi 		(void) printf("%s: %s\n", lengths_8636[i], val);
128*59596c01SRobert Mustacchi 	}
129*59596c01SRobert Mustacchi 
130*59596c01SRobert Mustacchi 	nvlist_free(nvl);
131*59596c01SRobert Mustacchi 
132*59596c01SRobert Mustacchi 	return (0);
133*59596c01SRobert Mustacchi }
134