1 #include "BatchTest.hxx"
3 #include "Batch_Date.hxx"
13 BatchTest::BatchTest(const Engines::MachineParameters& batch_descr)
15 _batch_descr = batch_descr;
18 Batch::Date date = Batch::Date(time(0));
20 int lend = _date.size() ;
24 if (_date[i] == '/' || _date[i] == '-' || _date[i] == ':' )
31 // Creating test temporary file
32 _test_filename = "/tmp/";
33 _test_filename += _date + "_test_cluster_file_";
34 _test_filename += _batch_descr.alias.in();
35 _base_filename = _date + "_test_cluster_file_" + _batch_descr.alias.in();
38 BatchTest::~BatchTest() {}
45 << "--- Testing batch Machine :" << std::endl
46 << "--- Name : " << _batch_descr.hostname << std::endl
47 << "--- Alias : " << _batch_descr.alias << std::endl
48 << "--- Protocol : " << _batch_descr.protocol << std::endl
49 << "--- User Name : " << _batch_descr.username << std::endl
50 << "--- Batch Type : " << _batch_descr.batch << std::endl
51 << "--- MPI Impl : " << _batch_descr.mpiImpl << std::endl
52 << "--- Appli Path : " << _batch_descr.applipath << std::endl
55 std::string result_connection("Not Tested");
56 std::string result_filecopy("Not Tested");
57 std::string result_getresult("Not Tested");
58 std::string result_jobsubmit_simple("Not Tested");
59 std::string result_jobsubmit_mpi("Not Tested");
60 std::string result_appli("Not Tested");
62 result_connection = test_connection();
63 result_filecopy = test_filecopy();
64 result_getresult = test_getresult();
65 result_jobsubmit_simple = test_jobsubmit_simple();
66 result_jobsubmit_mpi = test_jobsubmit_mpi();
67 result_appli = test_appli();
70 << "--- Test results" << std::endl
71 << "--- Connection : " << result_connection << std::endl
72 << "--- File copy : " << result_filecopy << std::endl
73 << "--- Get results : " << result_getresult << std::endl
74 << "--- Submit simple job : " << result_jobsubmit_simple << std::endl
75 << "--- Submit mpi job : " << result_jobsubmit_mpi << std::endl
76 << "--- Application : " << result_appli << std::endl
79 if (result_connection == "OK" &&
80 result_filecopy == "OK" &&
81 result_getresult == "OK" &&
82 result_jobsubmit_simple == "OK" &&
83 result_jobsubmit_mpi == "OK" &&
90 // For this test we use : alias, protocol, username
92 BatchTest::test_connection()
96 std::string result("Failed : ");
97 std::string alias = _batch_descr.alias.in();
98 std::string username = _batch_descr.username.in();
99 std::string protocol = _batch_descr.protocol.in();
104 result += "alias is empty !";
109 result += "username is empty !";
112 if( protocol != "rsh" && protocol != "ssh")
114 result += "protocol unknown ! (" + protocol + ")";
121 + username + "@" + alias;
124 status = system(command.c_str());
126 std::ostringstream oss;
128 result += "Error of connection on remote host ! status = ";
137 // For this test we use : alias, protocol, username
139 BatchTest::test_filecopy()
144 std::string result("Failed : ");
145 std::string alias = _batch_descr.alias.in();
146 std::string username = _batch_descr.username.in();
147 std::string protocol = _batch_descr.protocol.in();
149 // Getting home directory
150 std::string rst = get_home(&home);
156 // Writing into the tempory file
157 command = "echo Hello > " + _test_filename;
158 status = system(command.c_str());
160 std::ostringstream oss;
162 result += "Error in creating tempory file ! status = ";
169 if(protocol == "rsh")
171 command += " " + _test_filename + " "
172 + username + "@" + alias + ":" + home;
175 status = system(command.c_str());
177 std::ostringstream oss;
179 result += "Error in copy file on remote host ! status = ";
188 // For this test we use : alias, protocol, username
190 BatchTest::test_getresult()
195 std::string result("Failed : ");
196 std::string alias = _batch_descr.alias.in();
197 std::string username = _batch_descr.username.in();
198 std::string protocol = _batch_descr.protocol.in();
200 // Getting home directory
201 std::string rst = get_home(&home);
209 if(protocol == "rsh")
211 command += " " + username + "@" + alias + ":" + home
212 + "/" + _base_filename + " " + _test_filename + "_copy";
215 status = system(command.c_str());
217 std::ostringstream oss;
219 result += "Error in copy file from remote host ! status = ";
225 std::ifstream src_file(_test_filename.c_str());
228 result += "Error in reading temporary file ! filename = " + _test_filename;
231 std::string cp_filename = _test_filename + "_copy";
232 std::ifstream cp_file(cp_filename.c_str());
235 result += "Error in reading temporary copy file ! filename = " + cp_filename;
238 std::string src_firstline;
239 std::string cp_firstline;
240 std::getline(src_file, src_firstline);
241 std::getline(cp_file, cp_firstline);
244 if (src_firstline != cp_firstline)
246 result += "Error source file and copy file are not equa ! source = " + src_firstline + " copy = " + cp_firstline;
255 BatchTest::test_jobsubmit_simple()
260 std::string result("Failed : ");
261 std::string alias = _batch_descr.alias.in();
262 std::string username = _batch_descr.username.in();
263 std::string protocol = _batch_descr.protocol.in();
264 std::string batch_type = _batch_descr.batch.in();
267 if (batch_type == "slurm")
269 INFOS("test_jobsubmit_simple not yet implemented for slurm... return OK");
273 if (batch_type != "pbs")
275 result += "Batch type unknown ! : " + batch_type;
279 // Getting home directory
280 std::string rst = get_home(&home);
287 std::string _test_file_simple = _test_filename + "_simple";
289 file.open(_test_file_simple.c_str(), std::ofstream::out);
290 file << "#!/bin/bash\n"
291 << "#PBS -l nodes=1\n"
292 << "#PBS -l walltime=00:01:00\n"
293 << "#PBS -o " + home + "/" + _date + "_simple_output.log\n"
294 << "#PBS -e " + home + "/" + _date + "_simple_error.log\n"
296 << "echo Error >&2\n";
301 // Build command for copy
303 if(protocol == "rsh")
305 command += " " + _test_file_simple + " "
306 + username + "@" + alias + ":" + home;
307 status = system(command.c_str());
309 std::ostringstream oss;
311 result += "Error in copy job file to remote host ! status = ";
316 // Build command for submit job
317 std::string file_job_name = _test_filename + "_jobid";
318 command = protocol + " " + username + "@" + alias + " qsub " + _base_filename + "_simple > " + file_job_name;
319 status = system(command.c_str());
321 std::ostringstream oss;
323 result += "Error in sending qsub to remote host ! status = ";
328 std::ifstream file_job(file_job_name.c_str());
331 result += "Error in reading temporary file ! filename = " + file_job_name;
334 std::getline(file_job, jobid);
337 // Wait the end of the job
338 command = protocol + " " + username + "@" + alias + " qstat -f " + jobid + " > " + file_job_name;
342 status = system(command.c_str());
343 if(status && status != 153 && status != 256*153)
345 std::ostringstream oss;
347 result += "Error in sending qstat to remote host ! status = ";
352 if(status == 153 || status == 256*153 )
361 // Build command for getting results
363 if(protocol == "rsh")
366 + username + "@" + alias + ":" + home + "/" + _date + "_simple* /tmp";
367 status = system(command.c_str());
369 std::ostringstream oss;
371 result += "error in getting file result of qsub simple to remote host ! status = ";
377 std::string normal_input;
378 std::string file_normal_name = "/tmp/" + _date + "_simple_output.log";
379 std::ifstream file_normal(file_normal_name.c_str());
382 result += "Error in reading temporary file ! filename = " + file_normal_name;
385 std::getline(file_normal, normal_input);
387 if (normal_input != "Bonjour")
389 result += "error from simple ouput file ! waiting for Bonjour and get : " + normal_input;
392 std::string error_input;
393 std::string file_error_name = "/tmp/" + _date + "_simple_error.log";
394 std::ifstream file_error(file_error_name.c_str());
397 result += "Error in reading temporary file ! filename = " + file_error_name;
400 std::getline(file_error, error_input);
402 if (error_input != "Error")
404 result += "error from simple error file ! waiting for Error and get : " + error_input;
412 BatchTest::test_jobsubmit_mpi()
418 std::string result("Failed : ");
419 std::string alias = _batch_descr.alias.in();
420 std::string username = _batch_descr.username.in();
421 std::string protocol = _batch_descr.protocol.in();
422 std::string batch_type = _batch_descr.batch.in();
423 std::string mpi_type = _batch_descr.mpiImpl.in();
426 if(mpi_type == "lam")
427 mpiImpl = new MpiImpl_LAM();
428 else if(mpi_type == "mpich1")
429 mpiImpl = new MpiImpl_MPICH1();
430 else if(mpi_type == "mpich2")
431 mpiImpl = new MpiImpl_MPICH2();
432 else if(mpi_type == "openmpi")
433 mpiImpl = new MpiImpl_OPENMPI();
436 result += "Error MPI impl not supported : " + mpi_type;
440 // SLURM not yet implemented...
441 if (batch_type == "slurm")
443 INFOS("test_jobsubmit_simple not yet implemented for slurm... return OK");
448 // Getting home directory
449 std::string rst = get_home(&home);
456 std::string _test_file_script = _test_filename + "_script";
457 std::ofstream file_script;
458 file_script.open(_test_file_script.c_str(), std::ofstream::out);
459 file_script << "#!/bin/bash\n"
460 << "echo HELLO MPI\n";
468 (_test_file_script.c_str(), 0x1ED);
470 std::string _test_file_mpi = _test_filename + "_mpi";
471 std::ofstream file_mpi;
472 file_mpi.open(_test_file_mpi.c_str(), std::ofstream::out);
473 file_mpi << "#!/bin/bash\n"
474 << "#PBS -l nodes=1\n"
475 << "#PBS -l walltime=00:01:00\n"
476 << "#PBS -o " << home << "/" << _date << "_mpi_output.log\n"
477 << "#PBS -e " << home << "/" << _date << "_mpi_error.log\n"
478 << mpiImpl->boot("${PBS_NODEFILE}", 1)
479 << mpiImpl->run("${PBS_NODEFILE}", 1, _base_filename + "_script")
485 // Build command for copy
487 if(protocol == "rsh")
489 command += " " + _test_file_script + " "
490 + username + "@" + alias + ":" + home;
491 status = system(command.c_str());
493 std::ostringstream oss;
495 result += "Error in copy job file to remote host ! status = ";
500 if(protocol == "rsh")
502 command += " " + _test_file_mpi + " "
503 + username + "@" + alias + ":" + home;
504 status = system(command.c_str());
506 std::ostringstream oss;
508 result += "Error in copy job file to remote host ! status = ";
513 // Build command for submit job
514 std::string file_job_name = _test_filename + "_jobid";
515 command = protocol + " " + username + "@" + alias + " qsub " + _base_filename + "_mpi > " + file_job_name;
516 status = system(command.c_str());
518 std::ostringstream oss;
520 result += "Error in sending qsub to remote host ! status = ";
525 std::ifstream file_job(file_job_name.c_str());
528 result += "Error in reading temporary file ! filename = " + file_job_name;
531 std::getline(file_job, jobid);
534 // Wait the end of the job
535 command = protocol + " " + username + "@" + alias + " qstat -f " + jobid + " > " + file_job_name;
539 status = system(command.c_str());
540 if(status && status != 153 && status != 256*153)
542 std::ostringstream oss;
544 result += "Error in sending qstat to remote host ! status = ";
549 if(status == 153 || status == 256*153 )
558 // Build command for getting results
560 if(protocol == "rsh")
563 + username + "@" + alias + ":" + home + "/" + _date + "_mpi* /tmp";
564 status = system(command.c_str());
566 std::ostringstream oss;
568 result += "error in getting file result of qsub mpi from remote host ! status = ";
574 std::string normal_input;
575 std::string file_normal_name = "/tmp/" + _date + "_mpi_output.log";
576 std::ifstream file_normal(file_normal_name.c_str());
579 result += "Error in reading temporary file ! filename = " + file_normal_name;
582 bool test_ok = false;
583 while (std::getline(file_normal, normal_input))
585 if (normal_input == "HELLO MPI")
591 result += "error from mpi ouput file ! waiting for HELLO MPI please watch /tmp/" + _date + "_mpi_output.log file";
599 BatchTest::test_appli()
604 std::string result("Failed : ");
605 std::string alias = _batch_descr.alias.in();
606 std::string username = _batch_descr.username.in();
607 std::string protocol = _batch_descr.protocol.in();
608 std::string applipath = _batch_descr.applipath.in();
610 // Getting home directory
611 std::string rst = get_home(&home);
617 std::string _test_file_appli = _test_filename + "_appli_test";
618 std::ofstream file_appli;
619 file_appli.open(_test_file_appli.c_str(), std::ofstream::out);
620 file_appli << "#!/bin/bash\n"
621 << "if [ -f " << applipath << "/runAppli ]\n"
630 // Build command for copy
632 if(protocol == "rsh")
634 command += " " + _test_file_appli + " "
635 + username + "@" + alias + ":" + home;
636 status = system(command.c_str());
638 std::ostringstream oss;
640 result += "Error in copy appli test file to remote host ! status = ";
646 command = protocol + " " + username + "@" + alias
647 + " sh " + home + "/" + _base_filename + "_appli_test > "
648 + _test_filename + "_appli_test_result";
650 status = system(command.c_str());
652 std::ostringstream oss;
654 result += "Error in launching appli test on remote host ! status = ";
660 std::string rst_appli;
661 std::string file_appli_result_name = _test_filename + "_appli_test_result";
662 std::ifstream file_appli_result(file_appli_result_name.c_str());
663 if (!file_appli_result)
665 result += "Error in reading temporary file ! filename = " + file_appli_result_name;
668 std::getline(file_appli_result, rst_appli);
669 file_appli_result.close();
671 if (rst_appli != "OK")
673 result += "Error checking application on remote host ! result = " + rst;
683 BatchTest::get_home(std::string * home)
686 std::string result = "";
688 std::string alias = _batch_descr.alias.in();
689 std::string username = _batch_descr.username.in();
690 std::string protocol = _batch_descr.protocol.in();
691 std::string file_home_name = _test_filename + "_home";
693 command = protocol + " " + username + "@" + alias + " 'echo $HOME' > " + file_home_name;
694 status = system(command.c_str());
696 std::ostringstream oss;
698 result += "Error in getting home directory ! status = ";
703 std::ifstream file_home(file_home_name.c_str());
706 result += "Error in reading temporary file ! filename = " + file_home_name;
709 std::getline(file_home, *home);