Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
PrismParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
7
8TEST(PrismParser, StandardModelTest) {
10 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/coin2.nm"));
11 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/dtmc/crowds5_5.pm"));
12 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/csma2_2.nm"));
13 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm"));
14 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/firewire.nm"));
15 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/leader3.nm"));
16 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/dtmc/leader3_5.pm"));
17 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm"));
18 EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/wlan0_collide.nm"));
19}
20
21TEST(PrismParser, SimpleTest) {
22 std::string testInput =
23 R"(dtmc
24 module mod1
25 b : bool;
26 [a] true -> 1: (b'=true != false = b => false);
27 endmodule)";
28
30 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
31 EXPECT_EQ(1ul, result.getNumberOfModules());
33 EXPECT_FALSE(result.hasUnboundedVariables());
34
35 testInput =
36 R"(mdp
37
38 module main
39 x : [1..5] init 1;
40 [] x=1 -> 1:(x'=2);
41 [] x=2 -> 1:(x'=3);
42 [] x=3 -> 1:(x'=1);
43 [] x=3 -> 1:(x'=4);
44 [] x=4 -> 1:(x'=5);
45 [] x=5 -> 1: true;
46 endmodule)";
47 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
48 EXPECT_EQ(1ul, result.getNumberOfModules());
50 EXPECT_FALSE(result.hasUnboundedVariables());
51}
52
53TEST(PrismParser, expressionTest) {
54 std::string testInput = R"(dtmc
55
56 module test
57 c : [0..1] init 0;
58 [] c = ceil(log(1,2)) -> (c'=1);
59 endmodule)";
60
62 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
64 EXPECT_FALSE(result.hasUnboundedVariables());
65 EXPECT_EQ(1ul, result.getNumberOfModules());
66 ASSERT_TRUE(result.hasModule("test"));
67 EXPECT_EQ(1ul, result.getModule("test").getNumberOfCommands());
68 auto const& guard = result.getModule("test").getCommands().front().getGuardExpression().getBaseExpression();
69 ASSERT_TRUE(guard.isBinaryRelationExpression());
70 EXPECT_EQ(0ll, guard.asBinaryRelationExpression().getSecondOperand()->evaluateAsInt());
71}
73TEST(PrismParser, ComplexTest) {
74 std::string testInput =
75 R"(ma
76
77 const int a;
78 const int b = 10;
79 const bool c;
80 const bool d = true | false;
81 const double e;
82 const double f = 9;
84 formula test = a >= 10 & (max(a,b) > floor(e));
85 formula test2 = a+b;
86 formula test3 = (a + b > 10 ? floor(e) : h) + a;
87
88 global g : bool init false;
89 global h : [0 .. b];
90
91 module mod1
92 i : bool;
93 j : bool init c;
94 k : [125..a] init a;
95
96 [a] test&false -> (i'=true)&(k'=1+1) + 1 : (k'=floor(e) + max(k, b) - 1 + k);
97 [b] true -> (i'=i);
98 endmodule
99
100 module mod2
101 [] (k > 3) & false & (min(a, 0) < max(h, k)) -> 1-e: (g'=(1-a) * 2 + floor(f) > 2);
102 endmodule
103
104 module mod3 = mod1 [ i = i1, j = j1, k = k1 ] endmodule
105
106 label "mal" = max(a, 10) > 0;
107
108 rewards "testrewards"
109 [a] true : a + 7;
110 max(f, a) <= 8 : 2*b;
111 endrewards
113 rewards "testrewards2"
114 [b] true : a + 7;
115 max(f, a) <= 8 : 2*b;
116 endrewards)";
117
119 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
121 EXPECT_EQ(3ul, result.getNumberOfModules());
122 EXPECT_EQ(2ul, result.getNumberOfRewardModels());
123 EXPECT_EQ(1ul, result.getNumberOfLabels());
124 EXPECT_FALSE(result.hasUnboundedVariables());
125}
126
127TEST(PrismParser, UnboundedTest) {
128 std::string testInput =
129 R"(mdp
130 module main
131 b : int;
132 [a] true -> 1: (b'=b+1);
133 endmodule)";
134
136 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
137 EXPECT_EQ(1ul, result.getNumberOfModules());
139 EXPECT_TRUE(result.hasUnboundedVariables());
140}
141
142TEST(PrismParser, POMDPInputTest) {
143 std::string testInput =
144 R"(pomdp
145
146 observables
147 i
148 endobservables
149
150 module example
151 s : [0..4] init 0;
152 i : bool init true;
153 [] s=0 -> 0.5: (s'=1) & (i'=false) + 0.5: (s'=2) & (i'=false);
154 [] s=1 | s=2 -> 1: (s'=3) & (i'=true);
155 [r] s=1 -> 1: (s'=4) & (i'=true);
156 [r] s=2 -> 1: (s'=3) & (i'=true);
157 endmodule
158
159 )";
162 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
163
164 std::string testInput2 =
165 R"(pomdp
166
167 observable intermediate = s=1 | s=2;
168
169 module example
170 s : [0..4] init 0;
171 [] s=0 -> 0.5: (s'=1) + 0.5: (s'=2);
172 [l] s=1 -> 1: (s'=3);
173 [l] s=2 -> 1: (s'=4);
174 [r] s=1 -> 1: (s'=4);
175 [r] s=2 -> 1: (s'=3);
176 endmodule
177
178 )";
179
180 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput2, "testfile"));
181}
182
183TEST(PrismParser, NAryPredicates) {
184 std::string testInput =
185 R"(dtmc
186
187 module example
188 s : [0..4] init 0;
189 i : bool init true;
190 [] s=0 -> 0.5: (s'=1) & (i'=false) + 0.5: (s'=2) & (i'=false);
191 [] s=1 | s=2 -> 1: (s'=3) & (i'=true);
192 [r] s=1 -> 1: (s'=4) & (i'=true);
193 [r] s=2 -> 1: (s'=3) & (i'=true);
194 endmodule
195
196 label "test" = atMostOneOf(s=0, s=3, s=4);
197 label "test2" = exactlyOneOf(s=0, i, !i & s=3);
198 )";
200
201 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
202}
203
204TEST(PrismParser, Intervals) {
205 std::string testInput =
206 R"(dtmc
207
208 module example
209 s : [0..4] init 0;
210 i : bool init true;
211 [] s=0 -> [0.5,0.9]: (s'=1) & (i'=false) + [0.4,0.6] : (s'=2) & (i'=false);
212 [] s=1 -> 1: (s'=3) & (i'=true);
213 [] s>0 -> [i?0.3:1/s,1]: (s'=4) & (i'=true) + 0.5 : (s'=3);
214 [r] s=2 -> 1: (s'=3) & (i'=true);
215 endmodule
216 module example2 = example [ s = t, i = j ] endmodule
217
218 )";
220
221 EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
222}
223
224TEST(PrismParser, IllegalInputTest) {
225 std::string testInput =
226 R"(ctmc
227
228 const int a;
229 const bool a = true;
230
231 module mod1
232 c : [0 .. 8] init 1;
233 [] c < 3 -> 2: (c' = c+1);
234 endmodule
235 )";
236
238 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
239
240 testInput =
241 R"(dtmc
242
243 const int a;
244
245 module mod1
246 a : [0 .. 8] init 1;
247 [] a < 3 -> 1: (a' = a+1);
248 endmodule)";
249
250 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
251
252 testInput =
253 R"(dtmc
254
255 const int a = 2;
256 formula a = 41;
257
258 module mod1
259 c : [0 .. 8] init 1;
260 [] c < 3 -> 1: (c' = c+1);
261 endmodule)";
262
263 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
264
265 testInput =
266 R"(dtmc
267
268 const int a = 2;
269
270 init
271 c > 3
272 endinit
273
274 module mod1
275 c : [0 .. 8] init 1;
276 [] c < 3 -> 1: (c' = c+1);
277 endmodule
278
279 init
280 c > 3
281 endinit
282
283 )";
284
285 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
286
287 testInput =
288 R"(dtmc
289
290 module mod1
291 c : [0 .. 8] init 1;
292 [] c < 3 -> 1: (c' = c+1);
293 endmodule
294
295 module mod2
296 [] c < 3 -> 1: (c' = c+1);
297 endmodule)";
298
299 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
300
301 testInput =
302 R"(dtmc
303
304 module mod1
305 c : [0 .. 8] init 1;
306 [] c < 3 -> 1: (c' = c+1)&(c'=c-1);
307 endmodule)";
308
309 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
310
311 testInput =
312 R"(dtmc
313
314 module mod1
315 c : [0 .. 8] init 1;
316 [] c < 3 -> 1: (c' = true || false);
317 endmodule)";
318
319 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
320
321 testInput =
322 R"(dtmc
323
324 module mod1
325 c : [0 .. 8] init 1;
326 [] c + 3 -> 1: (c' = 1);
327 endmodule)";
328
329 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
330
331 testInput =
332 R"(dtmc
333
334 module mod1
335 c : [0 .. 8] init 1;
336 [] c + 3 -> 1: (c' = 1);
337 endmodule
338
339 label "test" = c + 1;
340
341 )";
342
343 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
344}
345
346TEST(PrismParser, IllegalSynchronizedWriteTest) {
347 STORM_SILENT_EXPECT_THROW(storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2-illegalSynchronizingWrite.nm"),
348 storm::exceptions::WrongFormatException);
349}
TEST(PrismParser, StandardModelTest)
static storm::prism::Program parseFromString(std::string const &input, std::string const &filename, bool prismCompatability=false)
Parses the given input stream into the PRISM storage classes assuming it complies with the PRISM synt...
static storm::prism::Program parse(std::string const &filename, bool prismCompatability=false)
Parses the given file into the PRISM storage classes assuming it complies with the PRISM syntax.
std::vector< storm::prism::Command > const & getCommands() const
Retrieves the commands of the module.
Definition Module.cpp:133
std::size_t getNumberOfCommands() const
Retrieves the number of commands of this module.
Definition Module.cpp:117
ModelType getModelType() const
Retrieves the model type of the model.
Definition Program.cpp:247
std::size_t getNumberOfLabels() const
Retrieves the number of labels in the program.
Definition Program.cpp:875
Module const & getModule(uint_fast64_t index) const
Retrieves the module with the given index.
Definition Program.cpp:615
std::size_t getNumberOfRewardModels() const
Retrieves the number of reward models in the program.
Definition Program.cpp:825
bool hasModule(std::string const &moduleName) const
Retrieves whether the program has a module with the given name.
Definition Program.cpp:619
bool hasUnboundedVariables() const
Definition Program.cpp:271
std::size_t getNumberOfModules() const
Retrieves the number of modules in the program.
Definition Program.cpp:611
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:31