[26] | 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: coverage.cpp,v 1.5 2003/12/15 07:32:13 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | #include "base/coverage_defs.h"
|
---|
| 54 | #include "base/coverage_undefs.h"
|
---|
| 55 |
|
---|
| 56 | #include <iostream>
|
---|
| 57 | #include <iomanip>
|
---|
| 58 |
|
---|
| 59 | using namespace std;
|
---|
| 60 |
|
---|
| 61 | #if defined(COVERAGE)
|
---|
| 62 | /*
|
---|
| 63 | * ç°¡åãªã«ãã¬ãã¸ãã§ãã¯
|
---|
| 64 | */
|
---|
| 65 |
|
---|
| 66 | //ãã©ã¼ãããæ¸ã¿ãã¡ã¤ã«ä½ç½®æ
|
---|
| 67 | å ±ã®åå¾
|
---|
| 68 | string Coverage::Location::getDetails(void) const
|
---|
| 69 | {
|
---|
| 70 | string result;
|
---|
| 71 |
|
---|
| 72 | result = string(filename) + ":" + String(lineno);
|
---|
| 73 | if(*additional != '\x0')
|
---|
| 74 | result += string("(") + additional + ")";
|
---|
| 75 |
|
---|
| 76 | return result;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | //è¦ç´ ã®å
|
---|
| 82 | ¨åé¤
|
---|
| 83 | Coverage::BranchMap::~BranchMap(void) throw()
|
---|
| 84 | {
|
---|
| 85 | iterator scope;
|
---|
| 86 |
|
---|
| 87 | scope = begin();
|
---|
| 88 | while(scope != end()) {
|
---|
| 89 | delete scope->second;
|
---|
| 90 | ++ scope;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | clear();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | //è¦ç´ ã®ç»é²
|
---|
| 97 | Coverage::BranchBase::BranchBase(const Location & location) throw()
|
---|
| 98 | {
|
---|
| 99 | BranchMap * bmap = Singleton<BranchMap>::getInstance();
|
---|
| 100 | NewBranchList * blist = Singleton<NewBranchList>::getInstance();
|
---|
| 101 |
|
---|
| 102 | (*bmap)[location] = this;
|
---|
| 103 | blist->push_back(this);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | //locationã«ä¸è´ããè¦ç´ ã®åå¾
|
---|
| 107 | Coverage::BranchBase * Coverage::BranchBase::find(const Location & location) throw()
|
---|
| 108 | {
|
---|
| 109 | BranchMap * bmap = Singleton<BranchMap>::getInstance();
|
---|
| 110 | BranchMap::iterator scope;
|
---|
| 111 | BranchBase * result = 0;
|
---|
| 112 |
|
---|
| 113 | scope = bmap->find(location);
|
---|
| 114 | if(scope != bmap->end())
|
---|
| 115 | result = scope->second;
|
---|
| 116 |
|
---|
| 117 | return result;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | //BranchIfã³ã³ã¹ãã©ã¯ã¿
|
---|
| 121 | Coverage::If::If(const Location & location) throw() : BranchBase(location), true_case(false), false_case(false)
|
---|
| 122 | {}
|
---|
| 123 |
|
---|
| 124 | //ifã®æ£å½æ§å¤å® (æç«/ä¸æç«ã®ä¸¡æ¹ãèµ·ã£ã¦ãã)
|
---|
| 125 | bool Coverage::If::checkValidity(void) const throw()
|
---|
| 126 | { return true_case && false_case; }
|
---|
| 127 |
|
---|
| 128 | //ééæ
|
---|
| 129 | å ±ã®åå¾
|
---|
| 130 | string Coverage::If::getDetails(void) const throw()
|
---|
| 131 | {
|
---|
| 132 | string result;
|
---|
| 133 |
|
---|
| 134 | if(true_case)
|
---|
| 135 | result += "true";
|
---|
| 136 |
|
---|
| 137 | if(false_case) {
|
---|
| 138 | if(true_case)
|
---|
| 139 | result += "/";
|
---|
| 140 | result += "false";
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | return result;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | //ifåå²ã®ãã§ãã¯
|
---|
| 147 | bool Coverage::If::branch(const Location & location, bool expression) throw()
|
---|
| 148 | {
|
---|
| 149 | If * node = dynamic_cast<If *>(find(location));
|
---|
| 150 | if(node == 0)
|
---|
| 151 | node = new(nothrow) If(location);
|
---|
| 152 |
|
---|
| 153 | if(node != 0) {
|
---|
| 154 | if(expression)
|
---|
| 155 | node->true_case = true;
|
---|
| 156 | else
|
---|
| 157 | node->false_case = true;
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | cerr << "[Coverage::Branch] Memory allocation error!\n";
|
---|
| 161 |
|
---|
| 162 | return expression;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 | //Whileã³ã³ã¹ãã©ã¯ã¿
|
---|
| 167 | Coverage::While::While(const Location & location) throw() : BranchBase(location), valid(false)
|
---|
| 168 | {}
|
---|
| 169 |
|
---|
| 170 | //Whileã®æ£å½æ§å¤å® (å°ãªãã¨ãä¸åã¯ã«ã¼ãã®ä¸ãã¾ãã£ã¦ãã)
|
---|
| 171 | bool Coverage::While::checkValidity(void) const throw()
|
---|
| 172 | { return valid; }
|
---|
| 173 |
|
---|
| 174 | //ééæ
|
---|
| 175 | å ±ã®åå¾
|
---|
| 176 | string Coverage::While::getDetails(void) const throw()
|
---|
| 177 | {
|
---|
| 178 | string result;
|
---|
| 179 |
|
---|
| 180 | if(valid)
|
---|
| 181 | result = "valid";
|
---|
| 182 | else
|
---|
| 183 | result = "invalid";
|
---|
| 184 |
|
---|
| 185 | return result;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | //whileåå²ã®ãã§ã㯠(å°ãªãã¨ãä¸åã¯ã«ã¼ãã®ä¸ãã¾ãã£ã¦ãã)
|
---|
| 189 | bool Coverage::While::branch(const Location & location, bool expression) throw()
|
---|
| 190 | {
|
---|
| 191 | While * node = dynamic_cast<While *>(find(location));
|
---|
| 192 | if(node == 0)
|
---|
| 193 | node = new(nothrow) While(location);
|
---|
| 194 |
|
---|
| 195 | if(node != 0) {
|
---|
| 196 | if(expression)
|
---|
| 197 | node->valid = true;
|
---|
| 198 | }
|
---|
| 199 | else
|
---|
| 200 | cerr << "[Coverage::Branch] Memory allocation error!\n";
|
---|
| 201 |
|
---|
| 202 | return expression;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | //Switchã³ã³ã¹ãã©ã¯ã¿
|
---|
| 207 | Coverage::Switch::Switch(const Location & location) throw() : BranchBase(location)
|
---|
| 208 | {}
|
---|
| 209 |
|
---|
| 210 | //Switchã®æ£å½æ§å¤å® (ééããè¦ç´ ã ããè¦ãã¦ãã (å¾ã
|
---|
| 211 | å¤å®ãå
|
---|
| 212 | ¥ããã))
|
---|
| 213 | bool Coverage::Switch::checkValidity(void) const throw()
|
---|
| 214 | { return true; }
|
---|
| 215 |
|
---|
| 216 | //ééæ
|
---|
| 217 | å ±ã®åå¾
|
---|
| 218 | string Coverage::Switch::getDetails(void) const throw()
|
---|
| 219 | {
|
---|
| 220 | stringstream buf;
|
---|
| 221 | set<int>::const_iterator scope;
|
---|
| 222 |
|
---|
| 223 | scope = checkpoint.begin();
|
---|
| 224 | while(scope != checkpoint.end()) {
|
---|
| 225 | buf << *scope;
|
---|
| 226 |
|
---|
| 227 | ++ scope;
|
---|
| 228 | if(scope != checkpoint.end())
|
---|
| 229 | buf << ", ";
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | return buf.str();
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | //Switchåå²ã®ãã§ãã¯
|
---|
| 236 | void Coverage::Switch::_branch(const Location & location, int expression) throw()
|
---|
| 237 | {
|
---|
| 238 | Switch * node = dynamic_cast<Switch *>(find(location));
|
---|
| 239 | if(node == 0)
|
---|
| 240 | node = new(nothrow) Switch(location);
|
---|
| 241 |
|
---|
| 242 | if(node != 0) {
|
---|
| 243 | if(expression)
|
---|
| 244 | node->checkpoint.insert(expression);
|
---|
| 245 | }
|
---|
| 246 | else
|
---|
| 247 | cerr << "[Coverage::Branch] Memory allocation error!\n";
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | //å
|
---|
| 251 | ¨ã¦ã®é
|
---|
| 252 | ç®ã表示
|
---|
| 253 | void Coverage::printCoverage(ostream & out)
|
---|
| 254 | {
|
---|
| 255 | BranchMap * bmap = Singleton<BranchMap>::getInstance();
|
---|
| 256 | BranchMap::iterator scope;
|
---|
| 257 |
|
---|
| 258 | unsigned long cases = 0;
|
---|
| 259 | unsigned long fails = 0;
|
---|
| 260 |
|
---|
| 261 | scope = bmap->begin();
|
---|
| 262 | while(scope != bmap->end()) {
|
---|
| 263 | ++ cases;
|
---|
| 264 |
|
---|
| 265 | if(scope->second->checkValidity())
|
---|
| 266 | out << "Success : ";
|
---|
| 267 | else {
|
---|
| 268 | out << "Failure : ";
|
---|
| 269 | ++ fails;
|
---|
| 270 | }
|
---|
| 271 | out << scope->first.getDetails() << ' ' << scope->second->getDetails() << '\n';
|
---|
| 272 |
|
---|
| 273 | ++ scope;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | out << fails << " fails in " << cases << " cases (" << setprecision(2) << (fails * 100.0 / cases) << "%)\n";
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | //å
|
---|
| 280 | ¨ã¦ééãããã©ããã®ãã§ãã¯
|
---|
| 281 | bool Coverage::checkValidity(void)
|
---|
| 282 | {
|
---|
| 283 | bool result = true;
|
---|
| 284 |
|
---|
| 285 | NewBranchList * blist = Singleton<NewBranchList>::getInstance();
|
---|
| 286 | NewBranchList::iterator scope;
|
---|
| 287 |
|
---|
| 288 | scope = blist->begin();
|
---|
| 289 | while(scope != blist->end()) {
|
---|
| 290 | if(!(*scope)->checkValidity())
|
---|
| 291 | result = false;
|
---|
| 292 | ++ scope;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | blist->clear();
|
---|
| 296 | return result;
|
---|
| 297 | }
|
---|
| 298 | //å称ã®åå¾
|
---|
| 299 | string Coverage::getBranchName(BranchBase * node)
|
---|
| 300 | {
|
---|
| 301 | //ä¸è´ããè¦ç´ ã®æ¤ç´¢
|
---|
| 302 | BranchMap * bmap = Singleton<BranchMap>::getInstance();
|
---|
| 303 | BranchMap::iterator scope;
|
---|
| 304 |
|
---|
| 305 | scope = bmap->begin();
|
---|
| 306 | while(scope != bmap->end()) {
|
---|
| 307 | if(scope->second == node)
|
---|
| 308 | break;
|
---|
| 309 | ++ scope;
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | //assert(scope != bmap->end());
|
---|
| 313 |
|
---|
| 314 | return scope->first.getDetails();
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | #endif /* COVERAGE */
|
---|
| 318 |
|
---|