1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * http://www.illumos.org/license/CDDL. 11 */ 12 13 /* 14 * Copyright (c) 2026, TrueNAS. 15 */ 16 17 #ifndef _MOCK_DMU_H 18 #define _MOCK_DMU_H 19 20 /* 21 * In-memory mock of the core DMU types for unit testing. 22 * 23 * Provides mock_dnode_t carrying a flat array of fixed-size blocks. 24 */ 25 26 #include <sys/types.h> 27 28 typedef struct mock_dnode mock_dnode_t; 29 typedef struct mock_dmu_tx mock_dmu_tx_t; 30 31 /* Create a mock dnode with the given block size and object type. */ 32 mock_dnode_t *mock_dnode_create(size_t blksize, dmu_object_type_t type); 33 34 /* Free a mock dnode and all its blocks. */ 35 void mock_dnode_destroy(mock_dnode_t *mdn); 36 37 /* Returns the current number of blocks underlying this dnode. */ 38 size_t mock_dnode_block_count(mock_dnode_t *mdn); 39 40 /* Returns a pointer to the data under the given block id. */ 41 const void *mock_dnode_block_data(mock_dnode_t *mdn, uint64_t blkid); 42 43 /* Returns the current dnode ref (hold) count. */ 44 uint64_t mock_dnode_refcount(mock_dnode_t *mdn); 45 46 /* Create/destroy a mock transaction handle. */ 47 mock_dmu_tx_t *mock_tx_create(void); 48 void mock_tx_destroy(mock_dmu_tx_t *tx); 49 50 #endif /* _MOCK_DMU_H */ 51