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 2024 Oxide Computer Company
14 */
15
16 /*
17 * Verify the basics of the common NVMe version interfaces.
18 */
19
20 #include <err.h>
21 #include <stdbool.h>
22 #include <stddef.h>
23 #include <sys/sysmacros.h>
24 #include <stdlib.h>
25
26 #include <nvme_common.h>
27
28 int vers_exit = EXIT_SUCCESS;
29
30 /*
31 * Each tests asks is the version nvt_dev >= nvt_targ.
32 */
33 typedef struct nvme_version_test {
34 const nvme_version_t *nvt_dev;
35 const nvme_version_t *nvt_targ;
36 bool nvt_pass;
37 const char *nvt_desc;
38 } nvme_version_test_t;
39
40 static const nvme_version_test_t vers_tests[] = {
41 { &nvme_vers_1v0, &nvme_vers_1v0, true, "same version (1.0)" },
42 { &nvme_vers_1v1, &nvme_vers_1v1, true, "same version (1.1)" },
43 { &nvme_vers_1v2, &nvme_vers_1v2, true, "same version (1.2)" },
44 { &nvme_vers_1v3, &nvme_vers_1v3, true, "same version (1.3)" },
45 { &nvme_vers_1v4, &nvme_vers_1v4, true, "same version (1.4)" },
46 { &nvme_vers_2v0, &nvme_vers_2v0, true, "same version (2.0)" },
47 { &nvme_vers_2v0, &nvme_vers_1v0, true, "greater major, same minor" },
48 { &nvme_vers_2v0, &nvme_vers_1v1, true, "greater major, lesser minor" },
49 { &nvme_vers_2v0, &nvme_vers_1v3, true, "greater major, lesser minor" },
50 { &nvme_vers_1v2, &nvme_vers_1v0, true, "same major, greater minor "
51 "(1)" },
52 { &nvme_vers_1v2, &nvme_vers_1v1, true, "same major, greater minor "
53 "(2)" },
54 { &nvme_vers_1v4, &nvme_vers_1v0, true, "same major, greater minor "
55 "(3)" },
56 { &nvme_vers_1v4, &nvme_vers_1v2, true, "same major, greater minor "
57 "(4)" },
58 { &nvme_vers_1v0, &nvme_vers_1v4, false, "same major, lesser minor "
59 "(1)" },
60 { &nvme_vers_1v1, &nvme_vers_1v4, false, "same major, lesser minor "
61 "(2)" },
62 { &nvme_vers_1v3, &nvme_vers_1v4, false, "same major, lesser minor "
63 "(3)" },
64 { &nvme_vers_1v4, &nvme_vers_2v0, false, "lesser major, greater minor "
65 "(1)" },
66 { &nvme_vers_1v3, &nvme_vers_2v0, false, "lesser major, greater minor "
67 "(2)" },
68 { &nvme_vers_1v2, &nvme_vers_2v0, false, "lesser major, greater minor "
69 "(3)" },
70 { &nvme_vers_1v1, &nvme_vers_2v0, false, "lesser major, greater minor "
71 "(4)" },
72 { &nvme_vers_1v0, &nvme_vers_2v0, false, "lesser major, same minor" },
73 };
74
75 static bool
vers_test_one(const nvme_version_test_t * test)76 vers_test_one(const nvme_version_test_t *test)
77 {
78 bool res = nvme_vers_atleast(test->nvt_dev, test->nvt_targ);
79 if (res != test->nvt_pass) {
80 const char *rstr = res ? "passed" : "failed";
81
82 warnx("TEST FAILED: %s (%u.%u >= %u.%u) erroneously %s",
83 test->nvt_desc, test->nvt_dev->v_major,
84 test->nvt_dev->v_minor, test->nvt_targ->v_major,
85 test->nvt_targ->v_minor, rstr);
86 return (false);
87 } else {
88 (void) printf("TEST PASSED: %s\n", test->nvt_desc);
89 return (true);
90 }
91 }
92
93 int
main(void)94 main(void)
95 {
96 int ret = EXIT_SUCCESS;
97
98 for (size_t i = 0; i < ARRAY_SIZE(vers_tests); i++) {
99 if (!vers_test_one(&vers_tests[i])) {
100 ret = EXIT_FAILURE;
101 }
102 }
103
104 if (ret == EXIT_SUCCESS) {
105 (void) printf("All tests passed successfully!\n");
106 }
107
108 return (ret);
109 }
110