Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
46201771
Commit
46201771
authored
Sep 06, 2016
by
Victor Kotlyar
Browse files
Moved threading tests for castor::server to cta::threading
parent
a336e284
Changes
8
Hide whitespace changes
Inline
Side-by-side
common/CMakeLists.txt
View file @
46201771
...
...
@@ -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
)
...
...
tapeserver/castor/server
/AtomicCounterTest.cpp
→
common/threading
/AtomicCounterTest.cpp
View file @
46201771
File moved
tapeserver/castor/server
/ThreadingBlockingQTests.cpp
→
common/threading
/ThreadingBlockingQTests.cpp
View file @
46201771
/******************************************************************************
/*
* 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
(
ca
stor_tape
_threading
,
BlockingQ_properly_working_on_helgrind
)
{
TEST
(
c
t
a_threading
,
BlockingQ_properly_working_on_helgrind
)
{
QueueType
sharedQueue
;
PingThread
ping
(
sharedQueue
);
...
...
tapeserver/castor/server
/ThreadingMPTests.cpp
→
common/threading
/ThreadingMPTests.cpp
View file @
46201771
/******************************************************************************
/*
* 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
c
astor
::
server
::
ChildProcess
::
Cleanup
{
class
emptyCleanup
:
public
c
ta
::
threading
::
ChildProcess
::
Cleanup
{
public:
virtual
void
operator
()()
{
};
};
class
myOtherProcess
:
public
c
astor
::
server
::
ChildProcess
{
class
myOtherProcess
:
public
c
ta
::
threading
::
ChildProcess
{
private:
int
run
()
{
...
...
@@ -49,17 +44,17 @@ namespace threadedUnitTests {
}
};
TEST
(
ca
stor_tape
_threading
,
ChildProcess_return_value
)
{
TEST
(
c
t
a_threading
,
ChildProcess_return_value
)
{
myOtherProcess
cp
;
emptyCleanup
cleanup
;
EXPECT_THROW
(
cp
.
exitCode
(),
c
astor
::
server
::
ChildProcess
::
ProcessNeverStarted
);
EXPECT_THROW
(
cp
.
exitCode
(),
c
ta
::
threading
::
ChildProcess
::
ProcessNeverStarted
);
EXPECT_NO_THROW
(
cp
.
start
(
cleanup
));
EXPECT_THROW
(
cp
.
exitCode
(),
c
astor
::
server
::
ChildProcess
::
ProcessStillRunning
);
EXPECT_THROW
(
cp
.
exitCode
(),
c
ta
::
threading
::
ChildProcess
::
ProcessStillRunning
);
EXPECT_NO_THROW
(
cp
.
wait
());
ASSERT_EQ
(
123
,
cp
.
exitCode
());
}
class
myInfiniteSpinner
:
public
c
astor
::
server
::
ChildProcess
{
class
myInfiniteSpinner
:
public
c
ta
::
threading
::
ChildProcess
{
private:
int
run
()
{
...
...
@@ -74,12 +69,12 @@ namespace threadedUnitTests {
}
};
TEST
(
ca
stor_tape
_threading
,
ChildProcess_killing
)
{
TEST
(
c
t
a_threading
,
ChildProcess_killing
)
{
myInfiniteSpinner
cp
;
emptyCleanup
cleanup
;
EXPECT_THROW
(
cp
.
kill
(),
c
astor
::
server
::
ChildProcess
::
ProcessNeverStarted
);
EXPECT_THROW
(
cp
.
kill
(),
c
ta
::
threading
::
ChildProcess
::
ProcessNeverStarted
);
EXPECT_NO_THROW
(
cp
.
start
(
cleanup
));
EXPECT_THROW
(
cp
.
exitCode
(),
c
astor
::
server
::
ChildProcess
::
ProcessStillRunning
);
EXPECT_THROW
(
cp
.
exitCode
(),
c
ta
::
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
(),
c
astor
::
server
::
ChildProcess
::
ProcessWasKilled
);
EXPECT_THROW
(
cp
.
exitCode
(),
c
ta
::
threading
::
ChildProcess
::
ProcessWasKilled
);
}
}
// namespace threadedUnitTests
tapeserver/castor/server
/ThreadingMTTests.cpp
→
common/threading
/ThreadingMTTests.cpp
View file @
46201771
/******************************************************************************
/*
* 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
(
ca
stor_tape
_threading
,
Thread_and_basic_locking
)
{
TEST
(
c
t
a_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
(
ca
stor_tape
_threading
,
PosixSemaphore_ping_pong
)
{
TEST
(
c
t
a_threading
,
PosixSemaphore_ping_pong
)
{
Semaphore_ping_pong
<
cta
::
threading
::
PosixSemaphore
>
spp
;
spp
.
start
();
spp
.
thread0
();
spp
.
wait
();
}
TEST
(
ca
stor_tape
_threading
,
CondVarSemaphore_ping_pong
)
{
TEST
(
c
t
a_threading
,
CondVarSemaphore_ping_pong
)
{
Semaphore_ping_pong
<
cta
::
threading
::
CondVarSemaphore
>
spp
;
spp
.
start
();
spp
.
thread0
();
...
...
@@ -106,7 +101,7 @@ namespace threadedUnitTests {
}
};
TEST
(
ca
stor_tape
_threading
,
Thread_exception_throwing
)
{
TEST
(
c
t
a_threading
,
Thread_exception_throwing
)
{
Thread_exception_throwing
t
,
t2
;
t
.
start
();
t2
.
start
();
...
...
tapeserver/castor/server
/ThreadingTests.cpp
→
common/threading
/ThreadingTests.cpp
View file @
46201771
/******************************************************************************
/*
* 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
(
ca
stor_tape
_threading
,
Mutex_properly_throws_exceptions
)
{
TEST
(
c
t
a_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
(
ca
stor_tape
_threading
,
MutexLocker_locks_and_properly_throws_exceptions
)
{
TEST
(
c
t
a_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
(
ca
stor_tape
_threading
,
PosixSemaphore_basic_counting
)
{
TEST
(
c
t
a_threading
,
PosixSemaphore_basic_counting
)
{
cta
::
threading
::
PosixSemaphore
s
(
2
);
ASSERT_NO_THROW
(
s
.
acquire
());
ASSERT_EQ
(
true
,
s
.
tryAcquire
());
ASSERT_FALSE
(
s
.
tryAcquire
());
}
TEST
(
ca
stor_tape
_threading
,
CondVarSemaphore_basic_counting
)
{
TEST
(
c
t
a_threading
,
CondVarSemaphore_basic_counting
)
{
cta
::
threading
::
CondVarSemaphore
s
(
2
);
ASSERT_NO_THROW
(
s
.
acquire
());
ASSERT_EQ
(
true
,
s
.
tryAcquire
());
ASSERT_FALSE
(
s
.
tryAcquire
());
}
TEST
(
ca
stor_tape
_threading
,
Semaphore_basic_counting
)
{
TEST
(
c
t
a_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
(
ca
stor_tape
_threading
,
Thread_exception_throwing
)
{
TEST
(
c
t
a_threading
,
Thread_exception_throwing
)
{
Thread_exception_throwing
t
,
t2
;
t
.
start
();
t2
.
start
();
...
...
tapeserver/castor/server/CMakeLists.txt
View file @
46201771
...
...
@@ -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
)
...
...
tests/helgrind.suppr
View file @
46201771
...
...
@@ -11,7 +11,7 @@
Helgrind:Misc
fun:pthread_mutex_*
...
fun:*unitTests*ca
stor_tape
_threading*
fun:*unitTests*c
t
a_threading*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
...
...
@@ -24,7 +24,7 @@
Helgrind:UnlockUnlocked
fun:pthread_mutex_*
...
fun:*unitTests*ca
stor_tape
_threading*
fun:*unitTests*c
t
a_threading*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
...
...
@@ -37,7 +37,7 @@
Helgrind:PthAPIerror
fun:pthread_mutex_*
...
fun:*unitTests*ca
stor_tape
_threading*
fun:*unitTests*c
t
a_threading*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
...
...
@@ -89,7 +89,7 @@
Helgrind:Misc
fun:pthread_cond_*
...
fun:_ZN9unitTests*ca
stor_tape
_threading_*
fun:_ZN9unitTests*c
t
a_threading_*
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8internal12TestInfoImpl3RunEv
fun:_ZN7testing8TestCase3RunEv
...
...
@@ -102,7 +102,7 @@
Helgrind:Misc
fun:pthread_mutex_*
...
fun:_ZN9unitTests*ca
stor_tape
_threading_*
fun:_ZN9unitTests*c
t
a_threading_*
...
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
...
...
@@ -119,7 +119,7 @@
Helgrind:PthAPIerror
fun:pthread_mutex_*
...
fun:_ZN9unitTests*ca
stor_tape
_threading_*
fun:_ZN9unitTests*c
t
a_threading_*
...
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
...
...
@@ -136,7 +136,7 @@
Helgrind:UnlockUnlocked
fun:pthread_mutex_*
...
fun:_ZN9unitTests*ca
stor_tape
_threading_*
fun:_ZN9unitTests*c
t
a_threading_*
...
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment