regression.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /* boost regression test program
  2. *
  3. * Copyright Jens Maurer 2000
  4. * Permission to use, copy, modify, sell, and distribute this software
  5. * is hereby granted without free provided that the above copyright notice
  6. * appears in all copies and that both that copyright notice and this
  7. * permission notice appear in supporting documentation,
  8. *
  9. * Jens Maurer makes no representations about the suitability of this
  10. * software for any purpose. It is provided "as is" without express or
  11. * implied warranty.
  12. *
  13. * See http://www.boost.org for most recent version including documentation.
  14. */
  15. #include <iostream>
  16. #include <string>
  17. #include <list>
  18. #include <vector>
  19. #include <cstdlib>
  20. #include <fstream>
  21. #include <utility>
  22. #include <ctime>
  23. // It is OK to use boost headers which contain entirely inline code.
  24. #include <boost/config.hpp>
  25. # ifdef BOOST_NO_STDC_NAMESPACE
  26. namespace std {
  27. using ::exit; using ::system; using ::strftime; using ::gmtime;
  28. using ::time; using ::time_t;
  29. }
  30. # endif
  31. std::string get_host()
  32. {
  33. #if defined __linux__
  34. return "linux";
  35. #elif defined __osf__
  36. return "tru64";
  37. #elif defined __sgi
  38. return "irix";
  39. #elif defined _WIN32
  40. return "win32";
  41. #elif defined __BEOS__
  42. return "beos";
  43. #else
  44. # error Please adapt for your platform
  45. #endif
  46. }
  47. // retrieve precise system configuration as descriptive string
  48. #ifdef __unix
  49. #include <sys/utsname.h>
  50. std::string get_system_configuration()
  51. {
  52. struct utsname ut; // "struct" is required for the DEC Tru64 compiler
  53. if(uname(&ut) < 0)
  54. return "";
  55. std::string config = std::string(ut.sysname) + " " + ut.release;
  56. return config;
  57. }
  58. #elif defined _WIN32
  59. std::string get_system_configuration()
  60. {
  61. return "Microsoft Windows 32bit";
  62. }
  63. #elif defined __BEOS__
  64. std::string get_system_configuration()
  65. {
  66. return "BeOS";
  67. }
  68. #else
  69. # error Please adapt for your platform
  70. #endif
  71. struct entry
  72. {
  73. std::string os, identifier, name, compile_only_command, compile_link_command, html;
  74. };
  75. // replace the first %name in s with value
  76. void replace(std::string & s,
  77. const std::string & name, const std::string & value)
  78. {
  79. std::string::size_type p = s.find(name);
  80. if(p != std::string::npos)
  81. s.replace(p, name.length(), value);
  82. }
  83. // replace all $XXX in s with the value of getenv("XXX")
  84. void replace_environment(std::string & s)
  85. {
  86. std::string::size_type end = 0;
  87. for(;;) {
  88. std::string::size_type pos = s.find('$', end);
  89. if(pos == std::string::npos)
  90. break;
  91. end = s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", pos+1);
  92. const char * env = getenv(s.substr(pos+1, end-pos-1).c_str());
  93. if(env)
  94. replace(s, s.substr(pos, end-pos), env);
  95. else
  96. break;
  97. }
  98. }
  99. // get a string line, ignoring empty lines and comment lines
  100. void getstringline( std::ifstream & is, std::string & s )
  101. {
  102. do {
  103. std::getline( static_cast<std::istream&>(is), s ); // cast required by IRIX
  104. } while ( is.good()
  105. && (!s.size() || (s.size() >= 2 && s[0] == '/' && s[1] == '/')) );
  106. }
  107. // read the compiler configuration from file and push entry's to out
  108. template<class OutputIterator>
  109. void read_compiler_configuration(const std::string & file, OutputIterator out)
  110. {
  111. std::ifstream f(file.c_str());
  112. int lineno = 0;
  113. while(f.good()) {
  114. entry e;
  115. getstringline(f, e.os);
  116. getstringline(f, e.identifier);
  117. getstringline(f, e.name);
  118. getstringline(f, e.compile_only_command);
  119. getstringline(f, e.compile_link_command);
  120. getstringline(f, e.html);
  121. *out = e;
  122. ++out;
  123. std::string l;
  124. std::getline(f, l);
  125. lineno += 6;
  126. if(l != "") {
  127. std::cerr << file << ", line " << lineno
  128. << ": Empty line expected, got " << l << "\n";
  129. std::exit(1);
  130. }
  131. }
  132. }
  133. // run command (possibly needs portability adjustment)
  134. bool execute(const std::string & command)
  135. {
  136. std::cout << command << std::endl; // fix: endl ensures cout ordering
  137. return std::system(command.c_str()) == 0;
  138. }
  139. enum test_result {
  140. ok = 0,
  141. unknown_type,
  142. compile_failed, compile_ok, link_failed, link_ok, run_failed, run_ok
  143. };
  144. test_result compile(std::string command, const std::string & boostpath,
  145. const std::string & file)
  146. {
  147. replace(command, "%source", boostpath + "/" + file);
  148. return execute(command) ? compile_ok : compile_failed;
  149. }
  150. test_result link(std::string command, const std::string & boostpath,
  151. const std::string & file)
  152. {
  153. replace(command, "%source", boostpath + "/" + file);
  154. return execute(command) ? link_ok : link_failed;
  155. }
  156. test_result run(std::string command, const std::string & boostpath,
  157. const std::string & file)
  158. {
  159. std::string exename = "boosttmp.exe";
  160. replace(command, "%source", boostpath + "/" + file);
  161. if(execute(command)) {
  162. return execute( (get_host() == "win32" ? "" : "./") + exename ) ?
  163. run_ok : run_failed;
  164. } else {
  165. return link_failed;
  166. }
  167. }
  168. std::pair<test_result, test_result>
  169. run_test(const std::string & type, std::string compile_only_command,
  170. std::string compile_link_command,
  171. const std::string & boostpath, const std::string & source)
  172. {
  173. replace(compile_only_command, "%include", boostpath);
  174. replace(compile_link_command, "%include", boostpath);
  175. if(type == "compile")
  176. return std::make_pair(compile(compile_only_command, boostpath, source), compile_ok);
  177. else if(type == "compile-fail")
  178. return std::make_pair(compile(compile_only_command, boostpath, source), compile_failed);
  179. else if(type == "link")
  180. return std::make_pair(link(compile_link_command, boostpath, source), link_ok);
  181. else if(type == "link-fail")
  182. return std::make_pair(link(compile_link_command, boostpath, source), link_failed);
  183. else if(type == "run")
  184. return std::make_pair(run(compile_link_command, boostpath, source), run_ok);
  185. else if(type == "run-fail")
  186. return std::make_pair(run(compile_link_command, boostpath, source), run_failed);
  187. else
  188. return std::make_pair(unknown_type, ok);
  189. }
  190. template<class ForwardIterator>
  191. void do_tests(std::ostream & out,
  192. ForwardIterator firstcompiler, ForwardIterator lastcompiler,
  193. const std::string & testconfig, const std::string & boostpath)
  194. {
  195. out << "<tr>\n"
  196. << "<td>Program</td>\n"
  197. << "<td>Test<br>Type</td>\n";
  198. for(ForwardIterator it = firstcompiler; it != lastcompiler; ++it) {
  199. out << "<td>" << it->html << "</td>\n";
  200. }
  201. out << "</tr>\n";
  202. std::ifstream f(testconfig.c_str());
  203. while(f.good()) {
  204. std::string l;
  205. getstringline(f, l);
  206. if (!f.good()) break;
  207. typedef std::string::size_type sz_type;
  208. sz_type p = l.find(' ');
  209. if(p == std::string::npos) {
  210. std::cerr << "Test " << l << " is wrong\n";
  211. continue;
  212. }
  213. std::string type(l, 0, p);
  214. std::string file(l, p+1, std::string::npos); // 3rd arg to fix VC++ bug
  215. std::cout << "*** " << file << " ***\n\n";
  216. out << "<tr>\n"
  217. << "<td><a href=\"../" << file << "\">" << file << "</a></td>\n"
  218. << "<td>" << type << "</td>\n";
  219. for(ForwardIterator it = firstcompiler; it != lastcompiler; ++it) {
  220. std::cout << "** " << it->name << "\n";
  221. std::pair<test_result, test_result> result =
  222. run_test(type, it->compile_only_command, it->compile_link_command, boostpath, file);
  223. if(result.first == unknown_type) {
  224. std::cerr << "Unknown test type " << type << ", skipped\n";
  225. continue;
  226. }
  227. out << "<td>"
  228. << (result.first == result.second ? "Pass" : "<font color=\"#FF0000\">Fail</font>")
  229. << "</td>" << std::endl;
  230. std::cout << (result.first == result.second ? "Pass" : "Fail") << "\n\n";
  231. }
  232. out << "</tr>\n";
  233. }
  234. }
  235. int main(int argc, char * argv[])
  236. {
  237. // std::vector<std::string> args(argv+1, argv+argc);
  238. // hack around VC++ lack of ctor taking iterator args
  239. std::vector<std::string> args;
  240. for ( const char ** ait = (const char **)(argv+1);
  241. ait != (const char **)(argv+argc); ++ait)
  242. args.push_back(std::string( *ait ));
  243. if(args.size() < 3) {
  244. std::cerr << argv[0]
  245. << " usage: compiler-config test-config boost-path [compiler|* [[command] file]]\n";
  246. std::exit(1);
  247. }
  248. std::string compiler = (args.size() >= 4 ? args[3] : "*");
  249. std::list<entry> l;
  250. read_compiler_configuration(args[0], std::back_inserter(l));
  251. std::string host = get_host();
  252. for(std::list<entry>::iterator it = l.begin(); it != l.end(); ) {
  253. if(it->os == host && (compiler == "*" || it->identifier == compiler)) {
  254. replace_environment(it->compile_only_command);
  255. replace_environment(it->compile_link_command);
  256. ++it;
  257. } else {
  258. it = l.erase(it);
  259. }
  260. }
  261. std::string boostpath = args[2];
  262. // if file argument present, write temporary test configuration file for do_tests
  263. if(args.size() >= 5) { // file argument present
  264. std::ofstream tmp((args[1]="boosttmp.tmp").c_str());
  265. if (args.size() >= 6) tmp << args[4] << " " << args[5] << std::endl; // command present
  266. else tmp << "compile " << args[4] << std::endl; // command not present
  267. }
  268. std::ofstream out( ("cs-" + host + ".html").c_str() );
  269. char run_date[100];
  270. std::time_t ct;
  271. std::time(&ct);
  272. std::strftime(run_date, sizeof(run_date), "%d %b %Y %H:%M GMT", std::gmtime(&ct));
  273. out << "<html>\n<head>\n<title>\nCompiler Status: " + host + "\n</title>\n</head>\n"
  274. << "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
  275. << "<h1><img border border=\"0\" src=\"../c++boost.gif\" width=\"277\" height=\"86\"></h1>\n"
  276. << "<h1>Compiler Status: " + host + "</h1>\n"
  277. << "\n"
  278. << "<p><b>Run Date:</b> " << run_date << "</p>\n"
  279. << "<p><b>System Configuration:</b> " << get_system_configuration()
  280. << "</p>\n"
  281. << "<p>\n"
  282. << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";
  283. do_tests(out, l.begin(), l.end(), args[1], boostpath);
  284. out << "</table></p>\n<p>\n";
  285. if(host == "linux")
  286. out << "Notes: A hand-crafted &lt;limits&gt; Standard header has been\n"
  287. << "applied to all configurations.\n"
  288. << "The tests were run on a GNU libc 2.2 system which has improved\n"
  289. << "wide character support compared to previous versions.";
  290. else if(host == "irix" || host == "tru64")
  291. out << "Note: For the 'clib' configuration, the missing new-style C\n"
  292. << "library headers &lt;cXXX&gt; have been supplied.\n";
  293. out << "</p>\n</body>\n</html>" << std::endl;
  294. return 0;
  295. }
粤ICP备19079148号