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 2025 Oxide Computer Company 14 */ 15 16 /* 17 * Misc. test utilities. 18 */ 19 20 #include <stdarg.h> 21 22 #include "libi2c_test_util.h" 23 24 /* 25 * For any test linked against libumem, ensure that umem debugging is enabled by 26 * default. Many tests use umem_setmtbf() and we need to make sure there is no 27 * per-thread cache. 28 */ 29 const char * 30 _umem_debug_init(void) 31 { 32 return ("default,verbose"); 33 } 34 35 const char * 36 _umem_logging_init(void) 37 { 38 return ("fail,contents"); 39 } 40 41 static void 42 libi2c_test_vwarn(i2c_hdl_t *hdl, const char *fmt, va_list ap) 43 { 44 (void) fprintf(stderr, "TEST FAILED: "); 45 (void) vfprintf(stderr, fmt, ap); 46 (void) fprintf(stderr, ": %s: %s (libi2c: 0x%x, sys: %d)\n", 47 i2c_errmsg(hdl), i2c_errtostr(hdl, i2c_err(hdl)), 48 i2c_err(hdl), i2c_syserr(hdl)); 49 } 50 51 void 52 libi2c_test_warn(i2c_hdl_t *hdl, const char *fmt, ...) 53 { 54 va_list ap; 55 56 va_start(ap, fmt); 57 libi2c_test_vwarn(hdl, fmt, ap); 58 va_end(ap); 59 } 60 61 void 62 libi2c_test_fatal(i2c_hdl_t *hdl, const char *fmt, ...) 63 { 64 va_list ap; 65 66 va_start(ap, fmt); 67 libi2c_test_vwarn(hdl, fmt, ap); 68 va_end(ap); 69 exit(EXIT_FAILURE); 70 } 71