Commit 46201771 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Moved threading tests for castor::server to cta::threading

parent a336e284
......@@ -143,6 +143,11 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
SmartFdTest.cpp
threading/DaemonTest.cpp
threading/SocketPairTest.cpp
threading/ThreadingBlockingQTests.cpp
# threading/ThreadingMPTests.cpp is commented out because of errors caused by libust
threading/ThreadingMTTests.cpp
threading/ThreadingTests.cpp
threading/AtomicCounterTest.cpp
utils/UtilsTest.cpp
UserIdentityTest.cpp
optionalTest.cpp)
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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.
*
* Copyright (C) 2003 CERN
* 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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/threading/BlockingQueue.hpp"
#include <gtest/gtest.h>
......@@ -63,7 +59,7 @@ namespace threadedUnitTests {
};
TEST(castor_tape_threading, BlockingQ_properly_working_on_helgrind) {
TEST(cta_threading, BlockingQ_properly_working_on_helgrind) {
QueueType sharedQueue;
PingThread ping(sharedQueue);
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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.
*
* Copyright (C) 2003 CERN
* 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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "Threading.hpp"
......@@ -30,13 +25,13 @@
many memory leaks in the child process. */
namespace threadedUnitTests {
class emptyCleanup : public castor::server::ChildProcess::Cleanup {
class emptyCleanup : public cta::threading::ChildProcess::Cleanup {
public:
virtual void operator ()() { };
};
class myOtherProcess : public castor::server::ChildProcess {
class myOtherProcess : public cta::threading::ChildProcess {
private:
int run() {
......@@ -49,17 +44,17 @@ namespace threadedUnitTests {
}
};
TEST(castor_tape_threading, ChildProcess_return_value) {
TEST(cta_threading, ChildProcess_return_value) {
myOtherProcess cp;
emptyCleanup cleanup;
EXPECT_THROW(cp.exitCode(), castor::server::ChildProcess::ProcessNeverStarted);
EXPECT_THROW(cp.exitCode(), cta::threading::ChildProcess::ProcessNeverStarted);
EXPECT_NO_THROW(cp.start(cleanup));
EXPECT_THROW(cp.exitCode(), castor::server::ChildProcess::ProcessStillRunning);
EXPECT_THROW(cp.exitCode(), cta::threading::ChildProcess::ProcessStillRunning);
EXPECT_NO_THROW(cp.wait());
ASSERT_EQ(123, cp.exitCode());
}
class myInfiniteSpinner : public castor::server::ChildProcess {
class myInfiniteSpinner : public cta::threading::ChildProcess {
private:
int run() {
......@@ -74,12 +69,12 @@ namespace threadedUnitTests {
}
};
TEST(castor_tape_threading, ChildProcess_killing) {
TEST(cta_threading, ChildProcess_killing) {
myInfiniteSpinner cp;
emptyCleanup cleanup;
EXPECT_THROW(cp.kill(), castor::server::ChildProcess::ProcessNeverStarted);
EXPECT_THROW(cp.kill(), cta::threading::ChildProcess::ProcessNeverStarted);
EXPECT_NO_THROW(cp.start(cleanup));
EXPECT_THROW(cp.exitCode(), castor::server::ChildProcess::ProcessStillRunning);
EXPECT_THROW(cp.exitCode(), cta::threading::ChildProcess::ProcessStillRunning);
ASSERT_EQ(true, cp.running());
EXPECT_NO_THROW(cp.kill());
/* The effect is not immediate, wait a bit. */
......@@ -88,6 +83,6 @@ namespace threadedUnitTests {
ts.tv_nsec = 100*1000*1000;
nanosleep(&ts, NULL);
ASSERT_FALSE(cp.running());
EXPECT_THROW(cp.exitCode(), castor::server::ChildProcess::ProcessWasKilled);
EXPECT_THROW(cp.exitCode(), cta::threading::ChildProcess::ProcessWasKilled);
}
} // namespace threadedUnitTests
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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.
*
* Copyright (C) 2003 CERN
* 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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/threading/MutexLocker.hpp"
#include "common/threading/Threading.hpp"
......@@ -46,7 +41,7 @@ namespace threadedUnitTests {
}
};
TEST(castor_tape_threading, Thread_and_basic_locking) {
TEST(cta_threading, Thread_and_basic_locking) {
/* If we have race conditions here, helgrind will trigger. */
Thread_and_basic_locking mt;
mt.counter = 0;
......@@ -84,14 +79,14 @@ namespace threadedUnitTests {
}
};
TEST(castor_tape_threading, PosixSemaphore_ping_pong) {
TEST(cta_threading, PosixSemaphore_ping_pong) {
Semaphore_ping_pong<cta::threading::PosixSemaphore> spp;
spp.start();
spp.thread0();
spp.wait();
}
TEST(castor_tape_threading, CondVarSemaphore_ping_pong) {
TEST(cta_threading, CondVarSemaphore_ping_pong) {
Semaphore_ping_pong<cta::threading::CondVarSemaphore> spp;
spp.start();
spp.thread0();
......@@ -106,7 +101,7 @@ namespace threadedUnitTests {
}
};
TEST(castor_tape_threading, Thread_exception_throwing) {
TEST(cta_threading, Thread_exception_throwing) {
Thread_exception_throwing t, t2;
t.start();
t2.start();
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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.
*
* Copyright (C) 2003 CERN
* 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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/threading/MutexLocker.hpp"
#include "common/threading/Threading.hpp"
......@@ -33,7 +28,7 @@
* be run in helgrind */
namespace unitTests {
TEST(castor_tape_threading, Mutex_properly_throws_exceptions) {
TEST(cta_threading, Mutex_properly_throws_exceptions) {
/* Check that we properly get exception when doing wrong semaphore
operations */
cta::threading::Mutex m;
......@@ -45,7 +40,7 @@ namespace unitTests {
ASSERT_THROW(m.unlock(),cta::exception::Errnum);
}
TEST(castor_tape_threading, MutexLocker_locks_and_properly_throws_exceptions) {
TEST(cta_threading, MutexLocker_locks_and_properly_throws_exceptions) {
cta::threading::Mutex m;
{
cta::threading::MutexLocker ml(m);
......@@ -60,21 +55,21 @@ namespace unitTests {
ASSERT_NO_THROW(m.unlock());
}
TEST(castor_tape_threading, PosixSemaphore_basic_counting) {
TEST(cta_threading, PosixSemaphore_basic_counting) {
cta::threading::PosixSemaphore s(2);
ASSERT_NO_THROW(s.acquire());
ASSERT_EQ(true, s.tryAcquire());
ASSERT_FALSE(s.tryAcquire());
}
TEST(castor_tape_threading, CondVarSemaphore_basic_counting) {
TEST(cta_threading, CondVarSemaphore_basic_counting) {
cta::threading::CondVarSemaphore s(2);
ASSERT_NO_THROW(s.acquire());
ASSERT_EQ(true, s.tryAcquire());
ASSERT_FALSE(s.tryAcquire());
}
TEST(castor_tape_threading, Semaphore_basic_counting) {
TEST(cta_threading, Semaphore_basic_counting) {
cta::threading::Semaphore s(2);
ASSERT_NO_THROW(s.acquire());
ASSERT_EQ(true, s.tryAcquire());
......@@ -87,7 +82,7 @@ namespace unitTests {
throw cta::exception::Exception("Exception in child thread");
}
};
TEST(castor_tape_threading, Thread_exception_throwing) {
TEST(cta_threading, Thread_exception_throwing) {
Thread_exception_throwing t, t2;
t.start();
t2.start();
......
......@@ -15,12 +15,7 @@ include_directories(${PROJECT_SOURCE_DIR}/tapeserver/h)
#target_link_libraries(ctaserverutils cap ctautils)
add_library (ctaserverunittests SHARED
AtomicCounterTest.cpp
DaemonTest.cpp
ThreadingBlockingQTests.cpp
# ThreadingMPTests.cpp is commented out because of errors caused by libust
ThreadingMTTests.cpp
ThreadingTests.cpp)
DaemonTest.cpp)
target_link_libraries (ctaserverunittests ctautils)
......
......@@ -11,7 +11,7 @@
Helgrind:Misc
fun:pthread_mutex_*
...
fun:*unitTests*castor_tape_threading*
fun:*unitTests*cta_threading*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
......@@ -24,7 +24,7 @@
Helgrind:UnlockUnlocked
fun:pthread_mutex_*
...
fun:*unitTests*castor_tape_threading*
fun:*unitTests*cta_threading*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
......@@ -37,7 +37,7 @@
Helgrind:PthAPIerror
fun:pthread_mutex_*
...
fun:*unitTests*castor_tape_threading*
fun:*unitTests*cta_threading*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
......@@ -89,7 +89,7 @@
Helgrind:Misc
fun:pthread_cond_*
...
fun:_ZN9unitTests*castor_tape_threading_*
fun:_ZN9unitTests*cta_threading_*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
......@@ -102,7 +102,7 @@
Helgrind:Misc
fun:pthread_mutex_*
...
fun:_ZN9unitTests*castor_tape_threading_*
fun:_ZN9unitTests*cta_threading_*
...
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
......@@ -119,7 +119,7 @@
Helgrind:PthAPIerror
fun:pthread_mutex_*
...
fun:_ZN9unitTests*castor_tape_threading_*
fun:_ZN9unitTests*cta_threading_*
...
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
......@@ -136,7 +136,7 @@
Helgrind:UnlockUnlocked
fun:pthread_mutex_*
...
fun:_ZN9unitTests*castor_tape_threading_*
fun:_ZN9unitTests*cta_threading_*
...
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment