regression.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. // It is OK to use boost headers which contain entirely inline code.
  23. #include <boost/config.hpp>
  24. # ifdef BOOST_NO_STDC_NAMESPACE
  25. namespace std { using ::exit; using ::system; }
  26. # endif
  27. std::string get_host()
  28. {
  29. #if defined __linux__
  30. return "linux";
  31. #elif defined _MSC_VER
  32. return "win32";
  33. #else
  34. #error Please adapt for your platform
  35. #endif
  36. }
  37. struct entry
  38. {
  39. std::string os, identifier, name, compile_only_command, compile_link_command, html;
  40. };
  41. void replace(std::string & s,
  42. const std::string & name, const std::string & value)
  43. {
  44. std::string::size_type p = s.find(name);
  45. if(p != std::string::npos)
  46. s.replace(p, name.length(), value);
  47. }
  48. void replace_environment(std::string & s)
  49. {
  50. std::string::size_type end = 0;
  51. for(;;) {
  52. std::string::size_type pos = s.find('$', end);
  53. if(pos == std::string::npos)
  54. break;
  55. end = s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", pos+1);
  56. const char * env = getenv(s.substr(pos+1, end-pos-1).c_str());
  57. if(env)
  58. replace(s, s.substr(pos, end-pos), env);
  59. else
  60. break;
  61. }
  62. }
  63. // get a string line, ignoring empty lines and comment lines
  64. void getstringline( std::ifstream & is, std::string & s )
  65. {
  66. do { std::getline( is, s ); }
  67. while ( is.good()
  68. && (!s.size() || (s.size() >= 2 && s[0] == '/' && s[1] == '/')) );
  69. }
  70. template<class OutputIterator>
  71. void read_compiler_configuration(const std::string & file, OutputIterator out)
  72. {
  73. std::ifstream f(file.c_str());
  74. int lineno = 0;
  75. while(f.good()) {
  76. entry e;
  77. getstringline(f, e.os);
  78. getstringline(f, e.identifier);
  79. getstringline(f, e.name);
  80. getstringline(f, e.compile_only_command);
  81. getstringline(f, e.compile_link_command);
  82. getstringline(f, e.html);
  83. *out = e;
  84. ++out;
  85. std::string l;
  86. std::getline(f, l);
  87. lineno += 6;
  88. if(l != "") {
  89. std::cerr << file << ", line " << lineno
  90. << ": Empty line expected, got " << l << "\n";
  91. std::exit(1);
  92. }
  93. }
  94. }
  95. bool execute(const std::string & command)
  96. {
  97. std::cout << command << "\n";
  98. return std::system(command.c_str()) == 0;
  99. }
  100. enum test_result {
  101. ok = 0,
  102. unknown_type,
  103. compile_failed, compile_ok, link_failed, link_ok, run_failed, run_ok
  104. };
  105. test_result compile(std::string command, const std::string & boostpath,
  106. const std::string & file)
  107. {
  108. replace(command, "%source", boostpath + "/" + file);
  109. return execute(command) ? compile_ok : compile_failed;
  110. }
  111. test_result link(std::string command, const std::string & boostpath,
  112. const std::string & file)
  113. {
  114. replace(command, "%source", boostpath + "/" + file);
  115. return execute(command) ? link_ok : link_failed;
  116. }
  117. test_result run(std::string command, const std::string & boostpath,
  118. const std::string & file)
  119. {
  120. std::string exename = "boosttmp.exe";
  121. replace(command, "%source", boostpath + "/" + file);
  122. if(execute(command)) {
  123. return execute( (get_host() == "win32" ? "" : "./") + exename ) ?
  124. run_ok : run_failed;
  125. } else {
  126. return link_failed;
  127. }
  128. }
  129. std::pair<test_result, test_result>
  130. run_test(const std::string & type, std::string compile_only_command,
  131. std::string compile_link_command,
  132. const std::string & boostpath, const std::string & source)
  133. {
  134. replace(compile_only_command, "%include", boostpath);
  135. replace(compile_link_command, "%include", boostpath);
  136. if(type == "compile")
  137. return std::make_pair(compile(compile_only_command, boostpath, source), compile_ok);
  138. else if(type == "compile-fail")
  139. return std::make_pair(compile(compile_only_command, boostpath, source), compile_failed);
  140. else if(type == "link")
  141. return std::make_pair(link(compile_link_command, boostpath, source), link_ok);
  142. else if(type == "link-fail")
  143. return std::make_pair(link(compile_link_command, boostpath, source), link_failed);
  144. else if(type == "run")
  145. return std::make_pair(run(compile_link_command, boostpath, source), run_ok);
  146. else if(type == "run-fail")
  147. return std::make_pair(run(compile_link_command, boostpath, source), run_failed);
  148. else
  149. return std::make_pair(unknown_type, ok);
  150. }
  151. template<class ForwardIterator>
  152. void do_tests(std::ostream & out,
  153. ForwardIterator firstcompiler, ForwardIterator lastcompiler,
  154. const std::string & testconfig, const std::string & boostpath)
  155. {
  156. out << "<tr>\n"
  157. << "<td>Program</td>\n"
  158. << "<td>Test<br>Type</td>\n";
  159. for(ForwardIterator it = firstcompiler; it != lastcompiler; ++it) {
  160. out << "<td>" << it->html << "</td>\n";
  161. }
  162. out << "</tr>\n";
  163. std::ifstream f(testconfig.c_str());
  164. while(f.good()) {
  165. std::string l;
  166. getstringline(f, l);
  167. typedef std::string::size_type sz_type;
  168. sz_type p = l.find(' ');
  169. if(p == std::string::npos) {
  170. std::cerr << "Test " << l << " is wrong\n";
  171. continue;
  172. }
  173. std::string type(l, 0, p);
  174. std::string file(l, p+1, std::string::npos); // 3rd arg to fix VC++ bug
  175. std::cout << "*** " << file << " ***\n\n";
  176. out << "<tr>\n"
  177. << "<td><a href=\"" << file << "\">" << file << "</a></td>\n"
  178. << "<td>" << type << "</td>\n";
  179. for(ForwardIterator it = firstcompiler; it != lastcompiler; ++it) {
  180. std::cout << "** " << it->name << std::endl;
  181. std::pair<test_result, test_result> result =
  182. run_test(type, it->compile_only_command, it->compile_link_command, boostpath, file);
  183. if(result.first == unknown_type) {
  184. std::cerr << "Unknown test type " << type << ", skipped\n";
  185. continue;
  186. }
  187. out << "<td>"
  188. << (result.first == result.second ? "Pass" : "<font color=\"#FF0000\">Fail</font>")
  189. << "</td>" << std::endl;
  190. std::cout << (result.first == result.second ? "Pass" : "Fail") << "\n\n";
  191. }
  192. out << "</tr>\n";
  193. }
  194. }
  195. int main(int argc, char * argv[])
  196. {
  197. // std::vector<std::string> args(argv+1, argv+argc);
  198. // hack around VC++ lack of ctor taking iterator args
  199. std::vector<std::string> args;
  200. for ( const char ** ait = (const char **)(argv+1);
  201. ait != (const char **)(argv+argc); ++ait)
  202. args.push_back(std::string( *ait ));
  203. if(args.size() < 3) {
  204. std::cerr << argv[0] << " usage: compiler-config test-config boost-path [compiler] [file]\n";
  205. std::exit(1);
  206. }
  207. std::string compiler = (args.size() >= 4 ? args[3] : "*");
  208. std::list<entry> l;
  209. read_compiler_configuration(args[0], std::back_inserter(l));
  210. std::string host = get_host();
  211. for(std::list<entry>::iterator it = l.begin(); it != l.end(); ) {
  212. if(it->os == host && (compiler == "*" || it->identifier == compiler)) {
  213. replace_environment(it->compile_only_command);
  214. replace_environment(it->compile_link_command);
  215. ++it;
  216. } else {
  217. it = l.erase(it);
  218. }
  219. }
  220. std::string boostpath = args[2];
  221. if(args.size() >= 5) {
  222. std::string cmd = l.front().compile_only_command;
  223. replace(cmd, "%include", boostpath);
  224. compile(cmd, boostpath, args[4]);
  225. return 0;
  226. }
  227. std::ofstream out( ("cs-" + host + ".html").c_str() );
  228. out << "<html>\n<head>\n<title>\nCompiler Status: " + host + "\n</title>\n</head>\n"
  229. << "<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
  230. << "<h1><img border border=\"0\" src=\"../c++boost.gif\" width=\"277\" height=\"86\"></h1>\n"
  231. << "<h1>Compiler Status: " + host + "</h1>\n"
  232. << "</p>\n"
  233. << "<p>\n"
  234. << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";
  235. do_tests(out, l.begin(), l.end(), args[1], boostpath);
  236. out << "</table>\n";
  237. return 0;
  238. }
粤ICP备19079148号