3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
6 * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
9 * 上記著作権者は,以下の (1)〜(4) の条件か,Free Software Foundation
10 * によって公表されている GNU General Public License の Version 2 に記
11 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
12 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
14 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
15 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
18 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
19 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
21 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
22 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
24 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
25 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
26 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
28 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
29 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
31 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
32 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
33 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
34 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
36 * @(#) $Id: coverage.cpp,v 1.1 2009/01/31 05:27:37 suikan Exp $
39 #include "base/coverage_defs.h"
40 #include "base/coverage_undefs.h"
53 string Coverage::Location::getDetails(void) const
57 result = string(filename) + ":" + String(lineno);
58 if(*additional != '\x0')
59 result += string("(") + additional + ")";
67 Coverage::BranchMap::~BranchMap(void) throw()
72 while(scope != end()) {
81 Coverage::BranchBase::BranchBase(const Location & location) throw()
83 BranchMap * bmap = Singleton<BranchMap>::getInstance();
84 NewBranchList * blist = Singleton<NewBranchList>::getInstance();
86 (*bmap)[location] = this;
87 blist->push_back(this);
91 Coverage::BranchBase * Coverage::BranchBase::find(const Location & location) throw()
93 BranchMap * bmap = Singleton<BranchMap>::getInstance();
94 BranchMap::iterator scope;
95 BranchBase * result = 0;
97 scope = bmap->find(location);
98 if(scope != bmap->end())
99 result = scope->second;
105 Coverage::If::If(const Location & location) throw() : BranchBase(location), true_case(false), false_case(false)
108 //ifの正当性判定 (成立/不成立の両方が起っている)
109 bool Coverage::If::checkValidity(void) const throw()
110 { return true_case && false_case; }
113 string Coverage::If::getDetails(void) const throw()
130 bool Coverage::If::branch(const Location & location, bool expression) throw()
132 If * node = dynamic_cast<If *>(find(location));
134 node = new(nothrow) If(location);
138 node->true_case = true;
140 node->false_case = true;
143 cerr << "[Coverage::Branch] Memory allocation error!\n";
150 Coverage::While::While(const Location & location) throw() : BranchBase(location), valid(false)
153 //Whileの正当性判定 (少なくとも一回はループの中をまわっている)
154 bool Coverage::While::checkValidity(void) const throw()
158 string Coverage::While::getDetails(void) const throw()
170 //while分岐のチェック (少なくとも一回はループの中をまわっている)
171 bool Coverage::While::branch(const Location & location, bool expression) throw()
173 While * node = dynamic_cast<While *>(find(location));
175 node = new(nothrow) While(location);
182 cerr << "[Coverage::Branch] Memory allocation error!\n";
189 Coverage::Switch::Switch(const Location & location) throw() : BranchBase(location)
192 //Switchの正当性判定 (通過した要素だけを覚えておく (後々判定も入れたい))
193 bool Coverage::Switch::checkValidity(void) const throw()
197 string Coverage::Switch::getDetails(void) const throw()
200 set<int>::const_iterator scope;
202 scope = checkpoint.begin();
203 while(scope != checkpoint.end()) {
207 if(scope != checkpoint.end())
215 void Coverage::Switch::_branch(const Location & location, int expression) throw()
217 Switch * node = dynamic_cast<Switch *>(find(location));
219 node = new(nothrow) Switch(location);
223 node->checkpoint.insert(expression);
226 cerr << "[Coverage::Branch] Memory allocation error!\n";
230 void Coverage::printCoverage(ostream & out)
232 BranchMap * bmap = Singleton<BranchMap>::getInstance();
233 BranchMap::iterator scope;
235 unsigned long cases = 0;
236 unsigned long fails = 0;
238 scope = bmap->begin();
239 while(scope != bmap->end()) {
242 if(scope->second->checkValidity())
248 out << scope->first.getDetails() << ' ' << scope->second->getDetails() << '\n';
253 out << fails << " fails in " << cases << " cases (" << setprecision(2) << (fails * 100.0 / cases) << "%)\n";
257 bool Coverage::checkValidity(void)
261 NewBranchList * blist = Singleton<NewBranchList>::getInstance();
262 NewBranchList::iterator scope;
264 scope = blist->begin();
265 while(scope != blist->end()) {
266 if(!(*scope)->checkValidity())
275 string Coverage::getBranchName(BranchBase * node)
278 BranchMap * bmap = Singleton<BranchMap>::getInstance();
279 BranchMap::iterator scope;
281 scope = bmap->begin();
282 while(scope != bmap->end()) {
283 if(scope->second == node)
288 //assert(scope != bmap->end());
290 return scope->first.getDetails();
293 #endif /* COVERAGE */