source: anotherchoice/tags/jsp-1.4.4-full-UTF8/cfg/base/coverage.cpp@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 8.4 KB
Line 
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
59using namespace std;
60
61#if defined(COVERAGE)
62/*
63 * 簡単なカバレッジチェック
64 */
65
66 //フォーマット済みファイル位置情
67報の取得
68string 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¨å‰Šé™¤
83Coverage::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 //要素の登録
97Coverage::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に一致する要素の取得
107Coverage::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コンストラクタ
121Coverage::If::If(const Location & location) throw() : BranchBase(location), true_case(false), false_case(false)
122{}
123
124 //ifの正当性判定 (成立/不成立の両方が起っている)
125bool Coverage::If::checkValidity(void) const throw()
126{ return true_case && false_case; }
127
128 //通過情
129報の取得
130string 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分岐のチェック
147bool 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コンストラクタ
167Coverage::While::While(const Location & location) throw() : BranchBase(location), valid(false)
168{}
169
170 //Whileの正当性判定 (少なくとも一回はループの中をまわっている)
171bool Coverage::While::checkValidity(void) const throw()
172{ return valid; }
173
174 //通過情
175報の取得
176string 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分岐のチェック (少なくとも一回はループの中をまわっている)
189bool 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コンストラクタ
207Coverage::Switch::Switch(const Location & location) throw() : BranchBase(location)
208{}
209
210 //Switchの正当性判定 (通過した要素だけを覚えておく (後々
211判定もå…
212¥ã‚ŒãŸã„))
213bool Coverage::Switch::checkValidity(void) const throw()
214{ return true; }
215
216 //通過情
217報の取得
218string 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分岐のチェック
236void 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目を表示
253void 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¨ã¦é€šéŽã—たかどうかのチェック
281bool 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 //名称の取得
299string 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
Note: See TracBrowser for help on using the repository browser.