From 92930964f186340538c84bdc713844ca4fad07ee Mon Sep 17 00:00:00 2001 From: Patrick Raphael Date: Mon, 6 Dec 2021 17:02:52 -0500 Subject: [PATCH] code coverage intrinsics --- libraries/eosiolib/capi/eosio/coverage.h | 29 ++++++++++++++ .../eosiolib/contracts/eosio/coverage.hpp | 38 +++++++++++++++++++ libraries/native/intrinsics.cpp | 12 ++++++ .../native/native/eosio/intrinsics_def.hpp | 7 +++- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 libraries/eosiolib/capi/eosio/coverage.h create mode 100644 libraries/eosiolib/contracts/eosio/coverage.hpp diff --git a/libraries/eosiolib/capi/eosio/coverage.h b/libraries/eosiolib/capi/eosio/coverage.h new file mode 100644 index 0000000000..c6b361b640 --- /dev/null +++ b/libraries/eosiolib/capi/eosio/coverage.h @@ -0,0 +1,29 @@ +/** + * @file + * @copyright defined in eos/LICENSE + */ +#pragma once +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Increments the call count of a function in specified code/file + * + * @brief + * @param name - + */ +__attribute__((eosio_wasm_import)) +void coverage_inc_fun_cnt( capi_name code, uint32_t file_num, uint32_t func_num ); + +__attribute__((eosio_wasm_import)) +void coverage_inc_line_cnt( capi_name code, uint32_t file_num, uint32_t line_num ); + +__attribute__((eosio_wasm_import)) +void coverage_dump(); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/libraries/eosiolib/contracts/eosio/coverage.hpp b/libraries/eosiolib/contracts/eosio/coverage.hpp new file mode 100644 index 0000000000..516f52768e --- /dev/null +++ b/libraries/eosiolib/contracts/eosio/coverage.hpp @@ -0,0 +1,38 @@ +/** + * @file + * @copyright defined in eos/LICENSE + */ +#pragma once +#include + +#include + +namespace eosio { + + namespace internal_use_do_not_use { + + extern "C" { + __attribute__((eosio_wasm_import)) + void coverage_inc_fun_cnt( capi_name code, uint32_t file_num, uint32_t func_num ); + + __attribute__((eosio_wasm_import)) + void coverage_inc_line_cnt( capi_name code, uint32_t file_num, uint32_t line_num ); + + __attribute__((eosio_wasm_import)) + void coverage_dump(); + } + }; + + inline void coverage_inc_fun_cnt( name code, uint32_t file_num, uint32_t func_num ) { + internal_use_do_not_use::coverage_inc_fun_cnt(code, file_num, func_num); + } + + inline void coverage_inc_line_cnt( name code, uint32_t file_num, uint32_t line_num ) { + internal_use_do_not_use::coverage_inc_line_cnt(code, file_num, line_num); + } + + inline void coverage_dump() { + internal_use_do_not_use::coverage_dump(); + } + +} // namespace eosio \ No newline at end of file diff --git a/libraries/native/intrinsics.cpp b/libraries/native/intrinsics.cpp index 8cf32e96a0..ac83bcc536 100644 --- a/libraries/native/intrinsics.cpp +++ b/libraries/native/intrinsics.cpp @@ -883,6 +883,18 @@ extern "C" { } } + void coverage_inc_fun_cnt( capi_name code, uint32_t file_num, uint32_t func_num ) { + intrinsics::get().call(code, file_num, func_num); + } + + void coverage_inc_line_cnt( capi_name code, uint32_t file_num, uint32_t line_num ) { + intrinsics::get().call(code, file_num, line_num); + } + + void coverage_dump() { + intrinsics::get().call(); + } + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-noreturn" void abort() { diff --git a/libraries/native/native/eosio/intrinsics_def.hpp b/libraries/native/native/eosio/intrinsics_def.hpp index d800111886..c76b30d7e2 100644 --- a/libraries/native/native/eosio/intrinsics_def.hpp +++ b/libraries/native/native/eosio/intrinsics_def.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -158,7 +159,11 @@ intrinsic_macro(send_deferred) \ intrinsic_macro(cancel_deferred) \ intrinsic_macro(get_context_free_data) \ intrinsic_macro(get_sender) \ -intrinsic_macro(set_action_return_value) +intrinsic_macro(set_action_return_value) \ +intrinsic_macro(coverage_inc_fun_cnt) \ +intrinsic_macro(coverage_inc_line_cnt) \ +intrinsic_macro(coverage_dump) + #define CREATE_ENUM(name) \ name,