]> pd.if.org Git - liblfds/blob - liblfds/liblfds6.1.0/test/src/main.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds6.1.0 / test / src / main.c
1 #include "internal.h"
2
3
4
5
6
7 /****************************************************************************/
8 int main( int argc, char **argv )
9 {
10   enum lfds610_test_operation
11     operation = UNKNOWN;
12
13   unsigned int
14     loop,
15     iterations = 1;
16
17   assert( argc >= 1 );
18   assert( argv != NULL );
19
20   if( argc == 1 or argc >= 4 )
21     operation = HELP;
22
23   if( operation == UNKNOWN )
24   {
25     if( 0 == strcmp(*(argv+1), "test") )
26     {
27       operation = TEST;
28
29       // TRD : sscanf() may fail, but iterations is initialised to 1, so it's okay
30       if( argc == 3 )
31         sscanf( *(argv+2), "%u", &iterations );
32     }
33
34     if( 0 == strcmp(*(argv+1), "benchmark") )
35     {
36       operation = BENCHMARK;
37
38       // TRD : sscanf() may fail, but iterations is initialised to 1, so it's okay
39       if( argc == 3 )
40         sscanf( *(argv+2), "%u", &iterations );
41     }
42   }
43
44   switch( operation )
45   {
46     case UNKNOWN:
47     case HELP:
48       printf( "test [test|benchmark] [iterations]\n"
49               "  test       : run the test suite\n"
50               "  benchmark  : run the benchmark suite\n"
51               "  iterations : optional, default is 1\n" );
52     break;
53
54     case TEST:
55       for( loop = 1 ; loop < iterations+1 ; loop++ )
56       {
57         printf( "\n"
58                 "Test Iteration %02u\n"
59                 "=================\n", loop );
60
61         test_lfds610_abstraction();
62         test_lfds610_freelist();
63         test_lfds610_queue();
64         test_lfds610_ringbuffer();
65         test_lfds610_slist();
66         test_lfds610_stack();
67       }
68     break;
69
70     case BENCHMARK:
71       for( loop = 1 ; loop < iterations+1 ; loop++ )
72       {
73         printf( "\n"
74                 "Benchmark Iteration %02u\n"
75                 "========================\n", loop );
76
77         benchmark_lfds610_freelist();
78         benchmark_lfds610_queue();
79         benchmark_lfds610_ringbuffer();
80         benchmark_lfds610_stack();
81       }
82     break;
83   }
84
85   return( EXIT_SUCCESS );
86 }
87