BEAST/BSE - Better Audio System and Sound Engine
0.8.2
|
00001 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __SFI_TESTS_H__ 00003 #define __SFI_TESTS_H__ 00004 00005 #include <sfi/sfi.hh> 00006 #include <rapicorn-test.hh> 00007 00008 static void RAPICORN_UNUSED 00009 sfi_init_test (int *argcp, char **argv) 00010 { 00011 sfi_init (argcp, argv, RAPICORN_PRETTY_FILE, Bse::cstrings_to_vector ("rapicorn-test-initialization=1", NULL)); 00012 unsigned int flags = g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK); 00013 g_log_set_always_fatal ((GLogLevelFlags) (flags | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL)); 00014 } 00015 00016 #define TICK() TOK() 00017 #define TACK() TOK() 00018 00019 #ifndef _ 00020 # define _(x) (x) 00021 # define Q_(x) (x) 00022 # define N_(x) (x) 00023 # define U_(x) (x) 00024 #endif 00025 00040 #define TEST_CALIBRATION(target_ms, CODE) ({ \ 00041 const uint runs = 7; \ 00042 const double max_calibration_time = 35.0; \ 00043 double factor = MAX (1.0, (runs * target_ms * 2) / max_calibration_time); \ 00044 double ms, scaled_target_ms = target_ms / factor; \ 00045 GTimer *calibration_timer = false ? g_timer_new() : NULL; \ 00046 if (calibration_timer) \ 00047 g_timer_start (calibration_timer); \ 00048 GTimer *timer = g_timer_new(); \ 00049 guint dups = 1; \ 00050 /* birnet_thread_yield(); * on some OSes, this can stabelize the loop benches */ \ 00051 do \ 00052 { \ 00053 uint i, j; \ 00054 ms = 9e300; \ 00055 for (i = 0; i < runs && ms >= scaled_target_ms; i++) \ 00056 { \ 00057 g_timer_start (timer); \ 00058 for (j = 0; j < dups; j++) \ 00059 { \ 00060 CODE; \ 00061 } \ 00062 g_timer_stop (timer); \ 00063 double current_run_ms = g_timer_elapsed (timer, NULL) * 1000; \ 00064 ms = MIN (current_run_ms, ms); \ 00065 } \ 00066 if (ms < scaled_target_ms) \ 00067 dups *= 2; \ 00068 } \ 00069 while (ms < scaled_target_ms); \ 00070 factor *= (scaled_target_ms / ms); \ 00071 g_timer_destroy (timer); \ 00072 if (calibration_timer) \ 00073 { \ 00074 g_timer_stop (calibration_timer); \ 00075 double calibration_time_ms = g_timer_elapsed (calibration_timer, NULL) * 1000; \ 00076 g_timer_destroy (calibration_timer); \ 00077 g_printerr ("TEST_CALIBRATION: this system can do %d dups in %.6f milliseconds\n",\ 00078 (guint) (dups * factor), ms * factor); \ 00079 g_printerr ("TEST_CALIBRATION: calibration took %.6f milliseconds\n", \ 00080 calibration_time_ms); \ 00081 } \ 00082 dups = MAX ((uint) (dups * factor), 1); \ 00083 dups; \ 00084 }) 00085 00086 00087 #endif /* __SFI_TESTS_H__ */