-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Antithesis intrumentation (#5042)
* Copy Antithesis SDK version 0.4.0 to directory external/ * Add build option `voidstar` to enable instrumentation with Antithesis SDK * Define instrumentation macros ASSERT and UNREACHABLE in terms of regular C assert * Replace asserts with named ASSERT or UNREACHABLE * Add UNREACHABLE to LogicError * Document instrumentation macros in CONTRIBUTING.md
- Loading branch information
Showing
261 changed files
with
3,852 additions
and
1,038 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
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
DisableFormat: true | ||
SortIncludes: false |
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,17 @@ | ||
cmake_minimum_required(VERSION 3.25) | ||
|
||
# Note, version set explicitly by rippled project | ||
project(antithesis-sdk-cpp VERSION 0.4.2 LANGUAGES CXX) | ||
|
||
add_library(antithesis-sdk-cpp INTERFACE antithesis_sdk.h) | ||
|
||
# Note, both sections below created by rippled project | ||
target_include_directories(antithesis-sdk-cpp INTERFACE | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
) | ||
|
||
install( | ||
FILES antithesis_sdk.h | ||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||
) |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Antithesis | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,8 @@ | ||
# Antithesis C++ SDK | ||
|
||
This library provides methods for C++ programs to configure the [Antithesis](https://antithesis.com) platform. It contains three kinds of functionality: | ||
* Assertion macros that allow you to define test properties about your software or workload. | ||
* Randomness functions for requesting both structured and unstructured randomness from the Antithesis platform. | ||
* Lifecycle functions that inform the Antithesis environment that particular test phases or milestones have been reached. | ||
|
||
For general usage guidance see the [Antithesis C++ SDK Documentation](https://antithesis.com/docs/using_antithesis/sdk/cpp/overview.html) |
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,113 @@ | ||
#pragma once | ||
|
||
/* | ||
This header file enables code coverage instrumentation. It is distributed with the Antithesis C++ SDK. | ||
This header file can be used in both C and C++ programs. (The rest of the SDK works only for C++ programs.) | ||
You should include it in a single .cpp or .c file. | ||
The instructions (such as required compiler flags) and usage guidance are found at https://antithesis.com/docs/using_antithesis/sdk/cpp/overview.html. | ||
*/ | ||
|
||
#include <unistd.h> | ||
#include <string.h> | ||
#include <dlfcn.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#ifndef __cplusplus | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#endif | ||
|
||
// If the libvoidstar(determ) library is present, | ||
// pass thru trace_pc_guard related callbacks to it | ||
typedef void (*trace_pc_guard_init_fn)(uint32_t *start, uint32_t *stop); | ||
typedef void (*trace_pc_guard_fn)(uint32_t *guard, uint64_t edge); | ||
|
||
static trace_pc_guard_init_fn trace_pc_guard_init = NULL; | ||
static trace_pc_guard_fn trace_pc_guard = NULL; | ||
static bool did_check_libvoidstar = false; | ||
static bool has_libvoidstar = false; | ||
|
||
static __attribute__((no_sanitize("coverage"))) void debug_message_out(const char *msg) { | ||
(void)printf("%s\n", msg); | ||
return; | ||
} | ||
|
||
extern | ||
#ifdef __cplusplus | ||
"C" | ||
#endif | ||
__attribute__((no_sanitize("coverage"))) void antithesis_load_libvoidstar() { | ||
#ifdef __cplusplus | ||
constexpr | ||
#endif | ||
const char* LIB_PATH = "/usr/lib/libvoidstar.so"; | ||
|
||
if (did_check_libvoidstar) { | ||
return; | ||
} | ||
debug_message_out("TRYING TO LOAD libvoidstar"); | ||
did_check_libvoidstar = true; | ||
void* shared_lib = dlopen(LIB_PATH, RTLD_NOW); | ||
if (!shared_lib) { | ||
debug_message_out("Can not load the Antithesis native library"); | ||
return; | ||
} | ||
|
||
void* trace_pc_guard_init_sym = dlsym(shared_lib, "__sanitizer_cov_trace_pc_guard_init"); | ||
if (!trace_pc_guard_init_sym) { | ||
debug_message_out("Can not forward calls to libvoidstar for __sanitizer_cov_trace_pc_guard_init"); | ||
return; | ||
} | ||
|
||
void* trace_pc_guard_sym = dlsym(shared_lib, "__sanitizer_cov_trace_pc_guard_internal"); | ||
if (!trace_pc_guard_sym) { | ||
debug_message_out("Can not forward calls to libvoidstar for __sanitizer_cov_trace_pc_guard"); | ||
return; | ||
} | ||
|
||
trace_pc_guard_init = (trace_pc_guard_init_fn)(trace_pc_guard_init_sym); | ||
trace_pc_guard = (trace_pc_guard_fn)(trace_pc_guard_sym); | ||
has_libvoidstar = true; | ||
debug_message_out("LOADED libvoidstar"); | ||
} | ||
|
||
// The following symbols are indeed reserved identifiers, since we're implementing functions defined | ||
// in the compiler runtime. Not clear how to get Clang on board with that besides narrowly suppressing | ||
// the warning in this case. The sample code on the CoverageSanitizer documentation page fails this | ||
// warning! | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wreserved-identifier" | ||
extern | ||
#ifdef __cplusplus | ||
"C" | ||
#endif | ||
void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) { | ||
debug_message_out("SDK forwarding to libvoidstar for __sanitizer_cov_trace_pc_guard_init()"); | ||
if (!did_check_libvoidstar) { | ||
antithesis_load_libvoidstar(); | ||
} | ||
if (has_libvoidstar) { | ||
trace_pc_guard_init(start, stop); | ||
} | ||
return; | ||
} | ||
|
||
extern | ||
#ifdef __cplusplus | ||
"C" | ||
#endif | ||
void __sanitizer_cov_trace_pc_guard( uint32_t *guard ) { | ||
if (has_libvoidstar) { | ||
uint64_t edge = (uint64_t)(__builtin_return_address(0)); | ||
trace_pc_guard(guard, edge); | ||
} else { | ||
if (guard) { | ||
*guard = 0; | ||
} | ||
} | ||
return; | ||
} | ||
#pragma clang diagnostic pop |
Oops, something went wrong.