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 2023 Oxide Computer Company 14 * Copyright 2024 Ryan Zezeski 15 */ 16 #include <sys/modctl.h> 17 #include <sys/strsun.h> 18 #include <sys/ktest.h> 19 20 /* 21 * Test the MBLKL macro. 22 */ 23 void 24 mblkl_test(ktest_ctx_hdl_t *ctx) 25 { 26 mblk_t *mp1 = allocb(64, 0); 27 28 KT_EASSERT3P(mp1, !=, NULL, ctx); 29 KT_ASSERT3UG(MBLKL(mp1), ==, 0, ctx, cleanup); 30 mp1->b_wptr += 14; 31 KT_ASSERT3UG(MBLKL(mp1), ==, 14, ctx, cleanup); 32 KT_PASS(ctx); 33 34 cleanup: 35 freeb(mp1); 36 } 37 38 void 39 msgsize_test(ktest_ctx_hdl_t *ctx) 40 { 41 mblk_t *mp1 = allocb(14, 0); 42 mblk_t *mp2 = allocb(20, 0); 43 44 KT_EASSERT3P(mp1, !=, NULL, ctx); 45 KT_EASSERT3PG(mp2, !=, NULL, ctx, cleanup); 46 KT_ASSERT3UG(msgsize(mp1), ==, 0, ctx, cleanup); 47 KT_ASSERT3UG(msgsize(mp2), ==, 0, ctx, cleanup); 48 mp1->b_wptr += 14; 49 mp2->b_wptr += 20; 50 KT_ASSERT3UG(msgsize(mp1), ==, 14, ctx, cleanup); 51 KT_ASSERT3UG(msgsize(mp2), ==, 20, ctx, cleanup); 52 mp1->b_cont = mp2; 53 KT_ASSERT3UG(msgsize(mp1), ==, 34, ctx, cleanup); 54 KT_ASSERT3UG(msgsize(mp2), ==, 20, ctx, cleanup); 55 KT_PASS(ctx); 56 57 cleanup: 58 freeb(mp1); 59 60 if (mp2 != NULL) { 61 freeb(mp2); 62 } 63 } 64 65 static struct modlmisc stream_test_modlmisc = { 66 .misc_modops = &mod_miscops, 67 .misc_linkinfo = "stream ktest module" 68 }; 69 70 static struct modlinkage stream_test_modlinkage = { 71 .ml_rev = MODREV_1, 72 .ml_linkage = { &stream_test_modlmisc, NULL } 73 }; 74 75 int 76 _init() 77 { 78 int ret; 79 ktest_module_hdl_t *km = NULL; 80 ktest_suite_hdl_t *ks = NULL; 81 82 VERIFY0(ktest_create_module("stream", &km)); 83 VERIFY0(ktest_add_suite(km, "mblk", &ks)); 84 VERIFY0(ktest_add_test(ks, "mblkl_test", mblkl_test, KTEST_FLAG_NONE)); 85 VERIFY0(ktest_add_test(ks, "msgsize_test", msgsize_test, 86 KTEST_FLAG_NONE)); 87 88 if ((ret = ktest_register_module(km)) != 0) { 89 ktest_free_module(km); 90 return (ret); 91 } 92 93 if ((ret = mod_install(&stream_test_modlinkage)) != 0) { 94 ktest_unregister_module("stream"); 95 return (ret); 96 } 97 98 return (0); 99 } 100 101 int 102 _fini() 103 { 104 ktest_unregister_module("stream"); 105 return (mod_remove(&stream_test_modlinkage)); 106 } 107 108 int 109 _info(struct modinfo *modinfop) 110 { 111 return (mod_info(&stream_test_modlinkage, modinfop)); 112 } 113