1- /* $OpenBSD: tests.c,v 1.2 2021/12/14 21:25:27 deraadt Exp $ */
1+ /* $OpenBSD: tests.c,v 1.3 2025/04/15 04:00:42 djm Exp $ */
22/*
33 * Regress test for bitmap.h bitmap API
44 *
2323
2424#include "bitmap.h"
2525
26- #define NTESTS 131
26+ #define DEFAULT_NTESTS 131
2727
2828void
2929tests (void )
@@ -32,10 +32,15 @@ tests(void)
3232 struct bitmap * b ;
3333 BIGNUM * bn ;
3434 size_t len ;
35- int i , j , k , n ;
35+ int i , j , k , n , ntests = DEFAULT_NTESTS ;
3636 u_char bbuf [1024 ], bnbuf [1024 ];
3737 int r ;
3838
39+ if (test_is_fast ())
40+ ntests /= 4 ;
41+ else if (test_is_slow ())
42+ ntests *= 2 ;
43+
3944 TEST_START ("bitmap_new" );
4045 b = bitmap_new ();
4146 ASSERT_PTR_NE (b , NULL );
@@ -44,9 +49,9 @@ tests(void)
4449 TEST_DONE ();
4550
4651 TEST_START ("bitmap_set_bit / bitmap_test_bit" );
47- for (i = -1 ; i < NTESTS ; i ++ ) {
48- for (j = -1 ; j < NTESTS ; j ++ ) {
49- for (k = -1 ; k < NTESTS ; k ++ ) {
52+ for (i = -1 ; i < ntests ; i ++ ) {
53+ for (j = -1 ; j < ntests ; j ++ ) {
54+ for (k = -1 ; k < ntests ; k ++ ) {
5055 bitmap_zero (b );
5156 BN_clear (bn );
5257
@@ -67,7 +72,7 @@ tests(void)
6772
6873 /* Check perfect match between bitmap and bn */
6974 test_subtest_info ("match %d/%d/%d" , i , j , k );
70- for (n = 0 ; n < NTESTS ; n ++ ) {
75+ for (n = 0 ; n < ntests ; n ++ ) {
7176 ASSERT_INT_EQ (BN_is_bit_set (bn , n ),
7277 bitmap_test_bit (b , n ));
7378 }
@@ -99,15 +104,15 @@ tests(void)
99104 bitmap_zero (b );
100105 ASSERT_INT_EQ (bitmap_from_string (b , bnbuf ,
101106 len ), 0 );
102- for (n = 0 ; n < NTESTS ; n ++ ) {
107+ for (n = 0 ; n < ntests ; n ++ ) {
103108 ASSERT_INT_EQ (BN_is_bit_set (bn , n ),
104109 bitmap_test_bit (b , n ));
105110 }
106111
107112 /* Test clearing bits */
108113 test_subtest_info ("clear %d/%d/%d" ,
109114 i , j , k );
110- for (n = 0 ; n < NTESTS ; n ++ ) {
115+ for (n = 0 ; n < ntests ; n ++ ) {
111116 ASSERT_INT_EQ (bitmap_set_bit (b , n ), 0 );
112117 ASSERT_INT_EQ (BN_set_bit (bn , n ), 1 );
113118 }
@@ -123,7 +128,7 @@ tests(void)
123128 bitmap_clear_bit (b , k );
124129 BN_clear_bit (bn , k );
125130 }
126- for (n = 0 ; n < NTESTS ; n ++ ) {
131+ for (n = 0 ; n < ntests ; n ++ ) {
127132 ASSERT_INT_EQ (BN_is_bit_set (bn , n ),
128133 bitmap_test_bit (b , n ));
129134 }
@@ -135,4 +140,9 @@ tests(void)
135140 TEST_DONE ();
136141#endif
137142}
143+ void
144+ benchmarks (void )
145+ {
146+ printf ("no benchmarks\n" );
147+ }
138148
0 commit comments