Storm
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
113
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 )";
161
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, IllegalInputTest) {
206 std::string testInput =
207 R"(ctmc
208
209 const int a;
210 const bool a = true;
211
212 module mod1
213 c : [0 .. 8] init 1;
214 [] c < 3 -> 2: (c' = c+1);
215 endmodule
216 )";
217
219 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
220
221 testInput =
222 R"(dtmc
223
224 const int a;
225
226 module mod1
227 a : [0 .. 8] init 1;
228 [] a < 3 -> 1: (a' = a+1);
229 endmodule)";
230
231 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
232
233 testInput =
234 R"(dtmc
235
236 const int a = 2;
237 formula a = 41;
238
239 module mod1
240 c : [0 .. 8] init 1;
241 [] c < 3 -> 1: (c' = c+1);
242 endmodule)";
243
244 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
245
246 testInput =
247 R"(dtmc
248
249 const int a = 2;
250
251 init
252 c > 3
253 endinit
254
255 module mod1
256 c : [0 .. 8] init 1;
257 [] c < 3 -> 1: (c' = c+1);
258 endmodule
259
260 init
261 c > 3
262 endinit
263
264 )";
265
266 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
267
268 testInput =
269 R"(dtmc
270
271 module mod1
272 c : [0 .. 8] init 1;
273 [] c < 3 -> 1: (c' = c+1);
274 endmodule
275
276 module mod2
277 [] c < 3 -> 1: (c' = c+1);
278 endmodule)";
279
280 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
281
282 testInput =
283 R"(dtmc
284
285 module mod1
286 c : [0 .. 8] init 1;
287 [] c < 3 -> 1: (c' = c+1)&(c'=c-1);
288 endmodule)";
289
290 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
291
292 testInput =
293 R"(dtmc
294
295 module mod1
296 c : [0 .. 8] init 1;
297 [] c < 3 -> 1: (c' = true || false);
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' = 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' = 1);
318 endmodule
319
320 label "test" = c + 1;
321
322 )";
323
324 STORM_SILENT_EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
325}
326
327TEST(PrismParser, IllegalSynchronizedWriteTest) {
328 STORM_SILENT_EXPECT_THROW(storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2-illegalSynchronizingWrite.nm"),
329 storm::exceptions::WrongFormatException);
330}
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:862
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:812
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)