regrtest.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. // boost compilation regression test
  2. // Usage: regrtest [*|compiler] [*|library/program]
  3. //
  4. // Default: regrtest * *
  5. //
  6. // Compilers: bcc = Borland 5.5.1
  7. // cw = Metrowerks CodeWarrior
  8. // gcc = GNU GCC
  9. // gcc-stlport = GNU GCC with STLport library
  10. // como = Comeau C++
  11. // vc = Microsoft Visual C++
  12. // vcstlport = Microsoft Visual C++ with STLport library
  13. //
  14. // Examples: regrtest
  15. // regrtest
  16. // regrtest gcc
  17. // regrtest * smart_ptr/smart_ptr_test.cpp
  18. // regrtest gcc smart_ptr/smart_ptr_test.cpp
  19. //
  20. // If the program argument is * or left out, then the file
  21. // ./regrtest_files.txt will be used as the list of files to be
  22. // tested. Each line of regrtest_files.txt must have the form:
  23. //
  24. // file-name mode [input-file]
  25. //
  26. // Where mode is
  27. // C compile
  28. // F compile, expecting failure
  29. // R compile and run
  30. //
  31. // The path to the input-file should be relative to where regrtest is
  32. // running.
  33. //
  34. // Required environment variables:
  35. // BOOST_PATH The directory containing the "boost/" header file directory.
  36. // OSTYPE The operating system, should be one of ...
  37. // BOOST_STLPORT_PATH The directory containing STLport headers
  38. // BOOST_BCC55_PATH The directory container Borland headers
  39. //
  40. // Note: use the following command line syntax if output is to be redirected:
  41. // python regrtest.py [*|compiler] [*|library/program] >log 2>&1
  42. // Revision history:
  43. // 17 Dec 00 Rewrote in C++ and retrieve file list from a file. (Jeremy Siek)
  44. // 21 Jun 00 Redesign to allow specifying compiler and program (Beman Dawes)
  45. // 18 Jun 00 Initial Version (Beman Dawes)
  46. // The Metrowerks and Microsoft compilers require various environment variables be set.
  47. // See mwcc -help
  48. // See http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_building_on_the_command_line.3a_.overview.htm
  49. // Others:
  50. // See bcb4.hlp. Don't bother with bcb4tools.hlp; it has a bad link to the command line options
  51. #include <iostream>
  52. #include <fstream>
  53. #include <string>
  54. #include <stdlib.h> // for getenv()
  55. #include <time.h> // for ctime()
  56. #include <stdio.h> // for sscanf()
  57. // Enumerated Types
  58. // Global variables
  59. std::string path, compiler_arg, program_arg,
  60. exe_suffix, exe_invoke_prefix = "./";
  61. std::ofstream outfile;
  62. //-----------------------------------------------------------------------------
  63. std::string platform()
  64. {
  65. char* os_ptr = getenv("OSTYPE");
  66. if (os_ptr == 0) {
  67. std::cerr << "The \"OSTYPE\" environment variable is not defined"
  68. << std::endl;
  69. exit(1);
  70. return "unknown";
  71. } else {
  72. std::string os = os_ptr;
  73. if (os == "linux")
  74. return "linux";
  75. else if (os == "solaris")
  76. return "sunos";
  77. else
  78. return "unknown";
  79. }
  80. }
  81. //-----------------------------------------------------------------------------
  82. void invoke(std::string desc,
  83. std::string command,
  84. char invoke_mode,
  85. std::string invoke_args,
  86. std::string program_name)
  87. {
  88. std::cout << " " << desc << std::endl;
  89. std::cout << " invoke mode: " << invoke_mode << std::endl;
  90. std::cout << " " << command << std::endl;
  91. outfile << "<td>";
  92. int rs = system(command.c_str());
  93. std::cout << " compile return status: " << rs << std::endl;
  94. switch (invoke_mode) {
  95. case 'C': // compile
  96. if (rs==0)
  97. outfile << "<FONT COLOR=#008000>yes</FONT>";
  98. else
  99. outfile << "<FONT COLOR=#800000>failed to compile</FONT>";
  100. break;
  101. case 'F': // compile, fail expected
  102. if (rs==0)
  103. outfile
  104. << "<FONT COLOR=#800000>failed to cause error</FONT>";
  105. else
  106. outfile
  107. << "<FONT COLOR=#008000>yes</FONT>";
  108. break;
  109. case 'R': // run
  110. if (rs==0) {
  111. //script debugging aid
  112. std::cout << " executing: " << exe_invoke_prefix << program_name
  113. << " " << invoke_args << std::endl;
  114. std::string cmd_line = exe_invoke_prefix + program_name
  115. + " " + invoke_args;
  116. rs = system(cmd_line.c_str());
  117. if (rs==0)
  118. outfile
  119. << "<FONT COLOR=#008000>yes</FONT>";
  120. else
  121. outfile << "<FONT COLOR=#800000>exited with code "
  122. << rs << "</FONT>";
  123. } else
  124. outfile << "<FONT COLOR=#800000>failed to compile</FONT>";
  125. break;
  126. default:
  127. outfile << "scripting error";
  128. } // switch (invoke_mode)
  129. outfile << "</td>" << std::endl;
  130. }
  131. //-----------------------------------------------------------------------------
  132. void compile(std::string program,
  133. char invoke_mode,
  134. std::string invoke_args,
  135. std::string program_name)
  136. {
  137. std::string fullpath = path + "/libs/" + program;
  138. std::cout << std::endl
  139. << "*****" << program << "*****" << std::endl;
  140. outfile << "<tr>" << std::endl
  141. << "<td><a href=\"" << program << "\">" << program << "</a></td>"
  142. << std::endl;
  143. std::string gcc_flags
  144. = "-Wall -pedantic -ftemplate-depth-30 -Wno-long-long";
  145. // should add -Werror
  146. std::string kcc_flags
  147. // = "--strict";
  148. = "--strict_warnings";
  149. std::string mwcc_flags = "-maxerrors 10 -cwd source";
  150. //John Maddock says use /Zm400 switch; it increases compiler memory
  151. std::string msvc_flags = "/nologo /Zm400 /MDd /W3 /GR /GX /GZ /D \"WIN32\" /D \"_DEBUG\" /D \"_MBCS\" /D \"_CONSOLE\"";
  152. if (platform() == "linux") {
  153. if (compiler_arg == "*" || compiler_arg == "gcc")
  154. invoke("GCC 2.95.2", "g++ " + gcc_flags
  155. + " -o " + program_name
  156. + " -I" + path + " " + fullpath,
  157. invoke_mode, invoke_args, program_name);
  158. if (compiler_arg == "*" || compiler_arg == "gcc-stlport")
  159. invoke( "GCC 2.95.2 STLport 4.0",
  160. "g++ -V 2.95.2-stlport " + gcc_flags
  161. + " -o " + program_name
  162. + " -I" + path + " " + fullpath,
  163. invoke_mode, invoke_args, program_name );
  164. if (compiler_arg == "*" || compiler_arg == "como")
  165. invoke( "Comeau C++ 4.2.44 beta3", "como -o " + program_name
  166. + " -I" + path + " " + fullpath,
  167. invoke_mode, invoke_args, program_name);
  168. } else if (platform() == "sunos") {
  169. if (compiler_arg == "*" || compiler_arg == "gcc")
  170. invoke("GCC 2.95.2",
  171. "g++ " + gcc_flags
  172. + " -o " + program_name
  173. + " -I" + path + " " + fullpath,
  174. invoke_mode, invoke_args, program_name);
  175. if (compiler_arg == "*" || compiler_arg == "kcc")
  176. invoke("KCC 3.4g", "KCC " + kcc_flags
  177. + " -o " + program_name
  178. + " -I" + path + " " + fullpath,
  179. invoke_mode, invoke_args, program_name);
  180. } else if (platform() == "beos") {
  181. if (compiler_arg=="*" || compiler_arg=="gcc")
  182. invoke( "GNU GCC", "c++ " + gcc_flags
  183. +" -o " + program_name
  184. + " -I" + path + " " + fullpath,
  185. invoke_mode, invoke_args, program_name );
  186. // shouldn't this next one be called gcc-stlport instead of gcc-sgi?
  187. if (compiler_arg=="*" || compiler_arg=="gcc-sgi")
  188. invoke("GNU GCC", "c++ " + gcc_flags
  189. + " -o " + program_name
  190. + " -I/boot/home/config/stlport/stl330 -I" + path
  191. + " " + fullpath,
  192. invoke_mode, invoke_args, program_name );
  193. } else {
  194. if (compiler_arg=="*" || compiler_arg=="bcc") {
  195. char* path_ptr = getenv("BOOST_BCC55_PATH");
  196. if (path_ptr == 0) {
  197. std::cerr << "Environment variable BOOST_BCC55_PATH not defined"
  198. << std::endl;
  199. exit(1);
  200. }
  201. std::string bcc55_path = path_ptr;
  202. invoke( "Borland C++ 5.5.1", "\"" + bcc55_path
  203. + "/bcc32\" -e" + program_name
  204. + " -I" + path + " -j10 -q -Ve" + fullpath,
  205. invoke_mode, invoke_args, program_name );
  206. }
  207. if (compiler_arg=="gcc") {
  208. // TODO: fix the absolute STLport paths
  209. invoke( "GNU GCC", "c++ " + gcc_flags
  210. + " -o " + program_name
  211. + " -I" + path + " -IC:/stl/STLport-4.0b8/stlport "
  212. + fullpath
  213. + " c:/stl/STLport-4.0b8/lib/libstlport_gcc.a",
  214. invoke_mode, invoke_args, program_name );
  215. }
  216. if (compiler_arg=="*" || compiler_arg=="cw")
  217. invoke( "Metrowerks CodeWarrior",
  218. "mwcc " + mwcc_flags
  219. + " -I- -o " + program_name
  220. + " -I" + path + " " + fullpath,
  221. invoke_mode, invoke_args, program_name );
  222. if (compiler_arg=="*" || compiler_arg=="vc")
  223. invoke( "VC++ with MS library",
  224. "cl -o " + program_name
  225. + " " + msvc_flags
  226. + " /I " + path + fullpath + " user32.lib",
  227. invoke_mode, invoke_args, program_name );
  228. if (compiler_arg=="*" || compiler_arg=="vcstlport") {
  229. char* path_ptr = getenv("BOOST_STLPORT_PATH");
  230. if (path_ptr == 0) {
  231. std::cerr << "Environment variable BOOST_STLPORT_PATH not defined"
  232. << std::endl;
  233. exit(1);
  234. }
  235. std::string stlport = path_ptr;
  236. invoke( "VC++ with STLport library",
  237. "cl -o " + program_name + msvc_flags
  238. + "/I " + stlport + " /I " + path + fullpath + " user32.lib",
  239. invoke_mode, invoke_args, program_name );
  240. }
  241. }
  242. outfile << "</tr>" << std::endl;
  243. }
  244. //-----------------------------------------------------------------------------
  245. void library()
  246. {
  247. std::cout << std::endl
  248. << "***** Boost Library *****" << std::endl;
  249. outfile << "<tr>" << std::endl
  250. << "<td>Boost library build</td>" << std::endl;
  251. // ...
  252. outfile << "</tr>" << std::endl;
  253. }
  254. //-----------------------------------------------------------------------------
  255. int main(int argc, char* argv[])
  256. {
  257. char* path_ptr = getenv("BOOST_PATH");
  258. if (path_ptr == 0) {
  259. std::cerr << "Environment variable BOOST_PATH not defined" << std::endl;
  260. return -1;
  261. }
  262. path = path_ptr;
  263. compiler_arg = "*";
  264. if (argc > 1)
  265. compiler_arg = argv[1];
  266. program_arg = "*";
  267. if (argc > 2)
  268. program_arg = argv[2];
  269. if (platform() == "unkown") {
  270. std::cerr << "**** Error: unknown platform ****" << std::endl;
  271. return 1;
  272. }
  273. std::string filename = "cs-" + platform() + ".htm";
  274. outfile.open(filename.c_str());
  275. time_t today;
  276. time(&today);
  277. outfile << "<html>\n<head>\n<title>\nCompiler Status: " << platform() << "\n</title>\n</head>"
  278. << "<body bgcolor=\"#FFFFFF\" text=\"#000000\">" << std::endl
  279. << "<h1><img border=\"0\" src=\"../c++boost.gif\" width=\"277\" height=\"86\"></h1>" << std::endl
  280. << "<h1>Compiler Status: " << platform() << "</h1>" << std::endl
  281. << "<p><b>Run Date:</b> " << ctime(&today)
  282. << "</p>" << std::endl
  283. << "<p>" << std::endl
  284. << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">" << std::endl
  285. << "<tr>" << std::endl
  286. << "<td>Program</td>" << std::endl;
  287. if (platform() == "linux") {
  288. if (compiler_arg == "*" || compiler_arg == "gcc")
  289. outfile << "<td>GNU<br>GCC<br>2.95.2</td>" << std::endl;
  290. if (compiler_arg == "*" || compiler_arg == "gcc-stlport")
  291. outfile << "<td>GNU<br>GCC<br>2.95.2<br>STLport<br>4.0</td>"
  292. << std::endl;
  293. #if 0
  294. if (compiler_arg == "*" || compiler_arg == "gcc-exp")
  295. outfile << "<td>GNU<br>GCC<br>pre-2.97 experimental</td>" << std::endl;
  296. #endif
  297. if (compiler_arg == "*" || compiler_arg == "como")
  298. outfile << "<td>Comeau C++<br>4.2.44 beta3<br>STLport<br>4.0</td>"
  299. << std::endl;
  300. #if 0
  301. if (compiler_arg == "*" || compiler_arg == "occ")
  302. outfile << "<td>OpenC++<br>2.5.9</td>" << std::endl;
  303. #endif
  304. } else if (platform() == "sunos") {
  305. if (compiler_arg == "*" || compiler_arg == "suncc")
  306. outfile << "<td>Sun C++<br>Sun WorkShop 6, C++ 5.1</td>" << std::endl;
  307. if (compiler_arg == "*" || compiler_arg == "gcc")
  308. outfile << "<td>GNU<br>GCC<br>2.95.2</td>" << std::endl;
  309. if (compiler_arg == "*" || compiler_arg == "kcc")
  310. outfile << "<td>KAI<br>KCC<br>3.4g</td>" << std::endl;
  311. } else if (platform() == "beos") {
  312. if (compiler_arg == "*" || compiler_arg == "gcc")
  313. outfile << "<td>GNUPro<br>GCC&nbsp;2.9</td>" << std::endl;
  314. if (compiler_arg == "*" || compiler_arg == "gcc-sgi")
  315. outfile
  316. << "<td>GNUPro<br>GCC&nbsp;2.9<br>+<br>SGI&nbsp;STL&nbsp;3.3</td>"
  317. << std::endl;
  318. } else {
  319. #if 0
  320. if (compiler_arg=="*" || compiler_arg=="bcc54")
  321. outfile << "<td>Borland<br>BCC<br>5.4 up2</td>" << std::endl;
  322. #endif
  323. if (compiler_arg=="*" || compiler_arg=="bcc")
  324. outfile << "<td>Borland<br>BCC<br>5.5.1</td>" << std::endl;
  325. // GCC 2.95.2 is looping on some tests, so only invoke if asked
  326. // for by name
  327. if (compiler_arg=="gcc")
  328. outfile << "<td>GNU<br>GCC<br>2.95.2<br>STLport<br>4.0 beta 8</td>"
  329. << std::endl;
  330. if (compiler_arg=="*" || compiler_arg=="cw")
  331. outfile << "<td>Metrowerks<br>CodeWarrior<br>6.0</td>" << std::endl;
  332. if (compiler_arg=="*" || compiler_arg=="vc")
  333. outfile << "<td>Microsoft<br>VC++<br>6.0 SP4</td>" << std::endl;
  334. if (compiler_arg=="*" || compiler_arg=="vcstlport")
  335. outfile << "<td>Microsoft<br>VC++<br>6.0 SP4<br>STLport<br>4.0</td>"
  336. << std::endl;
  337. }
  338. outfile << "</tr>" << std::endl;
  339. if (program_arg == "*") {
  340. std::string filelist = "regrtest_files.txt";
  341. std::ifstream regr_files(filelist.c_str());
  342. if (regr_files) {
  343. std::string line;
  344. while (std::getline(regr_files, line)) {
  345. char* program_buf = new char[line.size()];
  346. char mode;
  347. char* arg_buf = new char[line.size()];
  348. sscanf(line.c_str(), "%s %c %s", program_buf, &mode, arg_buf);
  349. compile(program_buf, mode, arg_buf,
  350. "regress" + exe_suffix);
  351. delete program_buf;
  352. delete arg_buf;
  353. }
  354. } else {
  355. std::cerr << "Could not open regression test file list: "
  356. << filelist << std::endl;
  357. return -1;
  358. }
  359. } else
  360. compile(program_arg, 'C', "", "regress" + exe_suffix);
  361. outfile << "</table>" << std::endl;
  362. if (platform() == "linux")
  363. outfile << "<p>\nNote: A hand-crafted &lt;limits&gt; "
  364. << "Standard header has been applied to all configurations."
  365. << std::endl;
  366. outfile << "</body>\n</html>" << std::endl;
  367. return 0;
  368. }
粤ICP备19079148号