xref: /titanic_50/usr/src/test/util-tests/tests/libsff/libsff_einval.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  * Test various error cases all of which should return EINVAL.
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 #include "sff.h"
27*59596c01SRobert Mustacchi 
28*59596c01SRobert Mustacchi int
main(void)29*59596c01SRobert Mustacchi main(void)
30*59596c01SRobert Mustacchi {
31*59596c01SRobert Mustacchi 	int ret;
32*59596c01SRobert Mustacchi 	uint8_t buf[256];
33*59596c01SRobert Mustacchi 	nvlist_t *nvl;
34*59596c01SRobert Mustacchi 
35*59596c01SRobert Mustacchi 	bzero(buf, sizeof (buf));
36*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(NULL, sizeof (buf), 0xa0, &nvl)) != EINVAL) {
37*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on NULL buffer");
38*59596c01SRobert Mustacchi 	}
39*59596c01SRobert Mustacchi 
40*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, NULL)) != EINVAL) {
41*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on NULL nvl");
42*59596c01SRobert Mustacchi 	}
43*59596c01SRobert Mustacchi 
44*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa1, &nvl)) != EINVAL) {
45*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad page");
46*59596c01SRobert Mustacchi 	}
47*59596c01SRobert Mustacchi 
48*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0, &nvl)) != EINVAL) {
49*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad page");
50*59596c01SRobert Mustacchi 	}
51*59596c01SRobert Mustacchi 
52*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xff, &nvl)) != EINVAL) {
53*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad page");
54*59596c01SRobert Mustacchi 	}
55*59596c01SRobert Mustacchi 
56*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, 0, 0xa0, &nvl)) != EINVAL) {
57*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
58*59596c01SRobert Mustacchi 		    "size");
59*59596c01SRobert Mustacchi 	}
60*59596c01SRobert Mustacchi 
61*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, 50, 0xa0, &nvl)) != EINVAL) {
62*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
63*59596c01SRobert Mustacchi 		    "size");
64*59596c01SRobert Mustacchi 	}
65*59596c01SRobert Mustacchi 
66*59596c01SRobert Mustacchi 	buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
67*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, 0, 0xa0, &nvl)) != EINVAL) {
68*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
69*59596c01SRobert Mustacchi 		    "size");
70*59596c01SRobert Mustacchi 	}
71*59596c01SRobert Mustacchi 
72*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, 50, 0xa0, &nvl)) != EINVAL) {
73*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
74*59596c01SRobert Mustacchi 		    "size");
75*59596c01SRobert Mustacchi 	}
76*59596c01SRobert Mustacchi 
77*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, 96, 0xa0, &nvl)) != EINVAL) {
78*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad 8635 "
79*59596c01SRobert Mustacchi 		    "size");
80*59596c01SRobert Mustacchi 	}
81*59596c01SRobert Mustacchi 
82*59596c01SRobert Mustacchi 	if ((ret = libsff_parse(buf, 128, 0xa0, &nvl)) != EINVAL) {
83*59596c01SRobert Mustacchi 		errx(1, "TEST FAILED: failed to return EINVAL on bad 8635 "
84*59596c01SRobert Mustacchi 		    "size");
85*59596c01SRobert Mustacchi 	}
86*59596c01SRobert Mustacchi 
87*59596c01SRobert Mustacchi 	return (0);
88*59596c01SRobert Mustacchi }
89