unit: rand helpers

Sponsored-by: TrueNAS
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@truenas.com>
Closes #18630
This commit is contained in:
Rob Norris
2026-06-05 14:21:38 +10:00
committed by Brian Behlendorf
parent 089a54fc19
commit 63fad3403c
2 changed files with 24 additions and 0 deletions
+20
View File
@@ -24,6 +24,7 @@
#include <sys/zfs_debug.h>
#include "munit.h"
#include "unit.h"
/*
* SET_ERROR() expands to __set_error() in debug builds. It's an
@@ -83,3 +84,22 @@ cmn_err(int ce, const char *fmt, ...)
break;
}
}
/* helpers to generate useful random data */
uint64_t
unit_rand_uint64(void)
{
uint64_t v =
(((uint64_t)munit_rand_uint32()) << 32) |
((uint64_t)munit_rand_uint32());
return (v);
}
char *
unit_rand_str(char *buf, size_t bufsz)
{
for (int i = 0; i < bufsz-1; i++)
buf[i] = munit_rand_int_range('a', 'z');
buf[bufsz-1] = '\0';
return (buf);
}
+4
View File
@@ -57,4 +57,8 @@
#define unit_ok(a) munit_assert_int((a), ==, 0)
#define unit_err(a, e) munit_assert_int((a), ==, (e))
/* helpers to generate useful random data */
extern uint64_t unit_rand_uint64(void);
extern char *unit_rand_str(char *buf, size_t bufsz);
#endif /* UNIT_H */