8699 Want NIC transceiver visibility
[unleashed.git] / usr / src / test / util-tests / tests / libsff / libsff_einval.c
blobac835f95e790f558e9b8b268cbbb144ca1cc4c0b
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.
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.
13 * Copyright (c) 2017, Joyent, Inc.
17 * Test various error cases all of which should return EINVAL.
20 #include <stdio.h>
21 #include <errno.h>
22 #include <strings.h>
23 #include <err.h>
24 #include <libsff.h>
26 #include "sff.h"
28 int
29 main(void)
31 int ret;
32 uint8_t buf[256];
33 nvlist_t *nvl;
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");
40 if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, NULL)) != EINVAL) {
41 errx(1, "TEST FAILED: failed to return EINVAL on NULL nvl");
44 if ((ret = libsff_parse(buf, sizeof (buf), 0xa1, &nvl)) != EINVAL) {
45 errx(1, "TEST FAILED: failed to return EINVAL on bad page");
48 if ((ret = libsff_parse(buf, sizeof (buf), 0, &nvl)) != EINVAL) {
49 errx(1, "TEST FAILED: failed to return EINVAL on bad page");
52 if ((ret = libsff_parse(buf, sizeof (buf), 0xff, &nvl)) != EINVAL) {
53 errx(1, "TEST FAILED: failed to return EINVAL on bad page");
56 if ((ret = libsff_parse(buf, 0, 0xa0, &nvl)) != EINVAL) {
57 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
58 "size");
61 if ((ret = libsff_parse(buf, 50, 0xa0, &nvl)) != EINVAL) {
62 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
63 "size");
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");
72 if ((ret = libsff_parse(buf, 50, 0xa0, &nvl)) != EINVAL) {
73 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 "
74 "size");
77 if ((ret = libsff_parse(buf, 96, 0xa0, &nvl)) != EINVAL) {
78 errx(1, "TEST FAILED: failed to return EINVAL on bad 8635 "
79 "size");
82 if ((ret = libsff_parse(buf, 128, 0xa0, &nvl)) != EINVAL) {
83 errx(1, "TEST FAILED: failed to return EINVAL on bad 8635 "
84 "size");
87 return (0);