vinyl-cache/bin/vinyltest/vtest_ext_vinyl_builtwith.c
0
/*-
1
 * Copyright (c) 2008-2011 Varnish Software AS
2
 * All rights reserved.
3
 *
4
 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
5
 *
6
 * SPDX-License-Identifier: BSD-2-Clause
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 * implements vcache_builtwith command
30
 */
31
32
#include "config.h"
33
34
#include <sys/wait.h>
35
#include <sys/socket.h>
36
37
#include <grp.h>
38
#include <pwd.h>
39
#include <signal.h>
40
#include <stdio.h>
41
#include <stdlib.h>
42
#include <string.h>
43
#include <sys/un.h>
44
#include <unistd.h>
45
46
#ifdef HAVE_SYS_PERSONALITY_H
47
#  include <sys/personality.h>
48
#endif
49
50
#include "vdef.h"
51
52
#include "vfil.h"
53
#include "vnum.h"
54
#include "vtcp.h"
55
#include "vss.h"
56
#include "vtim.h"
57
#include "vus.h"
58
59
#include <vtest_api.h>
60
#include "vtest_ext_vinyl.h"
61
62
/* SECTION: vcache_builtwith feature
63
 *
64
 * Test that the required feature(s) for a test have been compiled in, and skip
65
 * the test otherwise
66
 *
67
 * 64bit
68
 *        The environment is 64 bits
69
 * persistent_storage
70
 *        built with the deprecated persistent storage.
71
 * coverage
72
 *        built with code coverage enabled.
73
 * asan
74
 *        built with the address sanitizer.
75
 * msan
76
 *        built with the memory sanitizer.
77
 * tsan
78
 *        built with the thread sanitizer.
79
 * ubsan
80
 *        built with the undefined behavior sanitizer.
81
 * sanitizer
82
 *        built with a sanitizer.
83
 * workspace_emulator
84
 *        built with its workspace emulator.
85
 * witness
86
 *        A compile flag was present indicating the lock witness.
87
 *
88
 * A feature name can be prefixed with an exclamation mark (!) to skip a
89
 * test if the feature is present.
90
 */
91
92
#if ENABLE_COVERAGE
93
static const unsigned coverage = 1;
94
#else
95
static const unsigned coverage = 0;
96
#endif
97
98
#if ENABLE_ASAN
99
static const unsigned asan = 1;
100
#else
101
static const unsigned asan = 0;
102
#endif
103
104
#if ENABLE_MSAN
105
static const unsigned msan = 1;
106
#else
107
static const unsigned msan = 0;
108
#endif
109
110
#if ENABLE_TSAN
111
static const unsigned tsan = 1;
112
#else
113
static const unsigned tsan = 0;
114
#endif
115
116
#if ENABLE_UBSAN
117
static const unsigned ubsan = 1;
118
#else
119
static const unsigned ubsan = 0;
120
#endif
121
122
#if ENABLE_SANITIZER
123
static const unsigned sanitizer = 1;
124
#else
125
static const unsigned sanitizer = 0;
126
#endif
127
128
#if ENABLE_WORKSPACE_EMULATOR
129
static const unsigned workspace_emulator = 1;
130
#else
131
static const unsigned workspace_emulator = 0;
132
#endif
133
134
#if ENABLE_WITNESS
135
static const unsigned witness = 1;
136
#else
137
static const unsigned witness = 0;
138
#endif
139
140
#if WITH_PERSISTENT_STORAGE
141
static const unsigned with_persistent_storage = 1;
142
#else
143
static const unsigned with_persistent_storage = 0;
144
#endif
145
146
void v_matchproto_(cmd_f)
147 23877
cmd_vcache_builtwith(CMD_ARGS)
148
{
149
        const char *feat;
150
        int good, skip, neg;
151
152 23877
        (void)priv;
153
154 23877
        if (av == NULL)
155 23331
                return;
156
157
#define FEATURE(nm, tst)                                \
158
        do {                                            \
159
                if (!strcmp(feat, nm)) {                \
160
                        good = 1;                       \
161
                        if (tst) {                      \
162
                                skip = neg;             \
163
                        } else {                        \
164
                                skip = !neg;            \
165
                        }                               \
166
                }                                       \
167
        } while (0)
168
169 546
        skip = 0;
170
171 1071
        for (av++; *av != NULL; av++) {
172 546
                good = 0;
173 546
                neg = 0;
174 546
                feat = *av;
175
176 546
                if (feat[0] == '!') {
177 189
                        neg = 1;
178 189
                        feat++;
179 189
                }
180
181 546
                FEATURE("64bit", sizeof(void*) == 8);
182 546
                FEATURE("persistent_storage", with_persistent_storage);
183 546
                FEATURE("coverage", coverage);
184 546
                FEATURE("asan", asan);
185 546
                FEATURE("msan", msan);
186 546
                FEATURE("tsan", tsan);
187 546
                FEATURE("ubsan", ubsan);
188 546
                FEATURE("sanitizer", sanitizer);
189 546
                FEATURE("workspace_emulator", workspace_emulator);
190 546
                FEATURE("witness", witness);
191
192 546
                if (!good)
193 0
                        vtc_fatal(vl, "FAIL test, unknown feature: %s", feat);
194
195 546
                if (!skip)
196 525
                        continue;
197
198 21
                vtc_stop = 2;
199 21
                if (neg)
200 42
                        vtc_log(vl, 1,
201 21
                            "SKIPPING test, conflicting feature: %s", feat);
202
                else
203 0
                        vtc_log(vl, 1,
204 0
                            "SKIPPING test, lacking feature: %s", feat);
205 21
                return;
206
        }
207 23877
}
208