File: main.c

package info (click to toggle)
cbmc 5.10-5
  • links: PTS
  • area: main
  • in suites: buster
  • size: 73,416 kB
  • sloc: cpp: 264,330; ansic: 38,268; java: 19,025; python: 4,539; yacc: 4,275; makefile: 2,547; lex: 2,394; sh: 932; perl: 525; xml: 289; pascal: 169
file content (396 lines) | stat: -rw-r--r-- 21,306 bytes parent folder | download | duplicates (4)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

#define TIMEOUT1 4  //400
#define TIMEOUT2 6  //600
#define TIMEOUT3 10 //5400

/* Named Constants */

#define FALSE 0
#define TRUE 1

/* Type declarations */

typedef char INT8;

typedef unsigned char UINT8;

typedef short INT16;

typedef unsigned short UINT16;

typedef int INT32;

typedef unsigned int UINT32;

typedef double REAL;

typedef float SINGLE;

typedef unsigned char BOOL;


/* Function-like macros */

/*  Conversion to the BOOL type  */
#define TO_BOOL(X) ((X) ? 1 : 0)

/* Type declarations */

typedef struct {
    INT32 Counter;
    BOOL InitSystem_OPEN;
    BOOL VehicleOpen_OPEN;
    BOOL AlarmWillBeArmedAfter20sec_CounterStart_OPEN;
    BOOL AlarmWillBeArmedAfter20sec_CounterPlus_OPEN;
    BOOL AlarmWillBeArmedAfter20sec_CounterEnd_OPEN;
    BOOL AlarmWillBeArmedAfter20sec_OPEN;
    BOOL AlarmOnlyOptical_CounterPlus_OPEN;
    BOOL AlarmOnlyOptical_CounterStart_OPEN;
    BOOL AlarmOnlyOptical_CounterEnd_OPEN;
    BOOL AlarmOnlyOptical_OPEN;
    BOOL AlarmAcousticAndOptical_CounterStart_OPEN;
    BOOL AlarmAcousticAndOptical_CounterPlus_OPEN;
    BOOL AlarmAcousticAndOptical_CounterEnd_OPEN;
    BOOL AlarmAcousticAndOptical_OPEN;
    BOOL AlarmArmed_OPEN;
    BOOL Alarm_system_OPEN;
} t_Alarm_system_state;

typedef struct {
    BOOL OpticalAlarm;
    BOOL AlarmSensor;
    BOOL VehLocked;
    BOOL AcousticAlarm;
    BOOL AlarmArmed;
} t_Alarm_system_io;

/* Named Constants */

#define ALARM_SYSTEM_TICK 0

void Alarm_system_init(t_Alarm_system_io *_io_, t_Alarm_system_state *_state_) {
    _io_->OpticalAlarm = FALSE;
    _io_->AlarmSensor = FALSE;
    _io_->VehLocked = FALSE;
    _io_->AcousticAlarm = FALSE;
    _io_->AlarmArmed = FALSE;
    _state_->Counter = 0;
    _state_->InitSystem_OPEN = 0;
    _state_->VehicleOpen_OPEN = 0;
    _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = 0;
    _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = 0;
    _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = 0;
    _state_->AlarmWillBeArmedAfter20sec_OPEN = 0;
    _state_->AlarmOnlyOptical_CounterPlus_OPEN = 0;
    _state_->AlarmOnlyOptical_CounterStart_OPEN = 0;
    _state_->AlarmOnlyOptical_CounterEnd_OPEN = 0;
    _state_->AlarmOnlyOptical_OPEN = 0;
    _state_->AlarmAcousticAndOptical_CounterStart_OPEN = 0;
    _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = 0;
    _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = 0;
    _state_->AlarmAcousticAndOptical_OPEN = 0;
    _state_->AlarmArmed_OPEN = 0;
    _state_->Alarm_system_OPEN = 0;
}

void Alarm_system_compute(t_Alarm_system_io *_io_, t_Alarm_system_state *_state_) {
    UINT16 activeEvent = ALARM_SYSTEM_TICK;
    if (!_state_->Alarm_system_OPEN) {
        /*  Open the chart  */
        _state_->Alarm_system_OPEN = TRUE;
        /*  Enter the chart's composition  */
        /*  Enter state InitSystem  */
        _state_->InitSystem_OPEN = TRUE;
    } else {
        /*  Execute an open chart  */
        if (_state_->InitSystem_OPEN) {
            /*  Execute state InitSystem  */
            if (_io_->VehLocked == 1) {
                _state_->InitSystem_OPEN = FALSE;
                _state_->AlarmWillBeArmedAfter20sec_OPEN = TRUE;
                /*  Open the inner composition of state AlarmWillBeArmedAfter20sec  */
                /*  Enter state AlarmWillBeArmedAfter20sec.CounterStart  */
                _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = TRUE;
                /*  Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterStart  */
                _state_->Counter = 1;
            } else {
                if (_io_->VehLocked == 0) {
                    _state_->InitSystem_OPEN = FALSE;
                    _state_->VehicleOpen_OPEN = TRUE; //possible BUG
                } else {
                    /*  Perform during and on-event actions of state InitSystem  */
                    _io_->AlarmArmed = TO_BOOL(1);
                    _io_->AcousticAlarm = TO_BOOL(0);
                    _io_->OpticalAlarm = TO_BOOL(0);
                }
            }
        } else {
            if (_state_->VehicleOpen_OPEN) {
                /*  Execute state VehicleOpen  */
                if (_io_->VehLocked == 1) {
                    _state_->VehicleOpen_OPEN = FALSE;
                    _state_->AlarmWillBeArmedAfter20sec_OPEN = TRUE;
                    /*  Open the inner composition of state AlarmWillBeArmedAfter20sec  */
                    /*  Enter state AlarmWillBeArmedAfter20sec.CounterStart  */
                    _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = TRUE;
                    /*  Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterStart  */
                    _state_->Counter = 1;
                } else {
                    /*  Perform during and on-event actions of state VehicleOpen  */
                    _io_->AlarmArmed = TO_BOOL(0);
                    _io_->AcousticAlarm = TO_BOOL(0);
                    _io_->OpticalAlarm = TO_BOOL(0);
                }
            } else {
                if (_state_->AlarmWillBeArmedAfter20sec_OPEN) {
                    /*  Execute state AlarmWillBeArmedAfter20sec  */
                    if (_state_->Counter == 0 && _io_->VehLocked == 1) {
                        /*  Close the inner composition of state AlarmWillBeArmedAfter20sec  */
                        if (_state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN) {
                            _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = FALSE;
                        } else {
                            if (_state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN) {
                                _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE;
                            } else {
                                if (_state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN) {
                                    _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = FALSE;
                                }
                            }
                        }
                        _state_->AlarmWillBeArmedAfter20sec_OPEN = FALSE;
                        _state_->AlarmArmed_OPEN = TRUE;
                    } else {
                        if (_io_->VehLocked == 0) {
                            /*  Close the inner composition of state AlarmWillBeArmedAfter20sec  */
                            if (_state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN) {
                                _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = FALSE;
                            } else {
                                if (_state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN) {
                                    _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE;
                                } else {
                                    if (_state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN) {
                                        _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = FALSE;
                                    }
                                }
                            }
                            _state_->AlarmWillBeArmedAfter20sec_OPEN = FALSE;
			    _state_->VehicleOpen_OPEN = TRUE; //possible BUG
                        } else {
                            /*  Perform during and on-event actions of state AlarmWillBeArmedAfter20sec  */
                            _io_->AlarmArmed = TO_BOOL(0);
                            _io_->AcousticAlarm = TO_BOOL(0);
                            _io_->OpticalAlarm = TO_BOOL(0);
                            if (_state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN) {
                                /*  Execute state AlarmWillBeArmedAfter20sec.CounterStart  */
                                _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = FALSE;
                                _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = TRUE;
                                /*  Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterPlus  */
                                _state_->Counter = _state_->Counter + 1;
                            } else {
                                if (_state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN) {
                                    /*  Execute state AlarmWillBeArmedAfter20sec.CounterPlus  */
                                    if (_state_->Counter < TIMEOUT1 || _io_->VehLocked == 0) {
                                        _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE;
                                        _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = TRUE;
                                        /*  Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterPlus  */
                                        _state_->Counter = _state_->Counter + 1;
                                    } else {
                                        _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE;
                                        _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = TRUE;
                                        /*  Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterEnd  */
                                        _state_->Counter = 0;
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (_state_->AlarmOnlyOptical_OPEN) {
                        /*  Execute state AlarmOnlyOptical  */
                        if (_state_->Counter == 0) {
                            /*  Close the inner composition of state AlarmOnlyOptical  */
                            if (_state_->AlarmOnlyOptical_CounterPlus_OPEN) {
                                _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE;
                            } else {
                                if (_state_->AlarmOnlyOptical_CounterStart_OPEN) {
                                    _state_->AlarmOnlyOptical_CounterStart_OPEN = FALSE;
                                } else {
                                    if (_state_->AlarmOnlyOptical_CounterEnd_OPEN) {
                                        _state_->AlarmOnlyOptical_CounterEnd_OPEN = FALSE;
                                    }
                                }
                            }
                            _state_->AlarmOnlyOptical_OPEN = FALSE;
                            _state_->AlarmArmed_OPEN = TRUE;
                        } else {
                            if (_io_->VehLocked == 0) {
                                /*  Close the inner composition of state AlarmOnlyOptical  */
                                if (_state_->AlarmOnlyOptical_CounterPlus_OPEN) {
                                    _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE;
                                } else {
                                    if (_state_->AlarmOnlyOptical_CounterStart_OPEN) {
                                        _state_->AlarmOnlyOptical_CounterStart_OPEN = FALSE;
                                    } else {
                                        if (_state_->AlarmOnlyOptical_CounterEnd_OPEN) {
                                            _state_->AlarmOnlyOptical_CounterEnd_OPEN = FALSE;
                                        }
                                    }
                                }
                                _state_->AlarmOnlyOptical_OPEN = FALSE;
				_state_->VehicleOpen_OPEN = TRUE; //possible BUG
                            } else {
                                /*  Perform during and on-event actions of state AlarmOnlyOptical  */
                                _io_->AlarmArmed = TO_BOOL(0);
                                _io_->AcousticAlarm = TO_BOOL(0);
                                _io_->OpticalAlarm = TO_BOOL(1);
                                if (_state_->AlarmOnlyOptical_CounterPlus_OPEN) {
                                    /*  Execute state AlarmOnlyOptical.CounterPlus  */
                                    if (_state_->Counter < TIMEOUT3 && _io_->VehLocked == 1) {
                                        _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE;
                                        _state_->AlarmOnlyOptical_CounterPlus_OPEN = TRUE;
                                        /*  Perform entry actions of state AlarmOnlyOptical.CounterPlus  */
                                        _state_->Counter = _state_->Counter + 1;
                                    } else {
                                        _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE;
                                        _state_->AlarmOnlyOptical_CounterEnd_OPEN = TRUE;
                                        /*  Perform entry actions of state AlarmOnlyOptical.CounterEnd  */
                                        _state_->Counter = 0;
                                    }
                                } else {
                                    if (_state_->AlarmOnlyOptical_CounterStart_OPEN) {
                                        /*  Execute state AlarmOnlyOptical.CounterStart  */
                                        _state_->AlarmOnlyOptical_CounterStart_OPEN = FALSE;
                                        _state_->AlarmOnlyOptical_CounterPlus_OPEN = TRUE;
                                        /*  Perform entry actions of state AlarmOnlyOptical.CounterPlus  */
                                        _state_->Counter = _state_->Counter + 1;
                                    }
                                }
                            }
                        }
                    } else {
                        if (_state_->AlarmAcousticAndOptical_OPEN) {
                            /*  Execute state AlarmAcousticAndOptical  */
                            if (_state_->Counter == 0) {
                                /*  Close the inner composition of state AlarmAcousticAndOptical  */
                                if (_state_->AlarmAcousticAndOptical_CounterStart_OPEN) {
                                    _state_->AlarmAcousticAndOptical_CounterStart_OPEN = FALSE;
                                } else {
                                    if (_state_->AlarmAcousticAndOptical_CounterPlus_OPEN) {
                                        _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE;
                                    } else {
                                        if (_state_->AlarmAcousticAndOptical_CounterEnd_OPEN) {
                                            _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = FALSE;
                                        }
                                    }
                                }
                                _state_->AlarmAcousticAndOptical_OPEN = FALSE;
                                _state_->AlarmOnlyOptical_OPEN = TRUE;
                                /*  Open the inner composition of state AlarmOnlyOptical  */
                                /*  Enter state AlarmOnlyOptical.CounterStart  */
                                _state_->AlarmOnlyOptical_CounterStart_OPEN = TRUE;
                                /*  Perform entry actions of state AlarmOnlyOptical.CounterStart  */
                                _state_->Counter = 1;
                            } else {
                                if (_io_->VehLocked == 0) {
                                    /*  Close the inner composition of state AlarmAcousticAndOptical  */
                                    if (_state_->AlarmAcousticAndOptical_CounterStart_OPEN) {
                                        _state_->AlarmAcousticAndOptical_CounterStart_OPEN = FALSE;
                                    } else {
                                        if (_state_->AlarmAcousticAndOptical_CounterPlus_OPEN) {
                                            _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE;
                                        } else {
                                            if (_state_->AlarmAcousticAndOptical_CounterEnd_OPEN) {
                                                _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = FALSE;
                                            }
                                        }
                                    }
                                    _state_->AlarmAcousticAndOptical_OPEN = FALSE;
				    _state_->VehicleOpen_OPEN = TRUE; //BUG does not work
                                } else {
                                    /*  Perform during and on-event actions of state AlarmAcousticAndOptical  */
                                    _io_->AlarmArmed = TO_BOOL(0);
                                    _io_->AcousticAlarm = TO_BOOL(1);
                                    _io_->OpticalAlarm = TO_BOOL(1);
                                    if (_state_->AlarmAcousticAndOptical_CounterStart_OPEN) {
                                        /*  Execute state AlarmAcousticAndOptical.CounterStart  */
                                        _state_->AlarmAcousticAndOptical_CounterStart_OPEN = FALSE;
                                        _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = TRUE;
                                        /*  Perform entry actions of state AlarmAcousticAndOptical.CounterPlus  */
                                        _state_->Counter = _state_->Counter + 1;
                                    } else {
                                        if (_state_->AlarmAcousticAndOptical_CounterPlus_OPEN) {
                                            /*  Execute state AlarmAcousticAndOptical.CounterPlus  */
                                            if (_state_->Counter < TIMEOUT2 && _io_->VehLocked == 1) {
                                                _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE;
                                                _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = TRUE;
                                                /*  Perform entry actions of state AlarmAcousticAndOptical.CounterPlus  */
                                                _state_->Counter = _state_->Counter + 1;
                                            } else {
                                                _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE;
                                                _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = TRUE;
                                                /*  Perform entry actions of state AlarmAcousticAndOptical.CounterEnd  */
                                                _state_->Counter = 0;
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            if (_state_->AlarmArmed_OPEN) {
                                /*  Execute state AlarmArmed  */
                                if (_io_->AlarmSensor == 1) {
                                    _state_->AlarmArmed_OPEN = FALSE;
				    _state_->AlarmAcousticAndOptical_OPEN = TRUE; //BUG does not work
                                    /*  Open the inner composition of state AlarmAcousticAndOptical  */
                                    /*  Enter state AlarmAcousticAndOptical.CounterStart  */
                                    _state_->AlarmAcousticAndOptical_CounterStart_OPEN = TRUE;
                                    /*  Perform entry actions of state AlarmAcousticAndOptical.CounterStart  */
                                    _state_->Counter = 1;
                                } else {
                                    if (_io_->VehLocked == 0) {
                                        _state_->AlarmArmed_OPEN = FALSE;
					_state_->VehicleOpen_OPEN = TRUE; //BUG does not work
                                    } else {
                                        /*  Perform during and on-event actions of state AlarmArmed  */
                                        _io_->AlarmArmed = TO_BOOL(1);
                                        _io_->AcousticAlarm = TO_BOOL(0);
                                        _io_->OpticalAlarm = TO_BOOL(0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

extern int nondet_int();

t_Alarm_system_io havocIO() {
  t_Alarm_system_io _io_;
  _io_.VehLocked = nondet_int();
  _io_.AlarmSensor = nondet_int();
  __CPROVER_assume(0<=_io_.VehLocked && _io_.VehLocked<=1 &&
                   0<=_io_.AlarmSensor && _io_.AlarmSensor<=1);
  return _io_;
}

int main() {
  int k=0;
  t_Alarm_system_state _state_;
  t_Alarm_system_state _state_old;
  t_Alarm_system_io _io_;
  Alarm_system_init(&_io_,&_state_);
  while(1) {
    _state_old = _state_;
    _io_ = havocIO();
    Alarm_system_compute(&_io_,&_state_);
    if(_state_old.AlarmArmed_OPEN && _io_.AlarmSensor) {
      assert(_state_.AlarmAcousticAndOptical_OPEN);
    }
    if(!_state_.InitSystem_OPEN && _state_old.Counter!=0 && !_io_.AlarmSensor && !_io_.VehLocked) assert(_state_.VehicleOpen_OPEN);
  }
  return 0;
}