]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.0.0/test/src/main.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.0.0 / test / src / main.c
1 /***** includes *****/
2 #include "internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 int main( int argc, char **argv )
10 {
11   enum flag
12     run_flag = LOWERED,
13     show_error_flag = LOWERED,
14     show_help_flag = LOWERED,
15     show_version_flag = LOWERED;
16
17   int
18     rv;
19
20   lfds700_pal_uint_t
21     loop,
22     iterations = 1,
23     memory_in_megabytes = DEFAULT_TEST_MEMORY_IN_MEGABYTES;
24
25   struct lfds700_list_asu_state
26     list_of_logical_processors;
27
28   struct util_cmdline_state
29     cs;
30
31   union util_cmdline_arg_data
32     *arg_data;
33
34   assert( argc >= 1 );
35   assert( argv != NULL );
36
37   lfds700_misc_library_init_valid_on_current_logical_core();
38
39   util_cmdline_init( &cs );
40
41   util_cmdline_add_arg( &cs, 'h', LIBCOMMON_CMDLINE_ARG_TYPE_FLAG );
42   util_cmdline_add_arg( &cs, 'i', LIBCOMMON_CMDLINE_ARG_TYPE_INTEGER );
43   util_cmdline_add_arg( &cs, 'm', LIBCOMMON_CMDLINE_ARG_TYPE_INTEGER );
44   util_cmdline_add_arg( &cs, 'r', LIBCOMMON_CMDLINE_ARG_TYPE_FLAG );
45   util_cmdline_add_arg( &cs, 'v', LIBCOMMON_CMDLINE_ARG_TYPE_FLAG );
46
47   rv = util_cmdline_process_args( &cs, argc, argv );
48
49   if( rv == 0 )
50     show_error_flag = RAISED;
51
52   if( rv == 1 )
53   {
54     util_cmdline_get_arg_data( &cs, 'h', &arg_data );
55     if( arg_data != NULL )
56       show_help_flag = RAISED;
57
58     util_cmdline_get_arg_data( &cs, 'i', &arg_data );
59     if( arg_data != NULL )
60       iterations = (lfds700_pal_uint_t) arg_data->integer.integer;
61
62     util_cmdline_get_arg_data( &cs, 'm', &arg_data );
63     if( arg_data != NULL )
64       memory_in_megabytes = (lfds700_pal_uint_t) arg_data->integer.integer;
65
66     util_cmdline_get_arg_data( &cs, 'r', &arg_data );
67     if( arg_data != NULL )
68       run_flag = RAISED;
69
70     util_cmdline_get_arg_data( &cs, 'v', &arg_data );
71     if( arg_data != NULL )
72       show_version_flag = RAISED;
73   }
74
75   util_cmdline_cleanup( &cs );
76
77   if( argc == 1 or (run_flag == LOWERED and show_version_flag == LOWERED) )
78     show_help_flag = RAISED;
79
80   if( show_error_flag == RAISED )
81   {
82     printf( "\nInvalid arguments.  Sorry - it's a simple parser, so no clues.\n"
83             "-h or run with no args to see the help text.\n" );
84
85     return( EXIT_SUCCESS );
86   }
87
88   if( show_help_flag == RAISED )
89   {
90     printf( "test -h -i [n] -m [n] -r -v\n"
91             "  -h     : help\n"
92             "  -i [n] : number of iterations     (default : 1)\n"
93             "  -m [n] : memory for tests, in mb  (default : %u)\n"
94             "  -r     : run (causes test to run; present so no args gives help)\n"
95             "  -v     : version\n", DEFAULT_TEST_MEMORY_IN_MEGABYTES );
96
97     return( EXIT_SUCCESS );
98   }
99
100   if( show_version_flag == RAISED )
101   {
102     internal_show_version();
103     return( EXIT_SUCCESS );
104   }
105
106   if( run_flag == RAISED )
107   {
108     test_pal_get_logical_core_ids( &list_of_logical_processors );
109
110     for( loop = 0 ; loop < (lfds700_pal_uint_t) iterations ; loop++ )
111     {
112       printf( "\n"
113               "Test Iteration %02llu\n"
114               "=================\n", (int long long unsigned) (loop+1) );
115
116       test_lfds700_pal_atomic( &list_of_logical_processors, memory_in_megabytes );
117       test_lfds700_btree_au( &list_of_logical_processors, memory_in_megabytes );
118       test_lfds700_freelist( &list_of_logical_processors, memory_in_megabytes );
119       test_lfds700_hash_a( &list_of_logical_processors, memory_in_megabytes );
120       test_lfds700_list_aos( &list_of_logical_processors, memory_in_megabytes );
121       test_lfds700_list_asu( &list_of_logical_processors, memory_in_megabytes );
122       test_lfds700_queue( &list_of_logical_processors, memory_in_megabytes );
123       test_lfds700_queue_bss( &list_of_logical_processors );
124       test_lfds700_ringbuffer( &list_of_logical_processors, memory_in_megabytes );
125       test_lfds700_stack( &list_of_logical_processors, memory_in_megabytes );
126     }
127
128     lfds700_list_asu_cleanup( &list_of_logical_processors, internal_logical_core_id_element_cleanup_callback );
129   }
130
131   lfds700_misc_library_cleanup();
132
133   return( EXIT_SUCCESS );
134 }
135