This repository was archived by the owner on Jan 14, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcoverage_prop.cc
More file actions
161 lines (137 loc) · 3.56 KB
/
Copy pathcoverage_prop.cc
File metadata and controls
161 lines (137 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* fMBT, free Model Based Testing tool
* Copyright (c) 2011,2012 Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "coverage_prop.hh"
#include "model.hh"
#include "helper.hh"
Coverage_Prop::Coverage_Prop(Log& l, std::string& _params) :
Coverage(l),props_total(0),props_seen(0),params(_params)
{
}
void Coverage_Prop::history(int action,
std::vector<int>& props,
Verdict::Verdict verdict)
{
/* Not intrested about action or verdict. Just proposition */
for(unsigned i=0;i<props.size();i++) {
if (prop_included[props[i]] && !data[props[i]]) {
props_seen++;
data[props[i]]=true;
}
}
}
void Coverage_Prop::push()
{
std::pair<std::vector<bool>,int> p(data,props_seen);
state_save.push_front(p);
}
void Coverage_Prop::pop()
{
data=state_save.front().first;
props_seen=state_save.front().second;
state_save.pop_front();
}
bool Coverage_Prop::execute(int action)
{
int* pro;
int cnt=model->getprops(&pro);
for(int i=0;i<cnt;i++) {
if (prop_included[pro[i]] && !data[pro[i]]) {
props_seen++;
data[pro[i]]=true;
}
}
return true;
}
float Coverage_Prop::getCoverage()
{
if (props_total) {
return (1.0*props_seen)/(1.0*props_total);
}
return 1.0;
}
int Coverage_Prop::fitness(int* action,int n,float* fitness)
{
float m=-1;
int pos=-1;
if (props_total==0) {
for(int i=0;i<n;i++) {
fitness[i]=0.0;
}
return 0;
}
for(int i=0;i<n;i++) {
model->push();
model->execute(action[i]);
fitness[i]=getCoverage();
model->pop();
if (m<fitness[i]) {
pos=i;
m=fitness[i];
}
}
return pos;
}
void Coverage_Prop::regexp_try(std::string& s,std::vector<std::string>& sp) {
std::vector<int> regexp_match;
regexpmatch(s,sp,regexp_match,true);
if (regexp_match.empty()) {
status=false;
errormsg = "No tags matching \"" + s + "\"";
return;
}
for(unsigned i=0;i<regexp_match.size();i++) {
if (regexp_match[i]) {
prop_included[regexp_match[i]]=true;
}
}
}
void Coverage_Prop::set_model(Model* _model) {
Coverage::set_model(_model);
/*
props_total=model->getSPNames().size()-1; // let's ignore 0
*/
if (params=="") {
props_total=model->getSPNames().size()-1; // let's ignore 0
if (props_total<0) {
props_total=0;
}
for(unsigned i=1;i<model->getSPNames().size();i++) {
prop_included[i]=true;
}
} else {
// Only props in the params.
std::vector<std::string> props;
std::vector<std::string>& sp=model->getSPNames();
commalist(params,props);
strlist(props);
for(unsigned i=0;i<props.size();i++) {
int propnum = find(sp,props[i]);
if (propnum) {
prop_included[propnum]=true;
} else {
regexp_try(props[i],sp);
}
}
props_total=prop_included.size();
}
data.resize(model->getSPNames().size()+1);
if (status)
execute(0);
}
FACTORY_DEFAULT_CREATOR(Coverage, Coverage_Prop, "tag")