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

add code coverage host functions #10933

Open
wants to merge 35 commits into
base: develop-boxed
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7021484
add code coverage host functions
praphael Dec 6, 2021
9cbe513
code coverage now protocol feature instead of genesis
praphael Dec 7, 2021
1c67d03
add coverage_get_XXX() and coverage_reset() host functions
praphael Dec 7, 2021
f7d3423
correct intrinsic name
praphael Dec 7, 2021
2de3068
Revert "correct intrinsic name"
praphael Dec 8, 2021
4b5a68d
Revert "add coverage_get_XXX() and coverage_reset() host functions"
praphael Dec 8, 2021
57ca0e9
Revert "code coverage now protocol feature instead of genesis"
praphael Dec 8, 2021
73acc24
Revert "add code coverage host functions"
praphael Dec 8, 2021
74afa6f
add coverage intrinsics to eosio-tester
praphael Dec 8, 2021
9a05ec3
fix validation-reflect test failures, add param to covergae dump
praphael Dec 8, 2021
4a31d3b
rodeos coverage callbacks
praphael Dec 9, 2021
56e9f2f
add coverage intrinisic to eos-vm-oc
praphael Dec 9, 2021
ad65b38
whitelist tester intrinsics
praphael Dec 10, 2021
7e6b809
back to host function (verified working, generate coverage report)
praphael Dec 11, 2021
24ba301
missed changes from prior checkin
praphael Dec 14, 2021
c078fac
move rodoes coverage state to global
praphael Jan 4, 2022
033d0df
update programs/eosio-tester/main.cpp
praphael Jan 11, 2022
25c6b14
Refactor code coverage host functions to remove need for protocol fea…
heifner Jan 17, 2022
931775a
rm unused file
heifner Jan 17, 2022
e7ce00d
Additional cleanup
heifner Jan 17, 2022
1190d85
whitespace cleanup
heifner Jan 17, 2022
7d143da
Fix oc build
heifner Jan 18, 2022
52fe79e
Add missing returns
heifner Jan 21, 2022
475bc5a
Add missing returns
heifner Jan 25, 2022
443b964
new function coverage_dump_funcnt replaces coverage_dump
praphael Feb 2, 2022
9b75c43
separate coverage maps for chain/rodeos
praphael Feb 3, 2022
13a4795
reduce new coverage host functions to two
praphael Feb 3, 2022
c5d2347
Merge branch 'develop-boxed' of https://github.com/EOSIO/eos into pdr…
praphael Feb 4, 2022
7cd129d
remove improper semicolon in libraries/rodeos/include/eosio/coverage.hpp
praphael Feb 4, 2022
8308aa1
fix eosio-tester/main.cpp return paths
praphael Feb 4, 2022
2e3d942
address PR feedback
praphael Feb 7, 2022
ad98dff
address PR feedback
praphael Feb 7, 2022
284f478
address PR feedback
praphael Feb 7, 2022
60b8601
use static_cast to fix compile errors
praphael Feb 7, 2022
44720fd
Merge branch 'develop-boxed' of https://github.com/EOSIO/eos into pdr…
praphael Feb 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions libraries/rodeos/include/b1/rodeos/callbacks/coverage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace b1::rodeos {

template<eosio::name::raw Unique>
class coverage_maps {
heifner marked this conversation as resolved.
Show resolved Hide resolved
public:
static coverage_maps& instance() {
Expand All @@ -16,10 +17,13 @@ class coverage_maps {

cov_map_t funcnt_map;
cov_map_t linecnt_map;
eosio::name T;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

private:
coverage_maps() = default;
};

enum class coverage_mode = { func, line };
heifner marked this conversation as resolved.
Show resolved Hide resolved

struct coverage_state {
};

Expand All @@ -29,9 +33,9 @@ struct coverage_callbacks {

uint32_t coverage_getinc(uint64_t code, uint32_t file_num, uint32_t func_or_line_num, uint32_t mode, bool inc) {
if(inc) {
if (mode == 0) {
if (mode == coverage_mode::func) {
eosio::coverage::coverage_inc_cnt(code, file_num, func_or_line_num, coverage_maps::instance().funcnt_map);
} else if (mode == 1) {
} else if (mode == coverage_mode::line) {
eosio::coverage::coverage_inc_cnt(code, file_num, func_or_line_num, coverage_maps::instance().linecnt_map);
}
}
Expand All @@ -48,14 +52,14 @@ struct coverage_callbacks {

uint64_t coverage_dump(uint64_t code, uint32_t file_num, eosio::vm::span<const char> file_name, uint32_t max, bool append, uint32_t mode, bool reset) {
if (reset) {
coverage_maps::instance().funcnt_map.clear();
coverage_maps::instance().linecnt_map.clear();
coverage_maps<"rodeos"_n>::instance().funcnt_map.clear();
coverage_maps<"rodeos"_n>::instance().linecnt_map.clear();
}
else if (mode == 0) {
heifner marked this conversation as resolved.
Show resolved Hide resolved
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps::instance().funcnt_map);
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps<"rodeos"_n>::instance().funcnt_map);
}
else if (mode == 1) {
heifner marked this conversation as resolved.
Show resolved Hide resolved
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps::instance().linecnt_map);
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps<"rodeos"_n>::instance().linecnt_map);
}
return 0;
}
Expand Down
18 changes: 18 additions & 0 deletions libraries/rodeos/include/eosio/coverage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ using cov_map_t = std::unordered_map<uint64_t, std::unordered_map<uint32_t, std:
namespace eosio {
namespace coverage {

template<uint64_t Unique>
class coverage_maps {
public:
static coverage_maps& instance() {
static coverage_maps instance;
return instance;
}
coverage_maps(const coverage_maps&) = delete;
void operator=(const coverage_maps&) = delete;

cov_map_t funcnt_map;
cov_map_t linecnt_map;
private:
coverage_maps() = default;
};
heifner marked this conversation as resolved.
Show resolved Hide resolved

enum coverage_mode { func, line };
heifner marked this conversation as resolved.
Show resolved Hide resolved

inline void coverage_inc_cnt( uint64_t code, uint32_t file_num, uint32_t func_or_line_num, cov_map_t& cov_map) {
auto& code_map = cov_map[code];
auto& cnt_map = code_map[file_num];
Expand Down
48 changes: 20 additions & 28 deletions programs/eosio-tester/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ struct transaction_checktime_factory {
// Defined here to keep it out of nodeos
namespace eosio::chain::webassembly {

class coverage_maps {
public:
static coverage_maps& instance() {
static coverage_maps instance;
return instance;
}
coverage_maps(const coverage_maps&) = delete;
void operator=(const coverage_maps&) = delete;

cov_map_t funcnt_map;
cov_map_t linecnt_map;
private:
coverage_maps() = default;
};

#define REGISTER_HOST_FUNCTION(NAME, ...) \
static host_function_registrator<&interface::NAME, core_precondition, context_aware_check, ##__VA_ARGS__> \
NAME##_registrator_impl() { \
Expand All @@ -132,35 +117,42 @@ class coverage_maps {
REGISTER_HOST_FUNCTION(coverage_getinc)
REGISTER_HOST_FUNCTION(coverage_dump)

using eosio::coverage::coverage_maps;
using eosio::coverage::coverage_mode;

constexpr auto TESTCHAIN_N = eosio::name{"testchain"}.value;
heifner marked this conversation as resolved.
Show resolved Hide resolved

uint32_t interface::coverage_getinc(uint64_t code, uint32_t file_num, uint32_t func_or_line_num, uint32_t mode, bool inc) {
uint32_t r = 0;
if(inc) {
if (mode == 0) {
eosio::coverage::coverage_inc_cnt(code, file_num, func_or_line_num, coverage_maps::instance().funcnt_map);
} else if (mode == 1) {
eosio::coverage::coverage_inc_cnt(code, file_num, func_or_line_num, coverage_maps::instance().linecnt_map);
if (mode == coverage_mode::func) {
eosio::coverage::coverage_inc_cnt(code, file_num, func_or_line_num, coverage_maps<TESTCHAIN_N>::instance().funcnt_map);
} else if (mode == coverage_mode::line) {
eosio::coverage::coverage_inc_cnt(code, file_num, func_or_line_num, coverage_maps<TESTCHAIN_N>::instance().linecnt_map);
}
}
else {
if (mode == 0) {
return eosio::coverage::coverage_get_cnt(code, file_num, func_or_line_num, coverage_maps::instance().funcnt_map);
if (mode == coverage_mode::func) {
r = eosio::coverage::coverage_get_cnt(code, file_num, func_or_line_num, coverage_maps<TESTCHAIN_N>::instance().funcnt_map);
}
else if (mode == 1) {
return eosio::coverage::coverage_get_cnt(code, file_num, func_or_line_num, coverage_maps::instance().linecnt_map);
else if (mode == coverage_mode::line) {
r = eosio::coverage::coverage_get_cnt(code, file_num, func_or_line_num, coverage_maps<TESTCHAIN_N>::instance().linecnt_map);
}
}
return 0;
return r;
}

uint64_t interface::coverage_dump(uint64_t code, uint32_t file_num, eosio::vm::span<const char> file_name, uint32_t max, bool append, uint32_t mode, bool reset) {
if (reset) {
coverage_maps::instance().funcnt_map.clear();
coverage_maps::instance().linecnt_map.clear();
coverage_maps<TESTCHAIN_N>::instance().funcnt_map.clear();
coverage_maps<TESTCHAIN_N>::instance().linecnt_map.clear();
return 0;
}
if (mode == 0) {
heifner marked this conversation as resolved.
Show resolved Hide resolved
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps::instance().funcnt_map);
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps<TESTCHAIN_N>::instance().funcnt_map);
}
else if (mode == 1) {
heifner marked this conversation as resolved.
Show resolved Hide resolved
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps::instance().linecnt_map);
return eosio::coverage::coverage_dump(code, file_num, file_name.data(), file_name.size(), max, append, coverage_maps<TESTCHAIN_N>::instance().linecnt_map);
}
return 0;
}
Expand Down