From 515ed44cbc439dbda4302d088cc86db3cc223def Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 5 Oct 2005 10:09:40 +0000 Subject: [PATCH] PR: complement on unit tests --- src/Basics/Makefile.in | 2 +- src/Basics/Test/BasicMainTest.hxx | 62 +++++++++++++++++++ src/Basics/Test/Makefile.in | 57 +++++++++++++++++ src/Logger/Test/Makefile.in | 57 +++++++++++++++++ src/Logger/Test/TestKiller.py | 35 +++++++++++ src/Makefile.in | 4 +- src/SALOMELocalTrace/Test/Makefile.in | 10 ++- .../Test/TestSALOMELocalTrace.cxx | 8 +++ .../Test/TestSALOMELocalTrace.py | 16 +++++ src/SALOMETraceCollector/Test/Makefile.in | 12 +++- .../Test/TestSALOMETraceCollector.cxx | 9 +++ .../Test/TestSALOMETraceCollector.py | 29 +++++++++ src/UnitTests/Makefile.in | 2 +- src/UnitTests/UnitTests.cxx | 54 +--------------- src/UnitTests/UnitTests.py | 29 +++++++++ src/Utils/Test/Makefile.in | 13 +++- src/Utils/Test/TestUtils.cxx | 10 +++ src/Utils/Test/TestUtils.py | 29 +++++++++ 18 files changed, 381 insertions(+), 57 deletions(-) create mode 100644 src/Basics/Test/BasicMainTest.hxx create mode 100644 src/Basics/Test/Makefile.in create mode 100644 src/Logger/Test/Makefile.in create mode 100644 src/Logger/Test/TestKiller.py create mode 100644 src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx create mode 100644 src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py create mode 100644 src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx create mode 100644 src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py create mode 100644 src/UnitTests/UnitTests.py create mode 100644 src/Utils/Test/TestUtils.cxx create mode 100644 src/Utils/Test/TestUtils.py diff --git a/src/Basics/Makefile.in b/src/Basics/Makefile.in index 2abc13887..612581468 100644 --- a/src/Basics/Makefile.in +++ b/src/Basics/Makefile.in @@ -1,4 +1,4 @@ -# SALOMELocalTrace : log on local machine +# Basics: General purpose C++ # # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS diff --git a/src/Basics/Test/BasicMainTest.hxx b/src/Basics/Test/BasicMainTest.hxx new file mode 100644 index 000000000..ace8349ed --- /dev/null +++ b/src/Basics/Test/BasicMainTest.hxx @@ -0,0 +1,62 @@ +#ifndef _BASICMAINTEST_HXX_ +#define _BASICMAINTEST_HXX_ + +#include +#include +#include +#include +#include +#include +#include +#include + +// ============================================================================ +/*! + * Main program source for Unit Tests with cppunit package does not depend + * on actual tests, so we use the same for all partial unit tests. + */ +// ============================================================================ + +int main(int argc, char* argv[]) +{ + // --- Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + + // --- Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // --- Add a listener that print dots as test run. +#ifdef WIN32 + CPPUNIT_NS::TextTestProgressListener progress; +#else + CPPUNIT_NS::BriefTestProgressListener progress; +#endif + controller.addListener( &progress ); + + // --- Get the top level suite from the registry + + CPPUNIT_NS::Test *suite = + CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); + + // --- Adds the test to the list of test to run + + CPPUNIT_NS::TestRunner runner; + runner.addTest( suite ); + runner.run( controller); + + // --- Print test in a compiler compatible format. + + CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr ); + outputter.write(); + + // --- Run the tests. + + bool wasSucessful = result.wasSuccessful(); + + // --- Return error code 1 if the one of test failed. + + return wasSucessful ? 0 : 1; +} + +#endif diff --git a/src/Basics/Test/Makefile.in b/src/Basics/Test/Makefile.in new file mode 100644 index 000000000..a4de9de02 --- /dev/null +++ b/src/Basics/Test/Makefile.in @@ -0,0 +1,57 @@ +# Basics: General purpose C++ +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE (EDF) +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= BasicMainTest.hxx + +EXPORT_PYSCRIPTS = + +# Libraries targets + +LIB = +LIB_SRC = + +# Executables targets + +BIN = +BIN_SRC = + +LIBS= @LIBS@ +LDFLAGS+= + +LDFLAGSFORBIN+= + +@CONCLUDE@ diff --git a/src/Logger/Test/Makefile.in b/src/Logger/Test/Makefile.in new file mode 100644 index 000000000..23060427d --- /dev/null +++ b/src/Logger/Test/Makefile.in @@ -0,0 +1,57 @@ +# Logger: CORBA Logger Server +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE (EDF) +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= + +EXPORT_PYSCRIPTS = TestKiller.py + +# Libraries targets + +LIB = +LIB_SRC = + +# Executables targets + +BIN = +BIN_SRC = + +LIBS= @LIBS@ +LDFLAGS+= + +LDFLAGSFORBIN+= + +@CONCLUDE@ diff --git a/src/Logger/Test/TestKiller.py b/src/Logger/Test/TestKiller.py new file mode 100644 index 000000000..5e1e338b8 --- /dev/null +++ b/src/Logger/Test/TestKiller.py @@ -0,0 +1,35 @@ + +import sys, os,signal,string,commands + +def killNamingService(): + """ + kills omniORB4 Naming Service on local machine. + Selects process corresponding to the port used in $OMNIORB_CONFIG file. + works only with a single line $OMNIORB_CONFIG like + InitRef = NameService=corbaname::: + """ + fic=os.environ['OMNIORB_CONFIG'] + f=open(fic,'r') + line=f.readline() + f.close() + port=string.split(line,':')[-1][0:4] + command='ps -eo pid,command | grep "omniNames -start '+str(port)+'"' + pid=string.split(commands.getoutput(command))[0] + os.kill(int(pid),signal.SIGKILL) + + +def killProcess(process_id): + """ + kills process on local machine, given a dictionary of running process + generated by runSalome.Server() class and derived, (method run). + kills also local Naming server. + """ + for pid, cmd in process_id.items(): + print "stop process %s : %s"% (pid, cmd[0]) + try: + os.kill(int(pid),signal.SIGKILL) + except: + print " ---- process %s : %s inexistant"% (pid, cmd[0]) + pass + pass + killNamingService() diff --git a/src/Makefile.in b/src/Makefile.in index a826da10d..5fcaae1ea 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -40,8 +40,8 @@ SUBDIRS = \ Logger \ SALOMETraceCollector \ Utils \ - GenericObj \ NamingService \ + GenericObj \ Registry \ ModuleCatalog \ DataTypeCatalog \ @@ -61,7 +61,9 @@ SUBDIRS = \ ModuleGenerator \ Communication \ \ + Basics/Test \ SALOMELocalTrace/Test \ + Logger/Test \ SALOMETraceCollector/Test \ Utils/Test \ UnitTests diff --git a/src/SALOMELocalTrace/Test/Makefile.in b/src/SALOMELocalTrace/Test/Makefile.in index 4bbc1d204..d10b2e7d7 100644 --- a/src/SALOMELocalTrace/Test/Makefile.in +++ b/src/SALOMELocalTrace/Test/Makefile.in @@ -37,15 +37,23 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # header files EXPORT_HEADERS= SALOMELocalTraceTest.hxx -EXPORT_PYSCRIPTS = +EXPORT_PYSCRIPTS = TestSALOMELocalTrace.py # Libraries targets LIB = libSALOMELocalTraceTest.la LIB_SRC = SALOMELocalTraceTest.cxx +# Executables targets + +BIN = TestSALOMELocalTrace +BIN_SRC = + LIBS= @LIBS@ LDFLAGS+= -lSALOMELocalTrace +LDFLAGSFORBIN+= \ + -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ + -lcppunit @CONCLUDE@ diff --git a/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx new file mode 100644 index 000000000..0706565c7 --- /dev/null +++ b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx @@ -0,0 +1,8 @@ + +// --- include all Unit Test from basics until the present directory + +#include "SALOMELocalTraceTest.hxx" + +// --- generic Main program from Basic/Test + +#include "BasicMainTest.hxx" diff --git a/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py new file mode 100644 index 000000000..b909fa482 --- /dev/null +++ b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py @@ -0,0 +1,16 @@ + +import sys, os,signal,string,commands +import runSalome + +# get SALOME environment : +# here we need KERNEL_ROOT_DIR, PATH, LD_LIBRARY_PATH + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# execute Unit Test + +command = ['TestSALOMELocalTrace'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# no process to kill diff --git a/src/SALOMETraceCollector/Test/Makefile.in b/src/SALOMETraceCollector/Test/Makefile.in index ffd7f8092..b12f5bf90 100644 --- a/src/SALOMETraceCollector/Test/Makefile.in +++ b/src/SALOMETraceCollector/Test/Makefile.in @@ -37,14 +37,24 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # header files EXPORT_HEADERS= SALOMETraceCollectorTest.hxx -EXPORT_PYSCRIPTS = +EXPORT_PYSCRIPTS = TestSALOMETraceCollector.py # Libraries targets LIB = libSALOMETraceCollectorTest.la LIB_SRC = SALOMETraceCollectorTest.cxx +# Executables targets + +BIN = TestSALOMETraceCollector +BIN_SRC = + LIBS= @LIBS@ LDFLAGS+= +LDFLAGSFORBIN+= \ + -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ + -lSALOMETraceCollectorTest \ + -lcppunit + @CONCLUDE@ diff --git a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx new file mode 100644 index 000000000..1ce22b7c3 --- /dev/null +++ b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx @@ -0,0 +1,9 @@ + +// --- include all Unit Test from basics until the present directory + +#include "SALOMELocalTraceTest.hxx" +#include "SALOMETraceCollectorTest.hxx" + +// --- generic Main program from Basic/Test + +#include "BasicMainTest.hxx" diff --git a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py new file mode 100644 index 000000000..2ae9f8de4 --- /dev/null +++ b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py @@ -0,0 +1,29 @@ + +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# execute Unit Test + +command = ['TestSALOMETraceCollector'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill Test process + +TestKiller.killProcess(runSalome.process_id) diff --git a/src/UnitTests/Makefile.in b/src/UnitTests/Makefile.in index f31b0bb35..212f9a0c4 100644 --- a/src/UnitTests/Makefile.in +++ b/src/UnitTests/Makefile.in @@ -36,7 +36,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # header files EXPORT_HEADERS= -EXPORT_PYSCRIPTS = +EXPORT_PYSCRIPTS = UnitTests.py # Libraries targets diff --git a/src/UnitTests/UnitTests.cxx b/src/UnitTests/UnitTests.cxx index 0c691449b..ec77f4752 100644 --- a/src/UnitTests/UnitTests.cxx +++ b/src/UnitTests/UnitTests.cxx @@ -1,58 +1,10 @@ -#include -#include -#include -#include -#include -#include -//#include -#include -#include +// --- include all Unit Test from basics until the present directory #include "SALOMELocalTraceTest.hxx" #include "SALOMETraceCollectorTest.hxx" - #include "UtilsTest.hxx" -int main(int argc, char* argv[]) -{ - // Create the event manager and test controller - CPPUNIT_NS::TestResult controller; - - // Add a listener that colllects test result - CPPUNIT_NS::TestResultCollector result; - controller.addListener( &result ); - - // Add a listener that print dots as test run. -#ifdef WIN32 - CPPUNIT_NS::TextTestProgressListener progress; -#else - CPPUNIT_NS::BriefTestProgressListener progress; -#endif - controller.addListener( &progress ); - - // Get the top level suite from the registry - //CppUnit::Test *suite =CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - CPPUNIT_NS::Test *suite = - CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); - - // Adds the test to the list of test to run - //CppUnit::TextUi::TestRunner runner; - CPPUNIT_NS::TestRunner runner; - runner.addTest( suite ); - runner.run( controller); - // Print test in a compiler compatible format. - CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr ); - outputter.write(); - - // Change the default outputter to a compiler error format outputter - // runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - // std::cerr ) ); - - // Run the tests. - //bool wasSucessful = runner.run(); - bool wasSucessful = result.wasSuccessful(); +// --- generic Main program from Basic/Test - // Return error code 1 if the one of test failed. - return wasSucessful ? 0 : 1; -} +#include "BasicMainTest.hxx" diff --git a/src/UnitTests/UnitTests.py b/src/UnitTests/UnitTests.py new file mode 100644 index 000000000..d34e6beb2 --- /dev/null +++ b/src/UnitTests/UnitTests.py @@ -0,0 +1,29 @@ + +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# execute Unit Test + +command = ['UnitTests'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill Test process + +TestKiller.killProcess(runSalome.process_id) diff --git a/src/Utils/Test/Makefile.in b/src/Utils/Test/Makefile.in index 92ef4bb10..67241ca7f 100644 --- a/src/Utils/Test/Makefile.in +++ b/src/Utils/Test/Makefile.in @@ -37,14 +37,25 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # header files EXPORT_HEADERS= UtilsTest.hxx -EXPORT_PYSCRIPTS = +EXPORT_PYSCRIPTS = TestUtils.py # Libraries targets LIB = libUtilsTest.la LIB_SRC = UtilsTest.cxx +# Executables targets + +BIN = TestUtils +BIN_SRC = + LIBS= @LIBS@ LDFLAGS+= +LDFLAGSFORBIN+= \ + -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ + -lSALOMETraceCollectorTest \ + -lUtilsTest -lOpUtil \ + -lcppunit + @CONCLUDE@ diff --git a/src/Utils/Test/TestUtils.cxx b/src/Utils/Test/TestUtils.cxx new file mode 100644 index 000000000..ec77f4752 --- /dev/null +++ b/src/Utils/Test/TestUtils.cxx @@ -0,0 +1,10 @@ + +// --- include all Unit Test from basics until the present directory + +#include "SALOMELocalTraceTest.hxx" +#include "SALOMETraceCollectorTest.hxx" +#include "UtilsTest.hxx" + +// --- generic Main program from Basic/Test + +#include "BasicMainTest.hxx" diff --git a/src/Utils/Test/TestUtils.py b/src/Utils/Test/TestUtils.py new file mode 100644 index 000000000..226eba335 --- /dev/null +++ b/src/Utils/Test/TestUtils.py @@ -0,0 +1,29 @@ + +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# execute Unit Test + +command = ['TestUtils'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill Test process + +TestKiller.killProcess(runSalome.process_id) -- 2.39.2