2 * Copyright (c) 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* The mother of all test programs that links with libopevswitch.la */
23 #include "command-line.h"
27 static struct command *commands = NULL;
28 static size_t n_commands = 0;
29 static size_t allocated_commands = 0;
32 add_command(struct command *cmd)
34 const struct command nil = {NULL, 0, 0, NULL};
36 while (n_commands + 1 >= allocated_commands) {
37 commands = x2nrealloc(commands, &allocated_commands,
41 commands[n_commands] = *cmd;
42 commands[n_commands + 1] = nil;
47 list(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
49 const struct command *p;
51 for(p = commands; p->name != NULL; p++) {
52 printf("%s, %d, %d\n", p->name,p->min_args, p->max_args);
57 add_top_level_commands(void)
59 struct command help_cmd = {"--help", 0, 0, list};
61 add_command(&help_cmd);
65 ovstest_register(const char *test_name, ovstest_func f,
66 const struct command *sub_commands)
68 struct command test_cmd;
72 const struct command *p;
74 for(p = sub_commands; p->name != NULL; p++) {
75 if (p->max_args > max_args) {
76 max_args = p->max_args;
80 max_args++; /* adding in the sub program */
82 test_cmd.name = test_name;
83 test_cmd.min_args = 1;
84 test_cmd.max_args = max_args;
87 add_command(&test_cmd);
93 if (allocated_commands) {
99 main(int argc, char *argv[])
101 set_program_name(argv[0]);
103 add_top_level_commands();
105 run_command(argc - 1, argv + 1, commands);