diff --git a/core/src/tools/CMakeLists.txt b/core/src/tools/CMakeLists.txt index bc6344ee957..83413da0318 100644 --- a/core/src/tools/CMakeLists.txt +++ b/core/src/tools/CMakeLists.txt @@ -56,6 +56,10 @@ if(NOT HAVE_WIN32) target_link_libraries(bpluginfo bareos ${DL_LIBRARIES} CLI11::CLI11) endif() +add_executable(gentestdata) +target_sources(gentestdata PRIVATE gentestdata.cc) +target_link_libraries(gentestdata PRIVATE CLI11::CLI11) + set(TOOLS_BIN bsmtp bwild bregex) set(TOOLS_SBIN bscrypto bwild bregex) diff --git a/core/src/tools/gentestdata.cc b/core/src/tools/gentestdata.cc new file mode 100644 index 00000000000..b031799d27b --- /dev/null +++ b/core/src/tools/gentestdata.cc @@ -0,0 +1,56 @@ +/* + BAREOSĀ® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2023-2023 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include "CLI/App.hpp" +#include "CLI/Formatter.hpp" +#include "CLI/Config.hpp" +#include +#include + +static void print_random(long); + +int main(int argc, char** argv) +{ + CLI::App app{"Generate a stream of pseudo-random testdata"}; + + long bytes{1024}; + app.add_option("-s,--size", bytes, "Number of bytes to create"); + + CLI11_PARSE(app, argc, argv); + + print_random(bytes); + return 0; +} + + +void print_random(long bytes) +{ + std::mt19937_64 generator{}; + using val_type = decltype(generator()); + + char buf[sizeof(val_type)]; + for (auto remaining = bytes; remaining > 0; remaining -= sizeof(val_type)) { + auto value = generator(); + memcpy(buf, &value, sizeof(val_type)); + for (auto i = 0u; i < sizeof(val_type) && remaining - i > 0; i++) { + std::putchar(buf[i]); + } + } +}