2626 * variable time.
2727 */
2828
29- #include "fixture.h"
3029#include <assert.h>
3130#include <math.h>
3231#include <stdint.h>
3332#include <stdio.h>
3433#include <stdlib.h>
3534#include <string.h>
35+
3636#include "../console.h"
3737#include "../random.h"
38+
3839#include "constant.h"
40+ #include "fixture.h"
3941#include "ttest.h"
4042
41- #define enough_measure 10000
42- #define test_tries 10
43+ #define ENOUGH_MEASURE 10000
44+ #define TEST_TRIES 10
4345
44- extern const int drop_size ;
45- extern const size_t chunk_size ;
46- extern const size_t n_measure ;
4746static t_context_t * t ;
4847
4948/* threshold values for Welch's t-test */
@@ -61,13 +60,13 @@ static void differentiate(int64_t *exec_times,
6160 const int64_t * before_ticks ,
6261 const int64_t * after_ticks )
6362{
64- for (size_t i = 0 ; i < n_measure ; i ++ )
63+ for (size_t i = 0 ; i < N_MEASURES ; i ++ )
6564 exec_times [i ] = after_ticks [i ] - before_ticks [i ];
6665}
6766
6867static void update_statistics (const int64_t * exec_times , uint8_t * classes )
6968{
70- for (size_t i = 0 ; i < n_measure ; i ++ ) {
69+ for (size_t i = 0 ; i < N_MEASURES ; i ++ ) {
7170 int64_t difference = exec_times [i ];
7271 /* CPU cycle counter overflowed or dropped measurement */
7372 if (difference <= 0 )
@@ -86,9 +85,9 @@ static bool report(void)
8685
8786 printf ("\033[A\033[2K" );
8887 printf ("meas: %7.2lf M, " , (number_traces_max_t / 1e6 ));
89- if (number_traces_max_t < enough_measure ) {
88+ if (number_traces_max_t < ENOUGH_MEASURE ) {
9089 printf ("not enough measurements (%.0f still to go).\n" ,
91- enough_measure - number_traces_max_t );
90+ ENOUGH_MEASURE - number_traces_max_t );
9291 return false;
9392 }
9493
@@ -119,11 +118,11 @@ static bool report(void)
119118
120119static bool doit (int mode )
121120{
122- int64_t * before_ticks = calloc (n_measure + 1 , sizeof (int64_t ));
123- int64_t * after_ticks = calloc (n_measure + 1 , sizeof (int64_t ));
124- int64_t * exec_times = calloc (n_measure , sizeof (int64_t ));
125- uint8_t * classes = calloc (n_measure , sizeof (uint8_t ));
126- uint8_t * input_data = calloc (n_measure * chunk_size , sizeof (uint8_t ));
121+ int64_t * before_ticks = calloc (N_MEASURES + 1 , sizeof (int64_t ));
122+ int64_t * after_ticks = calloc (N_MEASURES + 1 , sizeof (int64_t ));
123+ int64_t * exec_times = calloc (N_MEASURES , sizeof (int64_t ));
124+ uint8_t * classes = calloc (N_MEASURES , sizeof (uint8_t ));
125+ uint8_t * input_data = calloc (N_MEASURES * CHUNK_SIZE , sizeof (uint8_t ));
127126
128127 if (!before_ticks || !after_ticks || !exec_times || !classes ||
129128 !input_data ) {
@@ -152,19 +151,19 @@ static void init_once(void)
152151 t_init (t );
153152}
154153
155- static bool TEST_CONST (char * text , int mode )
154+ static bool test_const (char * text , int mode )
156155{
157156 bool result = false;
158157 t = malloc (sizeof (t_context_t ));
159158
160- for (int cnt = 0 ; cnt < test_tries ; ++ cnt ) {
161- printf ("Testing %s...(%d/%d)\n\n" , text , cnt , test_tries );
159+ for (int cnt = 0 ; cnt < TEST_TRIES ; ++ cnt ) {
160+ printf ("Testing %s...(%d/%d)\n\n" , text , cnt , TEST_TRIES );
162161 init_once ();
163- for (int i = 0 ; i < enough_measure / (n_measure - drop_size * 2 ) + 1 ;
162+ for (int i = 0 ; i < ENOUGH_MEASURE / (N_MEASURES - DROP_SIZE * 2 ) + 1 ;
164163 ++ i )
165164 result = doit (mode );
166165 printf ("\033[A\033[2K\033[A\033[2K" );
167- if (result == true )
166+ if (result )
168167 break ;
169168 }
170169 free (t );
@@ -173,20 +172,20 @@ static bool TEST_CONST(char *text, int mode)
173172
174173bool is_insert_head_const (void )
175174{
176- return TEST_CONST ("insert_head" , 0 );
175+ return test_const ("insert_head" , 0 );
177176}
178177
179178bool is_insert_tail_const (void )
180179{
181- return TEST_CONST ("insert_tail" , 1 );
180+ return test_const ("insert_tail" , 1 );
182181}
183182
184183bool is_remove_head_const (void )
185184{
186- return TEST_CONST ("remove_head" , 2 );
185+ return test_const ("remove_head" , 2 );
187186}
188187
189188bool is_remove_tail_const (void )
190189{
191- return TEST_CONST ("remove_tail" , 3 );
190+ return test_const ("remove_tail" , 3 );
192191}
0 commit comments