-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add support for matching diagnostic traces
- Loading branch information
1 parent
07896f6
commit caee923
Showing
7 changed files
with
319 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Tracing functions and helpers. */ | ||
|
||
#ifndef TRACING_H_ | ||
#define TRACING_H_ | ||
|
||
#include "../include/vr.h" | ||
|
||
#define LIKELY(x) __builtin_expect(!!(x), 1) | ||
|
||
/* Use TRACER to trace an event of type TYPE with the given INFO. */ | ||
#define Trace(TRACER, TYPE, INFO) \ | ||
do { \ | ||
if (LIKELY(TRACER == NULL)) { \ | ||
break; \ | ||
} \ | ||
if (LIKELY(TRACER->version == 2)) { \ | ||
TRACER->emit(TRACER, TYPE, INFO); \ | ||
} \ | ||
} while (0) | ||
|
||
/* Emit a diagnostic message with the given tracer at level 3. */ | ||
#define Infof(TRACER, ...) Logf(TRACER, 3, __VA_ARGS__) | ||
|
||
/* Emit diagnostic message with the given tracer at level 5. */ | ||
#define Tracef(TRACER, ...) Logf(TRACER, 5, __VA_ARGS__) | ||
|
||
/* Use the tracer to log an event at the given level. | ||
* | ||
* The LEVEL parameter should be one of: | ||
* | ||
* - 1: error | ||
* - 2: warning | ||
* - 3: info | ||
* - 4: debug | ||
* - 5: trace | ||
*/ | ||
#define Logf(TRACER, LEVEL, ...) \ | ||
do { \ | ||
unsigned _type; \ | ||
struct vr_tracer_info _info; \ | ||
static char _msg[1024]; \ | ||
\ | ||
if (LIKELY(TRACER == NULL)) { \ | ||
break; \ | ||
} \ | ||
\ | ||
snprintf(_msg, sizeof _msg, __VA_ARGS__); \ | ||
\ | ||
_type = VR_TRACER_DIAGNOSTIC; \ | ||
_info.version = 1; \ | ||
_info.diagnostic.level = LEVEL; \ | ||
_info.diagnostic.message = _msg; \ | ||
_info.diagnostic.file = __FILE__; \ | ||
_info.diagnostic.line = __LINE__; \ | ||
TRACER->emit(TRACER, _type, &_info); \ | ||
} while (0) | ||
|
||
#endif /* TRACING_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
#include "../../include/vr.h" | ||
#include "../lib/runner.h" | ||
|
||
static void *setUp(const MunitParameter params[], MUNIT_UNUSED void *user_data) | ||
{ | ||
struct vr *v = munit_malloc(sizeof *v); | ||
int rv; | ||
|
||
(void)params; | ||
rv = vr_init(v, 1); | ||
munit_assert_int(rv, ==, 0); | ||
|
||
return v; | ||
} | ||
|
||
static void tearDown(void *data) | ||
{ | ||
struct vr *v = data; | ||
vr_close(v); | ||
free(v); | ||
} | ||
|
||
SUITE(step) | ||
|
||
/* Generation of the ID of the bootstrap dqlite node. */ | ||
TEST(step, noop, NULL, NULL, 0, NULL) | ||
/* Passing an invalid event code results in an error. */ | ||
TEST(step, invalid, setUp, tearDown, 0, NULL) | ||
{ | ||
struct vr *v = data; | ||
struct vr_event event; | ||
struct vr_update update; | ||
int rv; | ||
rv = vr_step(); | ||
munit_assert_int(0, ==, rv); | ||
event.type = 666; | ||
rv = vr_step(v, &event, &update); | ||
munit_assert_int(rv, ==, VR_INVALID); | ||
return MUNIT_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.