]> git.proxmox.com Git - mirror_ovs.git/blame - tests/ovstest.c
ofproto-dpif-xlate: Wildcard skb_priority if QoS is disabled
[mirror_ovs.git] / tests / ovstest.c
CommitLineData
3932d8db
AZ
1/*
2 * Copyright (c) 2014 Nicira, Inc.
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17/* The mother of all test programs that links with libopevswitch.la */
18
19#include <config.h>
20#include <inttypes.h>
21#include <limits.h>
22#include <stdlib.h>
23#include "command-line.h"
24#include "ovstest.h"
01fed651 25#include "dynamic-string.h"
3932d8db
AZ
26#include "util.h"
27
28static struct command *commands = NULL;
29static size_t n_commands = 0;
30static size_t allocated_commands = 0;
31
32static void
33add_command(struct command *cmd)
34{
35 const struct command nil = {NULL, 0, 0, NULL};
36
37 while (n_commands + 1 >= allocated_commands) {
38 commands = x2nrealloc(commands, &allocated_commands,
39 sizeof *cmd);
40 }
41
42 commands[n_commands] = *cmd;
43 commands[n_commands + 1] = nil;
44 n_commands++;
45}
46
01fed651
AZ
47#define OVSTEST_USAGE \
48"TEST [TESTARGS] where 'TEST' is a string, 'TESTARGS' are optional \n"\
49"arguments of the TEST"
50
51static void
52flush_help_string(struct ds *ds)
53{
54 if (ds->length > 2 ) {
55 ds->length -= 2;
56 printf ("%s\n", ds_cstr(ds));
57 ds_clear(ds);
58 }
59}
60
3932d8db 61static void
01fed651 62help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
3932d8db
AZ
63{
64 const struct command *p;
01fed651
AZ
65 struct ds test_names = DS_EMPTY_INITIALIZER;
66 const int linesize = 70;
67
68 printf("%s: the big test executable\n"
69 "usage: %s TEST [TESTARGS]\n"
70 "where TEST is one of the following. \n\n",
71 program_name, program_name);
3932d8db
AZ
72
73 for(p = commands; p->name != NULL; p++) {
01fed651
AZ
74 if (*p->name != '-') { /* Skip internal commands */
75 ds_put_format(&test_names, "%s, ", p->name);
76 if ((test_names.length) >= linesize) {
77 flush_help_string(&test_names);
78 }
79 }
3932d8db 80 }
01fed651
AZ
81 flush_help_string(&test_names);
82 ds_destroy(&test_names);
3932d8db
AZ
83}
84
85static void
86add_top_level_commands(void)
87{
01fed651 88 struct command help_cmd = {"--help", 0, 0, help};
3932d8db
AZ
89
90 add_command(&help_cmd);
91}
92
93void
01fed651 94ovstest_register(const char *test_name, ovstest_func f)
3932d8db
AZ
95{
96 struct command test_cmd;
3932d8db
AZ
97
98 test_cmd.name = test_name;
01fed651
AZ
99 test_cmd.min_args = 0;
100 test_cmd.max_args = INT_MAX;
3932d8db
AZ
101 test_cmd.handler = f;
102
103 add_command(&test_cmd);
104}
105
106static void
107cleanup(void)
108{
109 if (allocated_commands) {
110 free(commands);
111 }
112}
113
114int
115main(int argc, char *argv[])
116{
117 set_program_name(argv[0]);
118
01fed651
AZ
119 if (argc < 2) {
120 ovs_fatal(0, "expect test program to be specified; "
121 "use --help for usage");
122 }
123
3932d8db
AZ
124 add_top_level_commands();
125 if (argc > 1) {
126 run_command(argc - 1, argv + 1, commands);
127 }
128 cleanup();
129
130 return 0;
131}