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