Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/isle/veri/veri_engine/tests/veri.rs
1693 views
1
mod utils;
2
use utils::{all_failure_result, all_success_result};
3
use utils::{
4
test_aarch64_rule_with_lhs_termname_simple, test_aarch64_with_config_simple,
5
test_concrete_aarch64_rule_with_lhs_termname, test_concrete_input_from_file_with_lhs_termname,
6
test_from_file_with_config_simple, test_from_file_with_lhs_termname,
7
test_from_file_with_lhs_termname_simple, test_x64_rule_with_lhs_termname_simple, Bitwidth,
8
TestResult,
9
};
10
use veri_engine_lib::Config;
11
use veri_ir::{ConcreteInput, ConcreteTest, Counterexample, VerificationResult};
12
13
#[test]
14
fn test_named_iadd_base_concrete() {
15
test_concrete_aarch64_rule_with_lhs_termname(
16
"iadd_base_case",
17
"iadd",
18
ConcreteTest {
19
termname: "iadd".to_string(),
20
args: vec![
21
ConcreteInput {
22
literal: "#b00000001".to_string(),
23
ty: veri_ir::Type::BitVector(Some(8)),
24
},
25
ConcreteInput {
26
literal: "#b00000001".to_string(),
27
ty: veri_ir::Type::BitVector(Some(8)),
28
},
29
],
30
output: ConcreteInput {
31
literal: "#b00000010".to_string(),
32
ty: veri_ir::Type::BitVector(Some(8)),
33
},
34
},
35
)
36
}
37
38
#[test]
39
fn test_named_iadd_base() {
40
test_aarch64_rule_with_lhs_termname_simple("iadd_base_case", "iadd", all_success_result())
41
}
42
43
#[test]
44
fn test_named_iadd_imm12_right() {
45
test_aarch64_rule_with_lhs_termname_simple("iadd_imm12_right", "iadd", all_success_result())
46
}
47
48
#[test]
49
fn test_named_iadd_imm12_left() {
50
test_aarch64_rule_with_lhs_termname_simple("iadd_imm12_left", "iadd", all_success_result())
51
}
52
53
#[test]
54
fn test_named_iadd_imm12_neg_left() {
55
test_aarch64_rule_with_lhs_termname_simple(
56
"iadd_imm12_neg_left",
57
"iadd",
58
vec![
59
(Bitwidth::I8, VerificationResult::Success),
60
(Bitwidth::I16, VerificationResult::Success),
61
(Bitwidth::I32, VerificationResult::Success),
62
(Bitwidth::I64, VerificationResult::Success),
63
],
64
)
65
}
66
67
#[test]
68
fn test_named_iadd_imm12_neg_right() {
69
test_aarch64_rule_with_lhs_termname_simple(
70
"iadd_imm12_neg_right",
71
"iadd",
72
vec![
73
(Bitwidth::I8, VerificationResult::Success),
74
(Bitwidth::I16, VerificationResult::Success),
75
(Bitwidth::I32, VerificationResult::Success),
76
(Bitwidth::I64, VerificationResult::Success),
77
],
78
)
79
}
80
81
// Need a file test because this is a change on top of our latest rebase
82
#[test]
83
fn test_named_imm12_from_negated_value() {
84
test_aarch64_rule_with_lhs_termname_simple(
85
"imm12_from_negated_value",
86
"imm12_from_negated_value",
87
vec![
88
(Bitwidth::I8, VerificationResult::Success),
89
(Bitwidth::I16, VerificationResult::Success),
90
(Bitwidth::I32, VerificationResult::Success),
91
(Bitwidth::I64, VerificationResult::Success),
92
],
93
)
94
}
95
96
// Need a file test because this is a change on top of our latest rebase
97
#[test]
98
fn test_updated_iadd_imm12neg_right() {
99
test_from_file_with_lhs_termname_simple(
100
"./examples/iadd/updated_iadd_imm12neg_right.isle",
101
"iadd".to_string(),
102
all_success_result(),
103
)
104
}
105
106
// Need a file test because this is a change on top of our latest rebase
107
#[test]
108
fn test_updated_iadd_imm12neg_left() {
109
test_from_file_with_lhs_termname_simple(
110
"./examples/iadd/updated_iadd_imm12neg_left.isle",
111
"iadd".to_string(),
112
all_success_result(),
113
)
114
}
115
116
#[test]
117
fn test_named_iadd_extend_right() {
118
test_aarch64_rule_with_lhs_termname_simple(
119
"iadd_extend_right",
120
"iadd",
121
vec![
122
(Bitwidth::I8, VerificationResult::Success),
123
(Bitwidth::I16, VerificationResult::Success),
124
(Bitwidth::I32, VerificationResult::Success),
125
(Bitwidth::I64, VerificationResult::InapplicableRule),
126
],
127
)
128
}
129
130
#[test]
131
fn test_named_iadd_extend_right_concrete() {
132
test_concrete_aarch64_rule_with_lhs_termname(
133
"iadd_extend_right",
134
"iadd",
135
ConcreteTest {
136
termname: "iadd".to_string(),
137
args: vec![
138
ConcreteInput {
139
literal: "#b0000000000000001".to_string(),
140
ty: veri_ir::Type::BitVector(Some(16)),
141
},
142
ConcreteInput {
143
literal: "#b1111111111111111".to_string(),
144
ty: veri_ir::Type::BitVector(Some(16)),
145
},
146
],
147
output: ConcreteInput {
148
literal: "#b0000000000000000".to_string(),
149
ty: veri_ir::Type::BitVector(Some(16)),
150
},
151
},
152
);
153
test_concrete_aarch64_rule_with_lhs_termname(
154
"iadd_extend_right",
155
"iadd",
156
ConcreteTest {
157
termname: "iadd".to_string(),
158
args: vec![
159
ConcreteInput {
160
literal: "#b01000000000000000000000000000000".to_string(),
161
ty: veri_ir::Type::BitVector(Some(32)),
162
},
163
ConcreteInput {
164
literal: "#b00000000000000001111111111111111".to_string(),
165
ty: veri_ir::Type::BitVector(Some(32)),
166
},
167
],
168
output: ConcreteInput {
169
literal: "#b01000000000000001111111111111111".to_string(),
170
ty: veri_ir::Type::BitVector(Some(32)),
171
},
172
},
173
)
174
}
175
176
#[test]
177
fn test_named_iadd_extend_left() {
178
test_aarch64_rule_with_lhs_termname_simple(
179
"iadd_extend_left",
180
"iadd",
181
vec![
182
(Bitwidth::I8, VerificationResult::Success),
183
(Bitwidth::I16, VerificationResult::Success),
184
(Bitwidth::I32, VerificationResult::Success),
185
(Bitwidth::I64, VerificationResult::InapplicableRule),
186
],
187
)
188
}
189
190
#[test]
191
fn test_broken_iadd_extend() {
192
test_from_file_with_lhs_termname_simple(
193
"./examples/broken/iadd/broken_add_extend.isle",
194
"iadd".to_string(),
195
vec![
196
// The type of the iadd is the destination type, so for i8 there is no bad extend-to
197
(Bitwidth::I8, VerificationResult::Success),
198
(
199
Bitwidth::I16,
200
VerificationResult::Failure(Counterexample {}),
201
),
202
(
203
Bitwidth::I32,
204
VerificationResult::Failure(Counterexample {}),
205
),
206
(Bitwidth::I64, VerificationResult::InapplicableRule),
207
],
208
)
209
}
210
211
#[test]
212
fn test_named_iadd_ishl_left() {
213
test_aarch64_rule_with_lhs_termname_simple("iadd_ishl_left", "iadd", all_success_result())
214
}
215
216
#[test]
217
fn test_named_iadd_ishl_right() {
218
test_aarch64_rule_with_lhs_termname_simple("iadd_ishl_right", "iadd", all_success_result())
219
}
220
221
#[test]
222
fn test_named_iadd_imul_right() {
223
test_aarch64_rule_with_lhs_termname_simple(
224
"iadd_imul_right",
225
"iadd",
226
vec![
227
(Bitwidth::I8, VerificationResult::Success),
228
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
229
// (Bitwidth::I16, VerificationResult::Success),
230
// (Bitwidth::I32, VerificationResult::Success),
231
// (Bitwidth::I64, VerificationResult::Success),
232
],
233
)
234
}
235
236
#[test]
237
#[ignore]
238
fn test_named_slow_iadd_imul_right() {
239
test_aarch64_rule_with_lhs_termname_simple(
240
"iadd_imul_right",
241
"iadd",
242
vec![
243
(Bitwidth::I16, VerificationResult::Unknown),
244
(Bitwidth::I32, VerificationResult::Unknown),
245
(Bitwidth::I64, VerificationResult::Unknown),
246
],
247
)
248
}
249
250
#[test]
251
fn test_named_iadd_imul_left() {
252
test_aarch64_rule_with_lhs_termname_simple(
253
"iadd_imul_left",
254
"iadd",
255
vec![
256
(Bitwidth::I8, VerificationResult::Success),
257
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
258
// (Bitwidth::I16, VerificationResult::Success),
259
// (Bitwidth::I32, VerificationResult::Success),
260
// (Bitwidth::I64, VerificationResult::Success),
261
],
262
)
263
}
264
265
#[test]
266
#[ignore]
267
fn test_named_slow_iadd_imul_left() {
268
test_aarch64_rule_with_lhs_termname_simple(
269
"iadd_imul_left",
270
"iadd",
271
vec![
272
(Bitwidth::I16, VerificationResult::Unknown),
273
(Bitwidth::I32, VerificationResult::Unknown),
274
(Bitwidth::I64, VerificationResult::Unknown),
275
],
276
)
277
}
278
279
#[test]
280
fn test_named_isub_imul() {
281
test_aarch64_rule_with_lhs_termname_simple(
282
"isub_imul",
283
"isub",
284
vec![
285
(Bitwidth::I8, VerificationResult::Success),
286
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
287
// (Bitwidth::I16, VerificationResult::Success),
288
// (Bitwidth::I32, VerificationResult::Success),
289
// (Bitwidth::I64, VerificationResult::Success),
290
],
291
)
292
}
293
294
#[test]
295
#[ignore]
296
fn test_named_slow_isub_imul() {
297
test_aarch64_rule_with_lhs_termname_simple(
298
"isub_imul",
299
"isub",
300
vec![
301
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
302
(Bitwidth::I16, VerificationResult::Unknown),
303
(Bitwidth::I32, VerificationResult::Unknown),
304
(Bitwidth::I64, VerificationResult::Unknown),
305
],
306
)
307
}
308
309
#[test]
310
fn test_broken_iadd_base_case() {
311
test_from_file_with_lhs_termname_simple(
312
"./examples/broken/iadd/broken_base_case.isle",
313
"iadd".to_string(),
314
all_failure_result(),
315
)
316
}
317
318
#[test]
319
fn test_broken_iadd_imm12() {
320
test_from_file_with_lhs_termname_simple(
321
"./examples/broken/iadd/broken_imm12.isle",
322
"iadd".to_string(),
323
vec![
324
(Bitwidth::I8, VerificationResult::Success),
325
(
326
Bitwidth::I16,
327
VerificationResult::Failure(Counterexample {}),
328
),
329
(
330
Bitwidth::I32,
331
VerificationResult::Failure(Counterexample {}),
332
),
333
(
334
Bitwidth::I64,
335
VerificationResult::Failure(Counterexample {}),
336
),
337
],
338
)
339
}
340
341
#[test]
342
fn test_broken_iadd_imm12_2() {
343
test_from_file_with_lhs_termname_simple(
344
"./examples/broken/iadd/broken_imm12_2.isle",
345
"iadd".to_string(),
346
vec![
347
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
348
(
349
Bitwidth::I16,
350
VerificationResult::Failure(Counterexample {}),
351
),
352
(
353
Bitwidth::I32,
354
VerificationResult::Failure(Counterexample {}),
355
),
356
(
357
Bitwidth::I64,
358
VerificationResult::Failure(Counterexample {}),
359
),
360
],
361
)
362
}
363
364
#[test]
365
fn test_broken_iadd_imm12neg_not_distinct() {
366
test_from_file_with_lhs_termname_simple(
367
"./examples/broken/iadd/broken_imm12neg.isle",
368
"iadd".to_string(),
369
vec![
370
(Bitwidth::I8, VerificationResult::NoDistinctModels),
371
(Bitwidth::I16, VerificationResult::NoDistinctModels),
372
(Bitwidth::I32, VerificationResult::NoDistinctModels),
373
(
374
Bitwidth::I64,
375
VerificationResult::Failure(Counterexample {}),
376
),
377
],
378
)
379
}
380
381
#[test]
382
fn test_broken_iadd_imm12neg_2_not_distinct() {
383
test_from_file_with_lhs_termname_simple(
384
"./examples/broken/iadd/broken_imm12neg2.isle",
385
"iadd".to_string(),
386
vec![
387
(Bitwidth::I8, VerificationResult::NoDistinctModels),
388
(Bitwidth::I16, VerificationResult::NoDistinctModels),
389
(Bitwidth::I32, VerificationResult::NoDistinctModels),
390
(
391
Bitwidth::I64,
392
VerificationResult::Failure(Counterexample {}),
393
),
394
],
395
)
396
}
397
398
#[test]
399
fn test_broken_iadd_imul_right() {
400
test_from_file_with_lhs_termname_simple(
401
"./examples/broken/iadd/broken_madd.isle",
402
"iadd".to_string(),
403
all_failure_result(),
404
)
405
}
406
407
#[test]
408
fn test_broken_iadd_imul_left() {
409
test_from_file_with_lhs_termname_simple(
410
"./examples/broken/iadd/broken_madd2.isle",
411
"iadd".to_string(),
412
all_failure_result(),
413
)
414
}
415
416
#[test]
417
fn test_broken_iadd_msub() {
418
test_from_file_with_lhs_termname_simple(
419
"./examples/broken/iadd/broken_msub.isle",
420
"isub".to_string(),
421
vec![
422
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
423
(
424
Bitwidth::I16,
425
VerificationResult::Failure(Counterexample {}),
426
),
427
(
428
Bitwidth::I32,
429
VerificationResult::Failure(Counterexample {}),
430
),
431
(
432
Bitwidth::I64,
433
VerificationResult::Failure(Counterexample {}),
434
),
435
],
436
)
437
}
438
439
#[test]
440
fn test_broken_iadd_shift() {
441
test_from_file_with_lhs_termname_simple(
442
"./examples/broken/iadd/broken_shift.isle",
443
"iadd".to_string(),
444
all_failure_result(),
445
)
446
}
447
448
#[test]
449
fn test_broken_iadd_shift2() {
450
test_from_file_with_lhs_termname_simple(
451
"./examples/broken/iadd/broken_shift2.isle",
452
"iadd".to_string(),
453
all_failure_result(),
454
)
455
}
456
457
#[test]
458
fn test_named_isub_base_case() {
459
test_aarch64_rule_with_lhs_termname_simple("isub_base_case", "isub", all_success_result())
460
}
461
462
#[test]
463
fn test_named_isub_imm12() {
464
test_aarch64_rule_with_lhs_termname_simple("isub_imm12", "isub", all_success_result())
465
}
466
467
#[test]
468
fn test_named_isub_imm12_concrete() {
469
test_concrete_aarch64_rule_with_lhs_termname(
470
"isub_imm12",
471
"isub",
472
ConcreteTest {
473
termname: "isub".to_string(),
474
args: vec![
475
ConcreteInput {
476
literal: "#b00000001".to_string(),
477
ty: veri_ir::Type::BitVector(Some(8)),
478
},
479
ConcreteInput {
480
literal: "#b11111111".to_string(),
481
ty: veri_ir::Type::BitVector(Some(8)),
482
},
483
],
484
output: ConcreteInput {
485
literal: "#b00000010".to_string(),
486
ty: veri_ir::Type::BitVector(Some(8)),
487
},
488
},
489
)
490
}
491
492
#[test]
493
fn test_named_isub_imm12_neg() {
494
test_aarch64_rule_with_lhs_termname_simple(
495
"isub_imm12_neg",
496
"isub",
497
vec![
498
(Bitwidth::I8, VerificationResult::Success),
499
(Bitwidth::I16, VerificationResult::Success),
500
(Bitwidth::I32, VerificationResult::Success),
501
(Bitwidth::I64, VerificationResult::Success),
502
],
503
);
504
}
505
506
// The older version, which did not have distinct models for i8, i16, or i32.
507
#[test]
508
fn test_isub_imm12_neg_not_distinct() {
509
test_from_file_with_lhs_termname_simple(
510
"./examples/broken/isub/broken_imm12neg_not_distinct.isle",
511
"isub".to_string(),
512
vec![
513
(Bitwidth::I8, VerificationResult::NoDistinctModels),
514
(Bitwidth::I16, VerificationResult::NoDistinctModels),
515
(Bitwidth::I32, VerificationResult::NoDistinctModels),
516
(Bitwidth::I64, VerificationResult::Success),
517
],
518
);
519
}
520
521
#[test]
522
fn test_isub_imm12_neg_not_distinct_16_32() {
523
test_from_file_with_lhs_termname_simple(
524
"./examples/broken/isub/broken_imm12neg_not_distinct.isle",
525
"isub".to_string(),
526
vec![
527
(Bitwidth::I16, VerificationResult::NoDistinctModels),
528
(Bitwidth::I32, VerificationResult::NoDistinctModels),
529
],
530
);
531
}
532
533
// Need a file test because this is a change on top of our latest rebase
534
#[test]
535
fn test_isub_imm12neg_new() {
536
test_from_file_with_lhs_termname_simple(
537
"./examples/isub/imm12neg_new.isle",
538
"isub".to_string(),
539
all_success_result(),
540
);
541
}
542
543
#[test]
544
fn test_named_isub_imm12_neg_concrete32() {
545
test_concrete_aarch64_rule_with_lhs_termname(
546
"isub_imm12_neg",
547
"isub",
548
ConcreteTest {
549
termname: "isub".to_string(),
550
args: vec![
551
ConcreteInput {
552
literal: "#b0000000000000000000000000000000000000000000000000000000000000001"
553
.to_string(),
554
ty: veri_ir::Type::BitVector(Some(64)),
555
},
556
ConcreteInput {
557
literal: "#b1111111111111111111111111111111111111111111111111111111111111111"
558
.to_string(),
559
ty: veri_ir::Type::BitVector(Some(64)),
560
},
561
],
562
output: ConcreteInput {
563
literal: "#b0000000000000000000000000000000000000000000000000000000000000010"
564
.to_string(),
565
ty: veri_ir::Type::BitVector(Some(64)),
566
},
567
},
568
)
569
}
570
571
#[test]
572
fn test_named_isub_imm12_neg_concrete64() {
573
test_concrete_aarch64_rule_with_lhs_termname(
574
"isub_imm12_neg",
575
"isub",
576
ConcreteTest {
577
termname: "isub".to_string(),
578
args: vec![
579
ConcreteInput {
580
literal: "#b0000000000000000000000000000000000000000000000000000000000000001"
581
.to_string(),
582
ty: veri_ir::Type::BitVector(Some(64)),
583
},
584
ConcreteInput {
585
literal: "#b1111111111111111111111111111111111111111111111111111111111111111"
586
.to_string(),
587
ty: veri_ir::Type::BitVector(Some(64)),
588
},
589
],
590
output: ConcreteInput {
591
literal: "#b0000000000000000000000000000000000000000000000000000000000000010"
592
.to_string(),
593
ty: veri_ir::Type::BitVector(Some(64)),
594
},
595
},
596
)
597
}
598
599
#[test]
600
fn test_named_isub_extend() {
601
test_aarch64_rule_with_lhs_termname_simple(
602
"isub_extend",
603
"isub",
604
vec![
605
(Bitwidth::I8, VerificationResult::Success),
606
(Bitwidth::I16, VerificationResult::Success),
607
(Bitwidth::I32, VerificationResult::Success),
608
(Bitwidth::I64, VerificationResult::InapplicableRule),
609
],
610
)
611
}
612
613
#[test]
614
fn test_named_isub_ishl() {
615
test_aarch64_rule_with_lhs_termname_simple("isub_ishl", "isub", all_success_result())
616
}
617
618
#[test]
619
fn test_broken_isub_base_case() {
620
test_from_file_with_lhs_termname_simple(
621
"./examples/broken/isub/broken_base_case.isle",
622
"isub".to_string(),
623
vec![
624
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
625
(
626
Bitwidth::I16,
627
VerificationResult::Failure(Counterexample {}),
628
),
629
(
630
Bitwidth::I32,
631
VerificationResult::Failure(Counterexample {}),
632
),
633
(
634
Bitwidth::I64,
635
VerificationResult::Failure(Counterexample {}),
636
),
637
],
638
);
639
}
640
641
#[test]
642
fn test_broken_isub_imm12() {
643
test_from_file_with_lhs_termname_simple(
644
"./examples/broken/isub/broken_imm12.isle",
645
"isub".to_string(),
646
vec![
647
(Bitwidth::I8, VerificationResult::Success),
648
(
649
Bitwidth::I16,
650
VerificationResult::Failure(Counterexample {}),
651
),
652
(
653
Bitwidth::I32,
654
VerificationResult::Failure(Counterexample {}),
655
),
656
(
657
Bitwidth::I64,
658
VerificationResult::Failure(Counterexample {}),
659
),
660
],
661
);
662
}
663
664
#[test]
665
fn test_broken_isub_imm12neg_not_distinct() {
666
test_from_file_with_lhs_termname_simple(
667
"./examples/broken/isub/broken_imm12neg.isle",
668
"isub".to_string(),
669
vec![
670
(Bitwidth::I8, VerificationResult::NoDistinctModels),
671
(Bitwidth::I16, VerificationResult::NoDistinctModels),
672
(Bitwidth::I32, VerificationResult::NoDistinctModels),
673
(
674
Bitwidth::I64,
675
VerificationResult::Failure(Counterexample {}),
676
),
677
],
678
);
679
}
680
681
#[test]
682
fn test_broken_isub_shift() {
683
test_from_file_with_lhs_termname_simple(
684
"./examples/broken/isub/broken_shift.isle",
685
"isub".to_string(),
686
all_failure_result(),
687
);
688
}
689
690
#[test]
691
fn test_named_ineg_base_case() {
692
test_aarch64_rule_with_lhs_termname_simple("ineg_base_case", "ineg", all_success_result())
693
}
694
695
#[test]
696
fn test_named_imul_base_case() {
697
test_aarch64_rule_with_lhs_termname_simple(
698
"imul_base_case",
699
"imul",
700
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
701
vec![
702
(Bitwidth::I8, VerificationResult::Success),
703
// (Bitwidth::I16, VerificationResult::Success),
704
// (Bitwidth::I32, VerificationResult::Success),
705
// (Bitwidth::I64, VerificationResult::Success),
706
],
707
)
708
}
709
710
#[test]
711
#[ignore]
712
fn test_named_slow_imul_base_case() {
713
test_aarch64_rule_with_lhs_termname_simple(
714
"imul_base_case",
715
"imul",
716
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
717
vec![
718
// (Bitwidth::I8, VerificationResult::Success),
719
(Bitwidth::I16, VerificationResult::Unknown),
720
(Bitwidth::I32, VerificationResult::Unknown),
721
(Bitwidth::I64, VerificationResult::Unknown),
722
],
723
)
724
}
725
726
// TODO traps https://github.com/avanhatt/wasmtime/issues/31
727
#[test]
728
fn test_named_udiv() {
729
test_aarch64_rule_with_lhs_termname_simple(
730
"udiv",
731
"udiv",
732
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
733
vec![
734
(Bitwidth::I8, VerificationResult::Success),
735
// (Bitwidth::I16, VerificationResult::Success),
736
// (Bitwidth::I32, VerificationResult::Success),
737
// (Bitwidth::I64, VerificationResult::Success),
738
],
739
)
740
}
741
742
#[test]
743
#[ignore]
744
fn test_named_slow_udiv() {
745
test_aarch64_rule_with_lhs_termname_simple(
746
"udiv",
747
"udiv",
748
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
749
vec![
750
// (Bitwidth::I8, VerificationResult::Success),
751
(Bitwidth::I16, VerificationResult::Unknown),
752
(Bitwidth::I32, VerificationResult::Unknown),
753
(Bitwidth::I64, VerificationResult::Unknown),
754
],
755
)
756
}
757
758
#[test]
759
fn test_broken_udiv() {
760
test_from_file_with_lhs_termname_simple(
761
"./examples/broken/udiv/broken_udiv.isle",
762
"udiv".to_string(),
763
vec![
764
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
765
(
766
Bitwidth::I16,
767
VerificationResult::Failure(Counterexample {}),
768
),
769
(
770
Bitwidth::I32,
771
VerificationResult::Failure(Counterexample {}),
772
),
773
(Bitwidth::I64, VerificationResult::Success),
774
],
775
)
776
}
777
778
#[test]
779
fn test_named_sdiv_base_case() {
780
test_aarch64_rule_with_lhs_termname_simple(
781
"sdiv_base_case",
782
"sdiv",
783
vec![
784
(Bitwidth::I8, VerificationResult::Success),
785
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
786
// (Bitwidth::I16, VerificationResult::Success),
787
// (Bitwidth::I32, VerificationResult::Success),
788
// (Bitwidth::I64, VerificationResult::Success),
789
],
790
)
791
}
792
793
#[test]
794
#[ignore]
795
fn test_named_slow_sdiv_base_case() {
796
test_aarch64_rule_with_lhs_termname_simple(
797
"sdiv_base_case",
798
"sdiv",
799
vec![
800
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
801
(Bitwidth::I16, VerificationResult::Unknown),
802
(Bitwidth::I32, VerificationResult::Unknown),
803
(Bitwidth::I64, VerificationResult::Unknown),
804
],
805
)
806
}
807
808
#[test]
809
fn test_named_sdiv_safe_divisor() {
810
test_aarch64_rule_with_lhs_termname_simple(
811
"sdiv_safe_divisor",
812
"sdiv",
813
vec![
814
(Bitwidth::I8, VerificationResult::Success),
815
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
816
// (Bitwidth::I16, VerificationResult::Success),
817
// (Bitwidth::I32, VerificationResult::Success),
818
// (Bitwidth::I64, VerificationResult::Success),
819
],
820
)
821
}
822
823
#[test]
824
#[ignore]
825
fn test_named_slow_sdiv_safe_divisor() {
826
test_aarch64_rule_with_lhs_termname_simple(
827
"sdiv_safe_divisor",
828
"sdiv",
829
vec![
830
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
831
(Bitwidth::I16, VerificationResult::Unknown),
832
(Bitwidth::I32, VerificationResult::Unknown),
833
(Bitwidth::I64, VerificationResult::Unknown),
834
],
835
)
836
}
837
838
#[test]
839
fn test_broken_sdiv_safe_const() {
840
test_from_file_with_lhs_termname_simple(
841
"./examples/broken/sdiv/broken_sdiv_safe_const.isle",
842
"sdiv".to_string(),
843
vec![
844
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
845
(
846
Bitwidth::I16,
847
VerificationResult::Failure(Counterexample {}),
848
),
849
(
850
Bitwidth::I32,
851
VerificationResult::Failure(Counterexample {}),
852
),
853
(
854
Bitwidth::I64,
855
VerificationResult::Failure(Counterexample {}),
856
),
857
],
858
)
859
}
860
861
#[test]
862
fn test_broken_sdiv() {
863
test_from_file_with_lhs_termname_simple(
864
"./examples/broken/sdiv/broken_sdiv.isle",
865
"sdiv".to_string(),
866
vec![
867
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
868
(
869
Bitwidth::I16,
870
VerificationResult::Failure(Counterexample {}),
871
),
872
(
873
Bitwidth::I32,
874
VerificationResult::Failure(Counterexample {}),
875
),
876
(Bitwidth::I64, VerificationResult::Success),
877
],
878
)
879
}
880
881
#[test]
882
fn test_named_srem() {
883
test_aarch64_rule_with_lhs_termname_simple(
884
"srem",
885
"srem",
886
vec![
887
(Bitwidth::I8, VerificationResult::Success),
888
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
889
// (Bitwidth::I16, VerificationResult::Success),
890
// (Bitwidth::I32, VerificationResult::Success),
891
// (Bitwidth::I64, VerificationResult::Success),
892
],
893
)
894
}
895
896
#[test]
897
#[ignore]
898
fn test_named_slow_srem() {
899
test_aarch64_rule_with_lhs_termname_simple(
900
"srem",
901
"srem",
902
vec![
903
(Bitwidth::I16, VerificationResult::Unknown),
904
(Bitwidth::I32, VerificationResult::Unknown),
905
(Bitwidth::I64, VerificationResult::Unknown),
906
],
907
)
908
}
909
910
#[test]
911
fn test_named_urem() {
912
test_aarch64_rule_with_lhs_termname_simple(
913
"urem",
914
"urem",
915
vec![
916
(Bitwidth::I8, VerificationResult::Success),
917
// Too slow right now: https://github.com/avanhatt/wasmtime/issues/36
918
// (Bitwidth::I16, VerificationResult::Success),
919
// (Bitwidth::I32, VerificationResult::Success),
920
// (Bitwidth::I64, VerificationResult::Success),
921
],
922
)
923
}
924
925
#[test]
926
#[ignore]
927
fn test_named_slow_urem() {
928
test_aarch64_rule_with_lhs_termname_simple(
929
"urem",
930
"urem",
931
vec![
932
(Bitwidth::I16, VerificationResult::Unknown),
933
(Bitwidth::I32, VerificationResult::Unknown),
934
(Bitwidth::I64, VerificationResult::Unknown),
935
],
936
)
937
}
938
939
#[test]
940
fn test_named_urem_concrete() {
941
test_concrete_aarch64_rule_with_lhs_termname(
942
"urem",
943
"urem",
944
ConcreteTest {
945
termname: "urem".to_string(),
946
args: vec![
947
ConcreteInput {
948
literal: "#b11111110".to_string(),
949
ty: veri_ir::Type::BitVector(Some(8)),
950
},
951
ConcreteInput {
952
literal: "#b00110001".to_string(),
953
ty: veri_ir::Type::BitVector(Some(8)),
954
},
955
],
956
output: ConcreteInput {
957
literal: "#b00001001".to_string(),
958
ty: veri_ir::Type::BitVector(Some(8)),
959
},
960
},
961
)
962
}
963
964
#[test]
965
fn test_named_uextend() {
966
test_aarch64_rule_with_lhs_termname_simple("uextend", "uextend", all_success_result())
967
}
968
969
#[test]
970
fn test_named_sextend() {
971
test_aarch64_rule_with_lhs_termname_simple("sextend", "sextend", all_success_result())
972
}
973
974
#[test]
975
fn test_broken_uextend() {
976
test_from_file_with_lhs_termname(
977
"./examples/broken/broken_uextend.isle",
978
"uextend".to_string(),
979
TestResult::Expect(|sig| {
980
// In the spec for extend, zero_extend and sign_extend are swapped.
981
// However, this should still succeed if the input and output
982
// widths are the same
983
if sig.args[0] == sig.ret {
984
VerificationResult::Success
985
} else {
986
VerificationResult::Failure(Counterexample {})
987
}
988
}),
989
);
990
}
991
992
// AVH TODO: this rule requires priorities to be correct for narrow cases
993
// https://github.com/avanhatt/wasmtime/issues/32
994
#[test]
995
fn test_named_clz_32_64() {
996
test_aarch64_rule_with_lhs_termname_simple(
997
"clz_32_64",
998
"clz",
999
vec![
1000
// (Bitwidth::I8, VerificationResult::InapplicableRule),
1001
// (Bitwidth::I16, VerificationResult::InapplicableRule),
1002
(Bitwidth::I32, VerificationResult::Success),
1003
(Bitwidth::I64, VerificationResult::Success),
1004
],
1005
)
1006
}
1007
1008
#[test]
1009
fn test_named_clz_8() {
1010
test_aarch64_rule_with_lhs_termname_simple(
1011
"clz_8",
1012
"clz",
1013
vec![
1014
(Bitwidth::I8, VerificationResult::Success),
1015
(Bitwidth::I16, VerificationResult::InapplicableRule),
1016
(Bitwidth::I32, VerificationResult::InapplicableRule),
1017
(Bitwidth::I64, VerificationResult::InapplicableRule),
1018
],
1019
)
1020
}
1021
1022
#[test]
1023
fn test_named_clz_16() {
1024
test_aarch64_rule_with_lhs_termname_simple(
1025
"clz_16",
1026
"clz",
1027
vec![
1028
(Bitwidth::I8, VerificationResult::InapplicableRule),
1029
(Bitwidth::I16, VerificationResult::Success),
1030
(Bitwidth::I32, VerificationResult::InapplicableRule),
1031
(Bitwidth::I64, VerificationResult::InapplicableRule),
1032
],
1033
)
1034
}
1035
1036
#[test]
1037
fn test_broken_clz() {
1038
test_from_file_with_lhs_termname_simple(
1039
"./examples/broken/clz/broken_clz.isle",
1040
"clz".to_string(),
1041
vec![
1042
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1043
(
1044
Bitwidth::I16,
1045
VerificationResult::Failure(Counterexample {}),
1046
),
1047
(
1048
Bitwidth::I32,
1049
VerificationResult::Failure(Counterexample {}),
1050
),
1051
(Bitwidth::I64, VerificationResult::Success),
1052
],
1053
)
1054
}
1055
1056
#[test]
1057
fn test_broken_clz8() {
1058
test_from_file_with_lhs_termname_simple(
1059
"./examples/broken/clz/broken_clz8.isle",
1060
"clz".to_string(),
1061
vec![
1062
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1063
(Bitwidth::I16, VerificationResult::InapplicableRule),
1064
(Bitwidth::I32, VerificationResult::InapplicableRule),
1065
(Bitwidth::I64, VerificationResult::InapplicableRule),
1066
],
1067
)
1068
}
1069
1070
#[test]
1071
fn test_broken_clz_n6() {
1072
test_from_file_with_lhs_termname_simple(
1073
"./examples/broken/clz/broken_clz16.isle",
1074
"clz".to_string(),
1075
vec![
1076
(Bitwidth::I8, VerificationResult::InapplicableRule),
1077
(
1078
Bitwidth::I16,
1079
VerificationResult::Failure(Counterexample {}),
1080
),
1081
(Bitwidth::I32, VerificationResult::InapplicableRule),
1082
(Bitwidth::I64, VerificationResult::InapplicableRule),
1083
],
1084
)
1085
}
1086
1087
// AVH TODO: this rule requires priorities to be correct for narrow cases
1088
// https://github.com/avanhatt/wasmtime/issues/32
1089
#[test]
1090
fn test_named_cls_32_64() {
1091
test_aarch64_rule_with_lhs_termname_simple(
1092
"cls_32_64",
1093
"cls",
1094
vec![
1095
// (Bitwidth::I8, VerificationResult::InapplicableRule),
1096
// (Bitwidth::I16, VerificationResult::InapplicableRule),
1097
(Bitwidth::I32, VerificationResult::Success),
1098
(Bitwidth::I64, VerificationResult::Success),
1099
],
1100
)
1101
}
1102
1103
#[test]
1104
fn test_named_cls_8() {
1105
test_aarch64_rule_with_lhs_termname_simple(
1106
"cls_8",
1107
"cls",
1108
vec![
1109
(Bitwidth::I8, VerificationResult::Success),
1110
(Bitwidth::I16, VerificationResult::InapplicableRule),
1111
(Bitwidth::I32, VerificationResult::InapplicableRule),
1112
(Bitwidth::I64, VerificationResult::InapplicableRule),
1113
],
1114
)
1115
}
1116
1117
#[test]
1118
fn test_named_cls_16() {
1119
test_aarch64_rule_with_lhs_termname_simple(
1120
"cls_16",
1121
"cls",
1122
vec![
1123
(Bitwidth::I8, VerificationResult::InapplicableRule),
1124
(Bitwidth::I16, VerificationResult::Success),
1125
(Bitwidth::I32, VerificationResult::InapplicableRule),
1126
(Bitwidth::I64, VerificationResult::InapplicableRule),
1127
],
1128
)
1129
}
1130
1131
#[test]
1132
fn test_broken_cls_32_64() {
1133
test_from_file_with_lhs_termname_simple(
1134
"./examples/broken/cls/broken_cls.isle",
1135
"cls".to_string(),
1136
vec![
1137
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1138
(
1139
Bitwidth::I16,
1140
VerificationResult::Failure(Counterexample {}),
1141
),
1142
(Bitwidth::I32, VerificationResult::Success),
1143
(Bitwidth::I64, VerificationResult::Success),
1144
],
1145
)
1146
}
1147
1148
#[test]
1149
fn test_broken_cls_8() {
1150
test_from_file_with_lhs_termname_simple(
1151
"./examples/broken/cls/broken_cls8.isle",
1152
"cls".to_string(),
1153
vec![(Bitwidth::I8, VerificationResult::Failure(Counterexample {}))],
1154
)
1155
}
1156
1157
#[test]
1158
fn test_broken_cls_16() {
1159
test_from_file_with_lhs_termname_simple(
1160
"./examples/broken/cls/broken_cls16.isle",
1161
"cls".to_string(),
1162
vec![
1163
(Bitwidth::I8, VerificationResult::InapplicableRule),
1164
(
1165
Bitwidth::I16,
1166
VerificationResult::Failure(Counterexample {}),
1167
),
1168
(Bitwidth::I32, VerificationResult::InapplicableRule),
1169
(Bitwidth::I64, VerificationResult::InapplicableRule),
1170
],
1171
)
1172
}
1173
1174
#[test]
1175
fn test_named_ctz_32_64() {
1176
test_aarch64_rule_with_lhs_termname_simple(
1177
"ctz_32_64",
1178
"ctz",
1179
vec![
1180
// (Bitwidth::I8, VerificationResult::InapplicableRule),
1181
// (Bitwidth::I16, VerificationResult::InapplicableRule),
1182
(Bitwidth::I32, VerificationResult::Success),
1183
(Bitwidth::I64, VerificationResult::Success),
1184
],
1185
)
1186
}
1187
1188
#[test]
1189
fn test_named_ctz_8() {
1190
test_aarch64_rule_with_lhs_termname_simple(
1191
"ctz_8",
1192
"ctz",
1193
vec![
1194
(Bitwidth::I8, VerificationResult::Success),
1195
(Bitwidth::I16, VerificationResult::InapplicableRule),
1196
(Bitwidth::I32, VerificationResult::InapplicableRule),
1197
(Bitwidth::I64, VerificationResult::InapplicableRule),
1198
],
1199
)
1200
}
1201
1202
#[test]
1203
fn test_named_ctz_16() {
1204
test_aarch64_rule_with_lhs_termname_simple(
1205
"ctz_16",
1206
"ctz",
1207
vec![
1208
(Bitwidth::I8, VerificationResult::InapplicableRule),
1209
(Bitwidth::I16, VerificationResult::Success),
1210
(Bitwidth::I32, VerificationResult::InapplicableRule),
1211
(Bitwidth::I64, VerificationResult::InapplicableRule),
1212
],
1213
)
1214
}
1215
1216
#[test]
1217
fn test_broken_ctz_32_64() {
1218
test_from_file_with_lhs_termname_simple(
1219
"./examples/broken/ctz/broken_ctz.isle",
1220
"clz".to_string(),
1221
vec![
1222
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1223
(
1224
Bitwidth::I16,
1225
VerificationResult::Failure(Counterexample {}),
1226
),
1227
(
1228
Bitwidth::I32,
1229
VerificationResult::Failure(Counterexample {}),
1230
),
1231
(
1232
Bitwidth::I64,
1233
VerificationResult::Failure(Counterexample {}),
1234
),
1235
],
1236
)
1237
}
1238
1239
#[test]
1240
fn test_broken_ctz_8() {
1241
test_from_file_with_lhs_termname_simple(
1242
"./examples/broken/ctz/broken_ctz8.isle",
1243
"ctz".to_string(),
1244
vec![
1245
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1246
(Bitwidth::I16, VerificationResult::InapplicableRule),
1247
(Bitwidth::I32, VerificationResult::InapplicableRule),
1248
(Bitwidth::I64, VerificationResult::InapplicableRule),
1249
],
1250
)
1251
}
1252
1253
#[test]
1254
fn test_broken_ctz_16() {
1255
test_from_file_with_lhs_termname_simple(
1256
"./examples/broken/ctz/broken_ctz16.isle",
1257
"ctz".to_string(),
1258
vec![
1259
(Bitwidth::I8, VerificationResult::InapplicableRule),
1260
(
1261
Bitwidth::I16,
1262
VerificationResult::Failure(Counterexample {}),
1263
),
1264
(Bitwidth::I32, VerificationResult::InapplicableRule),
1265
(Bitwidth::I64, VerificationResult::InapplicableRule),
1266
],
1267
)
1268
}
1269
1270
#[test]
1271
fn test_named_small_rotr() {
1272
let config = Config {
1273
term: "small_rotr".to_string(),
1274
distinct_check: true,
1275
custom_assumptions: None,
1276
custom_verification_condition: Some(Box::new(|smt, args, lhs, rhs| {
1277
let ty_arg = *args.first().unwrap();
1278
let lower_8_bits_eq = {
1279
let mask = smt.atom("#x00000000000000FF");
1280
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1281
};
1282
let lower_16_bits_eq = {
1283
let mask = smt.atom("#x000000000000FFFF");
1284
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1285
};
1286
smt.ite(
1287
smt.eq(ty_arg, smt.atom("8")),
1288
lower_8_bits_eq,
1289
lower_16_bits_eq,
1290
)
1291
})),
1292
names: Some(vec!["small_rotr".to_string()]),
1293
};
1294
test_aarch64_with_config_simple(config, vec![(Bitwidth::I64, VerificationResult::Success)]);
1295
}
1296
1297
#[test]
1298
fn test_broken_small_rotr_to_shifts() {
1299
let config = Config {
1300
term: "small_rotr".to_string(),
1301
distinct_check: true,
1302
custom_assumptions: None,
1303
custom_verification_condition: Some(Box::new(|smt, args, lhs, rhs| {
1304
let ty_arg = *args.first().unwrap();
1305
let lower_8_bits_eq = {
1306
let mask = smt.atom("#x00000000000000FF");
1307
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1308
};
1309
let lower_16_bits_eq = {
1310
let mask = smt.atom("#x000000000000FFFF");
1311
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1312
};
1313
smt.ite(
1314
smt.eq(ty_arg, smt.atom("8")),
1315
lower_8_bits_eq,
1316
lower_16_bits_eq,
1317
)
1318
})),
1319
names: None,
1320
};
1321
test_from_file_with_config_simple(
1322
"./examples/broken/broken_mask_small_rotr.isle",
1323
config,
1324
vec![(
1325
Bitwidth::I64,
1326
VerificationResult::Failure(Counterexample {}),
1327
)],
1328
);
1329
}
1330
1331
#[test]
1332
fn test_broken_small_rotr_to_shifts_2() {
1333
let config = Config {
1334
term: "small_rotr".to_string(),
1335
distinct_check: true,
1336
custom_assumptions: None,
1337
custom_verification_condition: Some(Box::new(|smt, args, lhs, rhs| {
1338
let ty_arg = *args.first().unwrap();
1339
let lower_8_bits_eq = {
1340
let mask = smt.atom("#x00000000000000FF");
1341
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1342
};
1343
let lower_16_bits_eq = {
1344
let mask = smt.atom("#x000000000000FFFF");
1345
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1346
};
1347
smt.ite(
1348
smt.eq(ty_arg, smt.atom("8")),
1349
lower_8_bits_eq,
1350
lower_16_bits_eq,
1351
)
1352
})),
1353
names: None,
1354
};
1355
test_from_file_with_config_simple(
1356
"./examples/broken/broken_rule_or_small_rotr.isle",
1357
config,
1358
vec![(
1359
Bitwidth::I64,
1360
VerificationResult::Failure(Counterexample {}),
1361
)],
1362
);
1363
}
1364
1365
#[test]
1366
fn test_named_small_rotr_imm() {
1367
let config = Config {
1368
term: "small_rotr_imm".to_string(),
1369
distinct_check: true,
1370
custom_assumptions: None,
1371
custom_verification_condition: Some(Box::new(|smt, args, lhs, rhs| {
1372
let ty_arg = *args.first().unwrap();
1373
let lower_8_bits_eq = {
1374
let mask = smt.atom("#x00000000000000FF");
1375
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1376
};
1377
let lower_16_bits_eq = {
1378
let mask = smt.atom("#x000000000000FFFF");
1379
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1380
};
1381
smt.ite(
1382
smt.eq(ty_arg, smt.atom("8")),
1383
lower_8_bits_eq,
1384
lower_16_bits_eq,
1385
)
1386
})),
1387
names: Some(vec!["small_rotr_imm".to_string()]),
1388
};
1389
test_aarch64_with_config_simple(config, vec![(Bitwidth::I64, VerificationResult::Success)]);
1390
}
1391
1392
#[test]
1393
fn test_named_rotl_fits_in_16() {
1394
test_aarch64_rule_with_lhs_termname_simple(
1395
"rotl_fits_in_16",
1396
"rotl",
1397
vec![
1398
(Bitwidth::I8, VerificationResult::Success),
1399
(Bitwidth::I16, VerificationResult::Success),
1400
(Bitwidth::I32, VerificationResult::InapplicableRule),
1401
(Bitwidth::I64, VerificationResult::InapplicableRule),
1402
],
1403
)
1404
}
1405
1406
#[test]
1407
fn test_named_rotl_32_base_case() {
1408
test_aarch64_rule_with_lhs_termname_simple(
1409
"rotl_32_base_case",
1410
"rotl",
1411
vec![
1412
(Bitwidth::I8, VerificationResult::InapplicableRule),
1413
(Bitwidth::I16, VerificationResult::InapplicableRule),
1414
(Bitwidth::I32, VerificationResult::Success),
1415
(Bitwidth::I64, VerificationResult::InapplicableRule),
1416
],
1417
)
1418
}
1419
1420
#[test]
1421
fn test_broken_32_general_rotl_to_rotr() {
1422
test_from_file_with_lhs_termname_simple(
1423
"./examples/broken/broken_32_general_rotl_to_rotr.isle",
1424
"rotl".to_string(),
1425
vec![
1426
(Bitwidth::I8, VerificationResult::InapplicableRule),
1427
(Bitwidth::I16, VerificationResult::InapplicableRule),
1428
(
1429
Bitwidth::I32,
1430
VerificationResult::Failure(Counterexample {}),
1431
),
1432
(Bitwidth::I64, VerificationResult::InapplicableRule),
1433
],
1434
)
1435
}
1436
1437
#[test]
1438
fn test_named_rotl_64_base_case() {
1439
test_aarch64_rule_with_lhs_termname_simple(
1440
"rotl_64_base_case",
1441
"rotl",
1442
vec![
1443
(Bitwidth::I8, VerificationResult::InapplicableRule),
1444
(Bitwidth::I16, VerificationResult::InapplicableRule),
1445
(Bitwidth::I32, VerificationResult::InapplicableRule),
1446
(Bitwidth::I64, VerificationResult::Success),
1447
],
1448
)
1449
}
1450
1451
#[test]
1452
fn test_broken_fits_in_16_rotl_to_rotr() {
1453
test_from_file_with_lhs_termname_simple(
1454
"./examples/broken/broken_fits_in_16_rotl_to_rotr.isle",
1455
"rotl".to_string(),
1456
vec![
1457
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1458
(
1459
Bitwidth::I16,
1460
VerificationResult::Failure(Counterexample {}),
1461
),
1462
(Bitwidth::I32, VerificationResult::InapplicableRule),
1463
(Bitwidth::I64, VerificationResult::InapplicableRule),
1464
],
1465
)
1466
}
1467
1468
#[test]
1469
fn test_named_rotl_fits_in_16_imm() {
1470
test_aarch64_rule_with_lhs_termname_simple(
1471
"rotl_fits_in_16_imm",
1472
"rotl",
1473
vec![
1474
(Bitwidth::I8, VerificationResult::Success),
1475
(Bitwidth::I16, VerificationResult::Success),
1476
(Bitwidth::I32, VerificationResult::InapplicableRule),
1477
(Bitwidth::I64, VerificationResult::InapplicableRule),
1478
],
1479
)
1480
}
1481
1482
#[test]
1483
fn test_named_rotl_64_imm() {
1484
test_aarch64_rule_with_lhs_termname_simple(
1485
"rotl_64_imm",
1486
"rotl",
1487
vec![
1488
(Bitwidth::I8, VerificationResult::InapplicableRule),
1489
(Bitwidth::I16, VerificationResult::InapplicableRule),
1490
(Bitwidth::I32, VerificationResult::InapplicableRule),
1491
(Bitwidth::I64, VerificationResult::Success),
1492
],
1493
)
1494
}
1495
1496
#[test]
1497
fn test_named_rotl_32_imm() {
1498
test_aarch64_rule_with_lhs_termname_simple(
1499
"rotl_32_imm",
1500
"rotl",
1501
vec![
1502
(Bitwidth::I8, VerificationResult::InapplicableRule),
1503
(Bitwidth::I16, VerificationResult::InapplicableRule),
1504
(Bitwidth::I32, VerificationResult::Success),
1505
(Bitwidth::I64, VerificationResult::InapplicableRule),
1506
],
1507
)
1508
}
1509
1510
#[test]
1511
fn test_broken_fits_in_16_with_imm_rotl_to_rotr() {
1512
test_from_file_with_lhs_termname_simple(
1513
"./examples/broken/broken_fits_in_16_with_imm_rotl_to_rotr.isle",
1514
"rotl".to_string(),
1515
vec![
1516
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1517
(
1518
Bitwidth::I16,
1519
VerificationResult::Failure(Counterexample {}),
1520
),
1521
(Bitwidth::I32, VerificationResult::InapplicableRule),
1522
(Bitwidth::I64, VerificationResult::InapplicableRule),
1523
],
1524
)
1525
}
1526
1527
#[test]
1528
fn test_named_rotr_fits_in_16() {
1529
test_aarch64_rule_with_lhs_termname_simple(
1530
"rotr_fits_in_16",
1531
"rotr",
1532
vec![
1533
(Bitwidth::I8, VerificationResult::Success),
1534
(Bitwidth::I16, VerificationResult::Success),
1535
(Bitwidth::I32, VerificationResult::InapplicableRule),
1536
(Bitwidth::I64, VerificationResult::InapplicableRule),
1537
],
1538
)
1539
}
1540
1541
#[test]
1542
fn test_named_rotr_fits_in_16_imm() {
1543
test_aarch64_rule_with_lhs_termname_simple(
1544
"rotr_fits_in_16_imm",
1545
"rotr",
1546
vec![
1547
(Bitwidth::I8, VerificationResult::Success),
1548
(Bitwidth::I16, VerificationResult::Success),
1549
(Bitwidth::I32, VerificationResult::InapplicableRule),
1550
(Bitwidth::I64, VerificationResult::InapplicableRule),
1551
],
1552
)
1553
}
1554
1555
#[test]
1556
fn test_named_rotr_32_base_case() {
1557
test_aarch64_rule_with_lhs_termname_simple(
1558
"rotr_32_base_case",
1559
"rotr",
1560
vec![
1561
(Bitwidth::I8, VerificationResult::InapplicableRule),
1562
(Bitwidth::I16, VerificationResult::InapplicableRule),
1563
(Bitwidth::I32, VerificationResult::Success),
1564
(Bitwidth::I64, VerificationResult::InapplicableRule),
1565
],
1566
)
1567
}
1568
1569
#[test]
1570
fn test_named_rotr_32_imm() {
1571
test_aarch64_rule_with_lhs_termname_simple(
1572
"rotr_32_imm",
1573
"rotr",
1574
vec![
1575
(Bitwidth::I8, VerificationResult::InapplicableRule),
1576
(Bitwidth::I16, VerificationResult::InapplicableRule),
1577
(Bitwidth::I32, VerificationResult::Success),
1578
(Bitwidth::I64, VerificationResult::InapplicableRule),
1579
],
1580
)
1581
}
1582
1583
#[test]
1584
fn test_named_rotr_64_base_case() {
1585
test_aarch64_rule_with_lhs_termname_simple(
1586
"rotr_64_base_case",
1587
"rotr",
1588
vec![
1589
(Bitwidth::I8, VerificationResult::InapplicableRule),
1590
(Bitwidth::I16, VerificationResult::InapplicableRule),
1591
(Bitwidth::I32, VerificationResult::InapplicableRule),
1592
(Bitwidth::I64, VerificationResult::Success),
1593
],
1594
)
1595
}
1596
1597
#[test]
1598
fn test_named_rotr_64_imm() {
1599
test_aarch64_rule_with_lhs_termname_simple(
1600
"rotr_64_imm",
1601
"rotr",
1602
vec![
1603
(Bitwidth::I8, VerificationResult::InapplicableRule),
1604
(Bitwidth::I16, VerificationResult::InapplicableRule),
1605
(Bitwidth::I32, VerificationResult::InapplicableRule),
1606
(Bitwidth::I64, VerificationResult::Success),
1607
],
1608
)
1609
}
1610
1611
#[test]
1612
fn test_named_band_fits_in_64() {
1613
test_aarch64_rule_with_lhs_termname_simple(
1614
"band_fits_in_64",
1615
"band",
1616
vec![
1617
(Bitwidth::I8, VerificationResult::Success),
1618
(Bitwidth::I16, VerificationResult::Success),
1619
(Bitwidth::I32, VerificationResult::Success),
1620
(Bitwidth::I64, VerificationResult::Success),
1621
],
1622
)
1623
}
1624
1625
#[test]
1626
fn test_broken_band_fits_in_32() {
1627
test_from_file_with_lhs_termname_simple(
1628
"./examples/broken/broken_fits_in_32_band.isle",
1629
"band".to_string(),
1630
vec![
1631
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1632
(
1633
Bitwidth::I16,
1634
VerificationResult::Failure(Counterexample {}),
1635
),
1636
(
1637
Bitwidth::I32,
1638
VerificationResult::Failure(Counterexample {}),
1639
),
1640
(Bitwidth::I64, VerificationResult::InapplicableRule),
1641
],
1642
)
1643
}
1644
1645
#[test]
1646
fn test_named_bor_fits_in_64() {
1647
test_aarch64_rule_with_lhs_termname_simple(
1648
"bor_fits_in_64",
1649
"bor",
1650
vec![
1651
(Bitwidth::I8, VerificationResult::Success),
1652
(Bitwidth::I16, VerificationResult::Success),
1653
(Bitwidth::I32, VerificationResult::Success),
1654
(Bitwidth::I64, VerificationResult::Success),
1655
],
1656
)
1657
}
1658
1659
#[test]
1660
fn test_broken_bor_fits_in_32() {
1661
test_from_file_with_lhs_termname_simple(
1662
"./examples/broken/broken_fits_in_32_bor.isle",
1663
"bor".to_string(),
1664
vec![
1665
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
1666
(
1667
Bitwidth::I16,
1668
VerificationResult::Failure(Counterexample {}),
1669
),
1670
(
1671
Bitwidth::I32,
1672
VerificationResult::Failure(Counterexample {}),
1673
),
1674
(Bitwidth::I64, VerificationResult::InapplicableRule),
1675
],
1676
)
1677
}
1678
1679
#[test]
1680
fn test_named_bxor_fits_in_64() {
1681
test_aarch64_rule_with_lhs_termname_simple(
1682
"bxor_fits_in_64",
1683
"bxor",
1684
vec![
1685
(Bitwidth::I8, VerificationResult::Success),
1686
(Bitwidth::I16, VerificationResult::Success),
1687
(Bitwidth::I32, VerificationResult::Success),
1688
(Bitwidth::I64, VerificationResult::Success),
1689
],
1690
)
1691
}
1692
1693
#[test]
1694
fn test_named_band_not_right() {
1695
test_aarch64_rule_with_lhs_termname_simple(
1696
"band_not_right",
1697
"band",
1698
vec![
1699
(Bitwidth::I8, VerificationResult::Success),
1700
(Bitwidth::I16, VerificationResult::Success),
1701
(Bitwidth::I32, VerificationResult::Success),
1702
(Bitwidth::I64, VerificationResult::Success),
1703
],
1704
)
1705
}
1706
1707
#[test]
1708
fn test_named_band_not_left() {
1709
test_aarch64_rule_with_lhs_termname_simple(
1710
"band_not_left",
1711
"band",
1712
vec![
1713
(Bitwidth::I8, VerificationResult::Success),
1714
(Bitwidth::I16, VerificationResult::Success),
1715
(Bitwidth::I32, VerificationResult::Success),
1716
(Bitwidth::I64, VerificationResult::Success),
1717
],
1718
)
1719
}
1720
1721
#[test]
1722
fn test_named_bor_not_right() {
1723
test_aarch64_rule_with_lhs_termname_simple(
1724
"bor_not_right",
1725
"bor",
1726
vec![
1727
(Bitwidth::I8, VerificationResult::Success),
1728
(Bitwidth::I16, VerificationResult::Success),
1729
(Bitwidth::I32, VerificationResult::Success),
1730
(Bitwidth::I64, VerificationResult::Success),
1731
],
1732
)
1733
}
1734
1735
#[test]
1736
fn test_named_bor_not_left() {
1737
test_aarch64_rule_with_lhs_termname_simple(
1738
"bor_not_left",
1739
"bor",
1740
vec![
1741
(Bitwidth::I8, VerificationResult::Success),
1742
(Bitwidth::I16, VerificationResult::Success),
1743
(Bitwidth::I32, VerificationResult::Success),
1744
(Bitwidth::I64, VerificationResult::Success),
1745
],
1746
)
1747
}
1748
1749
#[test]
1750
fn test_named_bxor_not_right() {
1751
test_aarch64_rule_with_lhs_termname_simple(
1752
"bxor_not_right",
1753
"bxor",
1754
vec![
1755
(Bitwidth::I8, VerificationResult::Success),
1756
(Bitwidth::I16, VerificationResult::Success),
1757
(Bitwidth::I32, VerificationResult::Success),
1758
(Bitwidth::I64, VerificationResult::Success),
1759
],
1760
)
1761
}
1762
1763
#[test]
1764
fn test_named_bxor_not_left() {
1765
test_aarch64_rule_with_lhs_termname_simple(
1766
"bxor_not_left",
1767
"bxor",
1768
vec![
1769
(Bitwidth::I8, VerificationResult::Success),
1770
(Bitwidth::I16, VerificationResult::Success),
1771
(Bitwidth::I32, VerificationResult::Success),
1772
(Bitwidth::I64, VerificationResult::Success),
1773
],
1774
)
1775
}
1776
1777
#[test]
1778
fn test_named_bnot() {
1779
test_aarch64_rule_with_lhs_termname_simple("bnot_base_case", "bnot", all_success_result())
1780
}
1781
1782
#[test]
1783
fn test_named_bnot_ishl() {
1784
test_aarch64_rule_with_lhs_termname_simple("bnot_ishl", "bnot", all_success_result())
1785
}
1786
1787
#[test]
1788
fn test_named_ishl_64() {
1789
test_aarch64_rule_with_lhs_termname_simple(
1790
"ishl_64",
1791
"ishl",
1792
vec![
1793
(Bitwidth::I8, VerificationResult::InapplicableRule),
1794
(Bitwidth::I16, VerificationResult::InapplicableRule),
1795
(Bitwidth::I32, VerificationResult::InapplicableRule),
1796
(Bitwidth::I64, VerificationResult::Success),
1797
],
1798
)
1799
}
1800
1801
#[test]
1802
fn test_named_ishl_64_concrete() {
1803
test_concrete_aarch64_rule_with_lhs_termname(
1804
"ishl_64",
1805
"ishl",
1806
ConcreteTest {
1807
termname: "ishl".to_string(),
1808
args: vec![
1809
ConcreteInput {
1810
literal: "#b0000000000000000000000000000000000000000000000000000000000000001"
1811
.to_string(),
1812
ty: veri_ir::Type::BitVector(Some(64)),
1813
},
1814
ConcreteInput {
1815
literal: "#b0000000000000000000000000000000000000000000000000000000000000010"
1816
.to_string(),
1817
ty: veri_ir::Type::BitVector(Some(64)),
1818
},
1819
],
1820
output: ConcreteInput {
1821
literal: "#b0000000000000000000000000000000000000000000000000000000000000100"
1822
.to_string(),
1823
ty: veri_ir::Type::BitVector(Some(64)),
1824
},
1825
},
1826
)
1827
}
1828
1829
#[test]
1830
fn test_named_ishl_fits_in_32() {
1831
test_aarch64_rule_with_lhs_termname_simple(
1832
"ishl_fits_in_32",
1833
"ishl",
1834
vec![
1835
(Bitwidth::I8, VerificationResult::Success),
1836
(Bitwidth::I16, VerificationResult::Success),
1837
(Bitwidth::I32, VerificationResult::Success),
1838
(Bitwidth::I64, VerificationResult::InapplicableRule),
1839
],
1840
)
1841
}
1842
1843
#[test]
1844
fn test_named_ishl_fits_in_32_concrete() {
1845
test_concrete_aarch64_rule_with_lhs_termname(
1846
"ishl_fits_in_32",
1847
"ishl",
1848
ConcreteTest {
1849
termname: "ishl".to_string(),
1850
args: vec![
1851
ConcreteInput {
1852
literal: "#b00000001".to_string(),
1853
ty: veri_ir::Type::BitVector(Some(8)),
1854
},
1855
ConcreteInput {
1856
literal: "#b00000010".to_string(),
1857
ty: veri_ir::Type::BitVector(Some(8)),
1858
},
1859
],
1860
output: ConcreteInput {
1861
literal: "#b00000100".to_string(),
1862
ty: veri_ir::Type::BitVector(Some(8)),
1863
},
1864
},
1865
)
1866
}
1867
1868
#[test]
1869
fn test_named_sshr_64() {
1870
test_aarch64_rule_with_lhs_termname_simple(
1871
"sshr_64",
1872
"sshr",
1873
vec![
1874
(Bitwidth::I8, VerificationResult::InapplicableRule),
1875
(Bitwidth::I16, VerificationResult::InapplicableRule),
1876
(Bitwidth::I32, VerificationResult::InapplicableRule),
1877
(Bitwidth::I64, VerificationResult::Success),
1878
],
1879
)
1880
}
1881
1882
#[test]
1883
fn test_named_sshr_fits_in_32() {
1884
test_aarch64_rule_with_lhs_termname_simple(
1885
"sshr_fits_in_32",
1886
"sshr",
1887
vec![
1888
(Bitwidth::I8, VerificationResult::Success),
1889
(Bitwidth::I16, VerificationResult::Success),
1890
(Bitwidth::I32, VerificationResult::Success),
1891
(Bitwidth::I64, VerificationResult::InapplicableRule),
1892
],
1893
)
1894
}
1895
1896
#[test]
1897
fn test_named_sshr_fits_in_32_concrete() {
1898
test_concrete_aarch64_rule_with_lhs_termname(
1899
"sshr_fits_in_32",
1900
"sshr",
1901
ConcreteTest {
1902
termname: "sshr".to_string(),
1903
args: vec![
1904
ConcreteInput {
1905
literal: "#b10100000".to_string(),
1906
ty: veri_ir::Type::BitVector(Some(8)),
1907
},
1908
ConcreteInput {
1909
literal: "#b00000001".to_string(),
1910
ty: veri_ir::Type::BitVector(Some(8)),
1911
},
1912
],
1913
output: ConcreteInput {
1914
literal: "#b11010000".to_string(),
1915
ty: veri_ir::Type::BitVector(Some(8)),
1916
},
1917
},
1918
)
1919
}
1920
1921
#[test]
1922
fn test_named_ushr_64() {
1923
test_aarch64_rule_with_lhs_termname_simple(
1924
"ushr_64",
1925
"ushr",
1926
vec![
1927
(Bitwidth::I8, VerificationResult::InapplicableRule),
1928
(Bitwidth::I16, VerificationResult::InapplicableRule),
1929
(Bitwidth::I32, VerificationResult::InapplicableRule),
1930
(Bitwidth::I64, VerificationResult::Success),
1931
],
1932
)
1933
}
1934
1935
#[test]
1936
fn test_named_ushr_fits_in_32() {
1937
test_aarch64_rule_with_lhs_termname_simple(
1938
"ushr_fits_in_32",
1939
"ushr",
1940
vec![
1941
(Bitwidth::I8, VerificationResult::Success),
1942
(Bitwidth::I16, VerificationResult::Success),
1943
(Bitwidth::I32, VerificationResult::Success),
1944
(Bitwidth::I64, VerificationResult::InapplicableRule),
1945
],
1946
)
1947
}
1948
1949
#[test]
1950
fn test_named_ushr_fits_in_32_concrete() {
1951
test_concrete_aarch64_rule_with_lhs_termname(
1952
"ushr_fits_in_32",
1953
"ushr",
1954
ConcreteTest {
1955
termname: "ushr".to_string(),
1956
args: vec![
1957
ConcreteInput {
1958
literal: "#b10100000".to_string(),
1959
ty: veri_ir::Type::BitVector(Some(8)),
1960
},
1961
ConcreteInput {
1962
literal: "#b00000001".to_string(),
1963
ty: veri_ir::Type::BitVector(Some(8)),
1964
},
1965
],
1966
output: ConcreteInput {
1967
literal: "#b01010000".to_string(),
1968
ty: veri_ir::Type::BitVector(Some(8)),
1969
},
1970
},
1971
)
1972
}
1973
1974
#[test]
1975
fn test_named_do_shift_64_base_case() {
1976
test_aarch64_rule_with_lhs_termname_simple(
1977
"do_shift_64_base_case",
1978
"do_shift",
1979
vec![
1980
(Bitwidth::I8, VerificationResult::InapplicableRule),
1981
(Bitwidth::I16, VerificationResult::InapplicableRule),
1982
(Bitwidth::I32, VerificationResult::InapplicableRule),
1983
(Bitwidth::I64, VerificationResult::Success),
1984
],
1985
)
1986
}
1987
1988
#[test]
1989
fn test_named_do_shift_imm() {
1990
let config = Config {
1991
term: "do_shift".to_string(),
1992
distinct_check: true,
1993
custom_assumptions: None,
1994
custom_verification_condition: Some(Box::new(|smt, _args, lhs, rhs| {
1995
let mask = smt.atom("#x00000000000000FF");
1996
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
1997
})),
1998
names: Some(vec!["do_shift_imm".to_string()]),
1999
};
2000
test_aarch64_with_config_simple(config, vec![(Bitwidth::I8, VerificationResult::Success)]);
2001
let config = Config {
2002
term: "do_shift".to_string(),
2003
distinct_check: true,
2004
custom_assumptions: None,
2005
custom_verification_condition: Some(Box::new(|smt, _args, lhs, rhs| {
2006
let mask = smt.atom("#x000000000000FFFF");
2007
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2008
})),
2009
names: Some(vec!["do_shift_imm".to_string()]),
2010
};
2011
test_aarch64_with_config_simple(config, vec![(Bitwidth::I16, VerificationResult::Success)]);
2012
let config = Config {
2013
term: "do_shift".to_string(),
2014
distinct_check: true,
2015
custom_assumptions: None,
2016
custom_verification_condition: Some(Box::new(|smt, _args, lhs, rhs| {
2017
let mask = smt.atom("#x00000000FFFFFFFF");
2018
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2019
})),
2020
names: Some(vec!["do_shift_imm".to_string()]),
2021
};
2022
test_aarch64_with_config_simple(config, vec![(Bitwidth::I32, VerificationResult::Success)]);
2023
test_aarch64_rule_with_lhs_termname_simple(
2024
"do_shift_imm",
2025
"do_shift",
2026
vec![(Bitwidth::I64, VerificationResult::Success)],
2027
)
2028
}
2029
2030
#[test]
2031
fn test_named_do_shift_fits_in_16() {
2032
let config = Config {
2033
term: "do_shift".to_string(),
2034
distinct_check: true,
2035
custom_assumptions: None,
2036
custom_verification_condition: Some(Box::new(|smt, args, lhs, rhs| {
2037
let ty_arg = args[1];
2038
let lower_8_bits_eq = {
2039
let mask = smt.atom("#x00000000000000FF");
2040
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2041
};
2042
let lower_16_bits_eq = {
2043
let mask = smt.atom("#x000000000000FFFF");
2044
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2045
};
2046
smt.ite(
2047
smt.eq(ty_arg, smt.atom("8")),
2048
lower_8_bits_eq,
2049
lower_16_bits_eq,
2050
)
2051
})),
2052
names: Some(vec!["do_shift_fits_in_16".to_string()]),
2053
};
2054
test_aarch64_with_config_simple(
2055
config,
2056
vec![
2057
(Bitwidth::I8, VerificationResult::Success),
2058
(Bitwidth::I16, VerificationResult::Success),
2059
],
2060
);
2061
2062
test_aarch64_rule_with_lhs_termname_simple(
2063
"do_shift_fits_in_16",
2064
"do_shift",
2065
vec![
2066
(Bitwidth::I32, VerificationResult::InapplicableRule),
2067
(Bitwidth::I64, VerificationResult::InapplicableRule),
2068
],
2069
)
2070
}
2071
2072
#[test]
2073
fn test_named_do_shift_fits_in_16_concrete() {
2074
// (decl do_shift (ALUOp Type Reg Value) Reg)
2075
2076
test_concrete_aarch64_rule_with_lhs_termname(
2077
"do_shift_fits_in_16",
2078
"do_shift",
2079
ConcreteTest {
2080
termname: "do_shift".to_string(),
2081
args: vec![
2082
ConcreteInput {
2083
literal: "#x0e".to_string(),
2084
ty: veri_ir::Type::BitVector(Some(8)),
2085
},
2086
ConcreteInput {
2087
literal: "16".to_string(),
2088
ty: veri_ir::Type::Int,
2089
},
2090
ConcreteInput {
2091
literal: "#b0000000000000000000000000000000000000000000000000000000000000001"
2092
.to_string(),
2093
ty: veri_ir::Type::BitVector(Some(64)),
2094
},
2095
ConcreteInput {
2096
literal: "#b0000000000000001".to_string(),
2097
ty: veri_ir::Type::BitVector(Some(16)),
2098
},
2099
],
2100
output: ConcreteInput {
2101
literal: "#b0000000000000000000000000000000000000000000000000000000000000010"
2102
.to_string(),
2103
ty: veri_ir::Type::BitVector(Some(64)),
2104
},
2105
},
2106
)
2107
}
2108
2109
#[test]
2110
fn test_named_do_shift_32_base_case() {
2111
test_aarch64_rule_with_lhs_termname_simple(
2112
"do_shift_32_base_case",
2113
"do_shift",
2114
vec![
2115
(Bitwidth::I8, VerificationResult::InapplicableRule),
2116
(Bitwidth::I16, VerificationResult::InapplicableRule),
2117
(Bitwidth::I64, VerificationResult::InapplicableRule),
2118
],
2119
);
2120
let config = Config {
2121
term: "do_shift".to_string(),
2122
distinct_check: true,
2123
custom_assumptions: None,
2124
custom_verification_condition: Some(Box::new(|smt, _args, lhs, rhs| {
2125
let mask = smt.atom("#x00000000FFFFFFFF");
2126
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2127
})),
2128
names: Some(vec!["do_shift_32_base_case".to_string()]),
2129
};
2130
test_aarch64_with_config_simple(config, vec![(Bitwidth::I32, VerificationResult::Success)]);
2131
}
2132
2133
#[test]
2134
fn test_broken_do_shift_32() {
2135
test_from_file_with_lhs_termname_simple(
2136
"./examples/broken/shifts/broken_do_shift_32.isle",
2137
"do_shift".to_string(),
2138
vec![
2139
(Bitwidth::I8, VerificationResult::InapplicableRule),
2140
(Bitwidth::I16, VerificationResult::InapplicableRule),
2141
(Bitwidth::I64, VerificationResult::InapplicableRule),
2142
],
2143
);
2144
let config = Config {
2145
term: "do_shift".to_string(),
2146
distinct_check: true,
2147
custom_assumptions: None,
2148
custom_verification_condition: Some(Box::new(|smt, _args, lhs, rhs| {
2149
let mask = smt.atom("#x00000000FFFFFFFF");
2150
smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2151
})),
2152
names: None,
2153
};
2154
test_from_file_with_config_simple(
2155
"./examples/broken/shifts/broken_do_shift_32.isle",
2156
config,
2157
vec![(
2158
Bitwidth::I32,
2159
VerificationResult::Failure(Counterexample {}),
2160
)],
2161
);
2162
}
2163
2164
#[test]
2165
fn test_broken_ishl_to_do_shift_64() {
2166
test_from_file_with_lhs_termname_simple(
2167
"./examples/broken/shifts/broken_ishl_to_do_shift_64.isle",
2168
"ishl".to_string(),
2169
vec![
2170
(Bitwidth::I8, VerificationResult::InapplicableRule),
2171
(Bitwidth::I16, VerificationResult::InapplicableRule),
2172
(Bitwidth::I32, VerificationResult::InapplicableRule),
2173
(
2174
Bitwidth::I64,
2175
VerificationResult::Failure(Counterexample {}),
2176
),
2177
],
2178
)
2179
}
2180
2181
#[test]
2182
fn test_broken_sshr_to_do_shift_fits_in_32() {
2183
test_from_file_with_lhs_termname_simple(
2184
"./examples/broken/shifts/broken_sshr_to_do_shift_fits_in_32.isle",
2185
"sshr".to_string(),
2186
vec![
2187
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
2188
(
2189
Bitwidth::I16,
2190
VerificationResult::Failure(Counterexample {}),
2191
),
2192
(
2193
Bitwidth::I32,
2194
VerificationResult::Failure(Counterexample {}),
2195
),
2196
(Bitwidth::I64, VerificationResult::InapplicableRule),
2197
],
2198
)
2199
}
2200
2201
#[test]
2202
fn test_broken_sshr_to_do_shift_fits_in_32_concrete() {
2203
test_concrete_input_from_file_with_lhs_termname(
2204
"./examples/broken/shifts/broken_sshr_to_do_shift_fits_in_32.isle",
2205
"sshr".to_string(),
2206
ConcreteTest {
2207
termname: "sshr".to_string(),
2208
args: vec![
2209
ConcreteInput {
2210
literal: "#b10100000".to_string(),
2211
ty: veri_ir::Type::BitVector(Some(8)),
2212
},
2213
ConcreteInput {
2214
literal: "#b00000001".to_string(),
2215
ty: veri_ir::Type::BitVector(Some(8)),
2216
},
2217
],
2218
// Wrong output:
2219
output: ConcreteInput {
2220
literal: "#b01010000".to_string(),
2221
ty: veri_ir::Type::BitVector(Some(8)),
2222
},
2223
},
2224
)
2225
}
2226
2227
#[test]
2228
fn test_broken_ushr_to_do_shift_fits_in_32() {
2229
test_from_file_with_lhs_termname_simple(
2230
"./examples/broken/shifts/broken_ushr_to_do_shift_fits_in_32.isle",
2231
"ushr".to_string(),
2232
vec![
2233
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
2234
(
2235
Bitwidth::I16,
2236
VerificationResult::Failure(Counterexample {}),
2237
),
2238
(
2239
Bitwidth::I32,
2240
VerificationResult::Failure(Counterexample {}),
2241
),
2242
(Bitwidth::I64, VerificationResult::InapplicableRule),
2243
],
2244
)
2245
}
2246
2247
#[test]
2248
fn test_if_let() {
2249
test_from_file_with_lhs_termname_simple(
2250
"./examples/constructs/if-let.isle",
2251
"iadd".to_string(),
2252
all_success_result(),
2253
);
2254
}
2255
2256
#[test]
2257
fn test_named_icmp_8_16_32_64() {
2258
test_aarch64_rule_with_lhs_termname_simple(
2259
"icmp_8_16_32_64",
2260
"icmp",
2261
vec![
2262
(Bitwidth::I8, VerificationResult::Success),
2263
(Bitwidth::I16, VerificationResult::Success),
2264
(Bitwidth::I32, VerificationResult::Success),
2265
(Bitwidth::I64, VerificationResult::Success),
2266
],
2267
)
2268
}
2269
2270
#[test]
2271
fn test_named_lower_icmp_into_reg_8_16_32_64() {
2272
test_aarch64_rule_with_lhs_termname_simple(
2273
"lower_icmp_into_reg_8_16_32_64",
2274
"lower_icmp_into_reg",
2275
vec![
2276
(Bitwidth::I8, VerificationResult::Success),
2277
(Bitwidth::I16, VerificationResult::Success),
2278
(Bitwidth::I32, VerificationResult::Success),
2279
(Bitwidth::I64, VerificationResult::Success),
2280
],
2281
)
2282
}
2283
2284
#[test]
2285
fn test_named_lower_icmp_into_reg_8_16_32_64_concrete_1() {
2286
test_concrete_aarch64_rule_with_lhs_termname(
2287
"lower_icmp_into_reg_8_16_32_64",
2288
"lower_icmp_into_reg",
2289
ConcreteTest {
2290
termname: "lower_icmp_into_reg".to_string(),
2291
args: vec![
2292
ConcreteInput {
2293
literal: "#b00000000".to_string(),
2294
ty: veri_ir::Type::BitVector(Some(8)),
2295
},
2296
ConcreteInput {
2297
literal: "#b00000000".to_string(),
2298
ty: veri_ir::Type::BitVector(Some(8)),
2299
},
2300
ConcreteInput {
2301
literal: "#b00000001".to_string(),
2302
ty: veri_ir::Type::BitVector(Some(8)),
2303
},
2304
ConcreteInput {
2305
literal: "8".to_string(),
2306
ty: veri_ir::Type::Int,
2307
},
2308
ConcreteInput {
2309
literal: "8".to_string(),
2310
ty: veri_ir::Type::Int,
2311
},
2312
],
2313
output: ConcreteInput {
2314
literal: "#b00000000".to_string(),
2315
ty: veri_ir::Type::BitVector(Some(8)),
2316
},
2317
},
2318
)
2319
}
2320
2321
#[test]
2322
fn test_named_lower_icmp_into_reg_8_16_32_64_concrete_2() {
2323
test_concrete_aarch64_rule_with_lhs_termname(
2324
"lower_icmp_into_reg_8_16_32_64",
2325
"lower_icmp_into_reg",
2326
ConcreteTest {
2327
termname: "lower_icmp_into_reg".to_string(),
2328
args: vec![
2329
ConcreteInput {
2330
literal: "#b00000000".to_string(),
2331
ty: veri_ir::Type::BitVector(Some(8)),
2332
},
2333
ConcreteInput {
2334
literal: "#b00000000".to_string(),
2335
ty: veri_ir::Type::BitVector(Some(8)),
2336
},
2337
ConcreteInput {
2338
literal: "#b00000000".to_string(),
2339
ty: veri_ir::Type::BitVector(Some(8)),
2340
},
2341
ConcreteInput {
2342
literal: "8".to_string(),
2343
ty: veri_ir::Type::Int,
2344
},
2345
ConcreteInput {
2346
literal: "8".to_string(),
2347
ty: veri_ir::Type::Int,
2348
},
2349
],
2350
output: ConcreteInput {
2351
literal: "#b00000001".to_string(),
2352
ty: veri_ir::Type::BitVector(Some(8)),
2353
},
2354
},
2355
)
2356
}
2357
2358
// Narrow types fail because of rule priorities
2359
// https://github.com/avanhatt/wasmtime/issues/32
2360
#[test]
2361
fn test_named_lower_icmp_32_64() {
2362
test_aarch64_rule_with_lhs_termname_simple(
2363
"lower_icmp_32_64",
2364
"lower_icmp",
2365
vec![
2366
// (Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
2367
// (
2368
// Bitwidth::I16,
2369
// VerificationResult::Failure(Counterexample {}),
2370
// ),
2371
(Bitwidth::I32, VerificationResult::Success),
2372
(Bitwidth::I64, VerificationResult::Success),
2373
],
2374
)
2375
}
2376
2377
#[test]
2378
fn test_named_lower_icmp_8_16_signed() {
2379
test_aarch64_rule_with_lhs_termname_simple(
2380
"lower_icmp_8_16_signed",
2381
"lower_icmp",
2382
vec![
2383
(Bitwidth::I8, VerificationResult::Success),
2384
(Bitwidth::I16, VerificationResult::Success),
2385
(Bitwidth::I32, VerificationResult::InapplicableRule),
2386
(Bitwidth::I64, VerificationResult::InapplicableRule),
2387
],
2388
)
2389
}
2390
2391
// TODO AVH: Currently fails because needs priorities to show this
2392
// only applies to unsigned cond codes
2393
// https://github.com/avanhatt/wasmtime/issues/32
2394
#[test]
2395
fn test_named_lower_icmp_8_16_unsigned_imm() {
2396
test_aarch64_rule_with_lhs_termname_simple(
2397
"lower_icmp_8_16_unsigned_imm",
2398
"lower_icmp",
2399
vec![
2400
// (Bitwidth::I8, VerificationResult::Success),
2401
// (Bitwidth::I16, VerificationResult::Success),
2402
(Bitwidth::I32, VerificationResult::InapplicableRule),
2403
(Bitwidth::I64, VerificationResult::InapplicableRule),
2404
],
2405
)
2406
}
2407
2408
// TODO AVH: Currently fails because needs priorities to show this
2409
// only applies to unsigned cond codes
2410
// https://github.com/avanhatt/wasmtime/issues/32
2411
#[test]
2412
fn test_named_lower_icmp_8_16_unsigned() {
2413
test_aarch64_rule_with_lhs_termname_simple(
2414
"lower_icmp_8_16_unsigned",
2415
"lower_icmp",
2416
vec![
2417
// (Bitwidth::I8, VerificationResult::Success),
2418
// (Bitwidth::I16, VerificationResult::Success),
2419
(Bitwidth::I32, VerificationResult::InapplicableRule),
2420
(Bitwidth::I64, VerificationResult::InapplicableRule),
2421
],
2422
)
2423
}
2424
2425
// AVH TODO: this rule requires priorities to be correct for narrow cases
2426
// https://github.com/avanhatt/wasmtime/issues/32
2427
#[test]
2428
fn test_named_lower_icmp_32_64_const() {
2429
test_aarch64_rule_with_lhs_termname_simple(
2430
"lower_icmp_32_64_const",
2431
"lower_icmp",
2432
vec![
2433
// (Bitwidth::I8, VerificationResult::InapplicableRule),
2434
// (Bitwidth::I16, VerificationResult::InapplicableRule),
2435
(Bitwidth::I32, VerificationResult::Success),
2436
(Bitwidth::I64, VerificationResult::Success),
2437
],
2438
)
2439
}
2440
2441
#[test]
2442
fn test_named_lower_icmp_const_32_64_imm() {
2443
test_aarch64_rule_with_lhs_termname_simple(
2444
"lower_icmp_const_32_64_imm",
2445
"lower_icmp_const",
2446
vec![
2447
(Bitwidth::I8, VerificationResult::InapplicableRule),
2448
(Bitwidth::I16, VerificationResult::InapplicableRule),
2449
(Bitwidth::I32, VerificationResult::Success),
2450
(Bitwidth::I64, VerificationResult::Success),
2451
],
2452
)
2453
}
2454
2455
// AVH TODO: this rule requires priorities and a custom verification condition
2456
// https://github.com/avanhatt/wasmtime/issues/32
2457
#[test]
2458
fn test_named_lower_icmp_const_32_64_sgte() {
2459
// Note: only one distinct condition code is matched on, so need to disable
2460
// distinctness check
2461
2462
let config = Config {
2463
term: "lower_icmp_const".to_string(),
2464
distinct_check: false,
2465
custom_verification_condition: None,
2466
custom_assumptions: None,
2467
names: Some(vec!["lower_icmp_const_32_64_sgte".to_string()]),
2468
};
2469
test_aarch64_with_config_simple(
2470
config,
2471
vec![
2472
(Bitwidth::I8, VerificationResult::InapplicableRule),
2473
(Bitwidth::I16, VerificationResult::InapplicableRule),
2474
// Currently fails! The rewrite is not semantics-preserving
2475
(
2476
Bitwidth::I32,
2477
VerificationResult::Failure(Counterexample {}),
2478
),
2479
(
2480
Bitwidth::I64,
2481
VerificationResult::Failure(Counterexample {}),
2482
),
2483
],
2484
)
2485
}
2486
2487
// AVH TODO: this rule requires priorities and a custom verification condition
2488
// https://github.com/avanhatt/wasmtime/issues/32
2489
#[test]
2490
fn test_named_lower_icmp_const_32_64_ugte() {
2491
// Note: only one distinct condition code is matched on, so need to disable
2492
// distinctness check
2493
2494
let config = Config {
2495
term: "lower_icmp_const".to_string(),
2496
distinct_check: false,
2497
custom_verification_condition: None,
2498
custom_assumptions: None,
2499
names: Some(vec!["lower_icmp_const_32_64_ugte".to_string()]),
2500
};
2501
test_aarch64_with_config_simple(
2502
config,
2503
vec![
2504
(Bitwidth::I8, VerificationResult::InapplicableRule),
2505
(Bitwidth::I16, VerificationResult::InapplicableRule),
2506
// Currently fails! The rewrite is not semantics-preserving
2507
(
2508
Bitwidth::I32,
2509
VerificationResult::Failure(Counterexample {}),
2510
),
2511
(
2512
Bitwidth::I64,
2513
VerificationResult::Failure(Counterexample {}),
2514
),
2515
],
2516
)
2517
}
2518
2519
#[test]
2520
fn test_named_lower_icmp_const_32_64() {
2521
test_aarch64_rule_with_lhs_termname_simple(
2522
"lower_icmp_const_32_64",
2523
"lower_icmp_const",
2524
vec![
2525
(Bitwidth::I8, VerificationResult::InapplicableRule),
2526
(Bitwidth::I16, VerificationResult::InapplicableRule),
2527
(Bitwidth::I32, VerificationResult::Success),
2528
(Bitwidth::I64, VerificationResult::Success),
2529
],
2530
)
2531
}
2532
2533
#[test]
2534
fn test_named_umax() {
2535
test_aarch64_rule_with_lhs_termname_simple(
2536
"umax",
2537
"umax",
2538
vec![
2539
(Bitwidth::I8, VerificationResult::Success),
2540
(Bitwidth::I16, VerificationResult::Success),
2541
(Bitwidth::I32, VerificationResult::Success),
2542
(Bitwidth::I64, VerificationResult::Success),
2543
],
2544
)
2545
}
2546
2547
#[test]
2548
fn test_named_smax() {
2549
test_aarch64_rule_with_lhs_termname_simple(
2550
"smax",
2551
"smax",
2552
vec![
2553
(Bitwidth::I8, VerificationResult::Success),
2554
(Bitwidth::I16, VerificationResult::Success),
2555
(Bitwidth::I32, VerificationResult::Success),
2556
(Bitwidth::I64, VerificationResult::Success),
2557
],
2558
)
2559
}
2560
2561
#[test]
2562
fn test_named_umin() {
2563
test_aarch64_rule_with_lhs_termname_simple(
2564
"umin",
2565
"umin",
2566
vec![
2567
(Bitwidth::I8, VerificationResult::Success),
2568
(Bitwidth::I16, VerificationResult::Success),
2569
(Bitwidth::I32, VerificationResult::Success),
2570
(Bitwidth::I64, VerificationResult::Success),
2571
],
2572
)
2573
}
2574
2575
#[test]
2576
fn test_named_smin() {
2577
test_aarch64_rule_with_lhs_termname_simple(
2578
"smin",
2579
"smin",
2580
vec![
2581
(Bitwidth::I8, VerificationResult::Success),
2582
(Bitwidth::I16, VerificationResult::Success),
2583
(Bitwidth::I32, VerificationResult::Success),
2584
(Bitwidth::I64, VerificationResult::Success),
2585
],
2586
)
2587
}
2588
2589
#[test]
2590
fn test_named_iabs_64() {
2591
test_aarch64_rule_with_lhs_termname_simple(
2592
"iabs_64",
2593
"iabs",
2594
vec![
2595
(Bitwidth::I8, VerificationResult::InapplicableRule),
2596
(Bitwidth::I16, VerificationResult::InapplicableRule),
2597
(Bitwidth::I32, VerificationResult::InapplicableRule),
2598
(Bitwidth::I64, VerificationResult::Success),
2599
],
2600
)
2601
}
2602
2603
#[test]
2604
fn test_named_iabs_8_16_32() {
2605
test_aarch64_rule_with_lhs_termname_simple(
2606
"iabs_8_16_32",
2607
"iabs",
2608
vec![
2609
(Bitwidth::I8, VerificationResult::Success),
2610
(Bitwidth::I16, VerificationResult::Success),
2611
(Bitwidth::I32, VerificationResult::Success),
2612
(Bitwidth::I64, VerificationResult::InapplicableRule),
2613
],
2614
)
2615
}
2616
2617
#[test]
2618
fn test_named_bitselect() {
2619
test_aarch64_rule_with_lhs_termname_simple("bitselect", "bitselect", all_success_result())
2620
}
2621
2622
#[test]
2623
fn test_named_iconst() {
2624
test_aarch64_rule_with_lhs_termname_simple("iconst", "iconst", all_success_result())
2625
}
2626
2627
// Can't currently verify because ConsumesFlags requires a non-functional
2628
// interpretation
2629
// #[test]
2630
// fn test_named_cmp_and_choose_8_16() {
2631
//
2632
// let config = Config {
2633
// dyn_width: false,
2634
// term: "cmp_and_choose".to_string(),
2635
// distinct_check: true,
2636
// custom_verification_condition: Some(Box::new(|smt, args, lhs, rhs| {
2637
// let ty_arg = *args.first().unwrap();
2638
// let lower_8_bits_eq = {
2639
// let mask = smt.atom("#x00000000000000FF");
2640
// smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2641
// };
2642
// let lower_16_bits_eq = {
2643
// let mask = smt.atom("#x000000000000FFFF");
2644
// smt.eq(smt.bvand(mask, lhs), smt.bvand(mask, rhs))
2645
// };
2646
// smt.ite(
2647
// smt.eq(ty_arg, smt.atom("8")),
2648
// lower_8_bits_eq,
2649
// lower_16_bits_eq,
2650
// )
2651
// })),
2652
// names: Some(vec!["cmp_and_choose_8_16".to_string()]),
2653
// };
2654
// test_aarch64_with_config_simple(
2655
// config,
2656
// vec![
2657
// (Bitwidth::I8, VerificationResult::Failure(Counterexample { })),
2658
// (Bitwidth::I16, VerificationResult::Failure(Counterexample { })),
2659
// (Bitwidth::I32, VerificationResult::InapplicableRule),
2660
// (Bitwidth::I64, VerificationResult::InapplicableRule),
2661
// ],
2662
// );
2663
// })
2664
// }
2665
2666
#[test]
2667
fn test_named_popcnt_8() {
2668
test_aarch64_rule_with_lhs_termname_simple(
2669
"popcnt_8",
2670
"popcnt",
2671
vec![
2672
(Bitwidth::I8, VerificationResult::Success),
2673
(Bitwidth::I16, VerificationResult::InapplicableRule),
2674
(Bitwidth::I32, VerificationResult::InapplicableRule),
2675
(Bitwidth::I64, VerificationResult::InapplicableRule),
2676
],
2677
)
2678
}
2679
2680
#[test]
2681
fn test_named_popcnt_16() {
2682
test_aarch64_rule_with_lhs_termname_simple(
2683
"popcnt_16",
2684
"popcnt",
2685
vec![
2686
(Bitwidth::I8, VerificationResult::InapplicableRule),
2687
(Bitwidth::I16, VerificationResult::Success),
2688
(Bitwidth::I32, VerificationResult::InapplicableRule),
2689
(Bitwidth::I64, VerificationResult::InapplicableRule),
2690
],
2691
)
2692
}
2693
2694
#[test]
2695
fn test_named_popcnt_32() {
2696
test_aarch64_rule_with_lhs_termname_simple(
2697
"popcnt_32",
2698
"popcnt",
2699
vec![
2700
(Bitwidth::I8, VerificationResult::InapplicableRule),
2701
(Bitwidth::I16, VerificationResult::InapplicableRule),
2702
(Bitwidth::I32, VerificationResult::Success),
2703
(Bitwidth::I64, VerificationResult::InapplicableRule),
2704
],
2705
)
2706
}
2707
2708
// Currently too slow
2709
// https://github.com/avanhatt/wasmtime/issues/36
2710
#[test]
2711
fn test_named_popcnt_64() {
2712
test_aarch64_rule_with_lhs_termname_simple(
2713
"popcnt_64",
2714
"popcnt",
2715
vec![
2716
(Bitwidth::I8, VerificationResult::InapplicableRule),
2717
(Bitwidth::I16, VerificationResult::InapplicableRule),
2718
(Bitwidth::I32, VerificationResult::InapplicableRule),
2719
// (Bitwidth::I64, VerificationResult::Success),
2720
],
2721
)
2722
}
2723
2724
// Currently too slow
2725
// https://github.com/avanhatt/wasmtime/issues/36
2726
#[test]
2727
#[ignore]
2728
fn test_named_slow_popcnt_64() {
2729
test_aarch64_rule_with_lhs_termname_simple(
2730
"popcnt_64",
2731
"popcnt",
2732
vec![(Bitwidth::I64, VerificationResult::Unknown)],
2733
)
2734
}
2735
2736
#[test]
2737
fn test_named_operand_size_32() {
2738
// Since there are no bitvectors in the signature, need a custom assumption
2739
// hook to pass through the value of the type argument
2740
2741
static EXPECTED: [(Bitwidth, VerificationResult); 4] = [
2742
(Bitwidth::I8, VerificationResult::Success),
2743
(Bitwidth::I16, VerificationResult::Success),
2744
(Bitwidth::I32, VerificationResult::Success),
2745
(Bitwidth::I64, VerificationResult::InapplicableRule),
2746
];
2747
for (ty, result) in &EXPECTED {
2748
let config = Config {
2749
term: "operand_size".to_string(),
2750
distinct_check: true,
2751
custom_verification_condition: None,
2752
custom_assumptions: Some(Box::new(|smt, args| {
2753
let ty_arg = *args.first().unwrap();
2754
smt.eq(ty_arg, smt.numeral(*ty as usize))
2755
})),
2756
names: Some(vec!["operand_size_32".to_string()]),
2757
};
2758
test_aarch64_with_config_simple(config, vec![(*ty, result.clone())]);
2759
}
2760
}
2761
2762
#[test]
2763
fn test_named_operand_size_64() {
2764
// Since there are no bitvectors in the signature, need a custom assumption
2765
// hook to pass through the value of the type argument
2766
2767
// Lower types precluded by priorities
2768
static EXPECTED: [(Bitwidth, VerificationResult); 1] = [
2769
// (Bitwidth::I8, VerificationResult::Success),
2770
// (Bitwidth::I16, VerificationResult::Success),
2771
// (Bitwidth::I32, VerificationResult::Success),
2772
(Bitwidth::I64, VerificationResult::Success),
2773
];
2774
for (ty, result) in &EXPECTED {
2775
let config = Config {
2776
term: "operand_size".to_string(),
2777
distinct_check: true,
2778
custom_verification_condition: None,
2779
custom_assumptions: Some(Box::new(|smt, args| {
2780
let ty_arg = *args.first().unwrap();
2781
smt.eq(ty_arg, smt.numeral(*ty as usize))
2782
})),
2783
names: Some(vec!["operand_size_64".to_string()]),
2784
};
2785
test_aarch64_with_config_simple(config, vec![(*ty, result.clone())]);
2786
}
2787
}
2788
2789
#[test]
2790
fn test_named_output_reg() {
2791
test_aarch64_rule_with_lhs_termname_simple(
2792
"output_reg",
2793
"output_reg",
2794
vec![
2795
(Bitwidth::I8, VerificationResult::Success),
2796
(Bitwidth::I16, VerificationResult::Success),
2797
(Bitwidth::I32, VerificationResult::Success),
2798
(Bitwidth::I64, VerificationResult::Success),
2799
],
2800
)
2801
}
2802
2803
#[test]
2804
fn test_broken_imm_udiv_cve_underlying() {
2805
// Since there are no bitvectors in the signature, need a custom assumption
2806
// hook to pass through the value of the type argument
2807
2808
static EXPECTED: [(Bitwidth, VerificationResult); 4] = [
2809
(Bitwidth::I8, VerificationResult::Failure(Counterexample {})),
2810
(
2811
Bitwidth::I16,
2812
VerificationResult::Failure(Counterexample {}),
2813
),
2814
(
2815
Bitwidth::I32,
2816
VerificationResult::Failure(Counterexample {}),
2817
),
2818
(Bitwidth::I64, VerificationResult::Success),
2819
];
2820
for (ty, result) in &EXPECTED {
2821
let config = Config {
2822
term: "imm".to_string(),
2823
distinct_check: true,
2824
custom_verification_condition: None,
2825
custom_assumptions: Some(Box::new(|smt, args| {
2826
let ty_arg = *args.first().unwrap();
2827
smt.eq(ty_arg, smt.numeral(*ty as usize))
2828
})),
2829
names: None,
2830
};
2831
test_from_file_with_config_simple(
2832
"./examples/broken/udiv/udiv_cve_underlying.isle",
2833
config,
2834
vec![(*ty, result.clone())],
2835
);
2836
}
2837
}
2838
2839
#[test]
2840
fn test_broken_imm_udiv_cve_underlying_32() {
2841
// Since there are no bitvectors in the signature, need a custom assumption
2842
// hook to pass through the value of the type argument
2843
2844
static EXPECTED: [(Bitwidth, VerificationResult); 1] = [(
2845
Bitwidth::I32,
2846
VerificationResult::Failure(Counterexample {}),
2847
)];
2848
for (ty, result) in &EXPECTED {
2849
let config = Config {
2850
term: "imm".to_string(),
2851
distinct_check: true,
2852
custom_verification_condition: None,
2853
custom_assumptions: Some(Box::new(|smt, args| {
2854
let ty_arg = *args.first().unwrap();
2855
smt.eq(ty_arg, smt.numeral(*ty as usize))
2856
})),
2857
names: None,
2858
};
2859
test_from_file_with_config_simple(
2860
"./examples/broken/udiv/udiv_cve_underlying.isle",
2861
config,
2862
vec![(*ty, result.clone())],
2863
);
2864
}
2865
}
2866
2867
// x64
2868
2869
#[test]
2870
fn test_named_x64_iadd_base_case_32_or_64_lea() {
2871
test_x64_rule_with_lhs_termname_simple(
2872
"iadd_base_case_32_or_64_lea",
2873
"iadd",
2874
vec![
2875
(Bitwidth::I8, VerificationResult::InapplicableRule),
2876
(Bitwidth::I16, VerificationResult::InapplicableRule),
2877
(Bitwidth::I32, VerificationResult::Success),
2878
(Bitwidth::I64, VerificationResult::Success),
2879
],
2880
)
2881
}
2882
2883
#[test]
2884
fn test_named_x64_to_amode_add_base_case() {
2885
test_x64_rule_with_lhs_termname_simple(
2886
"to_amode_add_base_case",
2887
"to_amode_add",
2888
vec![(Bitwidth::I64, VerificationResult::Success)],
2889
)
2890
}
2891
2892
#[test]
2893
fn test_named_x64_to_amode_add_const_rhs() {
2894
test_x64_rule_with_lhs_termname_simple(
2895
"to_amode_add_const_rhs",
2896
"to_amode_add",
2897
vec![
2898
// TODO: make this work for I32
2899
// (Bitwidth::I32, VerificationResult::Success),
2900
(Bitwidth::I64, VerificationResult::Success),
2901
],
2902
)
2903
}
2904
2905
#[test]
2906
fn test_named_x64_to_amode_add_const_lhs() {
2907
test_x64_rule_with_lhs_termname_simple(
2908
"to_amode_add_const_lhs",
2909
"to_amode_add",
2910
vec![(Bitwidth::I64, VerificationResult::Success)],
2911
)
2912
}
2913
2914
#[test]
2915
fn test_named_x64_to_amode_add_const_fold_iadd_lhs_rhs() {
2916
test_x64_rule_with_lhs_termname_simple(
2917
"to_amode_add_const_fold_iadd_lhs_rhs",
2918
"to_amode_add",
2919
vec![(Bitwidth::I64, VerificationResult::Success)],
2920
)
2921
}
2922
2923
#[test]
2924
fn test_named_x64_to_amode_add_const_fold_iadd_lhs_lhs() {
2925
test_x64_rule_with_lhs_termname_simple(
2926
"to_amode_add_const_fold_iadd_lhs_lhs",
2927
"to_amode_add",
2928
vec![(Bitwidth::I64, VerificationResult::Success)],
2929
)
2930
}
2931
2932
#[test]
2933
fn test_named_x64_to_amode_add_const_fold_iadd_rhs_rhs() {
2934
test_x64_rule_with_lhs_termname_simple(
2935
"to_amode_add_const_fold_iadd_rhs_rhs",
2936
"to_amode_add",
2937
vec![(Bitwidth::I64, VerificationResult::Success)],
2938
)
2939
}
2940
2941
#[test]
2942
fn test_named_x64_to_amode_add_const_fold_iadd_rhs_lhs() {
2943
test_x64_rule_with_lhs_termname_simple(
2944
"to_amode_add_const_fold_iadd_rhs_lhs",
2945
"to_amode_add",
2946
vec![(Bitwidth::I64, VerificationResult::Success)],
2947
)
2948
}
2949
2950
#[test]
2951
fn test_named_x64_amode_imm_reg_base() {
2952
test_x64_rule_with_lhs_termname_simple(
2953
"amode_imm_reg_base",
2954
"amode_imm_reg",
2955
vec![(Bitwidth::I64, VerificationResult::Success)],
2956
)
2957
}
2958
2959
#[test]
2960
fn test_named_x64_amode_imm_reg_iadd() {
2961
test_x64_rule_with_lhs_termname_simple(
2962
"amode_imm_reg_iadd",
2963
"amode_imm_reg",
2964
vec![(Bitwidth::I64, VerificationResult::Success)],
2965
)
2966
}
2967
2968
#[test]
2969
fn test_named_x64_amode_imm_reg_reg_shift_no_shift() {
2970
test_x64_rule_with_lhs_termname_simple(
2971
"amode_imm_reg_reg_shift_no_shift",
2972
"amode_imm_reg_reg_shift",
2973
vec![(Bitwidth::I64, VerificationResult::Success)],
2974
)
2975
}
2976
2977
#[test]
2978
fn test_named_x64_amode_imm_reg_reg_shift_shl_rhs() {
2979
test_x64_rule_with_lhs_termname_simple(
2980
"amode_imm_reg_reg_shift_shl_rhs",
2981
"amode_imm_reg_reg_shift",
2982
vec![(Bitwidth::I64, VerificationResult::Success)],
2983
)
2984
}
2985
2986
#[test]
2987
fn test_named_x64_amode_imm_reg_reg_shift_shl_lhs() {
2988
test_x64_rule_with_lhs_termname_simple(
2989
"amode_imm_reg_reg_shift_shl_lhs",
2990
"amode_imm_reg_reg_shift",
2991
vec![(Bitwidth::I64, VerificationResult::Success)],
2992
)
2993
}
2994
2995
#[test]
2996
fn test_named_load_i8_aarch64_uload8() {
2997
test_aarch64_rule_with_lhs_termname_simple(
2998
"load_i8_aarch64_uload8",
2999
"load",
3000
vec![
3001
(Bitwidth::I8, VerificationResult::Success),
3002
(Bitwidth::I16, VerificationResult::InapplicableRule),
3003
(Bitwidth::I32, VerificationResult::InapplicableRule),
3004
(Bitwidth::I64, VerificationResult::InapplicableRule),
3005
],
3006
)
3007
}
3008
3009
#[test]
3010
fn test_named_load_i16_aarch64_uload16() {
3011
test_aarch64_rule_with_lhs_termname_simple(
3012
"load_i16_aarch64_uload16",
3013
"load",
3014
vec![
3015
(Bitwidth::I8, VerificationResult::InapplicableRule),
3016
(Bitwidth::I16, VerificationResult::Success),
3017
(Bitwidth::I32, VerificationResult::InapplicableRule),
3018
(Bitwidth::I64, VerificationResult::InapplicableRule),
3019
],
3020
)
3021
}
3022
3023
#[test]
3024
fn test_named_load_i32_aarch64_uload32() {
3025
test_aarch64_rule_with_lhs_termname_simple(
3026
"load_i32_aarch64_uload32",
3027
"load",
3028
vec![
3029
(Bitwidth::I8, VerificationResult::InapplicableRule),
3030
(Bitwidth::I16, VerificationResult::InapplicableRule),
3031
(Bitwidth::I32, VerificationResult::Success),
3032
(Bitwidth::I64, VerificationResult::InapplicableRule),
3033
],
3034
)
3035
}
3036
3037
#[test]
3038
fn test_named_load_i64_aarch64_uload64() {
3039
test_aarch64_rule_with_lhs_termname_simple(
3040
"load_i64_aarch64_uload64",
3041
"load",
3042
vec![
3043
(Bitwidth::I8, VerificationResult::InapplicableRule),
3044
(Bitwidth::I16, VerificationResult::InapplicableRule),
3045
(Bitwidth::I32, VerificationResult::InapplicableRule),
3046
(Bitwidth::I64, VerificationResult::Success),
3047
],
3048
)
3049
}
3050
3051
#[test]
3052
fn test_named_store_i8_aarch64_store8() {
3053
test_aarch64_rule_with_lhs_termname_simple(
3054
"store_i8_aarch64_store8",
3055
"store",
3056
vec![
3057
(Bitwidth::I8, VerificationResult::Success),
3058
(Bitwidth::I16, VerificationResult::InapplicableRule),
3059
(Bitwidth::I32, VerificationResult::InapplicableRule),
3060
(Bitwidth::I64, VerificationResult::InapplicableRule),
3061
],
3062
)
3063
}
3064
3065
#[test]
3066
fn test_named_store_i16_aarch64_store16() {
3067
test_aarch64_rule_with_lhs_termname_simple(
3068
"store_i16_aarch64_store16",
3069
"store",
3070
vec![
3071
(Bitwidth::I8, VerificationResult::InapplicableRule),
3072
(Bitwidth::I16, VerificationResult::Success),
3073
(Bitwidth::I32, VerificationResult::InapplicableRule),
3074
(Bitwidth::I64, VerificationResult::InapplicableRule),
3075
],
3076
)
3077
}
3078
3079
#[test]
3080
fn test_named_store_i32_aarch64_store32() {
3081
test_aarch64_rule_with_lhs_termname_simple(
3082
"store_i32_aarch64_store32",
3083
"store",
3084
vec![
3085
(Bitwidth::I8, VerificationResult::InapplicableRule),
3086
(Bitwidth::I16, VerificationResult::InapplicableRule),
3087
(Bitwidth::I32, VerificationResult::Success),
3088
(Bitwidth::I64, VerificationResult::InapplicableRule),
3089
],
3090
)
3091
}
3092
3093
#[test]
3094
fn test_named_store_i64_aarch64_store64() {
3095
test_aarch64_rule_with_lhs_termname_simple(
3096
"store_i64_aarch64_store64",
3097
"store",
3098
vec![
3099
(Bitwidth::I8, VerificationResult::InapplicableRule),
3100
(Bitwidth::I16, VerificationResult::InapplicableRule),
3101
(Bitwidth::I32, VerificationResult::InapplicableRule),
3102
(Bitwidth::I64, VerificationResult::Success),
3103
],
3104
)
3105
}
3106
3107
#[test]
3108
fn test_named_load_sub64_x64_movzx() {
3109
test_x64_rule_with_lhs_termname_simple(
3110
"load_sub64_x64_movzx",
3111
"load",
3112
vec![
3113
(Bitwidth::I8, VerificationResult::Success),
3114
(Bitwidth::I16, VerificationResult::Success),
3115
(Bitwidth::I32, VerificationResult::Success),
3116
(Bitwidth::I64, VerificationResult::InapplicableRule),
3117
],
3118
)
3119
}
3120
3121
#[test]
3122
fn test_named_store_x64_add_mem() {
3123
test_x64_rule_with_lhs_termname_simple(
3124
"store_x64_add_mem",
3125
"store",
3126
vec![
3127
(Bitwidth::I8, VerificationResult::InapplicableRule),
3128
(Bitwidth::I16, VerificationResult::InapplicableRule),
3129
(Bitwidth::I32, VerificationResult::Success),
3130
(Bitwidth::I64, VerificationResult::Success),
3131
],
3132
)
3133
}
3134
#[test]
3135
fn test_named_store_x64_movrm() {
3136
test_x64_rule_with_lhs_termname_simple(
3137
"store_x64_movrm",
3138
"store",
3139
vec![
3140
(Bitwidth::I8, VerificationResult::Success),
3141
(Bitwidth::I16, VerificationResult::Success),
3142
(Bitwidth::I32, VerificationResult::Success),
3143
(Bitwidth::I64, VerificationResult::Success),
3144
],
3145
)
3146
}
3147
3148
#[test]
3149
fn test_load_conditional() {
3150
test_from_file_with_lhs_termname_simple(
3151
"./examples/load/load_conditional.isle",
3152
"lhs".to_string(),
3153
vec![
3154
(Bitwidth::I8, VerificationResult::Success),
3155
(Bitwidth::I16, VerificationResult::Success),
3156
(Bitwidth::I32, VerificationResult::Success),
3157
(Bitwidth::I64, VerificationResult::Success),
3158
],
3159
);
3160
}
3161
3162
#[test]
3163
fn test_store_switch() {
3164
test_from_file_with_lhs_termname_simple(
3165
"./examples/store/store_switch.isle",
3166
"lhs".to_string(),
3167
vec![
3168
(Bitwidth::I8, VerificationResult::Success),
3169
(Bitwidth::I16, VerificationResult::Success),
3170
(Bitwidth::I32, VerificationResult::Success),
3171
(Bitwidth::I64, VerificationResult::Success),
3172
],
3173
);
3174
}
3175
3176
#[test]
3177
#[should_panic]
3178
fn test_load_add_panic() {
3179
test_from_file_with_lhs_termname_simple(
3180
"./examples/load/load_add_panic.isle",
3181
"lhs".to_string(),
3182
all_failure_result(),
3183
);
3184
}
3185
3186
#[test]
3187
fn test_broken_isub_store_with_load() {
3188
test_from_file_with_lhs_termname_simple(
3189
"./examples/store/broken_isub_store_with_load.isle",
3190
"store".to_string(),
3191
vec![
3192
(Bitwidth::I8, VerificationResult::InapplicableRule),
3193
(Bitwidth::I16, VerificationResult::InapplicableRule),
3194
(
3195
Bitwidth::I32,
3196
VerificationResult::Failure(Counterexample {}),
3197
),
3198
(
3199
Bitwidth::I64,
3200
VerificationResult::Failure(Counterexample {}),
3201
),
3202
],
3203
);
3204
}
3205
3206
#[test]
3207
fn test_broken_bvsub_store_with_load() {
3208
test_from_file_with_lhs_termname_simple(
3209
"./examples/store/broken_bvsub_store_with_load.isle",
3210
"store".to_string(),
3211
vec![
3212
(Bitwidth::I8, VerificationResult::InapplicableRule),
3213
(Bitwidth::I16, VerificationResult::InapplicableRule),
3214
(
3215
Bitwidth::I32,
3216
VerificationResult::Failure(Counterexample {}),
3217
),
3218
(
3219
Bitwidth::I64,
3220
VerificationResult::Failure(Counterexample {}),
3221
),
3222
],
3223
);
3224
}
3225
3226