Skip to content

Commit ad7196f

Browse files
committed
More isolation for simulation tests
perform simulation tests in a dedicated working dir have log files prefixed with the proper simulation prefix
1 parent 756f2c7 commit ad7196f

2 files changed

Lines changed: 42 additions & 17 deletions

File tree

run/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,16 @@ o2_data_file(COPY o2simtopology.json DESTINATION config)
103103
# perform
104104
# * # some checks on kinematics and track references
105105

106+
107+
# make workspace for simulation tests
108+
set(SIMTESTDIR ${CMAKE_BINARY_DIR}/o2sim_tests)
109+
file(MAKE_DIRECTORY ${SIMTESTDIR})
110+
106111
o2_name_target(sim NAME o2simExecutable IS_EXE)
107112
o2_name_target(sim-serial NAME o2simSerialExecutable IS_EXE)
108113

109114
o2_add_test_wrapper(NAME o2sim_G4
110-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
115+
WORKING_DIRECTORY ${SIMTESTDIR}
111116
DONT_FAIL_ON_TIMEOUT
112117
MAX_ATTEMPTS 2
113118
TIMEOUT 400
@@ -134,7 +139,7 @@ set_property(TEST o2sim_G4 APPEND PROPERTY ENVIRONMENT ${G4ENV})
134139

135140
# # note that the MT is currently only supported in the non FairMQ version
136141
o2_add_test_wrapper(NAME o2sim_G4_mt
137-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
142+
WORKING_DIRECTORY ${SIMTESTDIR}
138143
DONT_FAIL_ON_TIMEOUT
139144
MAX_ATTEMPTS 2
140145
TIMEOUT 400
@@ -160,7 +165,7 @@ set_property(TEST o2sim_G4_mt APPEND PROPERTY ENVIRONMENT ${G4ENV})
160165
o2_add_test(CheckStackG4
161166
SOURCES checkStack.cxx
162167
NAME o2sim_checksimkinematics_G4
163-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
168+
WORKING_DIRECTORY ${SIMTESTDIR}
164169
COMMAND_LINE_ARGS o2simG4
165170
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat
166171
NO_BOOST_TEST
@@ -170,7 +175,7 @@ set_tests_properties(o2sim_checksimkinematics_G4
170175
PROPERTIES FIXTURES_REQUIRED G4)
171176

172177
o2_add_test_wrapper(NAME o2sim_G3
173-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
178+
WORKING_DIRECTORY ${SIMTESTDIR}
174179
DONT_FAIL_ON_TIMEOUT
175180
MAX_ATTEMPTS 3
176181
COMMAND $<TARGET_FILE:${o2simExecutable}>
@@ -199,7 +204,7 @@ set_property(TEST o2sim_G3 APPEND PROPERTY ENVIRONMENT "ALICE_O2SIM_DUMPLOG=ON")
199204
o2_add_test(CheckStackG3
200205
SOURCES checkStack.cxx
201206
NAME o2sim_checksimkinematics_G3
202-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
207+
WORKING_DIRECTORY ${SIMTESTDIR}
203208
COMMAND_LINE_ARGS o2simG3
204209
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat
205210
NO_BOOST_TEST
@@ -210,7 +215,7 @@ set_tests_properties(o2sim_checksimkinematics_G3
210215
PROPERTIES FIXTURES_REQUIRED G3)
211216

212217
o2_add_test_wrapper(NAME o2sim_hepmc
213-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
218+
WORKING_DIRECTORY ${SIMTESTDIR}
214219
DONT_FAIL_ON_TIMEOUT
215220
MAX_ATTEMPTS 2
216221
TIMEOUT 400

run/o2sim_parallel.cxx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,29 @@
3636
#include "rapidjson/filereadstream.h"
3737
#include "rapidjson/filewritestream.h"
3838

39-
static const char* serverlogname = "serverlog";
40-
static const char* workerlogname = "workerlog";
41-
static const char* mergerlogname = "mergerlog";
39+
std::string getServerLogName()
40+
{
41+
auto& conf = o2::conf::SimConfig::Instance();
42+
std::stringstream str;
43+
str << conf.getOutPrefix() << "_serverlog";
44+
return str.str();
45+
}
46+
47+
std::string getWorkerLogName()
48+
{
49+
auto& conf = o2::conf::SimConfig::Instance();
50+
std::stringstream str;
51+
str << conf.getOutPrefix() << "_workerlog";
52+
return str.str();
53+
}
54+
55+
std::string getMergerLogName()
56+
{
57+
auto& conf = o2::conf::SimConfig::Instance();
58+
std::stringstream str;
59+
str << conf.getOutPrefix() << "_mergerlog";
60+
return str.str();
61+
}
4262

4363
void cleanup()
4464
{
@@ -49,21 +69,21 @@ void cleanup()
4969
if (getenv("ALICE_O2SIM_DUMPLOG")) {
5070
std::cerr << "------------- START OF EVENTSERVER LOG ----------" << std::endl;
5171
std::stringstream catcommand1;
52-
catcommand1 << "cat " << serverlogname << ";";
72+
catcommand1 << "cat " << getServerLogName() << ";";
5373
if (system(catcommand1.str().c_str()) != 0) {
5474
LOG(WARN) << "error executing system call";
5575
}
5676

5777
std::cerr << "------------- START OF SIM WORKER(S) LOG --------" << std::endl;
5878
std::stringstream catcommand2;
59-
catcommand2 << "cat " << workerlogname << "*;";
79+
catcommand2 << "cat " << getWorkerLogName() << "*;";
6080
if (system(catcommand2.str().c_str()) != 0) {
6181
LOG(WARN) << "error executing system call";
6282
}
6383

6484
std::cerr << "------------- START OF MERGER LOG ---------------" << std::endl;
6585
std::stringstream catcommand3;
66-
catcommand3 << "cat " << mergerlogname << ";";
86+
catcommand3 << "cat " << getMergerLogName() << ";";
6787
if (system(catcommand3.str().c_str()) != 0) {
6888
LOG(WARN) << "error executing system call";
6989
}
@@ -281,7 +301,7 @@ int main(int argc, char* argv[])
281301
// the server
282302
int pid = fork();
283303
if (pid == 0) {
284-
int fd = open(serverlogname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
304+
int fd = open(getServerLogName().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
285305
setenv("ALICE_O2SIMSERVERTODRIVER_PIPE", std::to_string(pipe_serverdriver_fd[1]).c_str(), 1);
286306

287307
dup2(fd, 1); // make stdout go to file
@@ -324,7 +344,7 @@ int main(int argc, char* argv[])
324344
} else {
325345
childpids.push_back(pid);
326346
close(pipe_serverdriver_fd[1]);
327-
std::cout << "Spawning particle server on PID " << pid << "; Redirect output to " << serverlogname << "\n";
347+
std::cout << "Spawning particle server on PID " << pid << "; Redirect output to " << getServerLogName() << "\n";
328348
launchThreadMonitoringEvents(pipe_serverdriver_fd[0], "DISTRIBUTING EVENT : ");
329349
}
330350

@@ -336,7 +356,7 @@ int main(int argc, char* argv[])
336356
for (int id = 0; id < nworkers; ++id) {
337357
// the workers
338358
std::stringstream workerlogss;
339-
workerlogss << workerlogname << id;
359+
workerlogss << getWorkerLogName() << id;
340360

341361
// the workers
342362
std::stringstream workerss;
@@ -370,7 +390,7 @@ int main(int argc, char* argv[])
370390

371391
pid = fork();
372392
if (pid == 0) {
373-
int fd = open(mergerlogname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
393+
int fd = open(getMergerLogName().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
374394
dup2(fd, 1); // make stdout go to file
375395
dup2(fd, 2); // make stderr go to file - you may choose to not do this
376396
// or perhaps send stderr to another file
@@ -384,7 +404,7 @@ int main(int argc, char* argv[])
384404
(char*)nullptr);
385405
return 0;
386406
} else {
387-
std::cout << "Spawning hit merger on PID " << pid << "; Redirect output to " << mergerlogname << "\n";
407+
std::cout << "Spawning hit merger on PID " << pid << "; Redirect output to " << getMergerLogName() << "\n";
388408
childpids.push_back(pid);
389409
close(pipe_mergerdriver_fd[1]);
390410
launchThreadMonitoringEvents(pipe_mergerdriver_fd[0], "EVENT FINISHED : ");

0 commit comments

Comments
 (0)