Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel execution of DICOM tests #1182

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Applications/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ if(CTK_APP_ctkDICOMQuery AND CTK_APP_ctkDICOMRetrieve)
)

set_property(TEST ${testname} PROPERTY ENVIRONMENT_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}")

set_property(TEST ${testname} PROPERTY RESOURCE_LOCK "dcmqrscp")

endif()
15 changes: 12 additions & 3 deletions Applications/Testing/Cpp/ctkDICOMApplicationTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,19 @@ int main(int argc, char * argv []) {
QCoreApplication app(argc, argv);
QTextStream out(stdout);

if ( argc < 10 )
QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 9)
{
out << "ERROR: invalid arguments. Should be:\n";
out << " ctkDICOMApplicationTest1 <dcmqrscp> <configfile> <dicomData1> <dcmData2> <storescu> <ctkDICOMQuery> <ctkDICOMRetrieve> <retrieveDirectory>\n";
std::cerr << "ERROR: invalid or missing arguments.\n\n"
<< "Usage: " << qPrintable(testName)
<< " <dcmqrscp> <configfile>"
" <dicomData1>"
" <dicomData2>"
" <storescu>"
" <ctkDICOMQuery> <databaseFile>"
" <ctkDICOMRetrieve> <retrieveDirectory>\n";
return EXIT_FAILURE;
}

Expand Down
18 changes: 13 additions & 5 deletions Applications/ctkDICOM/Testing/Cpp/ctkDICOMTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
int ctkDICOMTest1(int argc, char * argv [])
{
QCoreApplication app(argc, argv);
if (app.arguments().count() != 2)

QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 1)
{
std::cerr << "Line " << __LINE__ << " - Failed to run " << argv[0] << "\n"
<< "Usage:\n"
<< " " << argv[0] << " /path/to/ctkDICOM";
std::cerr << "Usage: " << qPrintable(testName)
<< " <path-to-ctkDICOM-executable>" << std::endl;
return EXIT_FAILURE;
}
QString command = app.arguments().at(1);

QString command = arguments.at(0);

std::cout << "Testing:\n"
<< qPrintable(command) << std::endl;

QProcess process;
process.start(command, /* arguments= */ QStringList());
bool res = process.waitForStarted();
Expand Down
18 changes: 13 additions & 5 deletions Applications/ctkDICOM2/Testing/Cpp/ctkDICOM2Test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
int ctkDICOM2Test1(int argc, char * argv [])
{
QCoreApplication app(argc, argv);
if (app.arguments().count() != 2)

QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 1)
{
std::cerr << "Line " << __LINE__ << " - Failed to run " << argv[0] << "\n"
<< "Usage:\n"
<< " " << argv[0] << " /path/to/ctkDICOM";
std::cerr << "Usage: " << qPrintable(testName)
<< " <path-to-ctkDICOM-executable>" << std::endl;
return EXIT_FAILURE;
}
QString command = app.arguments().at(1);

QString command = arguments.at(0);

std::cout << "Testing:\n"
<< qPrintable(command) << std::endl;

QProcess process;
process.start(command, /* arguments= */ QStringList());
bool res = process.waitForStarted();
Expand Down
23 changes: 16 additions & 7 deletions Applications/ctkDICOMDemoSCU/Testing/Cpp/ctkDICOMDemoSCUTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,28 @@
int ctkDICOMDemoSCUTest1(int argc, char * argv [])
{
QCoreApplication app(argc, argv);

QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 1)
{
std::cerr << "Usage: " << qPrintable(testName)
<< " <path-to-ctkDICOMDemoSCU-executable>" << std::endl;
return EXIT_FAILURE;
}

QString command = arguments.at(0);

QString peer("www.dicomserver.co.uk");
QString port("104");
QString aeTitle("MOVESCP");
QStringList parameters;
parameters << peer << port << aeTitle;

if (argc < 2)
{
std::cerr << "Must specify path to ctkDICOMDemoSCU on command line\n";
return EXIT_FAILURE;
}
std::cout << "Testing ctkDICOMDemoSCU: " << argv[1] << "\n";
QString command = QString(argv[1]);
std::cout << "Testing:\n"
<< qPrintable(command) << " "
<< qPrintable(parameters.join(" ")) << std::endl;

int res = QProcess::execute(command, parameters);
if (res != EXIT_SUCCESS)
Expand Down
12 changes: 9 additions & 3 deletions Applications/ctkDICOMHost/Testing/Cpp/ctkDICOMHostTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ int ctkDICOMHostTest1(int argc, char * argv [])
QCoreApplication app(argc, argv);

QStringList arguments = app.arguments();
arguments.pop_front(); // remove "program" name
if (!arguments.count())
QString testName = arguments.takeFirst();

if (arguments.count() != 1)
{
std::cerr << "Usage: ctkDICOMHostTest1 /path/to/ctkDICOMHost" << std::endl;
std::cerr << "Usage: " << qPrintable(testName)
<< " <path-to-ctkDICOMHost-executable>" << std::endl;
return EXIT_FAILURE;
}

QString command = arguments.at(0);

std::cout << "Testing:\n"
<< qPrintable(command) << std::endl;

QProcess process;
process.start(command, /* arguments= */ QStringList());
bool res = process.waitForStarted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,28 @@
int ctkDICOMIndexerAppTest1(int argc, char * argv [])
{
QCoreApplication app(argc, argv);

QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

QString database("test.db");

if (argc < 2)
if (arguments.count() != 1)
{
std::cerr << "Must specify path to ctkDICOMIndexer on command line\n";
std::cerr << "Usage: " << qPrintable(testName)
<< " <path-to-ctkDICOMIndexer-executable>" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Testing ctkDICOMIndexer: " << argv[1] << "\n";
QString command = QString(argv[1]);

QString command = arguments.at(0);

QStringList parameters;
parameters << "--init" << database;

std::cout << "Testing:\n"
<< qPrintable(command) << " "
<< qPrintable(parameters.join(" ")) << std::endl;

int res = QProcess::execute(command, parameters);
if (res != EXIT_SUCCESS)
{
Expand Down
8 changes: 6 additions & 2 deletions Libs/DICOM/Core/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SIMPLE_TEST(ctkDICOMIndexerTest1 )

# ctkDICOMModel
SIMPLE_TEST(ctkDICOMModelTest1
${CMAKE_CURRENT_BINARY_DIR}/dicom.db
${CMAKE_CURRENT_BINARY_DIR}/Testing/Temporary/ctkDICOMModelTest1-dicom.db
${CMAKE_CURRENT_SOURCE_DIR}/../../Resources/dicom-sample.sql
)
SIMPLE_TEST(ctkDICOMPersonNameTest1)
Expand All @@ -59,23 +59,27 @@ SIMPLE_TEST( ctkDICOMQueryTest2
${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA
${CTKData_DIR}/Data/DICOM/MRHEAD/000056.IMA
)
set_property(TEST "ctkDICOMQueryTest2" PROPERTY RESOURCE_LOCK "dcmqrscp")

# ctkDICOMRetrieve
SIMPLE_TEST( ctkDICOMRetrieveTest1)
SIMPLE_TEST( ctkDICOMRetrieveTest2
${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA
${CTKData_DIR}/Data/DICOM/MRHEAD/000056.IMA
)
set_property(TEST "ctkDICOMRetrieveTest2" PROPERTY RESOURCE_LOCK "dcmqrscp")

# ctkDICOMCore
SIMPLE_TEST( ctkDICOMCoreTest1
${CMAKE_CURRENT_BINARY_DIR}/dicom.db
${CMAKE_CURRENT_BINARY_DIR}/Testing/Temporary/ctkDICOMCoreTest1-dicom.db
${CMAKE_CURRENT_SOURCE_DIR}/../../Resources/dicom-sample.sql
)

# ctkDICOMTester
SIMPLE_TEST( ctkDICOMTesterTest1 )
set_property(TEST "ctkDICOMTesterTest1" PROPERTY RESOURCE_LOCK "dcmqrscp")
SIMPLE_TEST( ctkDICOMTesterTest2
${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA
${CTKData_DIR}/Data/DICOM/MRHEAD/000056.IMA
)
set_property(TEST "ctkDICOMTesterTest2" PROPERTY RESOURCE_LOCK "dcmqrscp")
40 changes: 26 additions & 14 deletions Libs/DICOM/Core/Testing/Cpp/ctkDICOMCoreTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <QCoreApplication>
#include <QTextStream>

// ctkCore includes
#include <ctkCoreTestingMacros.h>

// ctkDICOMCore includes
#include "ctkDICOMDatabase.h"

Expand All @@ -33,28 +36,37 @@
int ctkDICOMCoreTest1(int argc, char * argv []) {

QCoreApplication app(argc, argv);
QTextStream out(stdout);

QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 2)
{
std::cerr << "Usage: " << qPrintable(testName)
<< " <dumpfile1.sql> <dumpfile2.sql>" << std::endl;
return EXIT_FAILURE;
}

QString sqlFileName1(arguments.at(0));
QString sqlFileName2(arguments.at(1));

try
{
ctkDICOMDatabase myCTK( argv[1] );
out << "open db success\n";
/// make sure it is empty and properly initialized
if (! myCTK.initializeDatabase() ) {
out << "ERROR: basic DB init failed";
return EXIT_FAILURE;
};
ctkDICOMDatabase myCTK(sqlFileName1);
CHECK_BOOL(myCTK.initializeDatabase(), true);

/// insert some sample data
if (! myCTK.initializeDatabase(argv[2]) ) {
out << "ERROR: sample DB init failed";
return EXIT_FAILURE;
};
CHECK_BOOL(myCTK.initializeDatabase(sqlFileName2.toUtf8()), true);

myCTK.closeDatabase();
}
}
catch (const std::exception& e)
{
out << "ERROR: " << e.what();
std::cerr << "Error when opening the data base file: " << argv[1]
<< " error: " << e.what() << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

52 changes: 26 additions & 26 deletions Libs/DICOM/Core/Testing/Cpp/ctkDICOMDatabaseTest2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ int ctkDICOMDatabaseTest2( int argc, char * argv [] )
{
QCoreApplication app(argc, argv);

if (argc < 2)
QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 1)
{
std::cerr << "ctkDICOMDatabaseTest2: missing dicom filePath argument";
std::cerr << std::endl;
std::cerr << "Usage: " << qPrintable(testName)
<< " <path-to-dicom-file>" << std::endl;
return EXIT_FAILURE;
}

QString dicomFilePath(argv[1]);
QString dicomFilePath(arguments.at(0));

QTemporaryDir tempDirectory;
CHECK_BOOL(tempDirectory.isValid(), true);
Expand Down Expand Up @@ -91,28 +94,25 @@ int ctkDICOMDatabaseTest2( int argc, char * argv [] )
//
// Test that the tag interface works to parse ascii
//
QString tag("0008,103e");
unsigned short group, element;
if ( !database.tagToGroupElement(tag, group, element) )
{
std::cerr << "ctkDICOMDatabase: could not parse tag" << std::endl;
return EXIT_FAILURE;
}

if ( group != 0x8 || element != 0x103e )
{
std::cerr << "ctkDICOMDatabase: expected: " << "0008,103e" << std::endl;
std::cerr << "ctkDICOMDatabase: got: " << group << " " << element << std::endl;
std::cerr << "ctkDICOMDatabase: parsed tag does not match group/element" << std::endl;
return EXIT_FAILURE;
}

if ( database.groupElementToTag(group, element) != tag.toUpper() )
{
std::cerr << "ctkDICOMDatabase: could not convert a uints to tag string" << std::endl;
return EXIT_FAILURE;
}
{
unsigned short group, element;
QString tag("0008,103E"); // upper case
CHECK_BOOL(database.tagToGroupElement(tag, group, element), true);
CHECK_INT(group, 0x8);
CHECK_INT(element, 0x103E);
}
{
unsigned short group, element;
QString tag("0008,103e"); // lower case
CHECK_BOOL(database.tagToGroupElement(tag, group, element), true);
CHECK_INT(group, 0x8);
CHECK_INT(element, 0x103E);
}

//
// Test that conversion from uints to tag string works
//
CHECK_QSTRING(database.groupElementToTag(0x8, 0x103E), "0008,103E");

//
// Basic test:
Expand Down Expand Up @@ -161,7 +161,7 @@ int ctkDICOMDatabaseTest2( int argc, char * argv [] )
return EXIT_FAILURE;
}


QString tag("0008,103E");
if (database.cachedTag(instanceUID, tag) != QString(""))
{
std::cerr << "ctkDICOMDatabase: tag cache should return empty string for unknown instance tag" << std::endl;
Expand Down
14 changes: 10 additions & 4 deletions Libs/DICOM/Core/Testing/Cpp/ctkDICOMDatabaseTest3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ int ctkDICOMDatabaseTest3( int argc, char * argv [] )
{
QCoreApplication app(argc, argv);

if (argc <= 1)
QStringList arguments = app.arguments();
QString testName = arguments.takeFirst();

if (arguments.count() != 1)
{
std::cerr << "Warning, no sql file given. Test stops" << std::endl;
std::cerr << "Usage: ctkDICOMDatabaseTest3 <olddumpfile.sql>" << std::endl;
std::cerr << "Usage: " << qPrintable(testName)
<< " <dumpfile.sql>" << std::endl;
return EXIT_FAILURE;
}

QString sqlFileName(arguments.at(0));

QTemporaryDir tempDirectory;
CHECK_BOOL(tempDirectory.isValid(), true);

Expand All @@ -59,9 +65,9 @@ int ctkDICOMDatabaseTest3( int argc, char * argv [] )
{
ctkDICOMDatabase myCTK( databaseFileName );

if (!myCTK.initializeDatabase(argv[1]))
if (!myCTK.initializeDatabase(sqlFileName.toUtf8()))
{
std::cerr << "Error when initializing the data base with: " << argv[1]
std::cerr << "Error when initializing the data base with: " << qPrintable(sqlFileName)
<< " error: " << myCTK.lastError().toStdString();
return EXIT_FAILURE;
}
Expand Down
Loading