📄 coverage.cpp
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
* Toyohashi Univ. of Technology, JAPAN
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* @(#) $Id: coverage.cpp,v 1.1 2006/04/14 02:46:02 9564907 Exp $
*/
#include "base/coverage_defs.h"
#include "base/coverage_undefs.h"
#include <iostream>
#include <iomanip>
using namespace std;
#if defined(COVERAGE)
/*
* 娙扨側僇僶儗僢僕僠僃僢僋
*/
//僼僅乕儅僢僩嵪傒僼傽僀儖埵抲忣曬偺庢摼
string Coverage::Location::getDetails(void) const
{
string result;
result = string(filename) + ":" + String(lineno);
if(*additional != '\x0')
result += string("(") + additional + ")";
return result;
}
//梫慺偺慡嶍彍
Coverage::BranchMap::~BranchMap(void) throw()
{
iterator scope;
scope = begin();
while(scope != end()) {
delete scope->second;
++ scope;
}
clear();
}
//梫慺偺搊榐
Coverage::BranchBase::BranchBase(const Location & location) throw()
{
BranchMap * bmap = Singleton<BranchMap>::getInstance();
NewBranchList * blist = Singleton<NewBranchList>::getInstance();
(*bmap)[location] = this;
blist->push_back(this);
}
//location偵堦抳偡傞梫慺偺庢摼
Coverage::BranchBase * Coverage::BranchBase::find(const Location & location) throw()
{
BranchMap * bmap = Singleton<BranchMap>::getInstance();
BranchMap::iterator scope;
BranchBase * result = 0;
scope = bmap->find(location);
if(scope != bmap->end())
result = scope->second;
return result;
}
//BranchIf僐儞僗僩儔僋僞
Coverage::If::If(const Location & location) throw() : BranchBase(location), true_case(false), false_case(false)
{}
//if偺惓摉惈敾掕 (惉棫/晄惉棫偺椉曽偑婲偭偰偄傞)
bool Coverage::If::checkValidity(void) const throw()
{ return true_case && false_case; }
//捠夁忣曬偺庢摼
string Coverage::If::getDetails(void) const throw()
{
string result;
if(true_case)
result += "true";
if(false_case) {
if(true_case)
result += "/";
result += "false";
}
return result;
}
//if暘婒偺僠僃僢僋
bool Coverage::If::branch(const Location & location, bool expression) throw()
{
If * node = dynamic_cast<If *>(find(location));
if(node == 0)
node = new(nothrow) If(location);
if(node != 0) {
if(expression)
node->true_case = true;
else
node->false_case = true;
}
else
cerr << "[Coverage::Branch] Memory allocation error!\n";
return expression;
}
//While僐儞僗僩儔僋僞
Coverage::While::While(const Location & location) throw() : BranchBase(location), valid(false)
{}
//While偺惓摉惈敾掕 (彮側偔偲傕堦夞偼儖乕僾偺拞傪傑傢偭偰偄傞)
bool Coverage::While::checkValidity(void) const throw()
{ return valid; }
//捠夁忣曬偺庢摼
string Coverage::While::getDetails(void) const throw()
{
string result;
if(valid)
result = "valid";
else
result = "invalid";
return result;
}
//while暘婒偺僠僃僢僋 (彮側偔偲傕堦夞偼儖乕僾偺拞傪傑傢偭偰偄傞)
bool Coverage::While::branch(const Location & location, bool expression) throw()
{
While * node = dynamic_cast<While *>(find(location));
if(node == 0)
node = new(nothrow) While(location);
if(node != 0) {
if(expression)
node->valid = true;
}
else
cerr << "[Coverage::Branch] Memory allocation error!\n";
return expression;
}
//Switch僐儞僗僩儔僋僞
Coverage::Switch::Switch(const Location & location) throw() : BranchBase(location)
{}
//Switch偺惓摉惈敾掕 (捠夁偟偨梫慺偩偗傪妎偊偰偍偔 (屻乆敾掕傕擖傟偨偄))
bool Coverage::Switch::checkValidity(void) const throw()
{ return true; }
//捠夁忣曬偺庢摼
string Coverage::Switch::getDetails(void) const throw()
{
stringstream buf;
set<int>::const_iterator scope;
scope = checkpoint.begin();
while(scope != checkpoint.end()) {
buf << *scope;
++ scope;
if(scope != checkpoint.end())
buf << ", ";
}
return buf.str();
}
//Switch暘婒偺僠僃僢僋
void Coverage::Switch::_branch(const Location & location, int expression) throw()
{
Switch * node = dynamic_cast<Switch *>(find(location));
if(node == 0)
node = new(nothrow) Switch(location);
if(node != 0) {
if(expression)
node->checkpoint.insert(expression);
}
else
cerr << "[Coverage::Branch] Memory allocation error!\n";
}
//慡偰偺崁栚傪昞帵
void Coverage::printCoverage(ostream & out)
{
BranchMap * bmap = Singleton<BranchMap>::getInstance();
BranchMap::iterator scope;
unsigned long cases = 0;
unsigned long fails = 0;
scope = bmap->begin();
while(scope != bmap->end()) {
++ cases;
if(scope->second->checkValidity())
out << "Success : ";
else {
out << "Failure : ";
++ fails;
}
out << scope->first.getDetails() << ' ' << scope->second->getDetails() << '\n';
++ scope;
}
out << fails << " fails in " << cases << " cases (" << setprecision(2) << (fails * 100.0 / cases) << "%)\n";
}
//慡偰捠夁偟偨偐偳偆偐偺僠僃僢僋
bool Coverage::checkValidity(void)
{
bool result = true;
NewBranchList * blist = Singleton<NewBranchList>::getInstance();
NewBranchList::iterator scope;
scope = blist->begin();
while(scope != blist->end()) {
if(!(*scope)->checkValidity())
result = false;
++ scope;
}
blist->clear();
return result;
}
//柤徧偺庢摼
string Coverage::getBranchName(BranchBase * node)
{
//堦抳偡傞梫慺偺専嶕
BranchMap * bmap = Singleton<BranchMap>::getInstance();
BranchMap::iterator scope;
scope = bmap->begin();
while(scope != bmap->end()) {
if(scope->second == node)
break;
++ scope;
}
//assert(scope != bmap->end());
return scope->first.getDetails();
}
#endif /* COVERAGE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -