Skip to content

Commit

Permalink
Merge pull request #2055 from AntelopeIO/fix_eosvmoc_subtests_50
Browse files Browse the repository at this point in the history
[5.0] fix disabling EOS VM OC subjective limits in tests
  • Loading branch information
spoonincode authored Jan 8, 2024
2 parents 04774eb + 1b8d31a commit 4bfb636
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>
#include <string>

#include <fc/reflect/reflect.hpp>
#include <fc/io/raw.hpp>

#include <sys/resource.h>

Expand All @@ -25,6 +25,34 @@ struct config {
std::optional<size_t> generated_code_size_limit {16u*1024u*1024u};
};

}}}
//work around unexpected std::optional behavior
template <typename DS>
inline DS& operator>>(DS& ds, eosio::chain::eosvmoc::config& cfg) {
fc::raw::pack(ds, cfg.cache_size);
fc::raw::pack(ds, cfg.threads);

auto better_optional_unpack = [&]<typename T>(std::optional<T>& t) {
bool b; fc::raw::unpack( ds, b );
if(b) { t = T(); fc::raw::unpack( ds, *t ); }
else { t.reset(); }
};
better_optional_unpack(cfg.cpu_limit);
better_optional_unpack(cfg.vm_limit);
better_optional_unpack(cfg.stack_size_limit);
better_optional_unpack(cfg.generated_code_size_limit);

return ds;
}

template <typename DS>
inline DS& operator<<(DS& ds, const eosio::chain::eosvmoc::config& cfg) {
fc::raw::pack(ds, cfg.cache_size);
fc::raw::pack(ds, cfg.threads);
fc::raw::pack(ds, cfg.cpu_limit);
fc::raw::pack(ds, cfg.vm_limit);
fc::raw::pack(ds, cfg.stack_size_limit);
fc::raw::pack(ds, cfg.generated_code_size_limit);
return ds;
}

FC_REFLECT(eosio::chain::eosvmoc::config, (cache_size)(threads)(cpu_limit)(vm_limit)(stack_size_limit)(generated_code_size_limit))
}}}
17 changes: 13 additions & 4 deletions unittests/eosvmoc_limits_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ void limit_not_violated_test(const eosvmoc::config& eosvmoc_config) {
);
}

static eosvmoc::config make_eosvmoc_config_without_limits() {
eosvmoc::config cfg;
cfg.cpu_limit.reset();
cfg.vm_limit.reset();
cfg.stack_size_limit.reset();
cfg.generated_code_size_limit.reset();
return cfg;
}

// test all limits are not set for tests
BOOST_AUTO_TEST_CASE( limits_not_set ) { try {
validating_tester chain;
Expand All @@ -85,13 +94,13 @@ BOOST_AUTO_TEST_CASE( limits_not_set ) { try {
// test limits are not enforced unless limits in eosvmoc_config
// are modified
BOOST_AUTO_TEST_CASE( limits_not_enforced ) { try {
eosvmoc::config eosvmoc_config;
eosvmoc::config eosvmoc_config = make_eosvmoc_config_without_limits();
limit_not_violated_test(eosvmoc_config);
} FC_LOG_AND_RETHROW() }

// test VM limit are checked
BOOST_AUTO_TEST_CASE( vm_limit ) { try {
eosvmoc::config eosvmoc_config;
eosvmoc::config eosvmoc_config = make_eosvmoc_config_without_limits();

// set vm_limit to a small value such that it is exceeded
eosvmoc_config.vm_limit = 64u*1024u*1024u;
Expand All @@ -104,7 +113,7 @@ BOOST_AUTO_TEST_CASE( vm_limit ) { try {

// test stack size limit is checked
BOOST_AUTO_TEST_CASE( stack_limit ) { try {
eosvmoc::config eosvmoc_config;
eosvmoc::config eosvmoc_config = make_eosvmoc_config_without_limits();

// The stack size of the compiled WASM in the test is 104.
// Set stack_size_limit one less than the actual needed stack size
Expand All @@ -118,7 +127,7 @@ BOOST_AUTO_TEST_CASE( stack_limit ) { try {

// test generated code size limit is checked
BOOST_AUTO_TEST_CASE( generated_code_size_limit ) { try {
eosvmoc::config eosvmoc_config;
eosvmoc::config eosvmoc_config = make_eosvmoc_config_without_limits();

// The generated code size of the compiled WASM in the test is 36856.
// Set generated_code_size_limit to the actual generated code size
Expand Down

0 comments on commit 4bfb636

Please sign in to comment.