From a1b265e9eba018e9ea510c9224953c27fc271bc9 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 23 Oct 2020 15:32:30 +0200 Subject: [PATCH] clang-tidy --- test/lib/Cluster.hpp | 4 ++-- test/lib/Connection.cpp | 11 +++++++---- test/lib/Connection.hpp | 2 +- test/lib/ForkAndExec.cpp | 1 - test/lib/MemcachedCluster.cpp | 8 ++++---- test/lib/MemcachedCluster.hpp | 7 +++---- test/lib/Retry.cpp | 2 +- test/lib/ReturnMatcher.cpp | 9 --------- test/lib/ReturnMatcher.hpp | 3 --- test/lib/Server.hpp | 8 +++++--- test/lib/Shell.cpp | 5 ++--- test/lib/Shell.hpp | 2 +- test/lib/common.cpp | 1 - test/lib/common.hpp | 4 ++-- test/lib/random.cpp | 22 +++++++++++----------- 15 files changed, 39 insertions(+), 50 deletions(-) diff --git a/test/lib/Cluster.hpp b/test/lib/Cluster.hpp index c6c0cb92..1cc00ac8 100644 --- a/test/lib/Cluster.hpp +++ b/test/lib/Cluster.hpp @@ -27,11 +27,11 @@ public: Cluster(const Cluster &c) = delete; Cluster &operator=(const Cluster &c) = delete; - Cluster(Cluster &&c) + Cluster(Cluster &&c) noexcept : proto{} { *this = move(c); }; - Cluster &operator=(Cluster &&c) { + Cluster &operator=(Cluster &&c) noexcept { count = exchange(c.count, 0); proto = exchange(c.proto, Server{}); cluster = exchange(c.cluster, {}); diff --git a/test/lib/Connection.cpp b/test/lib/Connection.cpp index 05440723..b6df553b 100644 --- a/test/lib/Connection.cpp +++ b/test/lib/Connection.cpp @@ -2,15 +2,18 @@ #include #include -#include #include +#if !(HAVE_SOCK_NONBLOCK && HAVE_SOCK_CLOEXEC) +# include +# define SOCK_NONBLOCK O_NONBLOCK +# define SOCK_CLOEXEC O_CLOEXEC +#endif + static inline int socket_ex(int af, int so, int pf, int fl) { #if HAVE_SOCK_NONBLOCK && HAVE_SOCK_CLOEXEC return socket(af, so | fl, pf); #else -# define SOCK_NONBLOCK O_NONBLOCK -# define SOCK_CLOEXEC O_CLOEXEC auto sock = socket(af, so, pf); if (0 <= sock) { if (0 > fcntl(sock, F_SETFL, fl | fcntl(sock, F_GETFL))) { @@ -186,7 +189,7 @@ bool Connection::open() { string Connection::error(const initializer_list &args) { stringstream ss; - for (auto &arg : args) { + for (const auto &arg : args) { ss << arg; } diff --git a/test/lib/Connection.hpp b/test/lib/Connection.hpp index 380116e6..f087a697 100644 --- a/test/lib/Connection.hpp +++ b/test/lib/Connection.hpp @@ -51,7 +51,7 @@ private: UNIX = sizeof(sockaddr_un), INET = sizeof(sockaddr_in), INET6 = sizeof(sockaddr_in6) - } size; + } size = NONE; bool connected{false}; static string error(const initializer_list &args); diff --git a/test/lib/ForkAndExec.cpp b/test/lib/ForkAndExec.cpp index e182c7c4..ac30dd02 100644 --- a/test/lib/ForkAndExec.cpp +++ b/test/lib/ForkAndExec.cpp @@ -1,6 +1,5 @@ #include "ForkAndExec.hpp" -#include #include #include diff --git a/test/lib/MemcachedCluster.cpp b/test/lib/MemcachedCluster.cpp index 06e2c7f1..f94e86ca 100644 --- a/test/lib/MemcachedCluster.cpp +++ b/test/lib/MemcachedCluster.cpp @@ -46,7 +46,7 @@ void MemcachedCluster::init() { } MemcachedCluster::~MemcachedCluster() { - if (memcmp(&memc, &empty_memc, sizeof(memc))) { + if (!!memcmp(&memc, &empty_memc, sizeof(memc))) { memcached_free(&memc); } } @@ -71,13 +71,13 @@ MemcachedCluster::MemcachedCluster(Cluster &&cluster_, behaviors_t to_set_) init(); } -MemcachedCluster::MemcachedCluster(MemcachedCluster &&mc) +MemcachedCluster::MemcachedCluster(MemcachedCluster &&mc) noexcept : cluster{Server{}} { *this = move(mc); } -MemcachedCluster &MemcachedCluster::operator=(MemcachedCluster &&mc) { +MemcachedCluster &MemcachedCluster::operator=(MemcachedCluster &&mc) noexcept { cluster = move(mc.cluster); memcached_clone(&memc, &mc.memc); returns = ReturnMatcher{&memc}; @@ -146,7 +146,7 @@ void MemcachedCluster::enableReplication() { MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, memcached_server_count(&memc) - 1)); } -void MemcachedCluster::killOneServer() { +void MemcachedCluster::killOneServer() const { const auto &servers = cluster.getServers(); const auto &victim = servers[random_num(0UL, servers.size() - 1)]; ::kill(victim.getPid(), SIGKILL); diff --git a/test/lib/MemcachedCluster.hpp b/test/lib/MemcachedCluster.hpp index 202d878d..dcda9ddd 100644 --- a/test/lib/MemcachedCluster.hpp +++ b/test/lib/MemcachedCluster.hpp @@ -35,13 +35,12 @@ public: MemcachedCluster(const MemcachedCluster &) = delete; MemcachedCluster &operator=(const MemcachedCluster &) = delete; - MemcachedCluster(MemcachedCluster &&mc); - MemcachedCluster &operator=(MemcachedCluster &&mc); + MemcachedCluster(MemcachedCluster &&mc) noexcept; + MemcachedCluster &operator=(MemcachedCluster &&mc) noexcept; void enableBinaryProto(bool enable = true); void enableBuffering(bool enable = true); void enableReplication(); - void enableUdp(bool enable = true); void flush(); static MemcachedCluster mixed(); @@ -53,7 +52,7 @@ public: static MemcachedCluster sasl(); #endif - void killOneServer(); + void killOneServer() const; private: behaviors_t to_set; diff --git a/test/lib/Retry.cpp b/test/lib/Retry.cpp index 71fde0e0..d8061e31 100644 --- a/test/lib/Retry.cpp +++ b/test/lib/Retry.cpp @@ -15,7 +15,7 @@ bool Retry::operator()() { return true; } this_thread::sleep_for(dur); - dur *= 1.2; + dur += dur/10; } return false; diff --git a/test/lib/ReturnMatcher.cpp b/test/lib/ReturnMatcher.cpp index 863945e8..82f42d65 100644 --- a/test/lib/ReturnMatcher.cpp +++ b/test/lib/ReturnMatcher.cpp @@ -1,11 +1,5 @@ #include "ReturnMatcher.hpp" -ReturnMatcher &ReturnMatcher::operator=(ReturnMatcher &&rm) { - memc = exchange(rm.memc, nullptr); - expected = rm.expected; - return *this; -} - bool ReturnMatcher::match(const memcached_return_t &arg) const { return arg == expected; } @@ -23,6 +17,3 @@ string ReturnMatcher::describe() const { + "\n actual: " + memcached_last_error_message(memc); } -ReturnMatcher::ReturnMatcher(ReturnMatcher &&rm) { - *this = move(rm); -} diff --git a/test/lib/ReturnMatcher.hpp b/test/lib/ReturnMatcher.hpp index 5de5b3b2..a5225319 100644 --- a/test/lib/ReturnMatcher.hpp +++ b/test/lib/ReturnMatcher.hpp @@ -26,9 +26,6 @@ public: ReturnMatcher(const ReturnMatcher &) = default; - ReturnMatcher(ReturnMatcher &&rm); - ReturnMatcher &operator=(ReturnMatcher &&rm); - bool match(const memcached_return_t &arg) const override; ReturnMatcher success(); ReturnMatcher operator()(memcached_return_t expected_); diff --git a/test/lib/Server.hpp b/test/lib/Server.hpp index 5e263267..9b1d4a73 100644 --- a/test/lib/Server.hpp +++ b/test/lib/Server.hpp @@ -36,8 +36,10 @@ public: Server(const Server &s); Server &operator=(const Server &s); - Server(Server &&s) { *this = move(s); }; - Server &operator=(Server &&s) { + Server(Server &&s) noexcept { + *this = move(s); + }; + Server &operator=(Server &&s) noexcept { binary = exchange(s.binary, "false"); args = exchange(s.args, {}); pid = exchange(s.pid, 0); @@ -89,7 +91,7 @@ private: optional handleArg(vector &arr, const string &arg, const arg_func_t &next_arg); }; -inline ostream &operator<<(ostream &out, const socket_or_port_t sop) { +inline ostream &operator<<(ostream &out, const socket_or_port_t &sop) { if (holds_alternative(sop)) { out << get(sop); } else { diff --git a/test/lib/Shell.cpp b/test/lib/Shell.cpp index cd3017ac..4d669095 100644 --- a/test/lib/Shell.cpp +++ b/test/lib/Shell.cpp @@ -1,7 +1,6 @@ #include "Shell.hpp" #include -#include bool Shell::run(const string &command_, string &output) { auto command = prepareCommand(command_); @@ -47,8 +46,8 @@ Shell::Shell(bool redirect_stderr) } } -Shell::Shell(const string &prefix_, bool redirect_stderr) -: prefix{prefix_} +Shell::Shell(string prefix_, bool redirect_stderr) +: prefix{move(prefix_)} , redirect{redirect_stderr} { if (!system(nullptr)) { diff --git a/test/lib/Shell.hpp b/test/lib/Shell.hpp index a1496bb5..515bf1b5 100644 --- a/test/lib/Shell.hpp +++ b/test/lib/Shell.hpp @@ -20,7 +20,7 @@ class Shell { public: explicit Shell(bool redirect_stderr = true); - explicit Shell(const string &prefix, bool redirect_stderr = true); + explicit Shell(string prefix, bool redirect_stderr = true); bool run(const string &command, string &output); bool run(const string &command); diff --git a/test/lib/common.cpp b/test/lib/common.cpp index 04dd79d6..c516a3db 100644 --- a/test/lib/common.cpp +++ b/test/lib/common.cpp @@ -1,5 +1,4 @@ #include "common.hpp" -#include "Connection.hpp" #include diff --git a/test/lib/common.hpp b/test/lib/common.hpp index a76a1ca8..a0fdf384 100644 --- a/test/lib/common.hpp +++ b/test/lib/common.hpp @@ -87,8 +87,8 @@ public: close(fd); unlink(fn); } - int getFd() const { return fd; } - const char *getFn() const { return fn; } + [[nodiscard]] int getFd() const { return fd; } + [[nodiscard]] const char *getFn() const { return fn; } bool put(const char *buf, size_t len) const { return static_cast(len) == write(fd, buf, len); } diff --git a/test/lib/random.cpp b/test/lib/random.cpp index 50cc53db..6aab8875 100644 --- a/test/lib/random.cpp +++ b/test/lib/random.cpp @@ -4,17 +4,17 @@ #include // getpid() unsigned random_port() { - retry: - auto port = random_num(5000, 32000); - Connection conn(port); - - if (!conn.open()) { - return port; - } - if (!conn.isOpen()) { - return port; - } - goto retry; + do { + auto port = random_num(5000, 32000); + Connection conn(port); + + if (!conn.open()) { + return port; + } + if (!conn.isOpen()) { + return port; + } + } while(true); } string random_port_string(const string &) { -- 2.30.2