OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [test_suite/] [test_c2verilog] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jondawson
#!/usr/bin/env python
2
import os
3
import sys
4
 
5
os.system("python-coverage erase")
6
 
7
def test(test, code, no_init=False):
8
  f = open("test.c", 'w')
9
  f.write(code)
10
  f.close()
11
  if no_init:
12
      result = os.system("python-coverage run -p ../c2verilog iverilog run no_initialize_memory test.c")
13
  else:
14
      result = os.system("python-coverage run -p ../c2verilog iverilog run test.c")
15
  if(os.path.exists("main")):
16
      os.remove("main")
17
  if(os.path.exists("arbiter")):
18
      os.remove("arbiter")
19
  if(os.path.exists("real_main")):
20
      os.remove("real_main")
21
 
22
  if result == 0:
23
    print test, "...pass"
24
  else:
25
    print test, "...fail"
26
    sys.exit(0)
27
 
28
  if no_init:
29
      result = os.system("python-coverage run -p ../c2verilog iverilog run speed no_initialize_memory test.c")
30
  else:
31
      result = os.system("python-coverage run -p ../c2verilog iverilog run speed test.c")
32
  if(os.path.exists("main")):
33
      os.remove("main")
34
  if(os.path.exists("arbiter")):
35
      os.remove("arbiter")
36
  if(os.path.exists("real_main")):
37
      os.remove("real_main")
38
 
39
  if result == 0:
40
    print test, "...pass"
41
  else:
42
    print test, "...fail"
43
    sys.exit(0)
44
 
45
def test_fails(test, code, no_init=False):
46
  f = open("test.c", 'w')
47
  f.write(code)
48
  f.close()
49
  print "One error expected ..."
50
  if no_init:
51
      result = os.system("python-coverage run -p ../c2verilog iverilog run no_initialize_memory test.c")
52
  else:
53
      result = os.system("python-coverage run -p ../c2verilog iverilog run test.c")
54
  if result == 0:
55
    print test, "...fail"
56
    sys.exit(0)
57
  else:
58
    print test, "...pass"
59
 
60 4 jondawson
test("float file 1",
61
"""
62
void main(){
63
    file_write(1.0, "test_file");
64
    file_write(-1.0, "test_file");
65
    file_write(2.0, "test_file");
66
    file_write(-2.0, "test_file");
67
}
68
"""
69
)
70
 
71
test("float file 2",
72
"""
73
void main(){
74
    assert(file_read("test_file") == 1.0);
75
    assert(file_read("test_file") == -1.0);
76
    assert(file_read("test_file") == 2.0);
77
    assert(file_read("test_file") == -2.0);
78
}
79
"""
80
)
81
 
82
test_fails("array size1",
83
"""
84
int size(){
85
    return 10;
86
}
87
void main(){
88
    int blah[size()];
89
}
90
"""
91
)
92
 
93
test("array size2",
94
"""
95
void main(){
96
    const int b = 10;
97
    int a[b];
98
}
99
"""
100
)
101
 
102
test_fails("const 1",
103
"""
104
void main(){
105
    const int blah = 10;
106
    blah = 12;
107
}
108
"""
109
)
110
 
111
test("const 2",
112
"""
113
void main(){
114
    const int blah = 10;
115
    assert(blah == 10);
116
}
117
"""
118
)
119
 
120
test_fails("const 3",
121
"""
122
void main(){
123
    const float blah = 10;
124
    blah = 12;
125
}
126
"""
127
)
128
 
129
test("const 4",
130
"""
131
void main(){
132
    const float blah = 10;
133
    assert(blah == 10.0);
134
}
135
"""
136
)
137
 
138
test_fails("scope 1",
139
"""
140
void test(){
141
    int test_var = 1;
142
}
143
 
144
void main(){
145
    int blah = test_var;
146
}
147
"""
148
)
149
 
150
test("inplace float 1",
151
"""
152
void main(){
153
    float test = 1.0;
154
    test *= 2.0;
155
    assert(test == 2.0);
156
    test *= 2.0;
157
    assert(test == 4.0);
158
    test *= 2.0;
159
    assert(test == 8.0);
160
}
161
"""
162
)
163
 
164
test("inplace float 2",
165
"""
166
void main(){
167
    float test = 1.0;
168
    test += 2.0;
169
    assert(test == 3.0);
170
    test += 2.0;
171
    assert(test == 5.0);
172
    test += 2.0;
173
    assert(test == 7.0);
174
}
175
"""
176
)
177
 
178
test("inplace float 3",
179
"""
180
void main(){
181
    float test = 1.0;
182
    test -= 2.0;
183
    assert(test == -1.0);
184
    test -= 2.0;
185
    assert(test == -3.0);
186
    test -= 2.0;
187
    assert(test == -5.0);
188
}
189
"""
190
)
191
 
192
test("inplace float 4",
193
"""
194
void main(){
195
    float test = 1.0;
196
    test /= 2.0;
197
    assert(test == 0.5);
198
    test /= 2.0;
199
    assert(test == 0.25);
200
    test /= 2.0;
201
    assert(test == 0.125);
202
}
203
"""
204
)
205
 
206
test("inplace float 5",
207
"""
208
void main(){
209
    float test = 1.0;
210
    test *= 2;
211
    assert(test == 2.0);
212
    test *= 2;
213
    assert(test == 4.0);
214
    test *= 2;
215
    assert(test == 8.0);
216
}
217
"""
218
)
219
 
220
test("inplace float 6",
221
"""
222
void main(){
223
    float test = 1.0;
224
    test += 2;
225
    assert(test == 3.0);
226
    test += 2;
227
    assert(test == 5.0);
228
    test += 2;
229
    assert(test == 7.0);
230
}
231
"""
232
)
233
 
234
test("inplace float 7",
235
"""
236
void main(){
237
    float test = 1.0;
238
    test -= 2;
239
    assert(test == -1.0);
240
    test -= 2;
241
    assert(test == -3.0);
242
    test -= 2;
243
    assert(test == -5.0);
244
}
245
"""
246
)
247
 
248
test("inplace float 8",
249
"""
250
void main(){
251
    float test = 1.0;
252
    test /= 2;
253
    assert(test == 0.5);
254
    test /= 2;
255
    assert(test == 0.25);
256
    test /= 2;
257
    assert(test == 0.125);
258
}
259
"""
260
)
261
 
262
test("float 1",
263
"""
264
void main(){
265
    float test = 0.0;
266
    assert(test == 0.0);
267
}
268
"""
269
)
270
test("float 2",
271
"""
272
void main(){
273
    float test = 1.0;
274
    assert(test > 0.0);
275
}
276
"""
277
)
278
test("float 3",
279
"""
280
void main(){
281
    float test = 0.0;
282
    assert(test < 1.0);
283
}
284
"""
285
)
286
test("float 4",
287
"""
288
void main(){
289
    float test = 0.0;
290
    float a = -1.0;
291
    float b = -2.0;
292
    float c = 2.0;
293
    float d = 2.0;
294
    assert(test > -1.0);
295
    assert(a > b);
296
    assert(b < a);
297
    assert(c >= d);
298
    assert(c <= d);
299
}
300
"""
301
)
302
test("float 5",
303
"""
304
void main(){
305
    float test = 0.0;
306
    assert(test == 0.0);
307
}
308
"""
309
)
310
test("float 6",
311
"""
312
void main(){
313
    float blah[10];
314
    blah[0] = 0.0;
315
    blah[1] = 1.0;
316
    blah[2] = 2.0;
317
    blah[3] = 3.0;
318
    assert(blah[0] == 0.0);
319
    assert(blah[1] == 1.0);
320
    assert(blah[2] == 2.0);
321
    assert(blah[3] == 3.0);
322
}
323
"""
324
)
325
 
326
test("float 7",
327
"""
328
void main(){
329
    float a = 2.0;
330
    assert(a == 1.0 + 1.0);
331
}
332
"""
333
)
334
 
335
test("float 8",
336
"""
337
void main(){
338
    float a = 2.0;
339
    float b = 2.0;
340
    assert(a+b == 4.0);
341
}
342
"""
343
)
344
 
345
test("float 9",
346
"""
347
void main(){
348
    float a = -2.0;
349
    float b = -2.0;
350
    assert(a+b == -4.0);
351
}
352
"""
353
)
354
 
355
test("float 10",
356
"""
357
void main(){
358
    float a = 2.0;
359
    float b = 2.0;
360
    assert(a-b == -0.0);
361
}
362
"""
363
)
364
 
365
test("float 11",
366
"""
367
void main(){
368
    float a = 2.0;
369
    float b = 4.0;
370
    assert(a-b == -2.0);
371
}
372
"""
373
)
374
 
375
test("float 12",
376
"""
377
void main(){
378
    float a = 1.0;
379
    float b = 1.0;
380
    assert(a*b == 1.0);
381
}
382
"""
383
)
384
 
385
test("float 13",
386
"""
387
void main(){
388
    float a = 1.0;
389
    float b = -1.0;
390
    assert(a*b == -1.0);
391
}
392
"""
393
)
394
 
395
test("float 14",
396
"""
397
void main(){
398
    float a = -1.0;
399
    float b = -1.0;
400
    assert(a*b == 1.0);
401
}
402
"""
403
)
404
 
405
test("float 15",
406
"""
407
void main(){
408
    float a = -7.0;
409
    float b = 6.0;
410
    assert(a*b == -42.0);
411
}
412
"""
413
)
414
 
415
test("float 16",
416
"""
417
void main(){
418
    float a = 6.0;
419
    float b = 6.0;
420
    assert(a/b == 1.0);
421
}
422
"""
423
)
424
 
425
test("float 17",
426
"""
427
void main(){
428
    float a = 12.0;
429
    float b = 6.0;
430
    assert(a/b == 2.0);
431
}
432
"""
433
)
434
 
435
test("float 18",
436
"""
437
void main(){
438
    int a = 2;
439
    float b = 2.0;
440
    assert(a+b == 4.0);
441
}
442
"""
443
)
444
 
445
test("float 19",
446
"""
447
void main(){
448
    int a;
449
    float b = 2.0;
450
    a = b + 1.0;
451
    assert(a == 3);
452
}
453
"""
454
)
455
 
456
test("float 20",
457
"""
458
void main(){
459
    int a = 2;
460
    float b;
461
    b = a + 1.0;
462
    assert(b == 3.0);
463
}
464
"""
465
)
466
 
467
test("float 21",
468
"""
469
typedef struct {float a; float b;} mystruct;
470
void main(){
471
    mystruct a;
472
    a.a = 2.0;
473
    a.b = 3.0;
474
    assert(a.a == 2.0);
475
    assert(a.b == 3.0);
476
    assert(a.a + a.b == 5.0);
477
}
478
"""
479
)
480
test("float 22",
481
"""
482
typedef struct {float a; float b;} mystruct;
483
 
484
void test(mystruct a){
485
    assert(a.a == 2.0);
486
    assert(a.b == 3.0);
487
    assert(a.a + a.b == 5.0);
488
}
489
 
490
void main(){
491
    mystruct a;
492
    a.a = 2.0;
493
    a.b = 3.0;
494
    test(a);
495
}
496
"""
497
)
498
 
499
test("float 23",
500
"""
501
void test(float b){
502
    assert(b/6.0 == 2.0);
503
}
504
 
505
void main(){
506
    int a = 12.0;
507
    test(a);
508
}
509
"""
510
)
511
 
512
test("float 24",
513
"""
514
float test(){
515
    return 6.0;
516
}
517
 
518
void main(){
519
    int a = 12.0;
520
    assert(a/test() == 2.0);
521
}
522
"""
523
)
524
 
525
test("float 25",
526
"""
527
int main(){
528
  float a = 1.0;
529
  float b = 2.0;
530
  float c = 3.0;
531
  assert(a + b + c == 6.0);
532
  return 0;
533
}
534
 
535
""")
536
 
537
test("float 26",
538
"""
539
int main(){
540
  float a = 1.0;
541
  float b = 2.0;
542
  float c = 3.0;
543
  assert(a - b - c == -4.0);
544
  return 0;
545
}
546
 
547
""")
548
 
549
test("float 27",
550
"""
551
int main(){
552
  float a = 1.0;
553
  float b = 2.0;
554
  float c = 3.0;
555
  assert(a - (b - c) == 2.0);
556
  return 0;
557
}
558
 
559
""")
560
 
561
test("float 28",
562
"""
563
int main(){
564
  float a = 1.0;
565
  float b = 2.0;
566
  float c = 3.0;
567
  assert(a * b * c == 6.0);
568
  return 0;
569
}
570
 
571
""")
572
 
573
test("float 29",
574
"""
575
int main(){
576
  float a = 1.0;
577
  float b = 2.0;
578
  float c = 4.0;
579
  assert(a/b/c == 0.125);
580
  return 0;
581
}
582
 
583
""")
584
 
585
test("float 30",
586
"""
587
int main(){
588
  float a = 1.0;
589
  float b = 2.0;
590
  assert(a - - b == 3.0);
591
  return 0;
592
}
593
 
594
""")
595
 
596
test("struct_size 1",
597
"""
598
 
599
typedef struct {int a; int b;} mystruct;
600
 
601
void main(){
602
    assert(sizeof mystruct == 4);
603
}
604
"""
605
)
606
 
607
test("struct_size 2",
608
"""
609
 
610
typedef struct {long int a; int b;} mystruct;
611
 
612
void main(){
613
    assert(sizeof mystruct == 6);
614
}
615
"""
616
)
617
 
618
test("struct_size 3",
619
"""
620
 
621
typedef struct {long int a; int b;} struct_1;
622
typedef struct {long int a; struct_1 b;} mystruct;
623
 
624
void main(){
625
    assert(sizeof mystruct == 10);
626
}
627
"""
628
)
629
 
630
test("struct_size 4",
631
"""
632
 
633
typedef struct {long int a; int b[2];} mystruct;
634
 
635
void main(){
636
    assert(sizeof mystruct == 6);
637
}
638
"""
639
)
640
 
641
test("struct_passing 1",
642
"""
643
 
644
typedef struct {int a; int b;} mystruct;
645
 
646
void test(mystruct mine){
647
    assert(mine.a == 1);
648
    assert(mine.b == 2);
649
}
650
 
651
void main(){
652
    mystruct an;
653
    an.a = 1;
654
    an.b = 2;
655
    test(an);
656
}
657
"""
658
)
659
 
660
test("struct_passing 2",
661
"""
662
 
663
typedef struct {long int a; int b;} struct_1;
664
typedef struct {long int a; struct_1 b;} mystruct;
665
 
666
void test(mystruct my){
667
    assert(my.a == 1);
668
    assert(my.b.a == 2);
669
    assert(my.b.b == 3);
670
}
671
 
672
void main(){
673
    mystruct blah;
674
    blah.a = 1;
675
    blah.b.a = 2;
676
    blah.b.b = 3;
677
    test(blah);
678
}
679
"""
680
)
681
 
682
test("struct_passing 3",
683
"""
684
 
685
typedef struct {long int a; int b[10];} struct_1;
686
typedef struct {long int a; struct_1 b;} mystruct;
687
 
688
void test(mystruct my){
689
    assert(my.a == 1);
690
    assert(my.b.a == 2);
691
    assert(my.b.b[0] == 3);
692
}
693
 
694
void main(){
695
    mystruct blah;
696
    blah.a = 1;
697
    blah.b.a = 2;
698
    blah.b.b[0] = 3;
699
    test(blah);
700
}
701
"""
702
)
703
 
704
#test("struct_return 1",
705
#"""
706
#
707
#typedef struct {long int a; int b;} struct_1;
708
#
709
#struct_1 test(){
710
#    struct_1 my;
711
#    my.a = 1;
712
#    my.b = 2;
713
#    return my;
714
#}
715
#
716
#void main(){
717
#    struct_1 blah;
718
#    blah = test();
719
#    assert(blah.a == 1);
720
#    assert(blah.b == 2);
721
#}
722
#"""
723
#)
724
 
725
test("print 1",
726
"""
727
unsigned test[] = "Hello World!";
728
unsigned i=0;
729
void stdout_put_char(unsigned value){
730
    assert(test[i] == value);
731
    i++;
732
}
733
#include 
734
 
735
void main(){
736
    print_string("Hello World!");
737
}
738
"""
739
)
740
 
741
test("print 2",
742
"""
743
unsigned test[] = "12345";
744
unsigned i=0;
745
void stdout_put_char(unsigned value){
746
    assert(test[i] == value);
747
    i++;
748
}
749
#include 
750
 
751
void main(){
752
    print_decimal(12345);
753
}
754
"""
755
)
756
 
757
test("print 3",
758
"""
759
unsigned test[] = "-1234";
760
unsigned i=0;
761
void stdout_put_char(unsigned value){
762
    assert(test[i] == value);
763
    i++;
764
}
765
#include 
766
 
767
void main(){
768
    print_decimal(-1234);
769
}
770
"""
771
)
772
 
773
test("print 4",
774
"""
775
unsigned test[] = "-1";
776
unsigned i=0;
777
void stdout_put_char(unsigned value){
778
    assert(test[i] == value);
779
    i++;
780
}
781
#include 
782
 
783
void main(){
784
    print_decimal(-1);
785
}
786
"""
787
)
788
 
789
test("print 5",
790
"""
791
unsigned test[] = "7fff";
792
unsigned i=0;
793
void stdout_put_char(unsigned value){
794
    assert(test[i] == value);
795
    i++;
796
}
797
#include 
798
 
799
void main(){
800
    print_hex(0x7fff);
801
}
802
"""
803
)
804
 
805
test("print 6",
806
"""
807
unsigned test[] = "ffff";
808
unsigned i=0;
809
void stdout_put_char(unsigned value){
810
    assert(test[i] == value);
811
    i++;
812
}
813
#include 
814
 
815
void main(){
816
    print_uhex(0xffffu);
817
}
818
"""
819
)
820
 
821 2 jondawson
test("unsigned divide 1",
822
"""
823
void main(){
824
  unsigned a = 10;
825
  unsigned b = 5;
826
  assert(a/b==2);
827
}
828
"""
829
)
830
 
831
test("long unsigned divide 1",
832
"""
833
void main(){
834
  long unsigned a = 1000000L;
835
  long unsigned b = 500000L;
836
  assert(a/b==2);
837
}
838
"""
839
)
840
 
841
test("divide 1",
842
"""
843
void main(){
844
  int a = 10;
845
  int b = 5;
846
  assert(a/b==2);
847
}
848
"""
849
)
850
 
851
test("long divide 1",
852
"""
853
void main(){
854
  long a = 1000000L;
855
  long b = 500000L;
856
  assert(a/b==2);
857
}
858
"""
859
)
860
 
861
test("long 1",
862
"""
863
void main(){
864
  long a = 100000L;
865
  assert(a==100000L);
866
}
867
"""
868
)
869
 
870
test("long 2",
871
"""
872
void main(){
873
  long a = 100000L;
874
  assert(sizeof a == 4);
875
}
876
"""
877
)
878
 
879
test("long 3",
880
"""
881
void main(){
882
  long a = 0xffffL;
883
  assert(a+1 != 0);
884
  assert(a+1 == 0x10000L);
885
}
886
"""
887
)
888
 
889
test("long 4",
890
"""
891
void main(){
892
  long a = 0xffffL;
893
  long b = 0xffffL;
894
  assert(a+b == 0x1fffeL);
895
}
896
"""
897
)
898
test("long 5",
899
"""
900
void main(){
901
  long a = 0xffffffffUL;
902
  long b = 0x0;
903
  assert(a < b);
904
}
905
"""
906
)
907
test("long 6",
908
"""
909
void main(){
910
  unsigned long a = 0xffffffffUL;
911
  long b = 0x0;
912
  assert(a > b);
913
}
914
"""
915
)
916
 
917
test("long 7",
918
"""
919
void test_long(long a){
920
    assert(a+1 != 0);
921
    assert(a+1 == 0x10000L);
922
}
923
 
924
void main(){
925
  long a = 0xffffL;
926
  test_long(a);
927
}
928
"""
929
)
930
 
931
test("long 8",
932
"""
933
void test_long(unsigned long a){
934
    assert(a > 0);
935
}
936
 
937
void main(){
938
  unsigned long a = 0xffffffffUL;
939
  test_long(a);
940
}
941
"""
942
)
943
 
944
test("long 9",
945
"""
946
void test_long(long a){
947
    assert(a < 0);
948
}
949
 
950
void main(){
951
  unsigned long a = 0xffffffffUL;
952
  test_long(a);
953
}
954
"""
955
)
956
 
957
test("long 10",
958
"""
959
void test_long(unsigned long a){
960
    assert(a > 0);
961
}
962
 
963
void main(){
964
  long a = 0xffffffffUL;
965
  test_long(a);
966
}
967
"""
968
)
969
 
970
test("long 11",
971
"""
972
void main(){
973
  long a[2];
974
  a[0] = 0xffffffffUL;
975
  a[1] = 0xffffffffUL;
976
  assert(a[1] == 0xffffffffUL);
977
}
978
"""
979
)
980
 
981
test("long 12",
982
"""
983
void main(){
984
  long a[2];
985
  int b[2];
986
  a[0] = 1;
987
  b[0] = 2;
988
  a[1] = 3;
989
  b[1] = 4;
990
  assert(a[0] == 1);
991
  assert(b[0] == 2);
992
  assert(a[1] == 3);
993
  assert(b[1] == 4);
994
}
995
"""
996
)
997
 
998
test("void 1",
999
"""
1000
void func(unsigned i){
1001
}
1002
void main(){
1003
  int a = 1;
1004
  assert(a++ == 1);
1005
  assert(a++ == 2);
1006
  assert(a == 3);
1007
  assert(a-- == 3);
1008
  assert(a-- == 2);
1009
  assert(a == 1);
1010
}
1011
"""
1012
)
1013
 
1014
test("postfix 1",
1015
"""
1016
int main(){
1017
  int a = 1;
1018
  assert(a++ == 1);
1019
  assert(a++ == 2);
1020
  assert(a == 3);
1021
  assert(a-- == 3);
1022
  assert(a-- == 2);
1023
  assert(a == 1);
1024
  return 0;
1025
}
1026
"""
1027
)
1028
 
1029
 
1030
test("sizeof 1",
1031
"""
1032
int main(){
1033
  unsigned a = 0xffffU;
1034
  unsigned b = 0x7fff;
1035
  unsigned c[4];
1036
  unsigned d[] = "asdfg";
1037
  assert(sizeof a == 2);
1038
  assert(sizeof b == 2);
1039
  assert(sizeof c == 8);
1040
  assert(sizeof d == 12);
1041
  return 0;
1042
}
1043
"""
1044
)
1045
 
1046
test("type_unsigned 1",
1047
"""
1048
int main(){
1049
  unsigned a = 0xffffU;
1050
  unsigned b = 0x7fff;
1051
  assert(a==0xffffU);
1052
  assert(a > b);
1053
 
1054
  return 0;
1055
}
1056
"""
1057
)
1058
 
1059
test("type_unsigned 2",
1060
"""
1061
int main(){
1062
  unsigned a = 0xffffU;
1063
  unsigned b = 0x7fff;
1064
  assert(a==0xffffU);
1065
  assert(b < a);
1066
 
1067
  return 0;
1068
}
1069
"""
1070
)
1071
 
1072
test("type_unsigned 3",
1073
"""
1074
int test(unsigned a){
1075
    return a;
1076
}
1077
 
1078
int main(){
1079
  assert(test(3) == 3);
1080
  return 0;
1081
}
1082
"""
1083
)
1084
 
1085
test("type_unsigned 4",
1086
"""
1087
int main(){
1088
  int a = 1;
1089
  unsigned b = 1;
1090
  assert(a == b);
1091
  return 0;
1092
}
1093
"""
1094
)
1095
 
1096
test("type_unsigned 5",
1097
"""
1098
int main(){
1099
  int a = 1;
1100
  assert(a == 1);
1101
  return 0;
1102
}
1103
"""
1104
)
1105
test("type_unsigned 6",
1106
"""
1107
int main(){
1108
  int a = 1;
1109
  assert(1 == a);
1110
  return 0;
1111
}
1112
"""
1113
)
1114
test("type_unsigned 7",
1115
"""
1116
int main(){
1117
  unsigned b = 1;
1118
  assert(1 == b);
1119
  return 0;
1120
}
1121
"""
1122
)
1123
test("type_unsigned 8",
1124
"""
1125
int main(){
1126
  unsigned b = 1;
1127
  assert(b == 1);
1128
  return 0;
1129
}
1130
"""
1131
)
1132
 
1133
test("type_compatibility 1",
1134
"""
1135
int main(){
1136
  int a = 4;
1137
  char b = 6;
1138
  b = a;
1139
  assert(b==4);
1140
  return 0;
1141
}
1142
"""
1143
)
1144
 
1145
test("type_compatibility 2",
1146
"""
1147
int main(){
1148
  int a[2];
1149
  char b[2];
1150
  b = a;
1151
  return 0;
1152
}
1153
"""
1154
)
1155
 
1156
test("type_compatibility 3",
1157
"""
1158
int main(){
1159
  int a[2];
1160
  char b[2];
1161
  a = b;
1162
  return 0;
1163
}
1164
"""
1165
)
1166
 
1167
test("type_compatibility 4",
1168
"""
1169
int main(){
1170
  long a[2];
1171
  char b[2];
1172
  a = b;
1173
  return 0;
1174
}
1175
"""
1176
)
1177
 
1178
test("type_compatibility 5",
1179
"""
1180
int main(){
1181
  long a[2];
1182
  char b[2];
1183
  a = b;
1184
  return 0;
1185
}
1186
"""
1187
)
1188
 
1189
test("string 1 a",
1190
"""
1191
int main(){
1192
  int c[4] = "aA1";
1193
  assert(c[0] == 97);
1194
  assert(c[1] == 65);
1195
  assert(c[2] == 49);
1196
  assert(c[3] == 0);
1197
  return 0;
1198
}
1199
 
1200
""")
1201
 
1202
test("string 1 b",
1203
"""
1204
int main(){
1205
  int c[4] = "aA1";
1206
  assert(c[0] == 97);
1207
  assert(c[1] == 65);
1208
  assert(c[2] == 49);
1209
  assert(c[3] == 0);
1210
  return 0;
1211
}
1212
 
1213
""", True)
1214
 
1215
test("string 2a",
1216
"""
1217
int main(){
1218
  int c[] = "aA1";
1219
  assert(c[0] == 97);
1220
  assert(c[1] == 65);
1221
  assert(c[2] == 49);
1222
  assert(c[3] == 0);
1223
  return 0;
1224
}
1225
 
1226
""")
1227
 
1228
test("string 2b",
1229
"""
1230
int main(){
1231
  int c[] = "aA1";
1232
  assert(c[0] == 97);
1233
  assert(c[1] == 65);
1234
  assert(c[2] == 49);
1235
  assert(c[3] == 0);
1236
  return 0;
1237
}
1238
 
1239
""", True)
1240
 
1241
test_fails("string 3",
1242
"""
1243
int main(){
1244
  int c[];
1245
  assert(c[0] == 97);
1246
  assert(c[1] == 65);
1247
  assert(c[2] == 49);
1248
  assert(c[3] == 0);
1249
  return 0;
1250
}
1251
 
1252
""")
1253
 
1254
test("string 4a",
1255
"""
1256
int test(char c[]){
1257
  assert(c[0] == 97);
1258
  assert(c[1] == 65);
1259
  assert(c[2] == 49);
1260
  assert(c[3] == 0);
1261
  c[0] = 'b';
1262
  c[1] = 'B';
1263
  c[2] = '2';
1264
  c[3] = 0;
1265
  return 0;
1266
}
1267
int main(){
1268
  char c[] = "aA1";
1269
  assert(c[0] == 97);
1270
  assert(c[1] == 65);
1271
  assert(c[2] == 49);
1272
  assert(c[3] == 0);
1273
  test(c);
1274
  assert(c[0] == 'b');
1275
  assert(c[1] == 'B');
1276
  assert(c[2] == '2');
1277
  assert(c[3] == 0);
1278
  return 0;
1279
}
1280
 
1281
""")
1282
 
1283
test("string 4b",
1284
"""
1285
int test(char c[]){
1286
  assert(c[0] == 97);
1287
  assert(c[1] == 65);
1288
  assert(c[2] == 49);
1289
  assert(c[3] == 0);
1290
  c[0] = 'b';
1291
  c[1] = 'B';
1292
  c[2] = '2';
1293
  c[3] = 0;
1294
  return 0;
1295
}
1296
int main(){
1297
  char c[] = "aA1";
1298
  assert(c[0] == 97);
1299
  assert(c[1] == 65);
1300
  assert(c[2] == 49);
1301
  assert(c[3] == 0);
1302
  test(c);
1303
  assert(c[0] == 'b');
1304
  assert(c[1] == 'B');
1305
  assert(c[2] == '2');
1306
  assert(c[3] == 0);
1307
  return 0;
1308
}
1309
 
1310
""", True)
1311
 
1312
test_fails("string 5",
1313
"""
1314
int main(){
1315
  int c[] "\\n";
1316
  assert(c[0] == 10);
1317
  assert(c[1] == 0);
1318
  return 0;
1319
}
1320
 
1321
""")
1322
 
1323
test("string 6a",
1324
"""
1325
int test(char c[]){
1326
  assert(c[0] == 97);
1327
  assert(c[1] == 65);
1328
  assert(c[2] == 49);
1329
  assert(c[3] == 0);
1330
  return 0;
1331
}
1332
int main(){
1333
  test("aA1");
1334
  return 0;
1335
}
1336
""")
1337
 
1338
test("string 6b",
1339
"""
1340
int test(char c[]){
1341
  assert(c[0] == 97);
1342
  assert(c[1] == 65);
1343
  assert(c[2] == 49);
1344
  assert(c[3] == 0);
1345
  return 0;
1346
}
1347
int main(){
1348
  test("aA1");
1349
  return 0;
1350
}
1351
""", True)
1352
 
1353
test("string 7a",
1354
"""
1355
int main(){
1356
  char c[] = "a\\n";
1357
  assert(c[0] == 97);
1358
  assert(c[1] == 10);
1359
  assert(c[2] == 0);
1360
  return 0;
1361
}
1362
""")
1363
 
1364
test("string 7b",
1365
"""
1366
int main(){
1367
  char c[] = "a\\n";
1368
  assert(c[0] == 97);
1369
  assert(c[1] == 10);
1370
  assert(c[2] == 0);
1371
  return 0;
1372
}
1373
""", True)
1374
 
1375
test("char 1",
1376
"""
1377
int main(){
1378
  int c = 'a';
1379
  assert(c == 97);
1380
  return 0;
1381
}
1382
 
1383
""")
1384
test("char 2",
1385
"""
1386
int main(){
1387
  int c = 'A';
1388
  assert(c == 65);
1389
  return 0;
1390
}
1391
 
1392
""")
1393
test("char 3",
1394
"""
1395
int main(){
1396
  int c = '1';
1397
  assert(c == 49);
1398
  return 0;
1399
}
1400
 
1401
""")
1402
test("char 4",
1403
"""
1404
int main(){
1405
  int c = '\\n';
1406
  assert(c == 10);
1407
  return 0;
1408
}
1409
 
1410
""")
1411
 
1412
test("unsigned long modulo 1",
1413
"""
1414
unsigned long int main(){
1415
  unsigned long int a = 3;
1416
  unsigned long int b = 4;
1417
  assert(a%b == 3);
1418
  return 0;
1419
}
1420
 
1421
""")
1422
 
1423
test("unsigned long modulo 3",
1424
"""
1425
unsigned long int main(){
1426
  unsigned long int a = 7;
1427
  unsigned long int b = 8;
1428
  assert(a%b == 7);
1429
  return 0;
1430
}
1431
 
1432
""")
1433
 
1434
test("unsigned long modulo 4",
1435
"""
1436
unsigned long int main(){
1437
  unsigned long int a = 15;
1438
  unsigned long int b = 8;
1439
  assert(a%b == 7);
1440
  return 0;
1441
}
1442
 
1443
""")
1444
 
1445
test("unsigned long modulo 9",
1446
"""
1447
unsigned long int main(){
1448
  unsigned long int a = 32766;
1449
  unsigned long int b = 0;
1450
  assert(a%b == 32766);
1451
  return 0;
1452
}
1453
 
1454
""")
1455
 
1456
test("unsigned long division 1",
1457
"""
1458
unsigned long int main(){
1459
  unsigned long int a = 15;
1460
  unsigned long int b = 3;
1461
  assert(a/b == 5);
1462
  return 0;
1463
}
1464
 
1465
""")
1466
 
1467
 
1468
test("unsigned long division 2",
1469
"""
1470
unsigned long int main(){
1471
  unsigned long int a = 12;
1472
  unsigned long int b = 4;
1473
  assert(a/b == 3);
1474
  return 0;
1475
}
1476
 
1477
""")
1478
 
1479
test("unsigned long division 3",
1480
"""
1481
unsigned long int main(){
1482
  unsigned long int a = 1;
1483
  unsigned long int b = 1;
1484
  assert(a/b == 1);
1485
  return 0;
1486
}
1487
 
1488
""")
1489
 
1490
test("unsigned long division 6",
1491
"""
1492
unsigned long int main(){
1493
  unsigned long int a = 0;
1494
  unsigned long int b = 1;
1495
  assert(a/b == 0);
1496
  return 0;
1497
}
1498
 
1499
""")
1500
 
1501
test("unsigned long division 7",
1502
"""
1503
unsigned long int main(){
1504
  unsigned long int a = 5;
1505
  unsigned long int b = 2;
1506
  assert(a/b == 2);
1507
  return 0;
1508
}
1509
 
1510
""")
1511
 
1512
test("unsigned long division 9",
1513
"""
1514
unsigned long int main(){
1515
  unsigned long int a = 0;
1516
  unsigned long int b = 32767;
1517
  assert(a/b == 0);
1518
  return 0;
1519
}
1520
 
1521
""")
1522
 
1523
test("unsigned long division 10",
1524
"""
1525
unsigned long int main(){
1526
  unsigned long int a = 32767;
1527
  unsigned long int b = 1;
1528
  assert(a/b == 32767);
1529
  return 0;
1530
}
1531
 
1532
""")
1533
 
1534
test("unsigned long division 11",
1535
"""
1536
unsigned long int main(){
1537
  unsigned long int a = 32767;
1538
  unsigned long int b = 2;
1539
  assert(a/b == 16383);
1540
  return 0;
1541
}
1542
 
1543
""")
1544
 
1545
test("unsigned long division 12",
1546
"""
1547
unsigned long int main(){
1548
  unsigned long int a = 32767;
1549
  unsigned long int b = 32767;
1550
  assert(a/b == 1);
1551
  return 0;
1552
}
1553
 
1554
""")
1555
 
1556
test("unsigned modulo 1",
1557
"""
1558
unsigned int main(){
1559
  unsigned int a = 3;
1560
  unsigned int b = 4;
1561
  assert(a%b == 3);
1562
  return 0;
1563
}
1564
 
1565
""")
1566
 
1567
test("unsigned modulo 3",
1568
"""
1569
unsigned int main(){
1570
  unsigned int a = 7;
1571
  unsigned int b = 8;
1572
  assert(a%b == 7);
1573
  return 0;
1574
}
1575
 
1576
""")
1577
 
1578
test("unsigned modulo 4",
1579
"""
1580
unsigned int main(){
1581
  unsigned int a = 15;
1582
  unsigned int b = 8;
1583
  assert(a%b == 7);
1584
  return 0;
1585
}
1586
 
1587
""")
1588
 
1589
test("unsigned modulo 9",
1590
"""
1591
unsigned int main(){
1592
  unsigned int a = 32766;
1593
  unsigned int b = 0;
1594
  assert(a%b == 32766);
1595
  return 0;
1596
}
1597
 
1598
""")
1599
 
1600
test("unsigned division 1",
1601
"""
1602
unsigned int main(){
1603
  unsigned int a = 15;
1604
  unsigned int b = 3;
1605
  assert(a/b == 5);
1606
  return 0;
1607
}
1608
 
1609
""")
1610
 
1611
 
1612
test("unsigned division 2",
1613
"""
1614
unsigned int main(){
1615
  unsigned int a = 12;
1616
  unsigned int b = 4;
1617
  assert(a/b == 3);
1618
  return 0;
1619
}
1620
 
1621
""")
1622
 
1623
test("unsigned division 3",
1624
"""
1625
unsigned int main(){
1626
  unsigned int a = 1;
1627
  unsigned int b = 1;
1628
  assert(a/b == 1);
1629
  return 0;
1630
}
1631
 
1632
""")
1633
 
1634
test("unsigned division 6",
1635
"""
1636
unsigned int main(){
1637
  unsigned int a = 0;
1638
  unsigned int b = 1;
1639
  assert(a/b == 0);
1640
  return 0;
1641
}
1642
 
1643
""")
1644
 
1645
test("unsigned division 7",
1646
"""
1647
unsigned int main(){
1648
  unsigned int a = 5;
1649
  unsigned int b = 2;
1650
  assert(a/b == 2);
1651
  return 0;
1652
}
1653
 
1654
""")
1655
 
1656
test("unsigned division 9",
1657
"""
1658
unsigned int main(){
1659
  unsigned int a = 0;
1660
  unsigned int b = 32767;
1661
  assert(a/b == 0);
1662
  return 0;
1663
}
1664
 
1665
""")
1666
 
1667
test("unsigned division 10",
1668
"""
1669
unsigned int main(){
1670
  unsigned int a = 32767;
1671
  unsigned int b = 1;
1672
  assert(a/b == 32767);
1673
  return 0;
1674
}
1675
 
1676
""")
1677
 
1678
test("unsigned division 11",
1679
"""
1680
unsigned int main(){
1681
  unsigned int a = 32767;
1682
  unsigned int b = 2;
1683
  assert(a/b == 16383);
1684
  return 0;
1685
}
1686
 
1687
""")
1688
 
1689
test("unsigned division 12",
1690
"""
1691
unsigned int main(){
1692
  unsigned int a = 32767;
1693
  unsigned int b = 32767;
1694
  assert(a/b == 1);
1695
  return 0;
1696
}
1697
 
1698
""")
1699
 
1700
test("long modulo 1",
1701
"""
1702
long int main(){
1703
  long int a = 3;
1704
  long int b = 4;
1705
  assert(a%b == 3);
1706
  return 0;
1707
}
1708
 
1709
""")
1710
 
1711
test("long modulo 2",
1712
"""
1713
long int main(){
1714
  long int a = -3;
1715
  long int b = 4;
1716
  assert(a%b == -3);
1717
  return 0;
1718
}
1719
 
1720
""")
1721
 
1722
test("long modulo 3",
1723
"""
1724
long int main(){
1725
  long int a = 7;
1726
  long int b = 8;
1727
  assert(a%b == 7);
1728
  return 0;
1729
}
1730
 
1731
""")
1732
 
1733
test("long modulo 4",
1734
"""
1735
long int main(){
1736
  long int a = 15;
1737
  long int b = 8;
1738
  assert(a%b == 7);
1739
  return 0;
1740
}
1741
 
1742
""")
1743
 
1744
test("long modulo 5",
1745
"""
1746
long int main(){
1747
  long int a = -7;
1748
  long int b = 8;
1749
  assert(a%b == -7);
1750
  return 0;
1751
}
1752
 
1753
""")
1754
 
1755
test("long modulo 6",
1756
"""
1757
long int main(){
1758
  long int a = -15;
1759
  long int b = 8;
1760
  assert(a%b == -7);
1761
  return 0;
1762
}
1763
 
1764
""")
1765
 
1766
test("long modulo 7",
1767
"""
1768
long int main(){
1769
  long int a = 7;
1770
  long int b = -8;
1771
  assert(a%b == 7);
1772
  return 0;
1773
}
1774
 
1775
""")
1776
 
1777
test("long modulo 8",
1778
"""
1779
long int main(){
1780
  long int a = 15;
1781
  long int b = -8;
1782
  assert(a%b == 7);
1783
  return 0;
1784
}
1785
 
1786
""")
1787
 
1788
test("long modulo 9",
1789
"""
1790
long int main(){
1791
  long int a = 32766;
1792
  long int b = 0;
1793
  assert(a%b == 32766);
1794
  return 0;
1795
}
1796
 
1797
""")
1798
 
1799
test("long division 1",
1800
"""
1801
long int main(){
1802
  long int a = 15;
1803
  long int b = 3;
1804
  assert(a/b == 5);
1805
  return 0;
1806
}
1807
 
1808
""")
1809
 
1810
 
1811
test("long division 2",
1812
"""
1813
long int main(){
1814
  long int a = 12;
1815
  long int b = 4;
1816
  assert(a/b == 3);
1817
  return 0;
1818
}
1819
 
1820
""")
1821
 
1822
test("long division 3",
1823
"""
1824
long int main(){
1825
  long int a = 1;
1826
  long int b = 1;
1827
  assert(a/b == 1);
1828
  return 0;
1829
}
1830
 
1831
""")
1832
 
1833
test("long division 4",
1834
"""
1835
long int main(){
1836
  long int a = 1;
1837
  long int b = -1;
1838
  assert(a/b == -1);
1839
  return 0;
1840
}
1841
 
1842
""")
1843
 
1844
test("long division 5",
1845
"""
1846
long int main(){
1847
  long int a = -1;
1848
  long int b = 1;
1849
  assert(a/b == -1);
1850
  return 0;
1851
}
1852
 
1853
""")
1854
 
1855
test("long division 6",
1856
"""
1857
long int main(){
1858
  long int a = 0;
1859
  long int b = 1;
1860
  assert(a/b == 0);
1861
  return 0;
1862
}
1863
 
1864
""")
1865
 
1866
test("long division 7",
1867
"""
1868
long int main(){
1869
  long int a = 5;
1870
  long int b = 2;
1871
  assert(a/b == 2);
1872
  return 0;
1873
}
1874
 
1875
""")
1876
 
1877
test("long division 8",
1878
"""
1879
long int main(){
1880
  long int a = -5;
1881
  long int b = 2;
1882
  assert(a/b == -2);
1883
  return 0;
1884
}
1885
 
1886
""")
1887
 
1888
test("long division 9",
1889
"""
1890
long int main(){
1891
  long int a = 0;
1892
  long int b = 32767;
1893
  assert(a/b == 0);
1894
  return 0;
1895
}
1896
 
1897
""")
1898
 
1899
test("long division 10",
1900
"""
1901
long int main(){
1902
  long int a = 32767;
1903
  long int b = 1;
1904
  assert(a/b == 32767);
1905
  return 0;
1906
}
1907
 
1908
""")
1909
 
1910
test("long division 11",
1911
"""
1912
long int main(){
1913
  long int a = 32767;
1914
  long int b = 2;
1915
  assert(a/b == 16383);
1916
  return 0;
1917
}
1918
 
1919
""")
1920
 
1921
test("long division 12",
1922
"""
1923
long int main(){
1924
  long int a = 32767;
1925
  long int b = 32767;
1926
  assert(a/b == 1);
1927
  return 0;
1928
}
1929
 
1930
""")
1931
 
1932
test("long division 13",
1933
"""
1934
long int main(){
1935
  long int a = -32767-1;
1936
  long int b = -32767-1;
1937
  assert(a/b == 1);
1938
  return 0;
1939
}
1940
 
1941
""")
1942
 
1943
test("long division 14",
1944
"""
1945
long int main(){
1946
  long int a = -32767;
1947
  long int b = -1;
1948
  assert(a/b == 32767);
1949
  return 0;
1950
}
1951
 
1952
""")
1953
 
1954
test("modulo 1",
1955
"""
1956
int main(){
1957
  int a = 3;
1958
  int b = 4;
1959
  assert(a%b == 3);
1960
  return 0;
1961
}
1962
 
1963
""")
1964
 
1965
test("modulo 2",
1966
"""
1967
int main(){
1968
  int a = -3;
1969
  int b = 4;
1970
  assert(a%b == -3);
1971
  return 0;
1972
}
1973
 
1974
""")
1975
 
1976
test("modulo 3",
1977
"""
1978
int main(){
1979
  int a = 7;
1980
  int b = 8;
1981
  assert(a%b == 7);
1982
  return 0;
1983
}
1984
 
1985
""")
1986
 
1987
test("modulo 4",
1988
"""
1989
int main(){
1990
  int a = 15;
1991
  int b = 8;
1992
  assert(a%b == 7);
1993
  return 0;
1994
}
1995
 
1996
""")
1997
 
1998
test("modulo 5",
1999
"""
2000
int main(){
2001
  int a = -7;
2002
  int b = 8;
2003
  assert(a%b == -7);
2004
  return 0;
2005
}
2006
 
2007
""")
2008
 
2009
test("modulo 6",
2010
"""
2011
int main(){
2012
  int a = -15;
2013
  int b = 8;
2014
  assert(a%b == -7);
2015
  return 0;
2016
}
2017
 
2018
""")
2019
 
2020
test("modulo 7",
2021
"""
2022
int main(){
2023
  int a = 7;
2024
  int b = -8;
2025
  assert(a%b == 7);
2026
  return 0;
2027
}
2028
 
2029
""")
2030
 
2031
test("modulo 8",
2032
"""
2033
int main(){
2034
  int a = 15;
2035
  int b = -8;
2036
  assert(a%b == 7);
2037
  return 0;
2038
}
2039
 
2040
""")
2041
 
2042
test("modulo 9",
2043
"""
2044
int main(){
2045
  int a = 32766;
2046
  int b = 0;
2047
  assert(a%b == 32766);
2048
  return 0;
2049
}
2050
 
2051
""")
2052
 
2053
test("division 1",
2054
"""
2055
int main(){
2056
  int a = 15;
2057
  int b = 3;
2058
  assert(a/b == 5);
2059
  return 0;
2060
}
2061
 
2062
""")
2063
 
2064
 
2065
test("division 2",
2066
"""
2067
int main(){
2068
  int a = 12;
2069
  int b = 4;
2070
  assert(a/b == 3);
2071
  return 0;
2072
}
2073
 
2074
""")
2075
 
2076
test("division 3",
2077
"""
2078
int main(){
2079
  int a = 1;
2080
  int b = 1;
2081
  assert(a/b == 1);
2082
  return 0;
2083
}
2084
 
2085
""")
2086
 
2087
test("division 4",
2088
"""
2089
int main(){
2090
  int a = 1;
2091
  int b = -1;
2092
  assert(a/b == -1);
2093
  return 0;
2094
}
2095
 
2096
""")
2097
 
2098
test("division 5",
2099
"""
2100
int main(){
2101
  int a = -1;
2102
  int b = 1;
2103
  assert(a/b == -1);
2104
  return 0;
2105
}
2106
 
2107
""")
2108
 
2109
test("division 6",
2110
"""
2111
int main(){
2112
  int a = 0;
2113
  int b = 1;
2114
  assert(a/b == 0);
2115
  return 0;
2116
}
2117
 
2118
""")
2119
 
2120
test("division 7",
2121
"""
2122
int main(){
2123
  int a = 5;
2124
  int b = 2;
2125
  assert(a/b == 2);
2126
  return 0;
2127
}
2128
 
2129
""")
2130
 
2131
test("division 8",
2132
"""
2133
int main(){
2134
  int a = -5;
2135
  int b = 2;
2136
  assert(a/b == -2);
2137
  return 0;
2138
}
2139
 
2140
""")
2141
 
2142
test("division 9",
2143
"""
2144
int main(){
2145
  int a = 0;
2146
  int b = 32767;
2147
  assert(a/b == 0);
2148
  return 0;
2149
}
2150
 
2151
""")
2152
 
2153
test("division 10",
2154
"""
2155
int main(){
2156
  int a = 32767;
2157
  int b = 1;
2158
  assert(a/b == 32767);
2159
  return 0;
2160
}
2161
 
2162
""")
2163
 
2164
test("division 11",
2165
"""
2166
int main(){
2167
  int a = 32767;
2168
  int b = 2;
2169
  assert(a/b == 16383);
2170
  return 0;
2171
}
2172
 
2173
""")
2174
 
2175
test("division 12",
2176
"""
2177
int main(){
2178
  int a = 32767;
2179
  int b = 32767;
2180
  assert(a/b == 1);
2181
  return 0;
2182
}
2183
 
2184
""")
2185
 
2186
test("division 13",
2187
"""
2188
int main(){
2189
  int a = -32767-1;
2190
  int b = -32767-1;
2191
  assert(a/b == 1);
2192
  return 0;
2193
}
2194
 
2195
""")
2196
 
2197
test("division 14",
2198
"""
2199
int main(){
2200
  int a = -32767;
2201
  int b = -1;
2202
  assert(a/b == 32767);
2203
  return 0;
2204
}
2205
 
2206
""")
2207
 
2208
test("struct with array 1",
2209
"""
2210
typedef struct {int a; int b; int c[2];} blah;
2211
blah myblah;
2212
 
2213
void test(){
2214
  assert(myblah.a == 1);
2215
  assert(myblah.b == 2);
2216
  assert(myblah.c[0] == 3);
2217
  assert(myblah.c[1] == 4);
2218
  myblah.a = 5;
2219
  myblah.b = 6;
2220
  myblah.c[0] = 7;
2221
  myblah.c[1] = 8;
2222
}
2223
 
2224
void main(){
2225
  myblah.a = 1;
2226
  myblah.b = 2;
2227
  myblah.c[0] = 3;
2228
  myblah.c[1] = 4;
2229
  test();
2230
  assert(myblah.a == 5);
2231
  assert(myblah.b == 6);
2232
  assert(myblah.c[0] == 7);
2233
  assert(myblah.c[1] == 8);
2234
}
2235
"""
2236
)
2237
 
2238
test("global variables 1",
2239
"""
2240
int a;
2241
 
2242
void test(){
2243
  assert(a==12);
2244
  a = 24;
2245
}
2246
 
2247
void main(){
2248
  a = 12;
2249
  test();
2250
  assert(a==24);
2251
}
2252
 
2253
"""
2254
)
2255
 
2256
test("global variables 2",
2257
"""
2258
int a[10];
2259
 
2260
void test(){
2261
  assert(a[0] == 0);
2262
  assert(a[1] == 1);
2263
  assert(a[2] == 2);
2264
  assert(a[3] == 3);
2265
  a[0] = 4;
2266
  a[1] = 5;
2267
  a[2] = 6;
2268
  a[3] = 7;
2269
}
2270
 
2271
void main(){
2272
  a[0] = 0;
2273
  a[1] = 1;
2274
  a[2] = 2;
2275
  a[3] = 3;
2276
  test();
2277
  assert(a[0] == 4);
2278
  assert(a[1] == 5);
2279
  assert(a[2] == 6);
2280
  assert(a[3] == 7);
2281
}
2282
 
2283
"""
2284
)
2285
 
2286
test("global variables 3",
2287
"""
2288
int a=0, b=1, c=2;
2289
 
2290
void test(){
2291
  assert(a == 3);
2292
  assert(b == 4);
2293
  assert(c == 5);
2294
  a=6;
2295
  b=7;
2296
  c=8;
2297
}
2298
 
2299
void main(){
2300
  assert(a == 0);
2301
  assert(b == 1);
2302
  assert(c == 2);
2303
  a=3;
2304
  b=4;
2305
  c=5;
2306
  test();
2307
  assert(a == 6);
2308
  assert(b == 7);
2309
  assert(c == 8);
2310
}
2311
 
2312
"""
2313
)
2314
 
2315
test("global variables 4",
2316
"""
2317
typedef struct {int a; int b; int c;} blah;
2318
blah myblah;
2319
 
2320
void test(){
2321
  assert(myblah.a == 1);
2322
  assert(myblah.b == 2);
2323
  assert(myblah.c == 3);
2324
  myblah.a = 4;
2325
  myblah.b = 5;
2326
  myblah.c = 6;
2327
}
2328
 
2329
void main(){
2330
  myblah.a = 1;
2331
  myblah.b = 2;
2332
  myblah.c = 3;
2333
  test();
2334
  assert(myblah.a == 4);
2335
  assert(myblah.b == 5);
2336
  assert(myblah.c == 6);
2337
}
2338
"""
2339
)
2340
 
2341
test("void functions 1",
2342
"""
2343
void main(){
2344
  int a;
2345
  int b;
2346
  b = a;
2347
}
2348
 
2349
"""
2350
)
2351
 
2352
test("void functions 2",
2353
"""
2354
void test(){
2355
  return;
2356
}
2357
 
2358
void main(){
2359
  test();
2360
}
2361
 
2362
"""
2363
)
2364
 
2365
test_fails("void functions 3",
2366
"""
2367
void test(){
2368
  return;
2369
}
2370
 
2371
void main(){
2372
  int a;
2373
  a = test();
2374
}
2375
 
2376
"""
2377
)
2378
 
2379
test_fails("void functions 4",
2380
"""
2381
void test(){
2382
  return 10;
2383
}
2384
 
2385
void main(){
2386
  int a;
2387
  a = test();
2388
}
2389
 
2390
"""
2391
)
2392
 
2393
test_fails("type_checking 1",
2394
"""
2395
int main(){
2396
  int a[4];
2397
  int b;
2398
  b = a;
2399
  return 0;
2400
}
2401
 
2402
"""
2403
)
2404
 
2405
test_fails("type_checking 2",
2406
"""
2407
int main(){
2408
  int a[4];
2409
  int b[4];
2410
  b[a]=12;
2411
  return 0;
2412
}
2413
 
2414
"""
2415
)
2416
 
2417
test_fails("type_checking 3",
2418
"""
2419
int main(){
2420
  int a[4];
2421
  int b;
2422
  if(a) b=12;
2423
  return 0;
2424
}
2425
 
2426
"""
2427
)
2428
 
2429
test_fails("type_checking 4",
2430
"""
2431
int main(){
2432
  int a[4];
2433
  int b;
2434
  while(a) b=12;
2435
  return 0;
2436
}
2437
 
2438
"""
2439
)
2440
 
2441
test_fails("type_checking 5",
2442
"""
2443
int main(){
2444
  int a[4];
2445
  int b;
2446
  for(;a;) b=12;
2447
  return 0;
2448
}
2449
 
2450
"""
2451
)
2452
 
2453
test_fails("type_checking 6",
2454
"""
2455
int main(){
2456
  int a[4];
2457
  int b;
2458
  switch(a){}
2459
  return 0;
2460
}
2461
 
2462
"""
2463
)
2464
 
2465
test_fails("type_checking 7",
2466
"""
2467
int main(){
2468
  int a[4];
2469
  int b;
2470
  switch(b){case a:b=12;}
2471
  return 0;
2472
}
2473
 
2474
"""
2475
)
2476
 
2477
test_fails("type_checking 8",
2478
"""
2479
int test(int a[]){
2480
  return 0;
2481
}
2482
 
2483
int main(){
2484
  int b;
2485
  test(b);
2486
  return 0;
2487
}
2488
 
2489
"""
2490
)
2491
 
2492
test_fails("type_checking 9",
2493
"""
2494
int test(int a){
2495
  return 0;
2496
}
2497
 
2498
int main(){
2499
  int b[4];
2500
  test(b);
2501
  return 0;
2502
}
2503
 
2504
"""
2505
)
2506
 
2507
test("array passing 1",
2508
"""
2509
 
2510
int test(int a[]){
2511
    assert(a[0] == 0);
2512
    assert(a[1] == 1);
2513
    assert(a[2] == 2);
2514
    assert(a[3] == 3);
2515
    a[0] = 4;
2516
    a[1] = 5;
2517
    a[2] = 6;
2518
    a[3] = 7;
2519
    return 0;
2520
}
2521
 
2522
int main(){
2523
  int a[4];
2524
  a[0] = 0;
2525
  a[1] = 1;
2526
  a[2] = 2;
2527
  a[3] = 3;
2528
  test(a);
2529
  assert(a[0] == 4);
2530
  assert(a[1] == 5);
2531
  assert(a[2] == 6);
2532
  assert(a[3] == 7);
2533
  return 0;
2534
}
2535
 
2536
"""
2537
)
2538
 
2539
test("array passing 2",
2540
"""
2541
 
2542
int test(int a[]){
2543
    assert(a[0] == 0);
2544
    assert(a[1] == 1);
2545
    assert(a[2] == 2);
2546
    assert(a[3] == 3);
2547
    a[0] = 4;
2548
    a[1] = 5;
2549
    a[2] = 6;
2550
    a[3] = 7;
2551
    return 0;
2552
}
2553
 
2554
int main(){
2555
  int a[4];
2556
  int b[4];
2557
  a[0] = 0;
2558
  a[1] = 1;
2559
  a[2] = 2;
2560
  a[3] = 3;
2561
  b = a;
2562
  test(b);
2563
  assert(a[0] == 4);
2564
  assert(a[1] == 5);
2565
  assert(a[2] == 6);
2566
  assert(a[3] == 7);
2567
  return 0;
2568
}"""
2569
)
2570
 
2571
test("struct 1",
2572
"""
2573
struct blah {int a; int b; int c;};
2574
int main(){
2575
  struct blah myblah;
2576
  myblah.a = 1;
2577
  myblah.b = 2;
2578
  myblah.c = 3;
2579
  assert(myblah.a == 1);
2580
  assert(myblah.b == 2);
2581
  assert(myblah.c == 3);
2582
  return 0;
2583
}
2584
"""
2585
)
2586
test("struct 2",
2587
"""
2588
struct as {int a; int b; int c;};
2589
int main(){
2590
  struct as asa;
2591
  struct as asb;
2592
  asa.a = 1;
2593
  asb.a = 3;
2594
  asa.b = 2;
2595
  asb.b = 2;
2596
  asa.c = 3;
2597
  asb.c = 1;
2598
  assert(asa.a == 1);
2599
  assert(asb.a == 3);
2600
  assert(asa.b == 2);
2601
  assert(asb.b == 2);
2602
  assert(asa.c == 3);
2603
  assert(asb.c == 1);
2604
  return 0;
2605
}
2606
"""
2607
)
2608
test("struct 3",
2609
"""
2610
typedef struct {int a; int b; int c;} blah;
2611
int main(){
2612
  blah myblah;
2613
  myblah.a = 1;
2614
  myblah.b = 2;
2615
  myblah.c = 3;
2616
  assert(myblah.a == 1);
2617
  assert(myblah.b == 2);
2618
  assert(myblah.c == 3);
2619
  return 0;
2620
}
2621
"""
2622
)
2623
test("struct 4",
2624
"""
2625
typedef struct{int a; int b; int c;} mytype;
2626
typedef struct{mytype a;} othertype;
2627
int main(){
2628
  othertype a;
2629
  othertype b;
2630
  a.a.a = 1;
2631
  b.a.a = 2;
2632
  a.a.b = 3;
2633
  b.a.b = 4;
2634
  a.a.c = 5;
2635
  b.a.c = 6;
2636
  assert(a.a.a == 1);
2637
  assert(b.a.a == 2);
2638
  assert(a.a.b == 3);
2639
  assert(b.a.b == 4);
2640
  assert(a.a.c == 5);
2641
  assert(b.a.c == 6);
2642
  return 0;
2643
}
2644
"""
2645
)
2646
test("include 1",
2647
"""#include "test_include.c"
2648
int main(){
2649
  assert(include_function()==12);
2650
  return 0;
2651
}
2652
"""
2653
)
2654
test("switch 1",
2655
     """int main(){
2656
        switch(0){
2657
            case 0: return 3;
2658
            case 1: return 2;
2659
            case 2: return 1;
2660
            default: return 0;
2661
        }
2662
     }
2663
     """
2664
)
2665
test("switch 2",
2666
     """int main(){
2667
        switch(2){
2668
            case 0: return 3;
2669
            case 1: return 2;
2670
            case 2: return 1;
2671
            default: return 0;
2672
        }
2673
     }
2674
     """
2675
)
2676
test("switch 3",
2677
     """int main(){
2678
        switch(5){
2679
            case 0: return 3;
2680
            case 1: return 2;
2681
            case 2: return 1;
2682
            default: return 0;
2683
        }
2684
     }
2685
     """
2686
)
2687
test("switch 4",
2688
     """int main(){
2689
        int a = 0;
2690
        switch(0){
2691
            case 0: a = 1;
2692
            case 1: a = 2;
2693
            case 2: a = 3;
2694
            default: a = 4;
2695
        }
2696
        return a;
2697
     }
2698
     """
2699
)
2700
test("switch 5",
2701
     """int main(){
2702
        int a = 0;
2703
        switch(1){
2704
            case 0: a = 1;
2705
            case 1: a = 2;
2706
            case 2: a = 3;
2707
            default: a = 4;
2708
        }
2709
        return a;
2710
     }
2711
     """
2712
)
2713
test("switch 6",
2714
     """int main(){
2715
        int a = 1;
2716
        switch(10){
2717
            case 0: a = 1;
2718
            case 1: a = 2;
2719
            case 2: a = 3;
2720
            default: a = 4;
2721
        }
2722
        return a;
2723
     }
2724
     """
2725
)
2726
test("switch 7",
2727
     """int main(){
2728
        int a = 1;
2729
        switch(0){
2730
            case 0: a = 1; break;
2731
            case 1: a = 2; break;
2732
            case 2: a = 3; break;
2733
            default: a = 4; break;
2734
        }
2735
        return a;
2736
     }
2737
     """
2738
)
2739
test("switch 8",
2740
     """int main(){
2741
        int a = 1;
2742
        switch(2){
2743
            case 0: a = 1; break;
2744
            case 1: a = 2; break;
2745
            case 2: a = 3; break;
2746
            default: a = 4; break;
2747
        }
2748
        return a;
2749
     }
2750
     """
2751
)
2752
test("switch 9",
2753
"""int main(){
2754
int a = 1;
2755
switch(9){
2756
    case 0: a = 1; break;
2757
    case 1: a = 2; break;
2758
    case 2: a = 3; break;
2759
    default: a = 4; break;
2760
}
2761
return a;
2762
}
2763
"""
2764
)
2765
 
2766
test("break 0",
2767
"""
2768
int main(){
2769
  int a;
2770
  while(1){
2771
    break;
2772
    assert(0);
2773
  }
2774
  return 0;
2775
}
2776
""")
2777
test("break 1",
2778
"""
2779
int main(){
2780
  int a;
2781
  for(a=0; a<20; a++){
2782
    if(a == 10){
2783
      break;
2784
    }
2785
  }
2786
  assert(a == 10);
2787
  return 0;
2788
}
2789
""")
2790
test("continue 0",
2791
"""
2792
int main(){
2793
  int a;
2794
  for(a=1; a<=10; a++){
2795
    if(a <= 5){
2796
      continue;
2797
    }
2798
    assert(a > 5);
2799
  }
2800
  return 0;
2801
}
2802
""")
2803
test("ternary 0",
2804
"""
2805
int main(){
2806
  int a;
2807
  int b=2;
2808
  int c=3;
2809
  assert((1?2:3) == 2);
2810
  assert((0?2:3) == 3);
2811
  a = 1;
2812
  assert((a?b:c) == 2);
2813
  a = 0;
2814
  assert((a?b:c) == 3);
2815
  assert((1?b:c) == 2);
2816
  assert((0?b:c) == 3);
2817
  return 0;
2818
}
2819
""")
2820
test("inplace 0",
2821
"""
2822
int main(){
2823
  int a = 1;
2824
  a += 1;
2825
  assert(a == 2);
2826
  a -= 1;
2827
  assert(a == 1);
2828
  a *= 2;
2829
  assert(a == 2);
2830
  a /= 2;
2831
  assert(a == 1);
2832
  a |= 2;
2833
  assert(a == 3);
2834
  a &= 2;
2835
  assert(a == 2);
2836
  a <<= 1;
2837
  assert(a == 4);
2838
  a >>= 1;
2839
  assert(a == 2);
2840
  return 0;
2841
}
2842
""")
2843
test("inplace 1",
2844
"""
2845
int main(){
2846
  int a[100];
2847
  a[0] = 1;
2848
  a[20] = 1;
2849
  a[20] += 1;
2850
  assert(a[20] == 2);
2851
  a[20] -= 1;
2852
  assert(a[20] == 1);
2853
  a[20] *= 2;
2854
  assert(a[20] == 2);
2855
  a[20] /= 2;
2856
  assert(a[20] == 1);
2857
  a[20] |= 2;
2858
  assert(a[20] == 3);
2859
  a[20] &= 2;
2860
  assert(a[20] == 2);
2861
  a[20] <<= 1;
2862
  assert(a[20] == 4);
2863
  a[20] >>= 1;
2864
  assert(a[20] == 2);
2865
  assert(a[0] == 1);
2866
  return 0;
2867
}
2868
""")
2869
test("increment",
2870
"""
2871
int main(){
2872
  int a = 1;
2873
  a++;
2874
  assert(a == 2);
2875
  a--;
2876
  assert(a == 1);
2877
  return 0;
2878
}
2879
 
2880
""")
2881
 
2882
test("assert 0",
2883
"""int main(){
2884
  assert(1);
2885
  return 0;
2886
}
2887
""")
2888
test_fails("assert 1",
2889
"""int main(){
2890
  assert(0);
2891
  return 0;
2892
}
2893
""")
2894
test("assign",
2895
"""int main(){
2896
  int a;
2897
  int b;
2898
  int c;
2899
  a = 10;
2900
  b = 20;
2901
  c = a + b;
2902
  assert(a == 10);
2903
  assert(b == 20);
2904
  assert(c == 30);
2905
  return 0;
2906
}
2907
""")
2908
test("while",
2909
"""int main(){
2910
  int a = 10;
2911
  int b = 0;
2912
  while(a){
2913
    a = a - 1;
2914
    b = b + 1;
2915
  }
2916
  assert(b == 10);
2917
  return 0;
2918
}
2919
""")
2920
test("while 1",
2921
"""int main(){
2922
  int a = 0;
2923
  while(1){
2924
    a = a + 1;
2925
    if(a == 10){
2926
      return 0;
2927
    }
2928
  }
2929
}
2930
""")
2931
test("while 2",
2932
"""int main(){
2933
  while(0){
2934
    assert(0);
2935
  }
2936
  return 0;
2937
}
2938
""")
2939
test("if",
2940
"""int main(){
2941
  int a = 0;
2942
  int b = 0;
2943
  if(a){
2944
    b = 10;
2945
    assert(0);
2946
  } else {
2947
    b = 20;
2948
  }
2949
  assert(b == 20);
2950
  return 0;
2951
}
2952
""")
2953
test("if 1",
2954
"""int main(){
2955
  int a = 1;
2956
  int b = 0;
2957
  if(a){
2958
    b = 10;
2959
  } else {
2960
    b = 20;
2961
    assert(0);
2962
  }
2963
  assert(b == 10);
2964
  return 0;
2965
}
2966
""")
2967
test("if 2",
2968
"""int main(){
2969
  int b = 0;
2970
  if(0){
2971
    b = 10;
2972
    assert(0);
2973
  } else {
2974
    b = 20;
2975
  }
2976
  assert(b == 20);
2977
  return 0;
2978
}
2979
""")
2980
test("if 3",
2981
"""int main(){
2982
  int b = 0;
2983
  if(1){
2984
    b = 10;
2985
  } else {
2986
    b = 20;
2987
    assert(0);
2988
  }
2989
  assert(b == 10);
2990
  return 0;
2991
}
2992
""")
2993
test("if 4",
2994
"""int main(){
2995
  int b = 0;
2996
  if(0){
2997
    b = 10;
2998
    assert(0);
2999
  }
3000
  assert(b == 0);
3001
  return 0;
3002
}
3003
""")
3004
test("for 0",
3005
"""int main(){
3006
  int a = 0;
3007
  int b;
3008
  int c = 1;
3009
  for(a=0; a<10; a++){
3010
   b = b + 1;
3011
   c = c + 1;
3012
  }
3013
  assert(b == 10);
3014
  assert(c == 11);
3015
  return 0;
3016
}
3017
""")
3018
test("for 1",
3019
"""int main(){
3020
  int a = 0;
3021
  int b;
3022
  int c = 1;
3023
  for(; a<10; a++){
3024
   b = b + 1;
3025
   c = c + 1;
3026
  }
3027
  assert(b == 10);
3028
  assert(c == 11);
3029
  return 0;
3030
}
3031
""")
3032
test("for 2",
3033
"""int main(){
3034
  int a = 0;
3035
  int b;
3036
  int c = 1;
3037
  for(;a<10;){
3038
   b = b + 1;
3039
   c = c + 1;
3040
   a++;
3041
  }
3042
  assert(b == 10);
3043
  assert(c == 11);
3044
  return 0;
3045
}
3046
""")
3047
test("for 3",
3048
"""int main(){
3049
  int a = 0;
3050
  int b;
3051
  int c = 1;
3052
  for(;;){
3053
   if(a>=10) break;
3054
   b = b + 1;
3055
   c = c + 1;
3056
   a++;
3057
  }
3058
  assert(b == 10);
3059
  assert(c == 11);
3060
  return 0;
3061
}
3062
""")
3063
test("number 0",
3064
"""int main(){
3065
  return 1;
3066
}
3067
""")
3068
test("report 0",
3069
"""int main(){
3070
  int a = 0;
3071
  int b = 1;
3072
  int c = 2;
3073
  report(a);
3074
  report(b);
3075
  report(c);
3076
  return 0;
3077
}
3078
""")
3079
test("declare 0",
3080
"""int main(){
3081
  int a = 10;
3082
  int b = 20, c = 30;
3083
  int d[100], e[200];
3084
  assert(a==10);
3085
  assert(b==20);
3086
  assert(c==30);
3087
  return 0;
3088
}
3089
""")
3090
test("wait_clocks 0",
3091
"""int main(){
3092
  int a = 10;
3093
  wait_clocks(a);
3094
  wait_clocks(10);
3095
  return 0;
3096
}
3097
""")
3098
test("function",
3099
"""
3100
 
3101
int func(int a){
3102
  return a + 10;
3103
}
3104
 
3105
int main(){
3106
  int a = func(10);
3107
  assert(a == 20);
3108
  return 0;
3109
}
3110
 
3111
""")
3112
test("function 1",
3113
"""
3114
 
3115
int func(int a){
3116
  assert(a == 20);
3117
  return 0;
3118
}
3119
 
3120
int main(){
3121
  func(20);
3122
  return 0;
3123
}
3124
 
3125
""")
3126
 
3127
test("function 2",
3128
"""
3129
 
3130
int func(int a, int b, int c){
3131
  return a;
3132
}
3133
 
3134
int main(){
3135
  assert(func(1, 2, 3) == 1);
3136
  return 0;
3137
}
3138
 
3139
""")
3140
 
3141
test("function 3",
3142
"""
3143
 
3144
int func(int a, int b, int c){
3145
  return b;
3146
}
3147
 
3148
int main(){
3149
  assert(func(1, 2, 3) == 2);
3150
  return 0;
3151
}
3152
 
3153
""")
3154
 
3155
test("function 4",
3156
"""
3157
 
3158
int func(int a, int b, int c){
3159
  return c;
3160
}
3161
 
3162
int main(){
3163
  assert(func(1, 2, 3) == 3);
3164
  return 0;
3165
}
3166
 
3167
""")
3168
 
3169
test("function 5",
3170
"""
3171
 
3172
int another(int a){
3173
  return a + 1;
3174
}
3175
 
3176
int func(int a){
3177
  return another(a) + 1;
3178
}
3179
 
3180
int main(){
3181
  assert(func(0) == 2);
3182
  return 0;
3183
}
3184
 
3185
""")
3186
 
3187
test_fails("function 6",
3188
"""
3189
 
3190
int func(int a, int b){
3191
  return b;
3192
}
3193
 
3194
int main(){
3195
  assert(func(1, 2, 3) == 3);
3196
  return 0;
3197
}
3198
 
3199
""")
3200
test("expression 1",
3201
"""
3202
int main(){
3203
  int a = 1;
3204
  int b = 2;
3205
  int c = 3;
3206
  assert(a + b + c == 6);
3207
  return 0;
3208
}
3209
 
3210
""")
3211
test("expression 2",
3212
"""
3213
int main(){
3214
  int a = 1;
3215
  int b = 2;
3216
  int c = 3;
3217
  assert(a - b - c == -4);
3218
  return 0;
3219
}
3220
 
3221
""")
3222
test("expression 3",
3223
"""
3224
int main(){
3225
  int a = 1;
3226
  int b = 2;
3227
  int c = 3;
3228
  assert(a - (b - c) == 2);
3229
  return 0;
3230
}
3231
 
3232
""")
3233
test("expression 4",
3234
"""
3235
int main(){
3236
  int a = 1;
3237
  int b = 2;
3238
  int c = 3;
3239
  assert(a * b * c == 6);
3240
  return 0;
3241
}
3242
 
3243
""")
3244
test("expression 5",
3245
"""
3246
int main(){
3247
  int a = 1;
3248
  int b = 2;
3249
  int c = 3;
3250
  assert(a/b/c == 0);
3251
  return 0;
3252
}
3253
 
3254
""")
3255
test("expression 6",
3256
"""
3257
int main(){
3258
  int a = 1;
3259
  int b = 2;
3260
  int c = 3;
3261
  assert(a%b%c == 1);
3262
  return 0;
3263
}
3264
 
3265
""")
3266
test("expression 7",
3267
"""
3268
int main(){
3269
  int a = 1;
3270
  int b = 2;
3271
  int c = 3;
3272
  assert(-a - (b - c) == 0);
3273
  return 0;
3274
}
3275
 
3276
""")
3277
test("expression 8",
3278
"""
3279
int fail(){
3280
  assert(0);
3281
  return 0;
3282
}
3283
int main(){
3284
  int a = 0 && fail();
3285
  return 0;
3286
}
3287
 
3288
""")
3289
test("expression 9",
3290
"""
3291
int fail(){
3292
  assert(0);
3293
  return 0;
3294
}
3295
int main(){
3296
  int a = 1 || fail();
3297
  return 0;
3298
}
3299
 
3300
""")
3301
test("expression 10",
3302
"""
3303
int main(){
3304
  int a = 1;
3305
  assert(a << 2 == 4);
3306
  return 0;
3307
}
3308
 
3309
""")
3310
test("expression 11",
3311
"""
3312
int main(){
3313
  int a = 1;
3314
  int b = 2;
3315
  assert(a << b == 4);
3316
  return 0;
3317
}
3318
 
3319
""")
3320
test("expression 12",
3321
"""
3322
int main(){
3323
  int a = 4;
3324
  assert(a >> 2 == 1);
3325
  return 0;
3326
}
3327
 
3328
""")
3329
test("expression 13",
3330
"""
3331
int main(){
3332
  int a = 4;
3333
  int b = 2;
3334
  assert(a >> b == 1);
3335
  return 0;
3336
}
3337
 
3338
""")
3339
test("expression 14",
3340
"""
3341
int main(){
3342
  int a = -1;
3343
  assert(~a == 0);
3344
  return 0;
3345
}
3346
 
3347
""")
3348
test("expression 15",
3349
"""
3350
int main(){
3351
  int a = 1;
3352
  assert(!a == 0);
3353
  int a = 0;
3354
  assert(!a == 1);
3355
  return 0;
3356
}
3357
 
3358
""")
3359
test("expression 16",
3360
"""
3361
int main(){
3362
  int a = 0xA;
3363
  int b = 0x5;
3364
  assert((a | b) == 0xF);
3365
  assert((a ^ b) == 0xf);
3366
  assert((a & b) == 0);
3367
  return 0;
3368
}
3369
 
3370
""")
3371
test("expression 17",
3372
"""
3373
int fail(){
3374
  assert(0);
3375
  return 0;
3376
}
3377
int main(){
3378
  int b = 0;
3379
  int a = b && fail();
3380
  return 0;
3381
}
3382
 
3383
""")
3384
test("expression 18",
3385
"""
3386
int fail(){
3387
  assert(0);
3388
  return 0;
3389
}
3390
int main(){
3391
  assert(~1);
3392
  return 0;
3393
}
3394
 
3395
""")
3396
test("expression 19",
3397
"""
3398
int main(){
3399
  assert(-1 < 1);
3400
  assert(-1 < 0);
3401
  assert(0 <= 0);
3402
  assert(0 >= 0);
3403
  assert(1 >= 0);
3404
  assert(1 >= -1);
3405
  assert(1 > -1);
3406
  assert(1 > 0);
3407
  assert(12 != 13);
3408
  assert(100 == 100);
3409
  return 0;
3410
}
3411
 
3412
""")
3413
test("expression 20",
3414
"""
3415
int main(){
3416
  int a = -1;
3417
  assert(a >> 2 == -1);
3418
  return 0;
3419
}
3420
 
3421
""")
3422
test("comment 0",
3423
"""
3424
int main(){
3425
  //assert(0);
3426
  //assert(0);
3427
  //assert(0);
3428
  return 0;
3429
}
3430
 
3431
""")
3432
test("comment 1",
3433
"""
3434
int main(){
3435
  /*assert(0);
3436
  assert(0);
3437
  assert(0);*/
3438
  return 0;
3439
}
3440
 
3441
""")
3442
test("array 0",
3443
"""
3444
int main(){
3445
  int a [1024];
3446
  int b [1024];
3447
  a[0] = 1;
3448
  a[1] = 2;
3449
  a[3] = 3;
3450
  assert(a[0] == 1);
3451
  assert(a[1] == 2);
3452
  assert(a[3] == 3);
3453
  return 0;
3454
}
3455
 
3456
""")
3457
 
3458
test("array 1",
3459
"""
3460
int main(){
3461
  int a [1024];
3462
  int b [1024];
3463
  a[0] = 10;
3464
  b[0] = 20;
3465
  a[1] = 30;
3466
  b[1] = 40;
3467
  a[3] = 50;
3468
  b[3] = 60;
3469
  assert(a[0] == 10);
3470
  assert(b[0] == 20);
3471
  assert(a[1] == 30);
3472
  assert(b[1] == 40);
3473
  assert(a[3] == 50);
3474
  assert(b[3] == 60);
3475
  return 0;
3476
}
3477
 
3478
""")
3479
 
3480
test_fails("error 0",
3481
"""
3482
int main(){
3483
  int a;
3484
  a = c;
3485
  return 0;
3486
}
3487
 
3488
""")
3489
 
3490
test_fails("error 1",
3491
"""
3492
int main(){
3493
  int a;
3494
}
3495
 
3496
""")
3497
 
3498
test_fails("error 2",
3499
"""
3500
int main(){
3501
  int a blah;
3502
}
3503
 
3504
""")
3505
 
3506
test_fails("error 3",
3507
"""
3508
int main(){
3509
  int a;
3510
  b = a;
3511
}
3512
 
3513
""")
3514
 
3515
test_fails("error 4",
3516
"""
3517
int main(){
3518
  int a;
3519
  a = c();
3520
}
3521
 
3522
""")
3523
 
3524
test_fails("error 5",
3525
"""
3526
int main(){
3527
  int a;
3528
  a==;
3529
}
3530
 
3531
""")
3532
test_fails("error 6",
3533
"""
3534
int main(){
3535
  int a;
3536
  a=00x;
3537
}
3538
 
3539
""")
3540
test_fails("error 7",
3541
"""
3542
int main(){
3543
  switch(1){
3544
    case 0:
3545
    default:
3546
    default:
3547
  }
3548
  return 0;
3549
}
3550
""")
3551
test_fails("error 8",
3552
"""
3553
int main(){
3554
  default:
3555
  return 0;
3556
}
3557
""")
3558
test_fails("error 9",
3559
"""
3560
int main(){
3561
  case 1:
3562
  return 0;
3563
}
3564
""")
3565
test_fails("error 10",
3566
"""
3567
int main(){
3568
  int a = 12;
3569
  switch(a){
3570
    case a + 1:
3571
    a++;
3572
  }
3573
  return 0;
3574
}
3575
""")
3576
test_fails("error 11",
3577
"""
3578
int myfunction(){
3579
  return 0;
3580
}
3581
int main(){
3582
  int a = 12;
3583
  myfunction()=10;
3584
  return 0;
3585
}
3586
""")
3587 4 jondawson
 
3588
test_fails("error 12",
3589
"""
3590
 
3591
typedef struct {long int a; int b;} struct_1;
3592
typedef struct {long int a; struct_1 b;} mystruct;
3593
 
3594
void test(mystruct my){
3595
    assert(mystruct.a == 1);
3596
    assert(mystruct.b.a == 2);
3597
    assert(mystruct.b.b == 3);
3598
}
3599
 
3600
void main(){
3601
    mystruct blah;
3602
    blah.a = 1;
3603
    blah.b.a = 2;
3604
    blah.b.b = 3;
3605
    test(blah);
3606
}
3607
"""
3608
)
3609
 
3610 2 jondawson
test("input 1",
3611
"""
3612
int main(){
3613
  int b;
3614
  b = input_a();
3615
  return 0;
3616
}
3617
 
3618
""")
3619
 
3620
test("output 1",
3621
"""
3622
int main(){
3623
   output_a(12);
3624
  return 0;
3625
}
3626
 
3627
""")
3628
 
3629
test("input output 1",
3630
"""
3631
int main(){
3632
  if (input_select()){
3633
    output_z(input_a());
3634
  } else {
3635
    output_z(input_b());
3636
  }
3637
  return 0;
3638
}
3639
 
3640
""")
3641
 
3642
test("input output 2",
3643
"""
3644
int arbiter(){
3645
  while(1){
3646
    if(ready_a()) output_z(input_a());
3647
    if(ready_b()) output_z(input_b());
3648
  }
3649
  return 0;
3650
}
3651
 
3652
""")
3653
 
3654
test("main not main",
3655
"""
3656
int main(){
3657
  assert(0);
3658
  return 0;
3659
}
3660
 
3661
//last function is always main
3662
int real_main(){
3663
  return 0;
3664
}
3665
""")
3666
 
3667 4 jondawson
os.system("python-coverage run -p ../c2verilog")
3668 2 jondawson
os.system("python-coverage combine")
3669
os.system("python-coverage report")
3670 4 jondawson
os.system("python-coverage annotate ../c2verilog")
3671
os.system("python-coverage annotate ../chips/compiler/parser.py")

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.