]> git.proxmox.com Git - ovs.git/blame - tests/ovstest.h
tests: Convert ovsdb-monitor-sort utility from Perl to Python.
[ovs.git] / tests / ovstest.h
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#ifndef OVSTEST_H
18#define OVSTEST_H
19
01fed651
AZ
20#include "compiler.h"
21
1636c761
RB
22#include "command-line.h"
23
3932d8db
AZ
24/* Overview
25 * ========
26 *
27 * OVS tests directory contains many small test programs. One down side
28 * of building them as individual programs is that they all have to be
29 * linked whenever a library function is modified.
30 *
31 * ovstest is an attempt to improve the overall build time by linking
32 * all test programs into a single program, ovs-test. Regardless of
33 * the number of test programs, linking will be done only once to produce
34 * ovstest.
35 *
01fed651 36 * With ovstest, each test programs now becomes a sub program of ovstest.
9e0fa1f2 37 * For example, 'mytest' program, can now be invoked as 'ovstest mytest'.
3932d8db
AZ
38 *
39 * 'ovstest --help' will list all test programs can be invoked.
40 *
01fed651
AZ
41 * The 'Usage' section below documents how to add a new sub program
42 * to ovstest using OVSTEST_REIGSTER macros.
3932d8db
AZ
43 */
44
45typedef void (*ovstest_func)(int argc, char *argv[]);
1636c761
RB
46
47void ovstest_register(const char *test_name, ovs_cmdl_handler f);
3932d8db
AZ
48
49/* Usage
50 * =====
51 *
01fed651 52 * For each sub test program, its 'main' program should be named as
3932d8db
AZ
53 * '<test_name>_main()'.
54 *
01fed651
AZ
55 * The 'main' programs should be registered with ovstest as a sub program.
56 * OVSTEST_REGISTER(name, function)
57 *
58 * 'name' will be name of the test program. It is expected as argv[1] when
59 * invoking with ovstest.
3932d8db 60 *
01fed651 61 * 'function' is the 'main' program mentioned above.
3932d8db
AZ
62 *
63 * Example:
64 * ----------
65 *
66 * Suppose the test program is called my-test.c
67 * ...
68 *
69 * static void
70 * my_test_main(int argc, char *argv[])
71 * {
72 * ....
73 * }
74 *
01fed651 75 * OVSTEST_REGISTER("my-test", my_test_main);
3932d8db 76 */
01fed651 77#define OVSTEST_REGISTER(name, function) \
1636c761
RB
78 static void \
79 ovstest_wrapper_##function##__(struct ovs_cmdl_context *ctx) \
80 { \
81 function(ctx->argc, ctx->argv); \
82 } \
3932d8db 83 OVS_CONSTRUCTOR(register_##function) { \
1636c761 84 ovstest_register(name, ovstest_wrapper_##function##__); \
3932d8db
AZ
85 }
86
87#endif