-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathAssertionTests.cpp
2263 lines (1893 loc) · 55.2 KB
/
AssertionTests.cpp
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: Michael Popoloski
// SPDX-License-Identifier: MIT
#include "Test.h"
TEST_CASE("Named sequences") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence seq(x, y, min, max, delay1);
x ##delay1 y[*min:max];
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Named properties") {
auto tree = SyntaxTree::fromText(R"(
module m;
logic a,b,c,d,e,f;
property p1(x,y);
##1 x |-> y;
endproperty
wire clk;
property p2;
@(posedge clk)
a ##1 (b || c)[->1] |->
if (b)
p1(d,e)
else
f;
endproperty
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Concurrent assertion expressions") {
auto tree = SyntaxTree::fromText(R"(
module m;
string a;
logic b;
int c,d,e;
foo: assert property (a);
assert property (a ##1 b ##[+] c ##[*] d ##[1:5] e);
assert property (##0 a[*0:4] ##0 b[=4] ##0 c[->1:2] ##0 c[*] ##1 d[+]);
assert property (##[1:$] a[*0:$]);
assert property ((a ##0 b) and (c or d));
assert property ((a ##0 b) and (c or d));
assert property (a intersect b and d throughout e within c);
assert property (a iff b until d s_until e until_with c s_until_with d);
assert property (((a)) |-> b |=> (d implies (e #-# (d #=# a))));
assert property ((a within b) within (((c))[*3]));
assert property (((a)) throughout c);
assert property ((@(posedge b) a and b) intersect c);
assert property ((@(posedge b) a iff b) implies c);
assert property (first_match(a and b));
assert property (always b and c);
assert property ((s_always [3:4] b and c) and (s_eventually [1:$] b) and (eventually [1:2] c));
assert property ((nexttime [3] b) and (s_nexttime b));
assert property (strong(a ##1 b) and weak(a intersect b));
assert property (not a ##1 b);
assert property (accept_on(b) sync_reject_on(c) sync_accept_on(d) reject_on(e) b ##1 c);
assume property (if (b) a ##1 c else d ##1 e);
cover property (case (b) 1, 2, 3: 1 ##1 b; 4: a and b; default: 1 |-> b; endcase);
restrict property (@(posedge b) ((b) and b) ##0 b);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Concurrent assertion expression errors") {
auto tree = SyntaxTree::fromText(R"(
class C;
int bar;
endclass
function int func(output o);
endfunction
module m;
int a[];
int b;
chandle c;
C d = new;
logic o;
localparam real p = 3.14;
assert property (a ##1 b++);
assert property (c == null);
assert property (d.bar);
assert property (func(o));
assert property (b[* -1:4]);
assert property (b ##[4:1] b);
assert property (b ##p b);
assert property (##0 b[*3-:4] ##0 b[=]);
assert property (##[] b ##[1+:5] b);
assert property ((b iff b) |-> b);
assert property ((b and b)[*3] throughout b);
assert property (b[*3] throughout b);
assert property (always [] b);
assert property (always [4] b);
assert property (s_always b);
assert property (nexttime [1:2] b);
assert property (eventually [1:$] b);
assert property (b or @o);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 21);
CHECK(diags[0].code == diag::AssertionExprType);
CHECK(diags[1].code == diag::IncDecNotAllowed);
CHECK(diags[2].code == diag::CHandleInAssertion);
CHECK(diags[3].code == diag::ClassMemberInAssertion);
CHECK(diags[4].code == diag::AssertionFuncArg);
CHECK(diags[5].code == diag::ValueMustBePositive);
CHECK(diags[6].code == diag::SeqRangeMinMax);
CHECK(diags[7].code == diag::ExprMustBeIntegral);
CHECK(diags[8].code == diag::InvalidRepeatRange);
CHECK(diags[9].code == diag::ExpectedExpression);
CHECK(diags[10].code == diag::ExpectedExpression);
CHECK(diags[11].code == diag::InvalidRepeatRange);
CHECK(diags[12].code == diag::PropertyLhsInvalid);
CHECK(diags[13].code == diag::ThroughoutLhsInvalid);
CHECK(diags[14].code == diag::ThroughoutLhsInvalid);
CHECK(diags[15].code == diag::ExpectedExpression);
CHECK(diags[16].code == diag::InvalidPropertyRange);
CHECK(diags[17].code == diag::InvalidPropertyRange);
CHECK(diags[18].code == diag::InvalidPropertyIndex);
CHECK(diags[19].code == diag::UnboundedNotAllowed);
CHECK(diags[20].code == diag::ExpectedExpression);
}
TEST_CASE("Sequence & property instances") {
auto tree = SyntaxTree::fromText(R"(
module m;
assert property (n.a(3));
assert property (b);
int c, d;
sequence b;
##1 c ##1 d;
endsequence
endmodule
module n;
int c, d;
property a(int i, foo = 1);
##1 c ##1 d ##1 i;
endproperty
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Assertion instance arg errors") {
auto tree = SyntaxTree::fromText(R"(
module m;
assert property (a(, .a(1), .b(), .d(1)));
assert property (a(1, 2));
assert property (a(1, 2, 3, 4));
sequence a(a, b, c);
1;
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 7);
CHECK(diags[0].code == diag::UnconnectedArg);
CHECK(diags[1].code == diag::ArgCannotBeEmpty);
CHECK(diags[2].code == diag::DuplicateArgAssignment);
CHECK(diags[3].code == diag::ArgCannotBeEmpty);
CHECK(diags[4].code == diag::ArgDoesNotExist);
CHECK(diags[5].code == diag::TooFewArguments);
CHECK(diags[6].code == diag::TooManyArguments);
}
TEST_CASE("Assertion instance arg type checking") {
auto tree = SyntaxTree::fromText(R"(
module m;
int foo[];
assert property (a(1, 1 iff 2, foo, 1 and 2));
assert property (a(1 iff 2, 1, 1));
assert property (a(1, 1, foo[*]));
int e;
property a(sequence a, property b, int c[], untyped d = e);
1;
endproperty
sequence b(int i, untyped j);
1 ##[i:j] 1;
endsequence
assert property (b($, $));
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 4);
CHECK(diags[0].code == diag::AssertionArgTypeSequence);
CHECK(diags[1].code == diag::AssertionArgTypeMismatch);
CHECK(diags[2].code == diag::AssertionArgNeedsRegExpr);
CHECK(diags[3].code == diag::UnboundedNotAllowed);
}
TEST_CASE("Assertion instance arg expansion") {
auto tree = SyntaxTree::fromText(R"(
module m;
logic [7:0] bar;
assert property (s1($, 5));
assert property (s1(bar, 9.2));
assert property (s3(9));
assert property (s4(1 and 2));
sequence s1(a, int b);
s2(a) ##1 bar[b:0];
endsequence
sequence s2(foo);
1 ##[0:foo] 2 ##1 foo;
endsequence
sequence s3(sequence a);
1 ##[0:a] 2;
endsequence
sequence s4(foo);
foo ##1 1 + foo;
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 5);
CHECK(diags[0].code == diag::UnboundedNotAllowed);
CHECK(diags[1].code == diag::RangeOOB);
CHECK(diags[2].code == diag::ConstEvalNonConstVariable);
CHECK(diags[3].code == diag::AssertionDelayFormalType);
CHECK(diags[4].code == diag::BadBinaryExpression);
}
TEST_CASE("More complex sequence arg expansion") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s1;
int foo;
s2(s2(foo));
endsequence
sequence s2(a);
a;
endsequence
assert property (s1);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Default disable declarations") {
auto tree = SyntaxTree::fromText(R"(
module m;
int i;
default disable iff i > 1;
endmodule
module n;
int a, b;
default disable iff a > 0;
default disable iff b > 0;
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::MultipleDefaultDisable);
}
TEST_CASE("Hierarchical access to assertion ports") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s(int i);
i;
endsequence
int i = s.i;
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::TooFewArguments);
}
TEST_CASE("Local vars in assertions") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s(int i);
int j, k = j;
(i > 0 && j > 0, j = 1, j++)[*0:1];
endsequence
int baz;
sequence s2;
int j, k = j;
first_match(j, !j, j + k, baz = 1, baz++);
endsequence
typedef int Foo;
property p;
Foo u, v;
s(u) and v and s2;
endproperty
assert property (p);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 4);
CHECK(diags[0].code == diag::InvalidMatchItem);
CHECK(diags[1].code == diag::InvalidMatchItem);
CHECK(diags[2].code == diag::LocalVarMatchItem);
CHECK(diags[3].code == diag::LocalVarMatchItem);
}
TEST_CASE("Local vars default values") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s(i);
int j, k = j, l = i, m = baz;
(i > 0 && j > 0, j = 1, j++)[*1:2];
endsequence
assert property (s(3));
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::UndeclaredIdentifier);
}
TEST_CASE("Sequence triggered method") {
auto tree = SyntaxTree::fromText(R"(
module m;
wire clk, ready;
sequence e1;
@(posedge clk) $rose(ready) ##1 1 ##1 2;
endsequence
sequence rule;
@(posedge clk) e1.triggered ##1 1;
endsequence
sequence e2(a,b,c);
@(posedge clk) $rose(a) ##1 b ##1 c;
endsequence
wire proc1, proc2;
sequence rule2;
@(posedge clk) e2(ready,proc1,proc2).triggered ##1 1;
endsequence
sequence e3(sequence a, untyped b);
@(posedge clk) a.triggered ##1 b;
endsequence
sequence rule3;
@(posedge clk) e3(ready ##1 proc1, proc2) ##1 1;
endsequence
assert property (rule);
assert property (rule2);
assert property (rule3);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Sequence matched method") {
auto tree = SyntaxTree::fromText(R"(
module m;
wire clk;
sequence e1(a,b,c);
@(posedge clk) $rose(a) ##1 b ##1 c ;
endsequence
wire reset, inst, ready, proc1, proc2, branch_back;
sequence e2;
@(posedge clk) reset ##1 inst ##1 e1(ready,proc1,proc2).matched [->1]
##1 branch_back;
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Sequence triggered local vars") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s1(sequence a);
##1 a.triggered;
endsequence
sequence s2(a);
s1(a);
endsequence
sequence s3(local int foo); 1; endsequence
sequence s4;
s2(s3(1));
endsequence
sequence s5(a, event b, sequence c);
a ##1 c ##1 @b 1;
endsequence
event e;
sequence s6;
int i;
s5(i + 1, e, i + 1).triggered ##1 s5(i, e, i).triggered;
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 3);
CHECK(diags[0].code == diag::SeqMethodInputLocalVar);
CHECK(diags[1].code == diag::SequenceMethodLocalVar);
CHECK(diags[2].code == diag::SequenceMethodLocalVar);
}
TEST_CASE("Sequence event control") {
auto tree = SyntaxTree::fromText(R"(
wire a, b, c, clk;
sequence abc;
@(posedge clk) a ##1 b ##1 c;
endsequence
module m;
initial begin
@ abc $display("Saw a-b-c");
end
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Level-sensitive sequence control") {
auto tree = SyntaxTree::fromText(R"(
wire a, b, c, clk;
sequence abc;
@(posedge clk) a ##1 b ##1 c;
endsequence
wire d, e;
sequence de;
@(negedge clk) d ##[2:5] e;
endsequence
program check;
initial begin
wait (abc.triggered || de.triggered);
if (abc.triggered)
$display("abc succeeded");
if (de.triggered)
$display("de succeeded");
end
endprogram
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Recursive sequence expansion") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s1;
s2;
endsequence
sequence s2;
s1;
endsequence
assert property (s1);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 2);
CHECK(diags[0].code == diag::RecursiveSequence);
CHECK(diags[1].code == diag::RecursiveSequence);
}
TEST_CASE("Recursive property") {
auto tree = SyntaxTree::fromText(R"(
logic write_request, write_request_ack;
logic [0:127] data, model_data;
logic [3:0] write_request_ack_tag, data_valid_tag, retry_tag;
logic data_valid;
logic retry;
logic last_data_valid;
logic reset;
property check_write;
logic [0:127] expected_data;
logic [3:0] tag;
disable iff (reset) (
write_request && write_request_ack,
expected_data = model_data,
tag = write_request_ack_tag
)
|=> check_write_data_beat(expected_data, tag, 4'h0);
endproperty
property check_write_data_beat(
local input logic [0:127] expected_data,
local input logic [3:0] tag, i
);
(
(data_valid && (data_valid_tag == tag)) ||
(retry && (retry_tag == tag))
)[->1]
|-> ((
(data_valid && (data_valid_tag == tag))
|-> (data == expected_data[i*8+:8])
)
and (
if (retry && (retry_tag == tag)) (
1'b1 |=> check_write_data_beat(expected_data, tag, 4'h0)
) else if (!last_data_valid) (
1'b1 |=> check_write_data_beat(expected_data, tag, i+4'h1)
) else (
##1 (retry && (retry_tag == tag))
|=> check_write_data_beat(expected_data, tag, 4'h0)
)
)
);
endproperty
module m;
assert property (check_write);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Event argument to sequence instance") {
auto tree = SyntaxTree::fromText(R"(
logic x,y;
sequence event_arg_example (event ev);
@(ev) x ##1 y;
endsequence
sequence s2 (ev);
@(ev) x ##1 y;
endsequence
module m;
logic clk;
cover property (event_arg_example(clk));
cover property (event_arg_example(posedge clk));
cover property (event_arg_example((posedge clk iff x or edge clk, x iff y, negedge clk)));
cover property (event_arg_example((x iff y, negedge clk)));
cover property (event_arg_example(((x iff y) or negedge clk)));
cover property (s2(clk));
cover property (s2(posedge clk));
cover property (s2((posedge clk iff x or edge clk, x iff y, negedge clk)));
cover property (s2((x iff y, negedge clk)));
cover property (s2(((x iff y) or negedge clk)));
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Sequence event expr errors") {
auto tree = SyntaxTree::fromText(R"(
logic x,y;
sequence s1 (event ev);
@(ev) x ##1 y;
endsequence
module m;
logic clk;
sequence s2;
##1 (1, posedge clk) ##1 posedge clk;
endsequence
sequence s3(event ev);
##1 ev;
endsequence
property s4;
(x iff y, 1);
endproperty
assert property (s1((x and y) iff clk));
assert property (s1((x and y)[*0:1]));
assert property (s1(x[*0:1]));
assert property (s1(x |-> y));
assert property (s1(x throughout y));
assert property (s3(x));
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 9);
CHECK(diags[0].code == diag::InvalidMatchItem);
CHECK(diags[1].code == diag::InvalidSignalEventInSeq);
CHECK(diags[2].code == diag::EventExprAssertionArg);
CHECK(diags[3].code == diag::InvalidCommaInPropExpr);
CHECK(diags[4].code == diag::InvalidSyntaxInEventExpr);
CHECK(diags[5].code == diag::InvalidSyntaxInEventExpr);
CHECK(diags[6].code == diag::InvalidSyntaxInEventExpr);
CHECK(diags[7].code == diag::InvalidSyntaxInEventExpr);
CHECK(diags[8].code == diag::InvalidSyntaxInEventExpr);
}
TEST_CASE("Restrict / expect / cover statements") {
auto tree = SyntaxTree::fromText(R"(
module m;
logic clk, i;
initial begin
cover property (@(posedge clk) i);
cover sequence (@(posedge clk) i);
restrict property (@(posedge clk) i);
expect (@(posedge clk) i);
restrict property (@(posedge clk) i) i++;
end
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::RestrictStmtNoFail);
}
TEST_CASE("Property in event expression error") {
auto tree = SyntaxTree::fromText(R"(
module m;
property p; 1; endproperty
initial begin
@(p);
end
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::InvalidEventExpression);
}
TEST_CASE("Invalid assertion port array types") {
auto tree = SyntaxTree::fromText(R"(
property p(a, b[3], untyped c[2], sequence d, e[4]); 1; endproperty
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 3);
CHECK(diags[0].code == diag::InvalidArrayElemType);
CHECK(diags[1].code == diag::InvalidArrayElemType);
CHECK(diags[2].code == diag::InvalidArrayElemType);
}
TEST_CASE("Sequence with property port") {
auto tree = SyntaxTree::fromText(R"(
sequence s(property p);
1;
endsequence
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::PropertyPortInSeq);
}
TEST_CASE("Prop expressions inside sequences") {
auto tree = SyntaxTree::fromText(R"(
property p; 1; endproperty
sequence s(a, sequence b, untyped c);
p() or a or c;
endsequence
module m;
wire clk, a;
assert property (s(@(posedge clk) a |-> clk, p, p within clk));
assert property (p and p);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 4);
CHECK(diags[0].code == diag::PropExprInSequence);
CHECK(diags[1].code == diag::PropExprInSequence);
CHECK(diags[2].code == diag::PropExprInSequence);
CHECK(diags[3].code == diag::PropExprInSequence);
}
TEST_CASE("Invalid assertion instance repetitions") {
auto tree = SyntaxTree::fromText(R"(
property p; 1; endproperty
sequence s; 1; endsequence
module m;
assert property (p [*3]);
assert property (s [=3]);
assert property ((1 ##1 1) [-> 3]);
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 3);
CHECK(diags[0].code == diag::PropInstanceRepetition);
CHECK(diags[1].code == diag::SeqInstanceRepetition);
CHECK(diags[2].code == diag::SeqInstanceRepetition);
}
TEST_CASE("Formal arg types for sequence delay / abbrev") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s(shortint x, logic [31:0] y, byte z);
1 ##x 1 ##y 1 ##z 1;
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 2);
CHECK(diags[0].code == diag::AssertionDelayFormalType);
CHECK(diags[1].code == diag::AssertionDelayFormalType);
}
TEST_CASE("Local var formal arg") {
auto tree = SyntaxTree::fromText(R"(
module m;
int a,b,c;
int data_in, data_out;
sequence sub_seq2(local inout int lv);
(a ##1 !a, lv += data_in)
##1 !b[*0:$] ##1 b > 0 && (data_out == lv);
endsequence
sequence seq2;
int v1;
(c, v1 = data_in)
##1 sub_seq2(v1)
##1 (data_out == v1);
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
TEST_CASE("Local var formal arg errors") {
auto tree = SyntaxTree::fromText(R"(
module m;
logic b_d, d_d;
sequence legal_loc_var_formal (
local inout logic a,
local logic b = b_d,
c,
d = d_d,
logic e, f
);
logic g = c, h = g || d;
(1, e = 1);
endsequence
sequence illegal_loc_var_formal (
output logic a,
local inout logic b,
c = 1'b0,
local d = 1 + 2,
local event e,
local logic f = g
);
logic g = b;
1[*0];
endsequence
assert property (legal_loc_var_formal(1, 1, 1, 1, 1, 1));
property p(local inout logic a, local output logic b);
1;
endproperty
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 10);
CHECK(diags[0].code == diag::AssertionPortTypedLValue);
CHECK(diags[1].code == diag::AssertionPortDirNoLocal);
CHECK(diags[2].code == diag::AssertionPortOutputDefault);
CHECK(diags[3].code == diag::LocalVarTypeRequired);
CHECK(diags[4].code == diag::AssertionExprType);
CHECK(diags[5].code == diag::UndeclaredIdentifier);
CHECK(diags[6].code == diag::LocalVarOutputEmptyMatch);
CHECK(diags[7].code == diag::AssertionOutputLocalVar);
CHECK(diags[8].code == diag::AssertionPortPropOutput);
CHECK(diags[9].code == diag::AssertionPortPropOutput);
}
TEST_CASE("Match items + empty match") {
auto tree = SyntaxTree::fromText(R"(
module m;
int a,b,c;
sequence s;
int x,e;
a ##1 (b[*0:1], x = e) ##1 c[*];
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::MatchItemsAdmitEmpty);
}
TEST_CASE("Subroutine match items") {
auto tree = SyntaxTree::fromText(R"(
function automatic int foo(logic v, ref logic w);
endfunction
function int bar(output v);
endfunction
module m;
logic a,e,b,f;
sequence s1;
logic v, w;
(a, v = e) ##1
(b[->1], w = f, $display("%h,%h\n", v, w)) ##1
(a, foo(v, w)) ##1
(a, bar(v));
endsequence
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 2);
CHECK(diags[0].code == diag::SubroutineMatchAutoRefArg);
CHECK(diags[1].code == diag::SubroutineMatchOutArg);
}
TEST_CASE("Illegal disable iff instantiations") {
auto tree = SyntaxTree::fromText(R"(
module m;
wire clk;
property p;
@(posedge clk) disable iff (clk) 1;
endproperty
property q;
disable iff (clk) p();
endproperty
property r;
1 |-> p();
endproperty
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 2);
CHECK(diags[0].code == diag::NestedDisableIff);
CHECK(diags[1].code == diag::NestedDisableIff);
}
TEST_CASE("disable iff condition restrictions") {
auto tree = SyntaxTree::fromText(R"(
module m;
sequence s;
1;
endsequence
wire clk;
property p;
bit a;
@(posedge clk) disable iff (a || s.matched) 1;
endproperty
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);