]> git.proxmox.com Git - ovs.git/blob - tests/test-lib.c
tests: Fix sparse error on test-ovn.c
[ovs.git] / tests / test-lib.c
1 /*
2 * Copyright (C) 2014 Cisco Systems, 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 #include <config.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <getopt.h>
21 #include <openvswitch/compiler.h>
22 #include <openvswitch/thread.h>
23 #include <openvswitch/types.h>
24 #include <openvswitch/util.h>
25 #include <openvswitch/vconn.h>
26 #include <openvswitch/vlog.h>
27
28 static void
29 show_version(void)
30 {
31 printf("%s - %s\n",
32 ovs_get_program_name(), ovs_get_program_version());
33 exit(EXIT_SUCCESS);
34 }
35
36 static void
37 usage(void)
38 {
39 printf("%s: Open vSwitch library test utility\n"
40 "usage: %s [OPTIONS] COMMAND [ARG...]\n\n",
41 ovs_get_program_name(), ovs_get_program_name());
42 vlog_usage();
43 exit(EXIT_SUCCESS);
44 }
45
46 static void
47 parse_options(int argc, char *argv[])
48 {
49 static const struct option long_options[] = {
50 {"help", no_argument, NULL, 'h'},
51 {"version", no_argument, NULL, 'V'},
52 {"verbose", optional_argument, NULL, 'v'},
53 {NULL, 0, NULL, 0},
54 };
55 char *short_options = "hVv";
56
57 for (;;) {
58 int c;
59
60 c = getopt_long(argc, argv, short_options, long_options, NULL);
61 if (c == -1) {
62 break;
63 }
64
65 switch (c) {
66 case 'V':
67 show_version();
68 break;
69
70 case 'h':
71 usage();
72 break;
73
74 case 'v':
75 vlog_set_verbosity(optarg);
76 break;
77
78 case '?':
79 exit(EXIT_FAILURE);
80
81 default:
82 abort();
83 }
84 }
85 }
86
87 int
88 main(int argc, char *argv[])
89 {
90 ovs_set_program_name(argv[0], "1.0");
91 parse_options(argc, argv);
92
93 return 0;
94 }