ee287b947ab4c5c9768174a7fce058fa3d1425c4
[dpdk.git] / app / test / test.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 #include <string.h>
36 #include <stdio.h>
37 #include <stdint.h>
38 #include <stdarg.h>
39 #include <stdlib.h>
40 #include <errno.h>
41 #include <termios.h>
42 #include <ctype.h>
43 #include <sys/queue.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_socket.h>
48 #include <cmdline.h>
49
50 #include <rte_memory.h>
51 #include <rte_memzone.h>
52 #include <rte_tailq.h>
53 #include <rte_eal.h>
54 #include <rte_timer.h>
55 #include <rte_cycles.h>
56 #include <rte_log.h>
57 #include <rte_string_fns.h>
58
59 #include "test.h"
60
61 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
62
63 const char *prgname; /* to be set to argv[0] */
64
65 #ifndef RTE_EXEC_ENV_BAREMETAL
66 static const char *recursive_call; /* used in linuxapp for MP and other tests */
67
68 static int
69 no_action(void){ return 0; }
70
71 static int
72 do_recursive_call(void)
73 {
74         unsigned i;
75         struct {
76                 const char *env_var;
77                 int (*action_fn)(void);
78         } actions[] =  {
79                         { "run_secondary_instances", test_mp_secondary },
80                         { "test_missing_c_flag", no_action },
81                         { "test_missing_n_flag", no_action },
82                         { "test_no_hpet_flag", no_action },
83                         { "test_invalid_b_flag", no_action },
84                         { "test_invalid_r_flag", no_action },
85                         { "test_misc_flags", no_action },
86                         { "test_memory_flags", no_action },
87                         { "test_file_prefix", no_action },
88                         { "test_no_huge_flag", no_action },
89         };
90
91         if (recursive_call == NULL)
92                 return -1;
93         for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
94                 if (strcmp(actions[i].env_var, recursive_call) == 0)
95                         return (actions[i].action_fn)();
96         }
97         return -1;
98 }
99 #endif
100
101 int
102 main(int argc, char **argv)
103 {
104         struct cmdline *cl;
105         int ret;
106
107         ret = rte_eal_init(argc, argv);
108         if (ret < 0)
109                 return -1;
110
111         rte_timer_subsystem_init();
112
113         argv += ret;
114
115         prgname = argv[0];
116
117 #ifndef RTE_EXEC_ENV_BAREMETAL
118         if ((recursive_call = getenv(RECURSIVE_ENV_VAR)) != NULL)
119                 return do_recursive_call();
120 #endif
121
122 #ifdef RTE_LIBEAL_USE_HPET
123         if (rte_eal_hpet_init(1) < 0)
124 #endif
125                 RTE_LOG(INFO, APP,
126                                 "HPET is not enabled, using TSC as default timer\n");
127
128
129
130         cl = cmdline_stdin_new(main_ctx, "RTE>>");
131         if (cl == NULL) {
132                 return -1;
133         }
134         cmdline_interact(cl);
135         cmdline_stdin_exit(cl);
136
137         return 0;
138 }