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
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 our ability to parse SFF string values which are space encoded. As this
18 * is shared between the SFP and QSFP logic, we end up only testing the SFP
29 * Pick up private sff header file with offsets from lib/libsff. Strings are
30 * described as having spaces at the end of them. We mostly want to make sure
31 * that if we have strings without spaces that we parse them sanely as well as
32 * test what happens with embedded spaces and NUL characters.
37 uint8_t lss_bytes
[16];
38 const char *lss_parsed
;
41 static const lsfs_string_pair_t lsfs_bad_vals
[] = {
43 { { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
44 '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' },
47 { { 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
48 '\0', 'a', 'a', 'a', 'a', 'a', 'a', 'a' },
51 { { 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
52 156, 'a', 'a', 'a', 'a', 'a', 'a', 'a' },
55 { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
56 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
59 #define NBAD (sizeof (lsfs_bad_vals) / sizeof (lsfs_string_pair_t))
61 static const lsfs_string_pair_t lsfs_good_vals
[] = {
63 { { 'f', 'i', 'n', 'g', 'o', 'l', 'f', 'i',
64 'n', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
66 /* Non-padding Space */
67 { { 'G', 'l', 'o', 'b', 'e', 'x', ' ', 'C',
68 'o', 'r', 'p', ' ', ' ', ' ', ' ', ' ' },
70 /* 1-character name to catch off by one */
71 { { '~', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
72 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
74 /* Use all characters */
75 { { '!', '!', '!', '!', '!', '!', '!', '!',
76 '!', '!', '!', '!', '!', '!', '!', '!' },
79 #define NGOOD (sizeof (lsfs_good_vals) / sizeof (lsfs_string_pair_t))
89 for (i
= 0; i
< NBAD
; i
++) {
90 bzero(buf
, sizeof (buf
));
91 bcopy(lsfs_bad_vals
[i
].lss_bytes
, &buf
[SFF_8472_VENDOR
],
95 if ((ret
= libsff_parse(buf
, sizeof (buf
), 0xa0, &nvl
)) != 0) {
96 errx(1, "TEST FAILED: failed to parse SFP bad string "
97 "case %d: %s\n", i
, strerror(ret
));
100 if ((ret
= nvlist_lookup_string(nvl
, LIBSFF_KEY_VENDOR
,
102 errx(1, "TEST FALIED: found unexpected return value "
103 "for %s: %d\n", LIBSFF_KEY_VENDOR
, ret
);
108 for (i
= 0; i
< NGOOD
; i
++) {
109 bzero(buf
, sizeof (buf
));
110 bcopy(lsfs_good_vals
[i
].lss_bytes
, &buf
[SFF_8472_VENDOR
],
111 SFF_8472_VENDOR_LEN
);
113 if ((ret
= libsff_parse(buf
, sizeof (buf
), 0xa0, &nvl
)) != 0) {
114 errx(1, "TEST FAILED: failed to parse SFP good string "
115 "case %d: %s\n", i
, strerror(ret
));
118 if ((ret
= nvlist_lookup_string(nvl
, LIBSFF_KEY_VENDOR
,
120 errx(1, "TEST FALIED: failed to find expected key "
121 "%s: %d", LIBSFF_KEY_VENDOR
, ret
);
124 if (strcmp(val
, lsfs_good_vals
[i
].lss_parsed
) != 0) {
125 errx(1, "TEST FAILED: expected string %s, found %s\n",
126 lsfs_good_vals
[i
].lss_parsed
, val
);