]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/civetweb/unittest/main.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / 3rdparty / civetweb / unittest / main.c
CommitLineData
1e59de90
TL
1/* Copyright (c) 2015-2018 the Civetweb developers
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22#if defined(_MSC_VER)
23#define _CRT_SECURE_NO_WARNINGS /* Microsoft nonsense */
24#endif
25
26#include "civetweb_check.h"
27#include "private.h"
28#include "private_exe.h"
29#include "public_func.h"
30#include "public_server.h"
31#include "shared.h"
32#include "timertest.h"
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37
38/* This unit test file uses the excellent Check unit testing library.
39 * The API documentation is available here:
40 * http://check.sourceforge.net/doc/check_html/index.html
41 *
42 * Note: CivetWeb is tested using it's own fork of check:
43 * https://github.com/civetweb/check
44 * Required fixes from this fork are already available
45 * in the main repository:
46 * https://github.com/libcheck/check
47 */
48
49#define FILENAME_LEN (128)
50
51int
52main(const int argc, char *argv[])
53{
54 /* Supported command line arguments */
55 const char *const suite_arg = "--suite=";
56 const size_t suite_arg_size = strlen(suite_arg);
57 const char *const test_case_arg = "--test-case=";
58 const size_t test_case_arg_size = strlen(test_case_arg);
59 const char *const test_dir_arg = "--test-dir=";
60 const size_t test_dir_arg_size = strlen(test_dir_arg);
61 const char *const test_log_arg = "--test-log=";
62 const size_t test_log_arg_size = strlen(test_log_arg);
63 const char *const help_arg = "--help";
64
65 /* Test variables */
66 const char *suite = NULL;
67 const char *test_case = NULL;
68 SRunner *srunner;
69 int number_run = 0;
70 int number_failed = 0;
71 const char *test_log_prefix = NULL;
72 char test_log_name[FILENAME_LEN];
73 char test_xml_name[FILENAME_LEN];
74 const char *test_dir = NULL;
75
76 int i;
77
78 /* Check command line parameters for tests */
79 for (i = 1; i < argc; ++i) {
80 if (0 == strncmp(suite_arg, argv[i], suite_arg_size)
81 && (strlen(argv[i]) > suite_arg_size)) {
82 suite = &argv[i][suite_arg_size];
83 } else if (0 == strncmp(test_case_arg, argv[i], test_case_arg_size)
84 && (strlen(argv[i]) > test_case_arg_size)) {
85 test_case = &argv[i][test_case_arg_size];
86 } else if (0 == strncmp(test_dir_arg, argv[i], test_dir_arg_size)
87 && (strlen(argv[i]) > test_dir_arg_size)) {
88 set_test_directory(&argv[i][test_dir_arg_size]);
89 } else if (0 == strncmp(test_log_arg, argv[i], test_log_arg_size)
90 && (strlen(argv[i]) > test_log_arg_size)) {
91 test_log_prefix = &argv[i][test_log_arg_size];
92 if ((strlen(test_log_prefix) + 16) > FILENAME_LEN) {
93 fprintf(stderr, "Argument too long: %s\n", argv[i]);
94 exit(EXIT_FAILURE);
95 }
96 } else if (0 == strcmp(help_arg, argv[i])) {
97 printf(
98 "Usage: %s [options]\n"
99 " --suite=Suite Determines the suite to run\n"
100 " --test-case='Test Case' Determines the test case to run\n"
101 " --test-dir='folder/path' The location of the test directory "
102 "with the \n"
103 " 'fixtures' and 'expected\n",
104 argv[0]);
105 exit(EXIT_SUCCESS);
106 } else {
107 fprintf(stderr, "Invalid argument: %s\n", argv[i]);
108 exit(EXIT_FAILURE);
109 }
110 }
111
112 /* Register all tests to run them later */
113 srunner = srunner_create(make_public_func_suite());
114 srunner_add_suite(srunner, make_public_server_suite());
115 srunner_add_suite(srunner, make_private_suite());
116 srunner_add_suite(srunner, make_private_exe_suite());
117 srunner_add_suite(srunner, make_timertest_suite());
118
119 /* Print test directory */
120 test_dir = get_test_directory();
121 printf("Test directory: %s\n", test_dir);
122
123 /* Write test logs to a file */
124 if (test_log_prefix == NULL) {
125 /* Find the next free log name */
126 FILE *f;
127 for (i = 1;; i++) {
128 /* enumerate all log files (8.3 filename using 3 digits) */
129 sprintf(test_log_name, "test-%03i.log", i);
130 f = fopen(test_log_name, "r");
131 if (f) {
132 /* file already exists */
133 fclose(f);
134 /* try next name */
135 continue;
136 }
137 /* file does not exist - use this name */
138 srunner_set_log(srunner, test_log_name);
139 /* use the same index for xml as for log */
140 sprintf(test_xml_name, "test-%03i.xml", i);
141 srunner_set_xml(srunner, test_xml_name);
142 break;
143 }
144 } else {
145 /* We got a test log name from the command line */
146 sprintf(test_log_name, "%s.log", test_log_prefix);
147 srunner_set_log(srunner, test_log_name);
148 sprintf(test_xml_name, "%s.xml", test_log_prefix);
149 srunner_set_xml(srunner, test_xml_name);
150 }
151
152 /* Run tests, using log level CK_VERBOSE, since CK_NORMAL
153 * offers not enough diagnosis to analyze failed tests.
154 * see http://check.sourceforge.net/doc/check_html/check_3.html */
155 srunner_run(srunner, suite, test_case, CK_VERBOSE);
156
157 /* Check passed / failed */
158 number_run = srunner_ntests_run(srunner);
159 number_failed = srunner_ntests_failed(srunner);
160 srunner_free(srunner);
161 return ((number_failed == 0) && (number_run != 0)) ? EXIT_SUCCESS
162 : EXIT_FAILURE;
163}