Code Coverage: vinyl-cache/bin/vinyltest/vtest_ext_vinyl_builtwith.c
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
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 <signal.h>
35
36
#include "vdef.h"
37
38
#include <vtest_api.h>
39
#include "vtest_ext_vinyl.h"
40
41
/* SECTION: vcache_builtwith feature
42
 *
43
 * Test that the required feature(s) for a test have been compiled in, and skip
44
 * the test otherwise
45
 *
46
 * 64bit
47
 *        The environment is 64 bits
48
 * persistent_storage
49
 *        built with the deprecated persistent storage.
50
 * coverage
51
 *        built with code coverage enabled.
52
 * asan
53
 *        built with the address sanitizer.
54
 * msan
55
 *        built with the memory sanitizer.
56
 * tsan
57
 *        built with the thread sanitizer.
58
 * ubsan
59
 *        built with the undefined behavior sanitizer.
60
 * sanitizer
61
 *        built with a sanitizer.
62
 * workspace_emulator
63
 *        built with its workspace emulator.
64
 * witness
65
 *        A compile flag was present indicating the lock witness.
66
 *
67
 * A feature name can be prefixed with an exclamation mark (!) to skip a
68
 * test if the feature is present.
69
 */
70
71
#if ENABLE_COVERAGE
72
static const unsigned coverage = 1;
73
#else
74
static const unsigned coverage = 0;
75
#endif
76
77
#if ENABLE_ASAN
78
static const unsigned asan = 1;
79
#else
80
static const unsigned asan = 0;
81
#endif
82
83
#if ENABLE_MSAN
84
static const unsigned msan = 1;
85
#else
86
static const unsigned msan = 0;
87
#endif
88
89
#if ENABLE_TSAN
90
static const unsigned tsan = 1;
91
#else
92
static const unsigned tsan = 0;
93
#endif
94
95
#if ENABLE_UBSAN
96
static const unsigned ubsan = 1;
97
#else
98
static const unsigned ubsan = 0;
99
#endif
100
101
#if ENABLE_SANITIZER
102
static const unsigned sanitizer = 1;
103
#else
104
static const unsigned sanitizer = 0;
105
#endif
106
107
#if ENABLE_WORKSPACE_EMULATOR
108
static const unsigned workspace_emulator = 1;
109
#else
110
static const unsigned workspace_emulator = 0;
111
#endif
112
113
#if ENABLE_WITNESS
114
static const unsigned witness = 1;
115
#else
116
static const unsigned witness = 0;
117
#endif
118
119
#if WITH_PERSISTENT_STORAGE
120
static const unsigned with_persistent_storage = 1;
121
#else
122
static const unsigned with_persistent_storage = 0;
123
#endif
124
125
void v_matchproto_(cmd_f)
126
cmd_vcache_builtwith(CMD_ARGS)
127 1148
{
128 1148
        const char *feat;
129 1148
        int good, skip, neg;
130
131 1148
        (void)priv;
132
133 1148
        if (av == NULL)
134 1122
                return;
135
136 26
#define BUILTWITH(nm, tst)                              \
137 260
        do {                                            \
138 260
                if (!vstrcmp(feat, nm)) {               \
139 26
                        good = 1;                       \
140 26
                        if (tst) {                      \
141 17
                                skip = neg;             \
142 17
                        } else {                        \
143 9
                                skip = !neg;            \
144 9
                        }                               \
145 26
                }                                       \
146 260
        } while (0)
147
148 26
        skip = 0;
149
150 52
        for (av++; *av != NULL; av++) {
151 26
                good = 0;
152 26
                neg = 0;
153 26
                feat = *av;
154
155 26
                if (feat[0] == '!') {
156 9
                        neg = 1;
157 9
                        feat++;
158 9
                }
159
160 26
                BUILTWITH("64bit", sizeof(void*) == 8);
161 26
                BUILTWITH("persistent_storage", with_persistent_storage);
162 26
                BUILTWITH("coverage", coverage);
163 26
                BUILTWITH("asan", asan);
164 26
                BUILTWITH("msan", msan);
165 26
                BUILTWITH("tsan", tsan);
166 26
                BUILTWITH("ubsan", ubsan);
167 26
                BUILTWITH("sanitizer", sanitizer);
168 26
                BUILTWITH("workspace_emulator", workspace_emulator);
169 26
                BUILTWITH("witness", witness);
170
171 26
                if (!good)
172 0
                        vtc_fatal(vl, "FAIL test, unknown feature: %s", feat);
173
174 26
                if (!skip)
175 26
                        continue;
176
177 0
                vtc_stop = 2;
178 0
                if (neg)
179 0
                        vtc_log(vl, 1,
180 0
                            "SKIPPING test, conflicting feature: %s", feat);
181 0
                else
182 0
                        vtc_log(vl, 1,
183 0
                            "SKIPPING test, lacking feature: %s", feat);
184 0
                return;
185 26
        }
186 26
}
187