forked from lthn/blockchain
performance tests: free space check test improved (#133)
This commit is contained in:
parent
b24f3b5d6c
commit
309821c985
1 changed files with 59 additions and 0 deletions
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
std::string exec(const char* cmd)
|
||||
{
|
||||
std::array<char, 1024> buffer;
|
||||
|
|
@ -32,11 +34,59 @@ std::string exec(const char* cmd)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool try_write_test_file(size_t size_bytes)
|
||||
{
|
||||
|
||||
static const std::string filename = "test_out_file";
|
||||
static const fs::path filename_p = filename;
|
||||
|
||||
try
|
||||
{
|
||||
fs::ofstream s;
|
||||
s.open(filename, std::ios_base::binary | std::ios_base::out| std::ios::trunc);
|
||||
if(s.fail())
|
||||
return false;
|
||||
|
||||
uint8_t block[32 * 1024] = {};
|
||||
crypto::generate_random_bytes(sizeof block, &block);
|
||||
size_t size_total = 0;
|
||||
for (size_t i = 0; i < size_bytes / (sizeof block); ++i)
|
||||
{
|
||||
s.write((const char*)&block, sizeof block);
|
||||
size_total += sizeof block;
|
||||
}
|
||||
|
||||
if (size_bytes > size_total)
|
||||
s.write((const char*)&block, size_bytes - size_total);
|
||||
|
||||
s.close();
|
||||
|
||||
size_t size_actual = fs::file_size(filename_p);
|
||||
CHECK_AND_ASSERT_MES(size_bytes == size_actual, false, "size_bytes = " << size_bytes << ", size_actual = " << size_actual);
|
||||
|
||||
CHECK_AND_ASSERT_MES(fs::remove(filename_p), false, "remove failed");
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_PRINT_RED("caught: " << e.what(), LOG_LEVEL_0);
|
||||
return false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_PRINT_RED("caught unknown exception", LOG_LEVEL_0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void free_space_check()
|
||||
{
|
||||
static const size_t test_file_size = 1024 * 1024;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
std::string output;
|
||||
bool r = false;
|
||||
|
||||
#ifdef WIN32
|
||||
output = exec("dir");
|
||||
|
|
@ -46,6 +96,9 @@ void free_space_check()
|
|||
|
||||
LOG_PRINT_L0("test command output:" << std::endl << output);
|
||||
|
||||
r = try_write_test_file(test_file_size);
|
||||
LOG_PRINT_L0("test file write: " << (r ? "OK" : "fail"));
|
||||
|
||||
boost::filesystem::path current_path(".");
|
||||
|
||||
size_t counter = 0;
|
||||
|
|
@ -80,6 +133,12 @@ void free_space_check()
|
|||
si = fs::space(current_path);
|
||||
LOG_PRINT_YELLOW("2) fs::space() : available: " << si.available << ", free: " << si.free << ", capacity: " << si.capacity, LOG_LEVEL_0);
|
||||
|
||||
if (!try_write_test_file(test_file_size))
|
||||
{
|
||||
LOG_PRINT_YELLOW("try_write_test_file(" << test_file_size << ") failed", LOG_LEVEL_0);
|
||||
}
|
||||
|
||||
|
||||
need_backspace = false;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue