Path: blob/main/sys/contrib/openzfs/tests/unit/unit.h
289319 views
// SPDX-License-Identifier: CDDL-1.01/*2* This file and its contents are supplied under the terms of the3* Common Development and Distribution License ("CDDL"), version 1.0.4* You may only use this file in accordance with the terms of version5* 1.0 of the CDDL.6*7* A full copy of the text of the CDDL should have accompanied this8* source. A copy of the CDDL is also available via the Internet at9* http://www.illumos.org/license/CDDL.10*/1112/*13* Copyright (c) 2026, TrueNAS.14*/1516#ifndef UNIT_H17#define UNIT_H1819#include "munit.h"2021/* test/suite definition helpers */2223/* single element in a MunitTest array */24#define _UNIT_TEST(name, func, params, ...) \25{ (name), (func), NULL, NULL, MUNIT_TEST_OPTION_NONE, \26(MunitParameterEnum*)(params) }27#define UNIT_TEST(name, func, ...) \28_UNIT_TEST(name, func, ##__VA_ARGS__, NULL)2930/* single element in a MunitParameterEnum array */31#define UNIT_PARAM(name, ...) \32{ (char *)(name), (char **)(const char *[]) { __VA_ARGS__, NULL } }3334/* shortcut for truthy tests */35#define unit_true(a) munit_assert_true(a)36#define unit_false(a) munit_assert_false(a)3738/* shortcut for zero test */39#define unit_zero(a) munit_assert_uint64((a), ==, 0)4041/* shortcuts for integer comparisons */42#define _unit_op(a, op, b) munit_assert_uint64((a), op, (b))4344#define unit_eq(a, b) _unit_op((a), ==, (b))45#define unit_ne(a, b) _unit_op((a), !=, (b))46#define unit_le(a, b) _unit_op((a), <=, (b))47#define unit_ge(a, b) _unit_op((a), >=, (b))48#define unit_lt(a, b) _unit_op((a), <, (b))49#define unit_gt(a, b) _unit_op((a), >, (b))5051/* shortcuts for string comparisons */52#define unit_str_eq(a, b) munit_assert_string_equal(a, b)53#define unit_str_ne(a, b) munit_assert_string_not_equal(a, b)5455/* shortcuts for error-returning function call */56#define unit_ok(a) munit_assert_int((a), ==, 0)57#define unit_err(a, e) munit_assert_int((a), ==, (e))5859/* helpers to generate useful random data */60extern uint64_t unit_rand_uint64(void);61extern char *unit_rand_str(char *buf, size_t bufsz);6263#endif /* UNIT_H */646566