xref: /titanic_50/usr/src/test/util-tests/tests/libsff/libsff_8472.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 all SFF 8472 Compliance levels
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 	uint_t i;
35*59596c01SRobert Mustacchi 	uint8_t buf[256];
36*59596c01SRobert Mustacchi 
37*59596c01SRobert Mustacchi 	bzero(buf, sizeof (buf));
38*59596c01SRobert Mustacchi 	for (i = 0; i < UINT8_MAX; i++) {
39*59596c01SRobert Mustacchi 		int ret;
40*59596c01SRobert Mustacchi 		nvlist_t *nvl;
41*59596c01SRobert Mustacchi 		char *val;
42*59596c01SRobert Mustacchi 
43*59596c01SRobert Mustacchi 		buf[SFF_8472_SFF_8472_COMPLIANCE] = i;
44*59596c01SRobert Mustacchi 		if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
45*59596c01SRobert Mustacchi 			errx(1, "TEST FAILED: failed to parse SFP 8472 "
46*59596c01SRobert Mustacchi 			    "Compliance value %d: %s\n", i, strerror(ret));
47*59596c01SRobert Mustacchi 		}
48*59596c01SRobert Mustacchi 
49*59596c01SRobert Mustacchi 		if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_COMPLIANCE_8472,
50*59596c01SRobert Mustacchi 		    &val)) != 0) {
51*59596c01SRobert Mustacchi 			errx(1, "TEST FAILED: failed to find key %s with "
52*59596c01SRobert Mustacchi 			    "value %d: %s", LIBSFF_KEY_COMPLIANCE_8472, i,
53*59596c01SRobert Mustacchi 			    strerror(ret));
54*59596c01SRobert Mustacchi 		}
55*59596c01SRobert Mustacchi 
56*59596c01SRobert Mustacchi 		(void) puts(val);
57*59596c01SRobert Mustacchi 		nvlist_free(nvl);
58*59596c01SRobert Mustacchi 	}
59*59596c01SRobert Mustacchi 
60*59596c01SRobert Mustacchi 	return (0);
61*59596c01SRobert Mustacchi }
62