Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
code coverage intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
praphael committed Dec 6, 2021
1 parent b580842 commit 9293096
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
29 changes: 29 additions & 0 deletions libraries/eosiolib/capi/eosio/coverage.h
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions libraries/eosiolib/contracts/eosio/coverage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file
* @copyright defined in eos/LICENSE
*/
#pragma once
#include <cstdlib>

#include <eosio/name.hpp>

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
12 changes: 12 additions & 0 deletions libraries/native/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<intrinsics::coverage_inc_fun_cnt>(code, file_num, func_num);
}

void coverage_inc_line_cnt( capi_name code, uint32_t file_num, uint32_t line_num ) {
intrinsics::get().call<intrinsics::coverage_inc_line_cnt>(code, file_num, line_num);
}

void coverage_dump() {
intrinsics::get().call<intrinsics::coverage_dump>();
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-noreturn"
void abort() {
Expand Down
7 changes: 6 additions & 1 deletion libraries/native/native/eosio/intrinsics_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <eosio/system.h>
#include <eosio/transaction.h>
#include <eosio/types.h>
#include <eosio/coverage.h>

#include <type_traits>

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9293096

Please sign in to comment.