aboutsummaryrefslogtreecommitdiff
path: root/tests/sys
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2020-01-29 05:25:20 +0000
committerConrad Meyer <cem@FreeBSD.org>2020-01-29 05:25:20 +0000
commitd71e0db25bd9c66726cbba8e424937aa3a0e87c4 (patch)
tree04662d8bc5dc3b5aea3c9bc30b3fc6fa661acae1 /tests/sys
parent82b5e6440d0a89b081204315d989b93c29e9f216 (diff)
Notes
Diffstat (limited to 'tests/sys')
-rw-r--r--tests/sys/sys/qmath_test.c69
1 files changed, 17 insertions, 52 deletions
diff --git a/tests/sys/sys/qmath_test.c b/tests/sys/sys/qmath_test.c
index 56e726fc80851..1e06f09fc8d65 100644
--- a/tests/sys/sys/qmath_test.c
+++ b/tests/sys/sys/qmath_test.c
@@ -47,25 +47,7 @@
#define QTEST_QITRUNC(q, iv) ((iv) >> Q_RPSHFT(q))
#define QTEST_FFACTOR 32.0
-#define bitsperrand 31
-#define GENRAND(a, lb, ub) \
-({ \
- int _rembits; \
- do { \
- _rembits = Q_BITSPERBASEUP(ub) + Q_LTZ(lb); \
- *(a) = (__typeof(*(a)))0; \
- while (_rembits > 0) { \
- *(a) |= (((uint64_t)random()) & \
- ((1ULL << (_rembits > bitsperrand ? \
- bitsperrand : _rembits)) - 1)); \
- *(a) <<= (_rembits - (_rembits > bitsperrand ? \
- bitsperrand : _rembits)); \
- _rembits -= bitsperrand; \
- } \
- *(a) += lb; \
- } while (*(a) < (lb) || (uint64_t)*(a) > (ub)); \
- *(a); \
-})
+#define GENRAND(a) arc4random_buf((a), sizeof(*(a)))
/*
* Smoke tests for basic qmath operations, such as initialization
@@ -213,11 +195,9 @@ ATF_TC_BODY(qmulq_s64q, tc)
#endif
int error;
- srandomdev();
-
for (int i = 0; i < 10;) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXX: We cheat a bit, to stand any chance of multiplying
@@ -278,12 +258,9 @@ ATF_TC_BODY(qdivq_s64q, tc)
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
atf_tc_skip("https://bugs.freebsd.org/240219");
-
- srandomdev();
-
for (int i = 0; i < 10; i++) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.
@@ -324,11 +301,9 @@ ATF_TC_BODY(qaddq_s64q, tc)
double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl;
int error;
- srandomdev();
-
for (int i = 0; i < 10;) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.
@@ -372,11 +347,9 @@ ATF_TC_BODY(qsubq_s64q, tc)
double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl;
int error;
- srandomdev();
-
for (int i = 0; i < 10; i++) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.
@@ -418,11 +391,9 @@ ATF_TC_BODY(qfraci_s64q, tc)
int64_t a_int, b_int;
int error;
- srandomdev();
-
for (int i = 0; i < 10;) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.
@@ -465,11 +436,9 @@ ATF_TC_BODY(qmuli_s64q, tc)
int64_t a_int, b_int;
int error;
- srandomdev();
-
for (int i = 0; i < 10;) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.
@@ -512,11 +481,9 @@ ATF_TC_BODY(qaddi_s64q, tc)
int64_t a_int, b_int;
int error;
- srandomdev();
-
for (int i = 0; i < 10;) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.
@@ -563,11 +530,9 @@ ATF_TC_BODY(qsubi_s64q, tc)
int64_t a_int, b_int;
int error;
- srandomdev();
-
for (int i = 0; i < 10; i++) {
- GENRAND(&a_s64q, INT64_MIN, UINT64_MAX);
- GENRAND(&b_s64q, INT64_MIN, UINT64_MAX);
+ GENRAND(&a_s64q);
+ GENRAND(&b_s64q);
/*
* XXXLAS: Until Qmath handles precision normalisation, only
* test with equal precision.