[363] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 11 | * ã«ãã£ã¦å
|
---|
| 12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | * ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | * è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | * ã¨ï¼
|
---|
| 31 | * (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | * (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | * å ±åãããã¨ï¼
|
---|
| 39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | *
|
---|
| 44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: testsuite.cpp,v 1.3 2003/12/15 07:32:14 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | // $Header: /home/CVS/configurator/base/testsuite.cpp,v 1.3 2003/12/15 07:32:14 takayuki Exp $
|
---|
| 54 |
|
---|
| 55 | #include "base/testsuite.h"
|
---|
| 56 |
|
---|
| 57 | #include "base/coverage_defs.h"
|
---|
| 58 | #include "base/coverage_undefs.h"
|
---|
| 59 |
|
---|
| 60 | #ifdef TESTSUITE
|
---|
| 61 |
|
---|
| 62 | #undef main //ãã¹ãã¹ã£ã¼ãç¨ã®mainãå®ç¾©ããã®ã§undefãã
|
---|
| 63 | #undef cin
|
---|
| 64 | #undef cout
|
---|
| 65 | #undef cerr
|
---|
| 66 |
|
---|
| 67 | #include <stdlib.h> //EXIT_SUCCESS|EXIT_FAILUREç¨
|
---|
| 68 | #include <fstream> //ä½æ¥é¢æ°ç¨
|
---|
| 69 | #include <cstdio>
|
---|
| 70 | #include <iomanip>
|
---|
| 71 |
|
---|
| 72 | using namespace std;
|
---|
| 73 |
|
---|
| 74 | /* ã¹ããªã¼ã å
|
---|
| 75 | ¥æãç¨ã®å¤æ°å®ç¾© */
|
---|
| 76 | namespace std {
|
---|
| 77 | stringstream _cin;
|
---|
| 78 | stringstream _cout;
|
---|
| 79 | stringstream _cerr;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * ãã¹ãã¹ã£ã¼ãã®å®è¡å¶å¾¡ã¯ã©ã¹ ; class TestSuiteControl
|
---|
| 84 | */
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | //ã³ã³ã¹ãã©ã¯ã¿
|
---|
| 88 | TestSuiteControl::TestSuiteControl(ostream & _out, const char * _pattern) : target_session(_pattern), out(&_out), fail(false), verbose(false), case_count(0), fail_count(0)
|
---|
| 89 | {}
|
---|
| 90 |
|
---|
| 91 | //ã·ããªãªåã®åå¾
|
---|
| 92 | string TestSuiteControl::get_suitename(const char * name) const
|
---|
| 93 | {
|
---|
| 94 | string result;
|
---|
| 95 | list<string>::const_iterator scope;
|
---|
| 96 |
|
---|
| 97 | scope = session.begin();
|
---|
| 98 | while(scope != session.end()) {
|
---|
| 99 | result += *scope;
|
---|
| 100 | result += '.';
|
---|
| 101 | ++ scope;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | if(name != NULL)
|
---|
| 105 | result += name;
|
---|
| 106 |
|
---|
| 107 | return result;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | //ãã¹ãã·ããªãªã®è¡¨é¡è¨å® (è¿å´å¤ : å®è¡ããå¿
|
---|
| 112 | è¦ããããã©ãã)
|
---|
| 113 | bool TestSuiteControl::_enter_case(const char * session, const char * description, const char * filename, long lineno)
|
---|
| 114 | {
|
---|
| 115 | bool result;
|
---|
| 116 | stringstream buf;
|
---|
| 117 |
|
---|
| 118 | //表é¡ã®è¨å®
|
---|
| 119 | current_session.assign(get_suitename(session));
|
---|
| 120 |
|
---|
| 121 | //詳細æ
|
---|
| 122 | å ±ã®è¨å®
|
---|
| 123 | if(description != 0)
|
---|
| 124 | buf << description;
|
---|
| 125 |
|
---|
| 126 | //ãã¡ã¤ã«å (filename:lineno) ã®çæ
|
---|
| 127 | if(filename != 0) {
|
---|
| 128 | string work(filename);
|
---|
| 129 | string::size_type pos;
|
---|
| 130 |
|
---|
| 131 | //ãã«ãã¹ã§æ¥ããçãåã
|
---|
| 132 | pos = work.find_last_of("/\\");
|
---|
| 133 | if(pos != string::npos)
|
---|
| 134 | work.erase(0, pos + 1);
|
---|
| 135 |
|
---|
| 136 | buf << '(' << work;
|
---|
| 137 | if(lineno != -1)
|
---|
| 138 | buf << ':' << lineno;
|
---|
| 139 | buf << ')';
|
---|
| 140 | }
|
---|
| 141 | current_description = buf.str();
|
---|
| 142 |
|
---|
| 143 | //å®è¡ããå¿
|
---|
| 144 | è¦ã®æç¡ã®ç¢ºèª
|
---|
| 145 | result = (target_session.empty() || current_session.find(target_session) != string::npos);
|
---|
| 146 |
|
---|
| 147 | if(result) {
|
---|
| 148 | if(verbose) {
|
---|
| 149 | string indent;
|
---|
| 150 | indent.assign(2 * this->session.size(), ' ');
|
---|
| 151 | (*out) << indent << '[' << session << "] " << current_description << endl;
|
---|
| 152 |
|
---|
| 153 | //(*out) << '[' << current_session << "] " << current_description << endl;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | enter_session(session);
|
---|
| 157 | ++ case_count;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | return result;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | //ãã¹ãã»ãã·ã§ã³å (ã·ããªãªãã¬ãã£ã¯ã¹) ã®è¨å®
|
---|
| 164 | void TestSuiteControl::enter_session(const string & _session)
|
---|
| 165 | { session.push_back(_session); }
|
---|
| 166 |
|
---|
| 167 | //ãã¹ãã»ãã·ã§ã³å (ã·ããªãªãã¬ãã£ã¯ã¹) ã®è§£é¤
|
---|
| 168 | void TestSuiteControl::leave_session(void)
|
---|
| 169 | { session.pop_back(); }
|
---|
| 170 |
|
---|
| 171 | //ãã¹ãã·ããªãªã®å¤±æå ±å
|
---|
| 172 | void TestSuiteControl::fail_in_suite(string msg)
|
---|
| 173 | {
|
---|
| 174 | fail = true;
|
---|
| 175 | (*out) << "Failed : [" << current_session << "]\n " << current_description << endl;
|
---|
| 176 | if(!msg.empty())
|
---|
| 177 | (*out) << " #" << msg << endl;
|
---|
| 178 | ++ fail_count;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | //ã¹ã£ã¼ãæ
|
---|
| 183 | å ±ã³ã³ã¹ãã©ã¯ã¿
|
---|
| 184 | TestSuite::SuiteContainerNode::SuiteContainerNode(const char * _session, SuiteFunction _suite) : session(_session), suite(_suite)
|
---|
| 185 | {}
|
---|
| 186 |
|
---|
| 187 | //ã¹ã£ã¼ãæ
|
---|
| 188 | å ±ã³ã³ã¹ãã©ã¯ã¿
|
---|
| 189 | TestSuite::SuiteContainerNode::SuiteContainerNode(const SuiteContainerNode & src) : session(src.session), suite(src.suite)
|
---|
| 190 | {}
|
---|
| 191 |
|
---|
| 192 | //ã¹ã£ã¼ãã®å®è¡
|
---|
| 193 | bool TestSuite::SuiteContainerNode::invoke(TestSuiteControl & suite_control)
|
---|
| 194 | {
|
---|
| 195 | if(suite != 0) {
|
---|
| 196 | suite_control.enter_session(session);
|
---|
| 197 | (*suite)(suite_control);
|
---|
| 198 | suite_control.leave_session();
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | return !suite_control.is_failed();
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | /*
|
---|
| 205 | * ãã¹ãã¹ã£ã¼ãå®è¡ã¯ã©ã¹
|
---|
| 206 | */
|
---|
| 207 |
|
---|
| 208 | //ã³ã³ã¹ãã©ã¯ã¿
|
---|
| 209 | TestSuite::TestSuite(const char * session, SuiteFunction suite) : fail(false)
|
---|
| 210 | { Singleton<SuiteContainer>::getInstance()->push_back(SuiteContainerNode(session, suite)); }
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | //ãã¹ãã©ã¯ã¿
|
---|
| 214 | TestSuite::~TestSuite(void)
|
---|
| 215 | {}
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | //ãã¹ãã¹ã£ã¼ãã®å®è¡ (è¿å´å¤:ã¹ã£ã¼ããå®è¡ãããã©ãã)
|
---|
| 219 | bool TestSuite::performTestSuite(int flags, const char * pattern)
|
---|
| 220 | {
|
---|
| 221 | bool result;
|
---|
| 222 | TestSuiteControl suite_control(cerr, pattern);
|
---|
| 223 | SuiteContainer * container;
|
---|
| 224 | SuiteContainer::iterator scope;
|
---|
| 225 |
|
---|
| 226 | //å®è¡ã¹ã£ã¼ããªã¹ãã®åç
|
---|
| 227 | §
|
---|
| 228 | container = Singleton<SuiteContainer>::getInstance();
|
---|
| 229 |
|
---|
| 230 | //åé·åºåè¨å®
|
---|
| 231 | if( (flags & VERBOSE) != 0 )
|
---|
| 232 | suite_control.set_verbose();
|
---|
| 233 |
|
---|
| 234 | //å
|
---|
| 235 | ¨ç»é²ã¹ã£ã¼ãã®å®è¡
|
---|
| 236 | scope = container->begin();
|
---|
| 237 | while(scope != container->end()) {
|
---|
| 238 |
|
---|
| 239 | result = scope->invoke(suite_control);
|
---|
| 240 |
|
---|
| 241 | //ãã¡ãã¡æ¢ãã or éãã§å®è¡
|
---|
| 242 | if( !result && (flags & THROUGH) == 0)
|
---|
| 243 | break;
|
---|
| 244 |
|
---|
| 245 | ++ scope;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | //ã¨ã©ã¼ããªããã°OK表示
|
---|
| 249 | if(!suite_control.is_failed())
|
---|
| 250 | cerr << "OK (" << suite_control.countCases() << " passed)" << endl;
|
---|
| 251 | else
|
---|
| 252 | cerr << "Failed (" << suite_control.countFails() << '/' << suite_control.countCases() << ')' << endl;
|
---|
| 253 |
|
---|
| 254 | return !suite_control.is_failed(); //ã¹ã£ã¼ããæ£å¸¸ã«å®è¡ã§ãããtrue
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 | //ç»é²ããã¦ãããããã¬ãã«ã¹ã£ã¼ãã®ä¸è¦§è¡¨ç¤º
|
---|
| 259 | void TestSuite::listTestSuite(void)
|
---|
| 260 | {
|
---|
| 261 | SuiteContainer::iterator scope;
|
---|
| 262 | int count;
|
---|
| 263 | SuiteContainer * container;
|
---|
| 264 |
|
---|
| 265 | count = 0;
|
---|
| 266 | container = Singleton<SuiteContainer>::getInstance();
|
---|
| 267 |
|
---|
| 268 | scope = container->begin();
|
---|
| 269 | while(scope != container->end()) {
|
---|
| 270 | cout << " ";
|
---|
| 271 | cout.width(3);
|
---|
| 272 | cout << count << ':' << scope->getName() << endl;
|
---|
| 273 |
|
---|
| 274 | ++ count;
|
---|
| 275 | ++ scope;
|
---|
| 276 | }
|
---|
| 277 | cout << "Total " << count << " sets of suite exist.\n";
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | /*
|
---|
| 283 | * ãã§ãã¯ãã¤ã³ãç¨é¢æ°
|
---|
| 284 | */
|
---|
| 285 |
|
---|
| 286 | bool TestSuite::isReached(std::string checkname)
|
---|
| 287 | {
|
---|
| 288 | set<string>::iterator scope;
|
---|
| 289 |
|
---|
| 290 | scope = Singleton<Checkpoint>::getInstance()->find(checkname);
|
---|
| 291 |
|
---|
| 292 | return scope != Singleton<Checkpoint>::getInstance()->end();
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | /*
|
---|
| 297 | * ãã¹ãã¹ã£ã¼ãå®è¡ç¨ä½æ¥é¢æ°
|
---|
| 298 | */
|
---|
| 299 |
|
---|
| 300 | //ãã¡ã¤ã«å
|
---|
| 301 | 容æ¯è¼
|
---|
| 302 | bool TestSuite::compareFileContents(const char * filename, const char * filecontents, bool _remove)
|
---|
| 303 | {
|
---|
| 304 | fstream file(filename,ios::in);
|
---|
| 305 | int ch;
|
---|
| 306 | bool result = true;
|
---|
| 307 |
|
---|
| 308 | //å
|
---|
| 309 | 容ãã§ãã¯
|
---|
| 310 | while(result && *filecontents != '\x0' && file.good()) {
|
---|
| 311 | ch = file.get();
|
---|
| 312 |
|
---|
| 313 | if(ch != (int)*filecontents)
|
---|
| 314 | result = false;
|
---|
| 315 |
|
---|
| 316 | ++ filecontents;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | //EOFã«éãã¦ããã
|
---|
| 320 | if(result) {
|
---|
| 321 | if(!file.good() || file.get() != EOF)
|
---|
| 322 | result = false;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | file.close();
|
---|
| 326 |
|
---|
| 327 | if(_remove)
|
---|
| 328 | ::remove(filename);
|
---|
| 329 |
|
---|
| 330 | return result;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 |
|
---|
| 334 | /*
|
---|
| 335 | * ãã¹ãã¹ã£ã¼ãå®è¡ç¨mainé¢æ°
|
---|
| 336 | */
|
---|
| 337 | int main(int argc, char ** argv)
|
---|
| 338 | {
|
---|
| 339 | int result;
|
---|
| 340 | int pos;
|
---|
| 341 | int flags;
|
---|
| 342 | string category;
|
---|
| 343 |
|
---|
| 344 | flags = TestSuite::DEFAULT;
|
---|
| 345 |
|
---|
| 346 | for(pos = 1; pos < argc; ++ pos) {
|
---|
| 347 | if(*argv[pos] == '-') {
|
---|
| 348 | switch(argv[pos][1]) {
|
---|
| 349 | case 'v':
|
---|
| 350 | flags |= TestSuite::VERBOSE;
|
---|
| 351 | break;
|
---|
| 352 | case 'V':
|
---|
| 353 | flags &= ~TestSuite::VERBOSE;
|
---|
| 354 | break;
|
---|
| 355 | case 't':
|
---|
| 356 | flags |= TestSuite::THROUGH;
|
---|
| 357 | break;
|
---|
| 358 | case 'T':
|
---|
| 359 | flags &= ~TestSuite::THROUGH;
|
---|
| 360 | break;
|
---|
| 361 | case 'l':
|
---|
| 362 | TestSuite::listTestSuite();
|
---|
| 363 | return EXIT_SUCCESS;
|
---|
| 364 | case 'h':
|
---|
| 365 | cerr << "Usage : program (option) (suite)\n"
|
---|
| 366 | " -v, -V : Verbose output on(-v) / off(-V)\n"
|
---|
| 367 | " -t, -T : Go through with the suite, on(-t) / off(-T)\n"
|
---|
| 368 | " -l : List the top level suites\n";
|
---|
| 369 | return EXIT_SUCCESS;
|
---|
| 370 | default:
|
---|
| 371 | cerr << "Unknown option [" << argv[pos] << "]\n";
|
---|
| 372 | return EXIT_FAILURE;
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 | else {
|
---|
| 376 | if(!category.empty()) {
|
---|
| 377 | cerr << "Two or more category specified.\n";
|
---|
| 378 | return EXIT_FAILURE;
|
---|
| 379 | }
|
---|
| 380 | category.assign(argv[pos]);
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | result = EXIT_FAILURE;
|
---|
| 385 | if(TestSuite::performTestSuite(flags, category.c_str()))
|
---|
| 386 | result = EXIT_SUCCESS;
|
---|
| 387 |
|
---|
| 388 | #ifdef COVERAGE
|
---|
| 389 | fstream fout("coverage.txt",ios::out);
|
---|
| 390 | if(fout.is_open()) {
|
---|
| 391 | Coverage::printCoverage(fout);
|
---|
| 392 | fout.close();
|
---|
| 393 | }
|
---|
| 394 | #endif
|
---|
| 395 |
|
---|
| 396 | return result;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | #endif //TESTSUITE
|
---|
| 400 |
|
---|