From: Joel Rosdahl Date: Sun, 3 Jul 2022 09:48:14 +0000 (+0200) Subject: test: Add program for manually testing the lock file implementation X-Git-Tag: v4.7~167 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=62df0178c0e7915a95399986d5685990ac924703;p=thirdparty%2Fccache.git test: Add program for manually testing the lock file implementation --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dcb399fa6..c30fa8a92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,16 +61,19 @@ target_link_libraries( PRIVATE standard_settings standard_warnings ZSTD::ZSTD Threads::Threads third_party ) -target_include_directories(ccache_framework PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(ccache_framework PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) if(REDIS_STORAGE_BACKEND) - target_compile_definitions(ccache_framework PRIVATE -DHAVE_REDIS_STORAGE_BACKEND) + target_compile_definitions(ccache_framework PUBLIC -DHAVE_REDIS_STORAGE_BACKEND) target_link_libraries( ccache_framework PUBLIC standard_settings standard_warnings HIREDIS::HIREDIS third_party ) endif() +add_executable(test-lockfile test_lockfile.cpp) +target_link_libraries(test-lockfile PRIVATE ccache_framework) + add_subdirectory(compression) add_subdirectory(core) add_subdirectory(storage) diff --git a/src/test_lockfile.cpp b/src/test_lockfile.cpp new file mode 100644 index 000000000..25f5dc2f1 --- /dev/null +++ b/src/test_lockfile.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2022 Joel Rosdahl and other contributors +// +// See doc/AUTHORS.adoc for a complete list of contributors. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// 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 General Public License for +// more details. +// +// You should have received a copy of the GNU 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 +#include +#include +#include +#include + +#include +#include + +int +main(int argc, char** argv) +{ + if (argc != 3) { + PRINT_RAW(stderr, "Usage: test-lockfile PATH SECONDS\n"); + return 1; + } + Config config; + config.update_from_environment(); + Logging::init(config); + + std::string path(argv[1]); + auto seconds = util::parse_signed(argv[2]); + if (!seconds) { + PRINT_RAW(stderr, "Error: Failed to parse seconds\n"); + return 1; + } + + PRINT_RAW(stdout, "Acquiring\n"); + { + Lockfile lock(path); + if (lock.acquired()) { + PRINT_RAW(stdout, "Acquired\n"); + PRINT( + stdout, "Sleeping {} second{}\n", *seconds, *seconds == 1 ? "" : "s"); + std::this_thread::sleep_for(std::chrono::seconds{*seconds}); + } else { + PRINT_RAW(stdout, "Failed to acquire\n"); + } + PRINT_RAW(stdout, "Releasing\n"); + } + PRINT_RAW(stdout, "Released\n"); +}