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 uint8_t buf[256]; 32 nvlist_t *nvl; 33 int ret; 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 "(%s instead)", strerror(ret)); 43 } 44 45 if ((ret = libsff_parse(buf, sizeof (buf), 0xa1, &nvl)) != EINVAL) { 46 errx(1, "TEST FAILED: failed to return EINVAL on bad page " 47 "(%s instead)", strerror(ret)); 48 } 49 50 if ((ret = libsff_parse(buf, sizeof (buf), 0, &nvl)) != EINVAL) { 51 errx(1, "TEST FAILED: failed to return EINVAL on bad page " 52 "(%s instead)", strerror(ret)); 53 } 54 55 if ((ret = libsff_parse(buf, sizeof (buf), 0xff, &nvl)) != EINVAL) { 56 errx(1, "TEST FAILED: failed to return EINVAL on bad page " 57 "(%s instead)", strerror(ret)); 58 } 59 60 if ((ret = libsff_parse(buf, 0, 0xa0, &nvl)) != EINVAL) { 61 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 " 62 "size (%s instead)", strerror(ret)); 63 } 64 65 if ((ret = libsff_parse(buf, 50, 0xa0, &nvl)) != EINVAL) { 66 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 " 67 "size (%s instead)", strerror(ret)); 68 } 69 70 buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP; 71 if ((ret = libsff_parse(buf, 0, 0xa0, &nvl)) != EINVAL) { 72 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 " 73 "size (%s instead)", strerror(ret)); 74 } 75 76 if ((ret = libsff_parse(buf, 50, 0xa0, &nvl)) != EINVAL) { 77 errx(1, "TEST FAILED: failed to return EINVAL on bad 8476 " 78 "size (%s instead)", strerror(ret)); 79 } 80 81 if ((ret = libsff_parse(buf, 96, 0xa0, &nvl)) != EINVAL) { 82 errx(1, "TEST FAILED: failed to return EINVAL on bad 8635 " 83 "size (%s instead)", strerror(ret)); 84 } 85 86 if ((ret = libsff_parse(buf, 128, 0xa0, &nvl)) != EINVAL) { 87 errx(1, "TEST FAILED: failed to return EINVAL on bad 8635 " 88 "size (%s instead)", strerror(ret)); 89 } 90 91 return (0); 92 } 93