Unit tests included.
LTP tests pass. Here is an LTP emulation layer sufficient to run these tests on FreeBSD:
```
$ cat lapi/getrandom.h
#include <sys/random.h>
$ cat lapi/syscalls.h
#include <sys/syscall.h>
$ cat tst_test.h
#include <sys/param.h>
#include <err.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static long TEST_RETURN;
static int TEST_ERRNO;
static inline void
TEST(long a)
{
TEST_RETURN = a;
TEST_ERRNO = errno;
}
#define tst_syscall syscall
#define __NR_getrandom SYS_getrandom
#define TPASS 1
#define TFAIL 0
#define TPASSMASK 1
#define TTERRNO 2
static size_t tot_pass, tot_fail;
static inline void
tst_res(int flags, const char *fmt, ...)
{
va_list ap;
if ((flags & TPASSMASK) == TPASS) {
printf("PASS ");
tot_pass++;
} else {
printf("FAIL ");
tot_fail++;
}
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
if (flags & TTERRNO)
printf(": %d (%s)", errno, strerror(errno));
puts("\n");
}
#define ARRAY_SIZE nitems
static inline void
SAFE_GETRLIMIT(int res, struct rlimit *out)
{
int ret;
ret = getrlimit(res, out);
if (ret != 0)
err(1, "getrlimit");
}
static inline void
SAFE_SETRLIMIT(int res, const struct rlimit *in)
{
int ret;
ret = setrlimit(res, in);
if (ret != 0)
err(1, "setrlimit");
}
struct tst_test {
size_t tcnt;
void (*test)(unsigned);
void (*test_all)(void);
};
static struct tst_test test;
int
main(int argc __unused, char **argv __unused)
{
size_t i;
for (i = 0; i < test.tcnt; i++)
test.test(i);
if (test.test_all != NULL)
test.test_all();
printf("Pass: %zu/%zu\n", tot_pass, tot_pass + tot_fail);
return (tot_fail != 0);
}
```
Under this emulation, all LTP `getrandom(2)` tests pass.