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