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