X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftest%2Fcommon%2Ftest_mutex_debug.cc;fp=src%2Fceph%2Fsrc%2Ftest%2Fcommon%2Ftest_mutex_debug.cc;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=49cd499557f0dd40ac2bd1fde3066bee8d830040;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/test/common/test_mutex_debug.cc b/src/ceph/src/test/common/test_mutex_debug.cc deleted file mode 100644 index 49cd499..0000000 --- a/src/ceph/src/test/common/test_mutex_debug.cc +++ /dev/null @@ -1,101 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 &smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2011 New Dream Network - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License version 2, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include -#include -#include - -#include "common/mutex_debug.h" - -#include "gtest/gtest.h" - - -template -static bool test_try_lock(Mutex* m) { - if (!m->try_lock()) - return false; - m->unlock(); - return true; -} - -template -static void test_lock() { - Mutex m; - auto ttl = &test_try_lock; - - m.lock(); - ASSERT_TRUE(m.is_locked()); - auto f1 = std::async(std::launch::async, ttl, &m); - ASSERT_FALSE(f1.get()); - - ASSERT_TRUE(m.is_locked()); - ASSERT_TRUE(!!m); - - m.unlock(); - ASSERT_FALSE(m.is_locked()); - ASSERT_FALSE(!!m); - - auto f3 = std::async(std::launch::async, ttl, &m); - ASSERT_TRUE(f3.get()); - - ASSERT_FALSE(m.is_locked()); - ASSERT_FALSE(!!m); -} - -TEST(MutexDebug, Lock) { - test_lock(); -} - -TEST(MutexDebug, NotRecursive) { - ceph::mutex_debug m; - auto ttl = &test_try_lock; - - ASSERT_NO_THROW(m.lock()); - ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - - ASSERT_THROW(m.lock(), std::system_error); - ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - - ASSERT_NO_THROW(m.unlock()); - ASSERT_FALSE(m.is_locked()); - ASSERT_TRUE(std::async(std::launch::async, ttl, &m).get()); -} - -TEST(MutexRecursiveDebug, Lock) { - test_lock(); -} - - -TEST(MutexRecursiveDebug, Recursive) { - ceph::mutex_recursive_debug m; - auto ttl = &test_try_lock; - - ASSERT_NO_THROW(m.lock()); - ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - - ASSERT_NO_THROW(m.lock()); - ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - - ASSERT_NO_THROW(m.unlock()); - ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - - ASSERT_NO_THROW(m.unlock()); - ASSERT_FALSE(m.is_locked()); - ASSERT_TRUE(std::async(std::launch::async, ttl, &m).get()); -}