@@ -67,7 +67,6 @@ using namespace boost::unit_test_framework;
6767
6868namespace {
6969 int worker (std::string cmd) {
70- std::cout << cmd << std::endl;
7170 return std::system (cmd.c_str ());
7271 }
7372
@@ -143,7 +142,14 @@ int main(int argc, char* argv[]) {
143142 const char * const testRuntimeLogName = testRuntimeLogNameStr.c_str ();
144143
145144 const std::string clientModeStr = " --client_mode=true" ;
146- const bool clientMode = (std::string (argv[argc - 1 ]) == clientModeStr);
145+ bool clientMode = false ;
146+
147+ for (int i = 1 ; i < argc; ++i) {
148+ if (argv[i] == clientModeStr) {
149+ clientMode = true ;
150+ break ;
151+ }
152+ }
147153
148154 message_queue::size_type recvd_size;
149155
@@ -172,8 +178,6 @@ int main(int argc, char* argv[]) {
172178 cmd << " \" " << argv[0 ] << " \" " ;
173179
174180 std::vector<char *> localArgs (1 , argv[0 ]);
175-
176- std::vector<std::string> logSink;
177181 for (int i = 1 ; i < argc; ++i) {
178182 const std::string arg (argv[i]);
179183
@@ -182,15 +186,11 @@ int main(int argc, char* argv[]) {
182186 boost::split (tok, arg, boost::is_any_of (" =" ));
183187 if (tok.size () == 2 && tok[0 ] == " --nProc" ) {
184188 nProc = std::stoul (tok[1 ]);
185- } else if (tok[0 ] == " --log_sink" ) {
186- boost::split (logSink, tok[1 ], boost::is_any_of (" ." ));
187- localArgs.push_back (argv[i]);
188189 } else if (arg != " --build_info=yes" ) {
189190 cmd << arg << " " ;
190191 localArgs.push_back (argv[i]);
191192 }
192- }
193-
193+ }
194194
195195 framework::init (init_unit_test_suite, localArgs.size (), &localArgs[0 ]);
196196 framework::finalize_setup_phase ();
@@ -214,12 +214,9 @@ int main(int argc, char* argv[]) {
214214 std::vector<std::thread> threadGroup;
215215 std::vector<std::string> cmdStrs (nProc, cmd.str ());
216216 for (unsigned i = 0 ; i < nProc; ++i) {
217- std::stringstream newCmd;
218- if (logSink.size () == 2 ) {
219- newCmd << " --log_sink=" << logSink[0 ] << " _" << i << " ." << logSink[1 ] << " " ;
220- }
221- newCmd << clientModeStr;
222- cmdStrs[i] += newCmd.str ();
217+ std::stringstream proStr;
218+ proStr << " --process_id=" << i << " " << clientModeStr;
219+ cmdStrs[i] += proStr.str ();
223220 }
224221
225222 for (unsigned i = 0 ; i < nProc; ++i) {
@@ -323,7 +320,39 @@ int main(int argc, char* argv[]) {
323320 std::cout << std::fixed << std::setprecision (0 ) << seconds << " s" << std::endl;
324321
325322 } else {
326- framework::init (init_unit_test_suite, argc - 1 , argv);
323+
324+ // first get a process id
325+ std::string processId;
326+ for (int i = 1 ; i < argc; ++i) {
327+ if (boost::starts_with (argv[i], " --process_id" )) {
328+ std::vector<std::string> strs;
329+ boost::split (strs, argv[i], boost::is_any_of (" =" ));
330+ if (strs.size () > 1 )
331+ processId = strs[1 ];
332+ }
333+ }
334+
335+ std::vector<char *> localArgs (1 , argv[0 ]);
336+
337+ // update the log sink for each sub process
338+ for (int i = 1 ; i < argc; ++i) {
339+ const std::string arg (argv[i]);
340+
341+ std::vector<std::string> tok;
342+ boost::split (tok, arg, boost::is_any_of (" =" ));
343+ if (tok[0 ] == " --log_sink" ) {
344+ std::vector<std::string> logSink;
345+ boost::split (logSink, tok[1 ], boost::is_any_of (" ." ));
346+ std::string newLog =
347+ tok[0 ] + " =" + logSink[0 ] + " _" + processId + " ." + logSink[1 ];
348+ char * pString = new char [newLog.length () + 1 ];
349+ std::copy (newLog.c_str (), newLog.c_str () + newLog.length () + 1 , pString);
350+ localArgs.push_back (pString);
351+ } else
352+ localArgs.push_back (argv[i]);
353+ }
354+
355+ framework::init (init_unit_test_suite, localArgs.size (), &localArgs[0 ]);
327356 framework::finalize_setup_phase ();
328357
329358 framework::impl::s_frk_state ().deduce_run_status (framework::master_test_suite ().p_id );
0 commit comments