The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
time_tests.c
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /** Tests for a generic string buffer structure for string printing and parsing
18  *
19  * @file src/lib/util/time_tests.c
20  *
21  * @copyright 2022 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
22  */
23 #include <freeradius-devel/util/acutest.h>
24 #include <freeradius-devel/util/acutest_helpers.h>
25 #include <freeradius-devel/util/time.h>
26 
27 #define ROUNDS (100000)
28 
29 DIAG_OFF(unused-but-set-variable)
30 static void time_benchmark(void)
31 {
32  int i;
33  fr_time_t start, stop;
34  uint64_t rate;
35 
36  start = fr_time();
37  for (i = 0; i < ROUNDS; i++) {
38  volatile fr_time_t now;
39 
40  now = fr_time();
41  }
42  stop = fr_time();
43 
44  rate = (uint64_t)((float)NSEC / (fr_time_delta_unwrap(fr_time_sub(stop, start)) / ROUNDS));
45  printf("fr_time rate %" PRIu64 "\n", rate);
46 
47  /* shared runners are terrible for performance tests */
48  if (!getenv("NO_PERFORMANCE_TESTS")) TEST_CHECK(rate > (ROUNDS * 10));
49 }
50 DIAG_ON(unused-but-set-variable)
51 
53  { "time_const_benchmark", time_benchmark },
54 
55  { 0 }
56 };
#define TEST_CHECK(cond)
Definition: acutest.h:85
static bool stop
Definition: radmin.c:70
#define DIAG_ON(_x)
Definition: build.h:456
#define DIAG_OFF(_x)
Definition: build.h:455
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition: state_test.c:8
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition: time.h:154
#define NSEC
Definition: time.h:379
#define fr_time_sub(_a, _b)
Subtract one time from another.
Definition: time.h:229
"server local" time.
Definition: time.h:69
TEST_LIST
Definition: time_tests.c:52
#define ROUNDS
Definition: time_tests.c:27
static void time_benchmark(void)
Definition: time_tests.c:30