libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-fault-injection.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * Fault injection api if built with LWS_WITH_SYS_FAULT_INJECTION
25 */
26
27typedef struct lws_xos {
28 uint64_t s[4];
30
40lws_xos_init(struct lws_xos *xos, uint64_t seed);
41
52lws_xos(struct lws_xos *xos);
53
65lws_xos_percent(struct lws_xos *xos, int percent);
66
67#if defined(LWS_WITH_SYS_FAULT_INJECTION)
68
69enum {
70 LWSFI_ALWAYS,
71 LWSFI_DETERMINISTIC, /* do .count injections after .pre then stop */
72 LWSFI_PROBABILISTIC, /* .pre % chance of injection */
73 LWSFI_PATTERN, /* use .count bits in .pattern after .pre */
74 LWSFI_PATTERN_ALLOC, /* as _PATTERN, but .pattern is malloc'd */
75 LWSFI_RANGE /* pick a number between pre and count */
76};
77
78typedef struct lws_fi {
79 const char *name;
80 const uint8_t *pattern;
81 uint64_t pre;
82 uint64_t count;
83 uint64_t times; /* start at 0, tracks usage */
84 char type; /* LWSFI_* */
85} lws_fi_t;
86
87typedef struct lws_fi_ctx {
88 lws_dll2_owner_t fi_owner;
89 struct lws_xos xos;
90 const char *name;
91} lws_fi_ctx_t;
92
110lws_fi(const lws_fi_ctx_t *fic, const char *fi_name);
111
131lws_fi_range(const lws_fi_ctx_t *fic, const char *name, uint64_t *result);
132
143lws_fi_add(lws_fi_ctx_t *fic, const lws_fi_t *fi);
144
155lws_fi_remove(lws_fi_ctx_t *fic, const char *name);
156
167lws_fi_import(lws_fi_ctx_t *fic_dest, const lws_fi_ctx_t *fic_src);
168
183lws_fi_inherit_copy(lws_fi_ctx_t *fic_dest, const lws_fi_ctx_t *fic_src,
184 const char *scope, const char *value);
185
196lws_fi_destroy(const lws_fi_ctx_t *fic);
197
210
212lws_fi_deserialize(lws_fi_ctx_t *fic, const char *sers);
213
215_lws_fi_user_wsi_fi(struct lws *wsi, const char *name);
217_lws_fi_user_context_fi(struct lws_context *ctx, const char *name);
218
219#if defined(LWS_WITH_SECURE_STREAMS)
220struct lws_ss_handle;
222_lws_fi_user_ss_fi(struct lws_ss_handle *h, const char *name);
223#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
224struct lws_sspc_handle;
226_lws_fi_user_sspc_fi(struct lws_sspc_handle *h, const char *name);
227#endif
228#endif
229
230#define lws_fi_user_wsi_fi(_wsi, _name) _lws_fi_user_wsi_fi(_wsi, _name)
231#define lws_fi_user_context_fi(_ctx, _name) _lws_fi_user_context_fi(_ctx, _name)
232#define lws_fi_user_ss_fi(_h, _name) _lws_fi_user_ss_fi(_h, _name)
233#define lws_fi_user_sspc_fi(_h, _name) _lws_fi_user_sspc_fi(_h, _name)
234
235#else
236
237/*
238 * Helper so we can leave lws_fi() calls embedded in the code being tested,
239 * if fault injection is not enabled then it just always says "no" at buildtime.
240 */
241
242#define lws_fi(_fi_name, _fic) (0)
243#define lws_fi_destroy(_x)
244#define lws_fi_inherit_copy(_a, _b, _c, _d)
245#define lws_fi_deserialize(_x, _y)
246#define lws_fi_user_wsi_fi(_wsi, _name) (0)
247#define lws_fi_user_context_fi(_wsi, _name) (0)
248#define lws_fi_user_ss_fi(_h, _name) (0)
249#define lws_fi_user_sspc_fi(_h, _name) (0)
250
251#endif
struct lws_dll2_owner lws_dll2_owner_t
#define LWS_EXTERN
#define LWS_WARN_UNUSED_RESULT
#define LWS_VISIBLE
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_xos_percent(struct lws_xos *xos, int percent)
#define lws_fi(_fi_name, _fic)
#define lws_fi_deserialize(_x, _y)
struct lws_xos lws_xos_t
LWS_VISIBLE LWS_EXTERN uint64_t LWS_WARN_UNUSED_RESULT lws_xos(struct lws_xos *xos)
uint64_t s[4]
LWS_VISIBLE LWS_EXTERN void lws_xos_init(struct lws_xos *xos, uint64_t seed)
#define lws_fi_inherit_copy(_a, _b, _c, _d)
#define lws_fi_destroy(_x)