regrtest.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. // OS 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. #include <string.h> // for strtok()
  58. // Enumerated Types
  59. // Global variables
  60. std::string path, compiler_arg, program_arg, exe_suffix, exe_invoke_prefix;
  61. std::ofstream outfile;
  62. //-----------------------------------------------------------------------------
  63. std::string platform()
  64. {
  65. char* os_ptr = getenv("OS");
  66. if (os_ptr == 0) {
  67. std::cerr << "The \"OS\" 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 == "solaris2.7")
  76. return "sunos";
  77. else if (os == "Windows_NT")
  78. return "windows";
  79. else
  80. return "unknown";
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. void invoke(std::string desc,
  85. std::string command,
  86. char invoke_mode,
  87. std::string invoke_args,
  88. std::string program_name)
  89. {
  90. std::cout << " " << desc << std::endl;
  91. std::cout << " invoke mode: " << invoke_mode << std::endl;
  92. std::cout << " " << command << std::endl;
  93. outfile << "<td>";
  94. int rs = system(command.c_str());
  95. std::cout << " compile return status: " << rs << std::endl;
  96. switch (invoke_mode) {
  97. case 'C': // compile
  98. if (rs==0)
  99. outfile << "<FONT COLOR=#008000>yes</FONT>";
  100. else
  101. outfile << "<FONT COLOR=#800000>failed to compile</FONT>";
  102. break;
  103. case 'F': // compile, fail expected
  104. if (rs==0)
  105. outfile
  106. << "<FONT COLOR=#800000>failed to cause error</FONT>";
  107. else
  108. outfile
  109. << "<FONT COLOR=#008000>yes</FONT>";
  110. break;
  111. case 'R': // run
  112. if (rs==0) {
  113. //script debugging aid
  114. std::cout << " executing: " << exe_invoke_prefix << program_name
  115. << " " << invoke_args << std::endl;
  116. std::string cmd_line = exe_invoke_prefix + program_name
  117. + " " + invoke_args;
  118. rs = system(cmd_line.c_str());
  119. if (rs==0)
  120. outfile
  121. << "<FONT COLOR=#008000>yes</FONT>";
  122. else
  123. outfile << "<FONT COLOR=#800000>exited with code "
  124. << rs << "</FONT>";
  125. } else
  126. outfile << "<FONT COLOR=#800000>failed to compile</FONT>";
  127. break;
  128. default:
  129. outfile << "scripting error";
  130. } // switch (invoke_mode)
  131. outfile << "</td>" << std::endl;
  132. }
  133. //-----------------------------------------------------------------------------
  134. void compile(std::string program,
  135. char invoke_mode,
  136. std::string invoke_args,
  137. std::string program_name)
  138. {
  139. std::string fullpath = path + "/libs/" + program;
  140. std::cout << std::endl
  141. << "*****" << program << "*****" << std::endl;
  142. outfile << "<tr>" << std::endl
  143. << "<td><a href=\"" << program << "\">" << program << "</a></td>"
  144. << std::endl;
  145. std::string gcc_flags
  146. = "-Wall -pedantic -ftemplate-depth-30 -Wno-long-long";
  147. // should add -Werror
  148. std::string kcc_flags
  149. // = "--strict";
  150. = "--strict_warnings";
  151. std::string mwcc_flags = "-maxerrors 10 -cwd source";
  152. //John Maddock says use /Zm400 switch; it increases compiler memory
  153. std::string msvc_flags = "/nologo /Zm400 /MDd /W3 /GR /GX /GZ /D \"WIN32\" /D \"_DEBUG\" /D \"_MBCS\" /D \"_CONSOLE\"";
  154. if (platform() == "linux") {
  155. if (compiler_arg == "*" || compiler_arg == "gcc")
  156. invoke("GCC 2.95.2", "g++ " + gcc_flags
  157. + " -o " + program_name
  158. + " -I" + path + " " + fullpath,
  159. invoke_mode, invoke_args, program_name);
  160. if (compiler_arg == "*" || compiler_arg == "gcc-stlport")
  161. invoke( "GCC 2.95.2 STLport 4.0",
  162. "g++ -V 2.95.2-stlport " + gcc_flags
  163. + " -o " + program_name
  164. + " -I" + path + " " + fullpath,
  165. invoke_mode, invoke_args, program_name );
  166. if (compiler_arg == "*" || compiler_arg == "como")
  167. invoke( "Comeau C++ 4.2.44 beta3", "como -o " + program_name
  168. + " -I" + path + " " + fullpath,
  169. invoke_mode, invoke_args, program_name);
  170. } else if (platform() == "sunos") {
  171. if (compiler_arg == "*" || compiler_arg == "gcc")
  172. invoke("GCC 2.95.2",
  173. "g++ " + gcc_flags
  174. + " -o " + program_name
  175. + " -I" + path + " " + fullpath,
  176. invoke_mode, invoke_args, program_name);
  177. if (compiler_arg == "*" || compiler_arg == "kcc")
  178. invoke("KCC 3.4g", "KCC " + kcc_flags
  179. + " -o " + program_name
  180. + " -I" + path + " " + fullpath,
  181. invoke_mode, invoke_args, program_name);
  182. } else if (platform() == "beos") {
  183. if (compiler_arg=="*" || compiler_arg=="gcc")
  184. invoke( "GNU GCC", "c++ " + gcc_flags
  185. +" -o " + program_name
  186. + " -I" + path + " " + fullpath,
  187. invoke_mode, invoke_args, program_name );
  188. // shouldn't this next one be called gcc-stlport instead of gcc-sgi?
  189. if (compiler_arg=="*" || compiler_arg=="gcc-sgi")
  190. invoke("GNU GCC", "c++ " + gcc_flags
  191. + " -o " + program_name
  192. + " -I/boot/home/config/stlport/stl330 -I" + path
  193. + " " + fullpath,
  194. invoke_mode, invoke_args, program_name );
  195. } else {
  196. if (compiler_arg=="*" || compiler_arg=="bcc") {
  197. char* path_ptr = getenv("BOOST_BCC55_PATH");
  198. if (path_ptr == 0) {
  199. std::cerr << "Environment variable BOOST_BCC55_PATH not defined"
  200. << std::endl;
  201. exit(1);
  202. }
  203. std::string bcc55_path = path_ptr;
  204. invoke( "Borland C++ 5.5.1", "\"" + bcc55_path
  205. + "/bcc32\" -e" + program_name
  206. + " -I" + path + " -j10 -q -Ve" + fullpath,
  207. invoke_mode, invoke_args, program_name );
  208. }
  209. if (compiler_arg=="gcc") {
  210. // TODO: fix the absolute STLport paths
  211. invoke( "GNU GCC", "c++ " + gcc_flags
  212. + " -o " + program_name
  213. + " -I" + path + " -IC:/stl/STLport-4.0b8/stlport "
  214. + fullpath
  215. + " c:/stl/STLport-4.0b8/lib/libstlport_gcc.a",
  216. invoke_mode, invoke_args, program_name );
  217. }
  218. if (compiler_arg=="*" || compiler_arg=="cw")
  219. invoke( "Metrowerks CodeWarrior",
  220. "mwcc " + mwcc_flags
  221. + " -I- -o " + program_name
  222. + " -I" + path + " " + fullpath,
  223. invoke_mode, invoke_args, program_name );
  224. if (compiler_arg=="*" || compiler_arg=="vc")
  225. invoke( "VC++ with MS library",
  226. "cl -o " + program_name
  227. + " " + msvc_flags
  228. + " /I " + path + " " + fullpath + " user32.lib",
  229. invoke_mode, invoke_args, program_name );
  230. if (compiler_arg=="*" || compiler_arg=="vcstlport") {
  231. char* path_ptr = getenv("BOOST_STLPORT_PATH");
  232. if (path_ptr == 0) {
  233. std::cerr << "Environment variable BOOST_STLPORT_PATH not defined"
  234. << std::endl;
  235. exit(1);
  236. }
  237. std::string stlport = path_ptr;
  238. invoke( "VC++ with STLport library",
  239. "cl -o " + program_name + msvc_flags
  240. + "/I " + stlport + " /I " + path + fullpath + " user32.lib",
  241. invoke_mode, invoke_args, program_name );
  242. }
  243. }
  244. outfile << "</tr>" << std::endl;
  245. }
  246. //-----------------------------------------------------------------------------
  247. void library()
  248. {
  249. std::cout << std::endl
  250. << "***** Boost Library *****" << std::endl;
  251. outfile << "<tr>" << std::endl
  252. << "<td>Boost library build</td>" << std::endl;
  253. // ...
  254. outfile << "</tr>" << std::endl;
  255. }
  256. //-----------------------------------------------------------------------------
  257. int main(int argc, char* argv[])
  258. {
  259. char* path_ptr = getenv("BOOST_PATH");
  260. if (path_ptr == 0) {
  261. std::cerr << "Environment variable BOOST_PATH not defined" << std::endl;
  262. return -1;
  263. }
  264. path = path_ptr;
  265. compiler_arg = "*";
  266. if (argc > 1)
  267. compiler_arg = argv[1];
  268. program_arg = "*";
  269. if (argc > 2)
  270. program_arg = argv[2];
  271. if (platform() == "unkown") {
  272. std::cerr << "**** Error: unknown platform ****" << std::endl;
  273. return 1;
  274. }
  275. if (platform() == "windows") {
  276. exe_suffix = ".exe";
  277. exe_invoke_prefix = "";
  278. } else {
  279. exe_suffix = "";
  280. exe_invoke_prefix = "./";
  281. }
  282. std::string filename = "cs-" + platform() + ".htm";
  283. outfile.open(filename.c_str());
  284. time_t today;
  285. time(&today);
  286. outfile << "<html>\n<head>\n<title>\nCompiler Status: " << platform() << "\n</title>\n</head>"
  287. << "<body bgcolor=\"#FFFFFF\" text=\"#000000\">" << std::endl
  288. << "<h1><img border=\"0\" src=\"../c++boost.gif\" width=\"277\" height=\"86\"></h1>" << std::endl
  289. << "<h1>Compiler Status: " << platform() << "</h1>" << std::endl
  290. << "<p><b>Run Date:</b> " << ctime(&today)
  291. << "</p>" << std::endl
  292. << "<p>" << std::endl
  293. << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">" << std::endl
  294. << "<tr>" << std::endl
  295. << "<td>Program</td>" << std::endl;
  296. if (platform() == "linux") {
  297. if (compiler_arg == "*" || compiler_arg == "gcc")
  298. outfile << "<td>GNU<br>GCC<br>2.95.2</td>" << std::endl;
  299. if (compiler_arg == "*" || compiler_arg == "gcc-stlport")
  300. outfile << "<td>GNU<br>GCC<br>2.95.2<br>STLport<br>4.0</td>"
  301. << std::endl;
  302. #if 0
  303. if (compiler_arg == "*" || compiler_arg == "gcc-exp")
  304. outfile << "<td>GNU<br>GCC<br>pre-2.97 experimental</td>" << std::endl;
  305. #endif
  306. if (compiler_arg == "*" || compiler_arg == "como")
  307. outfile << "<td>Comeau C++<br>4.2.44 beta3<br>STLport<br>4.0</td>"
  308. << std::endl;
  309. #if 0
  310. if (compiler_arg == "*" || compiler_arg == "occ")
  311. outfile << "<td>OpenC++<br>2.5.9</td>" << std::endl;
  312. #endif
  313. } else if (platform() == "sunos") {
  314. if (compiler_arg == "*" || compiler_arg == "suncc")
  315. outfile << "<td>Sun C++<br>Sun WorkShop 6, C++ 5.1</td>" << std::endl;
  316. if (compiler_arg == "*" || compiler_arg == "gcc")
  317. outfile << "<td>GNU<br>GCC<br>2.95.2</td>" << std::endl;
  318. if (compiler_arg == "*" || compiler_arg == "kcc")
  319. outfile << "<td>KAI<br>KCC<br>3.4g</td>" << std::endl;
  320. } else if (platform() == "beos") {
  321. if (compiler_arg == "*" || compiler_arg == "gcc")
  322. outfile << "<td>GNUPro<br>GCC&nbsp;2.9</td>" << std::endl;
  323. if (compiler_arg == "*" || compiler_arg == "gcc-sgi")
  324. outfile
  325. << "<td>GNUPro<br>GCC&nbsp;2.9<br>+<br>SGI&nbsp;STL&nbsp;3.3</td>"
  326. << std::endl;
  327. } else {
  328. #if 0
  329. if (compiler_arg=="*" || compiler_arg=="bcc54")
  330. outfile << "<td>Borland<br>BCC<br>5.4 up2</td>" << std::endl;
  331. #endif
  332. if (compiler_arg=="*" || compiler_arg=="bcc")
  333. outfile << "<td>Borland<br>BCC<br>5.5.1</td>" << std::endl;
  334. // GCC 2.95.2 is looping on some tests, so only invoke if asked
  335. // for by name
  336. if (compiler_arg=="gcc")
  337. outfile << "<td>GNU<br>GCC<br>2.95.2<br>STLport<br>4.0 beta 8</td>"
  338. << std::endl;
  339. if (compiler_arg=="*" || compiler_arg=="cw")
  340. outfile << "<td>Metrowerks<br>CodeWarrior<br>6.0</td>" << std::endl;
  341. if (compiler_arg=="*" || compiler_arg=="vc")
  342. outfile << "<td>Microsoft<br>VC++<br>6.0 SP4</td>" << std::endl;
  343. if (compiler_arg=="*" || compiler_arg=="vcstlport")
  344. outfile << "<td>Microsoft<br>VC++<br>6.0 SP4<br>STLport<br>4.0</td>"
  345. << std::endl;
  346. }
  347. outfile << "</tr>" << std::endl;
  348. if (program_arg == "*") {
  349. std::string filelist = "regrtest_files.txt";
  350. std::ifstream regr_files(filelist.c_str());
  351. if (regr_files) {
  352. const int max_line = 1000;
  353. char line[max_line];
  354. while (regr_files.getline(line, max_line)) {
  355. char *program_ptr, *mode_ptr, *arg_ptr;
  356. program_ptr = strtok(line, " ");
  357. if (program_ptr == 0) {
  358. std::cerr << "file format error, no program file name" << std::endl;
  359. return -1;
  360. }
  361. mode_ptr = strtok(0, " \n");
  362. if (mode_ptr == 0) {
  363. std::cerr << "file format error, no mode character" << std::endl;
  364. return -1;
  365. }
  366. arg_ptr = strtok(0, " \n");
  367. char* empty_string = "";
  368. if (arg_ptr == 0)
  369. arg_ptr = empty_string;
  370. compile(program_ptr, *mode_ptr, arg_ptr, "regress" + exe_suffix);
  371. }
  372. } else {
  373. std::cerr << "Could not open regression test file list: "
  374. << filelist << std::endl;
  375. return -1;
  376. }
  377. } else
  378. compile(program_arg, 'C', "", "regress" + exe_suffix);
  379. outfile << "</table>" << std::endl;
  380. if (platform() == "linux")
  381. outfile << "<p>\nNote: A hand-crafted &lt;limits&gt; "
  382. << "Standard header has been applied to all configurations."
  383. << std::endl;
  384. outfile << "</body>\n</html>" << std::endl;
  385. return 0;
  386. }
粤ICP备19079148号