/
test_api7.c
410 lines (346 loc) · 8.94 KB
/
test_api7.c
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*
* This file is part of the Yices SMT Solver.
* Copyright (C) 2017 SRI International.
*
* Yices is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Yices is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Yices. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* TEST CONTEXT CONFIGURATION FUNCTIONS
*/
#include <assert.h>
#include <stdio.h>
#include <inttypes.h>
#include "api/context_config.h"
#include "yices.h"
/*
* Conversion of internal codes to strings
*/
static const char* const mode2string[NUM_MODES] = {
"one-shot", // CTX_MODE_ONECHECK
"multi-checks", // CTX_MODE_MULTICHECKS
"push-pop", // CTX_MODE_PUSHPOP
"interactive", // CTX_MODE_INTERACTIVE
};
static const char* const logic2string[NUM_SMT_LOGICS+1] = {
"NONE",
"AX",
"BV",
"IDL",
"LIA",
"LRA",
"LIRA",
"NIA",
"NRA",
"NIRA",
"RDL",
"UF",
"ABV",
"ALIA",
"ALRA",
"ALIRA",
"ANIA",
"ANRA",
"ANIRA",
"AUF",
"UFBV",
"UFIDL",
"UFLIA",
"UFLRA",
"UFLIRA",
"UFNIA",
"UFNRA",
"UFNIRA",
"UFRDL",
"AUFBV",
"AUFLIA",
"AUFLRA",
"AUFLIRA",
"AUFNIA",
"AUFNRA",
"AUFNIRA",
"QF_AX",
"QF_BV",
"QF_IDL",
"QF_LIA",
"QF_LRA",
"QF_LIRA",
"QF_NIA",
"QF_NRA",
"QF_NIRA",
"QF_RDL",
"QF_UF",
"QF_ABV",
"QF_ALIA",
"QF_ALRA",
"QF_ALIRA",
"QF_ANIA",
"QF_ANRA",
"QF_ANIRA",
"QF_AUF",
"QF_UFBV",
"QF_UFIDL",
"QF_UFLIA",
"QF_UFLRA",
"QF_UFLIRA",
"QF_UFNIA",
"QF_UFNRA",
"QF_UFNIRA",
"QF_UFRDL",
"QF_AUFBV",
"QF_AUFLIA",
"QF_AUFLRA",
"QF_AUFLIRA",
"QF_AUFNIA",
"QF_AUFNRA",
"QF_AUFNIRA",
"ALL",
"unknown",
};
static const char* const solver_code2string[NUM_SOLVER_CODES] = {
"none",
"default",
"auto",
"simplex",
"ifw",
"rfw",
};
/*
* Which logics are currently supported
*/
static const bool supported[NUM_SMT_LOGICS] = {
true, // NONE
false, // AX
false, // BV
false, // IDL
false, // LIA
false, // LRA
false, // LIRA
false, // NIA
false, // NRA
false, // NIRA
false, // RDL
false, // UF
false, // ABV
false, // ALIA
false, // ALRA
false, // ALIRA
false, // ANIA
false, // ANRA
false, // ANIRA
false, // AUF
false, // UFBV
false, // UFIDL
false, // UFLIA
false, // UFLRA
false, // UFLIRA
false, // UFNIA
false, // UFNRA
false, // UFNIRA
false, // UFRDL
false, // AUFBV
false, // AUFLIA
false, // AUFLRA
false, // AUFLIRA
false, // AUFNIA
false, // AUFNRA
false, // AUFNIRA
true, // QF_AX
true, // QF_BV
true, // QF_IDL
true, // QF_RDL
true, // QF_LIA
true, // QF_LRA
true, // QF_LIRA
true, // QF_NIA
true, // QF_NRA
true, // QF_NIRA
true, // QF_UF
true, // QF_ABV
true, // QF_ALIA
true, // QF_ALRA
true, // QF_ALIRA
true, // QF_ANIA
true, // QF_ANRA
true, // QF_ANIRA
true, // QF_AUF
true, // QF_UFBV
true, // QF_UFIDL
true, // QF_UFLIA
true, // QF_UFLRA
true, // QF_UFLIRA
true, // QF_UFNIA
true, // QF_UFNRA
true, // QF_UFNIRA
true, // QF_UFRDL
true, // QF_AUFBV
true, // QF_AUFLIA
true, // QF_AUFLRA
true, // QF_AUFLIRA
true, // QF_AUFNIA
true, // QF_AUFNRA
true, // QF_AUFNIRA
true, // ALL ==> QF_AUFLIRA + QF+_BV
};
/*
* Print a configuration descriptor
*/
static void show_config(ctx_config_t *config) {
printf("config: %p\n", config);
printf(" mode = %s\n", mode2string[config->mode]);
printf(" logic = %s\n", logic2string[config->logic]);
printf(" uf solver = %s\n", solver_code2string[config->uf_config]);
printf(" array solver = %s\n", solver_code2string[config->array_config]);
printf(" bv solver = %s\n", solver_code2string[config->bv_config]);
printf(" arith solver = %s\n", solver_code2string[config->arith_config]);
printf("\n");
fflush(stdout);
}
/*
* Test of default_config_for_logic:
* - name = logic name to test
* - k = expected returned value from the yices function
* - error = expected error code (if k < 0)
*/
static void test_config_for_logic(ctx_config_t *config, const char *name, int32_t k, int32_t error) {
int32_t code;
error_code_t ecode;
yices_clear_error();
printf("Testing config for logic %s: ", name);
fflush(stdout);
code = yices_default_config_for_logic(config, name);
if (code >= 0) {
printf("ok\n");
show_config(config);
} else {
printf("error\n");
yices_print_error(stdout);
}
if (code != k) {
printf("TEST FAILED\n");
printf("--> Yices function returned %"PRId32"; %"PRId32" was expected\n", code, k);
fflush(stdout);
exit(1);
} else if (k < 0) {
ecode = yices_error_code();
if (ecode != error) {
printf("TEST FAILED\n");
printf("--> Found error code %"PRId32"; %"PRId32" was expected\n", ecode, error);
fflush(stdout);
exit(1);
}
}
printf("\n");
fflush(stdout);
}
/*
* Test of set_config:
* - name = test parameter name
* - value = test value
* - k = expected returned value
* - error = expected error code (if k < 0)
*/
static void test_set_config(ctx_config_t *config, const char *name, const char *value, int32_t k, int32_t error) {
int32_t code;
error_code_t ecode;
printf("Testing set_config %s := %s: ", name, value);
fflush(stdout);
code = yices_set_config(config, name, value);
if (code >= 0) {
printf("ok\n");
show_config(config);
} else {
printf("error\n");
yices_print_error(stdout);
}
if (code != k) {
printf("TEST FAILED\n");
printf("--> Yices function returned %"PRId32"; %"PRId32" was expected\n", code, k);
fflush(stdout);
exit(1);
} else if (k < 0) {
ecode = yices_error_code();
if (ecode != error) {
printf("TEST FAILED\n");
printf("--> Found error code %"PRId32"; %"PRId32" was expected\n", ecode, error);
fflush(stdout);
exit(1);
}
}
printf("\n");
fflush(stdout);
}
/*
* Tests of config for logic
*/
static void test_logic_configs(ctx_config_t *config) {
uint32_t i;
// all valid logic names first
for (i=0; i<NUM_SMT_LOGICS; i++) {
if (supported[i]) {
test_config_for_logic(config, logic2string[i], 0, 0);
} else {
test_config_for_logic(config, logic2string[i], -1, CTX_LOGIC_NOT_SUPPORTED);
}
}
// some random stuff
test_config_for_logic(config, "XXX", -1, CTX_UNKNOWN_LOGIC);
test_config_for_logic(config, "unknown", -1, CTX_UNKNOWN_LOGIC);
}
/*
* Tests of set config
*/
static void test_set_configs(ctx_config_t *config) {
test_set_config(config, "mode", "one-shot", 0, 0);
test_set_config(config, "mode", "multi-checks", 0, 0);
test_set_config(config, "mode", "push-pop", 0, 0);
test_set_config(config, "mode", "interactive", 0, 0);
test_set_config(config, "mode", "xxxx", -1, CTX_INVALID_PARAMETER_VALUE);
test_set_config(config, "uf-solver", "default", 0, 0);
test_set_config(config, "uf-solver", "none", 0, 0);
test_set_config(config, "uf-solver", "simplex", -1, CTX_INVALID_PARAMETER_VALUE);
test_set_config(config, "uf-solver", "xxxx", -1, CTX_INVALID_PARAMETER_VALUE);
test_set_config(config, "array-solver", "default", 0, 0);
test_set_config(config, "array-solver", "none", 0, 0);
test_set_config(config, "array-solver", "xxxx", -1, CTX_INVALID_PARAMETER_VALUE);
test_set_config(config, "bv-solver", "default", 0, 0);
test_set_config(config, "bv-solver", "none", 0, 0);
test_set_config(config, "bv-solver", "xxxx", -1, CTX_INVALID_PARAMETER_VALUE);
test_set_config(config, "arith-solver", "default", 0, 0);
test_set_config(config, "arith-solver", "none", 0, 0);
test_set_config(config, "arith-solver", "auto", 0, 0);
test_set_config(config, "arith-solver", "simplex", 0, 0);
test_set_config(config, "arith-solver", "ifw", 0, 0);
test_set_config(config, "arith-solver", "rfw", 0, 0);
test_set_config(config, "arith-solver", "xxxx", -1, CTX_INVALID_PARAMETER_VALUE);
// yices_set_config is not intended to be used for setting the logic
// so "logic" should not be recognized as a value parameter here.
test_set_config(config, "logic", "QF_UFLIA", -1, CTX_UNKNOWN_PARAMETER);
}
int main(void) {
ctx_config_t *c1, *c2;
yices_init();
c1 = yices_new_config();
printf("Allocated config %p\n", c1);
show_config(c1);
c2 = yices_new_config();
printf("Allocated config %p\n", c2);
show_config(c2);
test_logic_configs(c1);
test_set_configs(c2);
yices_free_config(c2);
yices_free_config(c1);
yices_exit();
printf("All tests succeeded\n");
return 0;
}