Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
sfitests.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __SFI_TESTS_H__
3 #define __SFI_TESTS_H__
4 
5 #include <sfi/sfi.hh>
6 #include <rapicorn-test.hh>
7 
8 static void RAPICORN_UNUSED
9 sfi_init_test (int *argcp, char **argv)
10 {
11  sfi_init (argcp, argv, Bse::cstrings_to_vector ("rapicorn-test-initialization=1", NULL));
12  unsigned int flags = g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
13  g_log_set_always_fatal ((GLogLevelFlags) (flags | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL));
14 }
15 
17 template<class ...Args> void
18 test_error (const char *format, const Args &...args)
19 {
20  Bse::info ("error: %s", Bse::string_format (format, args...));
21  Bse::breakpoint();
22 }
23 
24 #define TICK() TOK()
25 #define TACK() TOK()
26 
41 #define TEST_CALIBRATION(target_ms, CODE) ({ \
42  const uint runs = 7; \
43  const double max_calibration_time = 35.0; \
44  double factor = MAX (1.0, (runs * target_ms * 2) / max_calibration_time); \
45  double ms, scaled_target_ms = target_ms / factor; \
46  GTimer *calibration_timer = false ? g_timer_new() : NULL; \
47  if (calibration_timer) \
48  g_timer_start (calibration_timer); \
49  GTimer *timer = g_timer_new(); \
50  uint dups = 1; \
51  /* birnet_thread_yield(); * on some OSes, this can stabelize the loop benches */ \
52  do \
53  { \
54  uint i, j; \
55  ms = 9e300; \
56  for (i = 0; i < runs && ms >= scaled_target_ms; i++) \
57  { \
58  g_timer_start (timer); \
59  for (j = 0; j < dups; j++) \
60  { \
61  CODE; \
62  } \
63  g_timer_stop (timer); \
64  double current_run_ms = g_timer_elapsed (timer, NULL) * 1000; \
65  ms = MIN (current_run_ms, ms); \
66  } \
67  if (ms < scaled_target_ms) \
68  dups *= 2; \
69  } \
70  while (ms < scaled_target_ms); \
71  factor *= (scaled_target_ms / ms); \
72  g_timer_destroy (timer); \
73  if (calibration_timer) \
74  { \
75  g_timer_stop (calibration_timer); \
76  double calibration_time_ms = g_timer_elapsed (calibration_timer, NULL) * 1000; \
77  g_timer_destroy (calibration_timer); \
78  printerr ("TEST_CALIBRATION: this system can do %d dups in %.6f milliseconds\n", \
79  guint (dups * factor), ms * factor); \
80  printerr ("TEST_CALIBRATION: calibration took %.6f milliseconds\n", \
81  calibration_time_ms); \
82  } \
83  dups = MAX (uint (dups * factor), 1); \
84  dups; \
85 })
86 
87 
88 #endif /* __SFI_TESTS_H__ */
void info(const char *format, const Args &...args)
Issue an informative printf-like message.
Definition: bcore.hh:135
void test_error(const char *format, const Args &...args)
Issue a printf-like message and abort the program with a breakpoint.
Definition: sfitests.hh:18