ktest_tc_ipc.c
172 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* ktest_tc_ipc.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* The file implements MediaTek KAL (Kernel Abstraction Layer) auto test
* task functions.
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
*
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================*/
/* this file is valid only when __KTEST__ has been defined */
#ifdef __KTEST__
#include "ktest_common.h"
#include "kal_release.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h"
#include "stack_ltlcom.h"
#include "stack_config.h"
#include "stack_types.h"
#include "task_config.h"
#include "lcd_ip_cqueue.h"
/******************************************************************************
* external APIs and variables that will be used in this file.
*****************************************************************************/
extern kal_uint32 kal_get_mytask_priority( void );
extern void *kal_sys_mem_alloc( kal_uint32 size );
extern int rand( void );
/******************************************************************************
* macros
*****************************************************************************/
#define tick_diff(t1, t2) ((int)( (t1) - (t2) ))
#define GPT_TICKSPERSEC 100
typedef void (*gpt_timer_handler)( void * );
#define MY_REPORT_RETURN3( code, tcname, fmt ) \
ktest_report_reset3( code, tcname, fmt );\
return code;
/******************************************************************************
* Name:
* busyloop_delay_count
* Functionality:
* delay some time in a busy loop.
* Parameters:
* count: how many loops do you want to delay.
* Returns:
* void.
* Note:
* this function is used to support test cases.
* and it can modify the value of __useless.
*****************************************************************************/
static volatile int __useless;
static void busyloop_delay_count( int count )
{
int i;
for( i = 0; i < count; i++ )
{
__useless = i;
}
}
/******************************************************************************
* Name:
* busyloop_delay_base
* Functionality:
* caculate the delay_base ( how many loops in a million second ).
* Parameters:
* void.
* Returns:
* the value of that how many loops will be executed in a million second.
* Note:
* this function is used to support test cases.
* and it can modify the value of __useless.
*****************************************************************************/
static int delay_base;
static int busyloop_delay_base( void )
{
int i = 0;
#define DELAY_MAX ( 1024 * 1024 * 4 )
kal_uint32 start, now;
kal_get_time( &start );
for( i = 0; i < DELAY_MAX; i++ )
{
__useless = i;
}
kal_get_time( &now );
delay_base = DELAY_MAX / (int) ( now - start );
return delay_base;
}
/******************************************************************************
* Name:
* busyloop_delay
* Functionality:
* delay some time in a busy loop.
* Parameters:
* ticks: how many ticks do you want to delay.
* Returns:
* void.
* Notes:
* this function is used to support test cases.
* and it can modify the value of __useless indirectly.
*****************************************************************************/
static void busyloop_delay( kal_int32 ticks )
{
busyloop_delay_count( ticks * delay_base );
}
/******************************************************************************
* Name:
* rand2
* Functionality:
* randomize a value.
* Parameters:
* lower: the lower limitation of the generated value.
* upper: the upper limitation of the generated value.
* Returns:
* the generated value.
* Notes:
* this function is used to support test cases.
* and the generated value is in cope of [lower, upper)
*****************************************************************************/
int rand2( int lower, int upper )
{
int range = upper - lower;
if( range <= 0 )
{
return lower;
}
return lower + rand() % range;
}
/******************************************************************************
* a structure that contains 2 parts:
* part1: the header of a local_para_struct
* part2: a integer value.
*****************************************************************************/
struct local_para_test_t
{
LOCAL_PARA_HDR
int a;
};
/******************************************************************************
* Name:
* ktest_ipc_allocate_ilm1
* Functionality:
* test the basic functionality of allocate_ilm/free_ilm.
* Results:
* if the functions executed correctly, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_allocate_ilm1( kal_uint32 argc, void *argv )
{
ilm_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = allocate_ilm( MOD_IDLE );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"allocate_ilm returns NULL" );
}
p->msg_id = (msg_type) 100;
free_ilm( p );
/* allocate_ilm/free_ilm executed successfully. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_allocate_ilm2
* Functionality:
* test the basic functionality of allocate_ilm/cancel_ilm.
* Results:
* if the functions executed correctly, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_allocate_ilm2( kal_uint32 argc, void *argv )
{
ilm_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = allocate_ilm( MOD_IDLE );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"allocate_ilm returns NULL" );
}
cancel_ilm( MOD_IDLE );
/* allocate_ilm/cancel_ilm executed successfully. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_allocate_ilm3
* Functionality:
* test whether allocate_ilm can detect double-allocation.
* Results:
* if KAL_ERROR_ITC_ILM_MULTIALLOC occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_allocate_ilm3( kal_uint32 argc, void *argv )
{
ilm_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_ILM_MULTIALLOC;
p = allocate_ilm( MOD_IDLE );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"the first allocate_ilm returns NULL" );
}
p->msg_id = (msg_type) 100;
/* below is a double-allocation, and a fatal error is expected. */
p = allocate_ilm( MOD_IDLE );
/* no fatal error occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_allocate_ilm4
* Functionality:
* test whether allocate_ilm can detect double-allocation with a free_ilm
* between them.
* Results:
* if KAL_ERROR_ITC_ILM_MULTIALLOC occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_allocate_ilm4( kal_uint32 argc, void *argv )
{
ilm_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_ILM_MULTIALLOC;
p = allocate_ilm( MOD_IDLE );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"the first allocate_ilm returns NULL" );
}
p->msg_id = (msg_type) 100;
free_ilm( p );
/* below is a double-allocation, and a fatal error is expected. */
p = allocate_ilm( MOD_IDLE );
/* no fatal error occurs, and this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_allocate_ilm5
* Functionality:
* test the execution sequence of allocate_ilm, cancel_ilm, allocate_ilm.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_allocate_ilm5( kal_uint32 argc, void *argv )
{
ilm_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = allocate_ilm( MOD_IDLE );
cancel_ilm( MOD_IDLE );
/* since cancel_ilm can clear the allocation bit mask, so we can use
* allocate_ilm again, and no fatal error occurs. */
p = allocate_ilm( MOD_IDLE );
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_construct_local_para
* Functionality:
* test the basic functionality of construct_local_para/free_local_para.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_construct_local_para( kal_uint32 argc, void *argv )
{
struct local_para_test_t *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_local_para( sizeof( struct local_para_test_t ), TD_RESET );
/* since we used TD_RESET as a parameter when calling construct_local_para,
* so the integer value "a" in local_para_test_t will be 0. */
if( p->a != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "p->a != 0" );
}
p->a = 0xFE3D124A;
free_local_para( (local_para_struct *) p );
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_hold_local_para
* Functionality:
* test multiple hold_local_para followed by multiple free_local_para.
* note that free_local_para is called one more time that hold_local_para.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_hold_local_para( kal_uint32 argc, void *argv )
{
struct local_para_test_t *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_local_para( sizeof( struct local_para_test_t ), TD_RESET );
/* since we used TD_RESET as a parameter when calling construct_local_para,
* so the integer value "a" in local_para_test_t will be 0. */
if( p->a != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "p->a != 0" );
}
p->a = 0xFE3D124A;
/* hold_local_para is called 2 times */
hold_local_para( (local_para_struct *) p );
hold_local_para( (local_para_struct *) p );
/* free_local_para is called one more time than hold_local_para, so no
* double-free error occurs here. */
free_local_para( (local_para_struct *) p );
free_local_para( (local_para_struct *) p );
free_local_para( (local_para_struct *) p );
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_hold_local_para2
* Functionality:
* test whether free_local_para can detect a double-free error.
* Results:
* if KAL_ERROR_ITC_ILM_DOUBLE_FREE occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_hold_local_para2( kal_uint32 argc, void *argv )
{
struct local_para_test_t *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_local_para( sizeof( struct local_para_test_t ), TD_RESET );
/* since we used TD_RESET as a parameter when calling construct_local_para,
* so the integer value "a" in local_para_test_t will be 0. */
if( p->a != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "p->a != 0" );
}
p->a = 0xFE3D124A;
/* hold_local_para 2 times and free_local_para 3 times,
* after this, the ref_count of local para will be 0. */
hold_local_para( (local_para_struct *) p );
hold_local_para( (local_para_struct *) p );
free_local_para( (local_para_struct *) p );
free_local_para( (local_para_struct *) p );
free_local_para( (local_para_struct *) p );
/* below is a double-free fatal error, and a fatal error is expected here.
*/
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_ILM_DOUBLE_FREE;
free_local_para( (local_para_struct *) p );
/* no error occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "We should detect extra free" );
}
/******************************************************************************
* Name:
* ktest_ipc_get_local_para_ptr
* Functionality:
* test the basic functionality of get_local_para_ptr
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_get_local_para_ptr( kal_uint32 argc, void *argv )
{
struct local_para_test_t *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_local_para( sizeof( struct local_para_test_t ), TD_RESET );
/* since we used TD_RESET as a parameter when calling construct_local_para,
* so the integer value "a" in local_para_test_t will be 0. */
if( p->a != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "p->a != 0" );
}
p->a = 0xFE3D124A;
/* test the basic functionality of get_local_para */
{
void *dp;
kal_uint16 dlen;
dp = get_local_para_ptr( (local_para_struct *) p, &dlen );
if( dp == NULL || dlen < sizeof( struct local_para_test_t ) )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"dp(%p) == NULL || dlen(%u) < sizeof(local_para_test_t)(%u)",
dp, dlen, sizeof( struct local_para_test_t ) );
return KTEST_FAIL;
}
}
/* no error occurs in get_local_para_ptr, free the local_para_struct
* and report PASS. */
free_local_para( (local_para_struct *) p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_construct_peer_buff
* Functionality:
* test the basic functionality of construct_peer_buff/free_peer_buff.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_construct_peer_buff( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_peer_buff( 100, 16, 16, 0 );
/* if can't construct a peer_buff, report FAIL. */
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "p == NULL" );
}
/* no error occurs, free the peer_buff and report PASS. */
free_peer_buff( p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_hold_peer_buff
* Functionality:
* test hold_peer_buff multiple times followed by free_peer_buff multiple
* times ( one more than hold_peer_buff ).
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_hold_peer_buff( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* call hold_peer_buff 2 times*/
hold_peer_buff( p );
hold_peer_buff( p );
/* call free_peer_buff 3 times, so the ref_count will be 0,
*and no double-free fatal error occurs. */
free_peer_buff( p );
free_peer_buff( p );
free_peer_buff( p );
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_hold_peer_buff2
* Functionality:
* test whether free_peer_buff can detect double-free fatal error.
* Results:
* if KAL_ERROR_ITC_ILM_DOUBLE_FREE occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_hold_peer_buff2( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* hold_peer_buff 2 times and free_peer_buff 3 times, then the ref_count
* will be 0, and no double-free fatal error occurs till now. */
hold_peer_buff( p );
hold_peer_buff( p );
free_peer_buff( p );
free_peer_buff( p );
free_peer_buff( p );
/* one more free_peer_buff, a double-free fatal error is expected here. */
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_ILM_DOUBLE_FREE;
free_peer_buff( p );
/* no error occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "We should detect extra free" );
}
/******************************************************************************
* Name:
* ktest_ipc_get_pdu_ptr
* Functionality:
* test the basic functionality of ktest_ipc_get_pdu_ptr
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_get_pdu_ptr( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test the basic functionality of ktest_ipc_get_pdu_ptr */
{
void *dp;
kal_uint16 dlen;
dp = get_pdu_ptr( p, &dlen );
/* if can't get pdu_ptr correctly, report FAIL. */
if( dp == NULL || dlen != 100 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp == NULL || dlen != 100" );
}
strcpy( (char *) dp, "Hello world.\n" );
}
/* no error occurs, free peer buffer and report PASS. */
free_peer_buff( p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_prepend_to_peer_buff
* Functionality:
* test the basic functionality of prepend_to_peer_buff and
remove_hdr_of_peer_buff.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_prepend_to_peer_buff( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL ) {
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test the basic functionality of
* prepend_to_peer_buff and remove_hdr_of_peer_buff */
{
void *dp, *dp2;
kal_uint16 dlen, dlen2;
dp = get_pdu_ptr( p, &dlen );
/* if can't get pdu_ptr correctly, report FAIL. */
if( dp == NULL || dlen != 100 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp == NULL || dlen != 100" );
}
/* prepend 8 characters to peer buffer */
prepend_to_peer_buff( p, "12345678", 8 );
dp2 = get_pdu_ptr( p, &dlen2 );
if( ( (char *) dp2 + 8 ) != dp || ( dlen2 - 8 ) != dlen )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"(dp2 + 8) != dp || (dlen2 - 8) != dlen" );
}
/* remove 8 characters from the hdr of peer_buff */
remove_hdr_of_peer_buff( p, 8 );
dp2 = get_pdu_ptr( p, &dlen2 );
if( dp2 != dp || dlen2 != dlen )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp2 != dp || dlen2 != dlen" );
}
}
/* no error occurs, free peer buffer and report PASS. */
free_peer_buff( p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_prepend_to_peer_buff2
* Functionality:
* test prepend_to_peer_buff when its header buffer room is not enough.
* Results:
* if RPS_COMMON_ERROR_INSUFF_MEM occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_prepend_to_peer_buff2( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0x10; /* RPS_COMMON_ERROR_INSUFF_MEM */
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test prepend_to_peer_buff when its header buffer room is not enough */
{
void *dp;
kal_uint16 dlen;
dp = get_pdu_ptr( p, &dlen );
/* if can't get pdu_ptr correctly, report FAIL. */
if( dp == NULL || dlen != 100 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp == NULL || dlen != 100" );
}
/* prepend 16 characters to peer_buff, and header of peer_buff will have
* no room now. */
prepend_to_peer_buff( p, "1234567890ABCDEF", 16 );
/* prepend another character to peer_buff, since the header has no room
* now, so a fatal error is expected here. */
prepend_to_peer_buff( p, "a", 1 );
}
/* no error occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "exception should happened" );
}
/******************************************************************************
* Name:
* ktest_ipc_append_to_peer_buff
* Functionality:
* test the basic functionality of append_to_peer_buff and
* remove_tail_of_peer_buff.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_append_to_peer_buff( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test append_to_peer_buff and remove_tail_of_peer_buff */
{
void *dp, *dp2;
kal_uint16 dlen, dlen2;
dp = get_pdu_ptr( p, &dlen );
if( dp == NULL || dlen != 100 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp == NULL || dlen != 100" );
}
/* append 8 characters to peer_buff's tail,
* if not success, report FAIL. */
append_to_peer_buff( p, "12345678", 8 );
dp2 = get_pdu_ptr( p, &dlen2 );
if( dp2 != dp || ( dlen2 - 8 ) != dlen )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp2 != dp || (dlen2 - 8) != dlen" );
}
/* remove 8 characters from peer_buff's tail,
* if not success, report FAIL. */
remove_tail_of_peer_buff( p, 8 );
dp2 = get_pdu_ptr( p, &dlen2 );
if( dp2 != dp || dlen2 != dlen )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp2 != dp || dlen2 != dlen" );
}
}
/* no error occurs, free peer_buff and report PASS. */
free_peer_buff( p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_append_to_peer_buff2
* Functionality:
* test append_to_peer_buff with insufficient room in peer_buff's tail.
* Results:
* if RPS_COMMON_ERROR_INSUFF_MEM occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_append_to_peer_buff2( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0x10; /* RPS_COMMON_ERROR_INSUFF_MEM */
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test append_to_peer_buff with insufficient room in peer_buff's tail */
{
void *dp;
kal_uint16 dlen;
dp = get_pdu_ptr( p, &dlen );
if( dp == NULL || dlen != 100 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"dp == NULL || dlen != 100" );
}
/* append 16 characters to peer_buff's tail, then peer_buff's tail will
* have no room left. */
append_to_peer_buff( p, "1234567890ABCDEF", 16 );
/* append another character to peer_buff's tail, and a fatal error is
* expected here. */
append_to_peer_buff( p, "a", 1 );
}
/* no error occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "exception should happened" );
}
/******************************************************************************
* Name:
* ktest_ipc_update_peer_buff_hdr
* Functionality:
* test update_peer_buff_hdr with the total size unchanged.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_update_peer_buff_hdr( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0x10;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test update_peer_buff with the total size unchanged */
{
void *dp;
kal_uint16 dlen;
/* set new size of peer_buff's header, pdu and tail.
* the new size is: header: 0, pdu: 132, tail: 0. */
update_peer_buff_hdr( p, 0, 132, 0 );
dp = get_pdu_ptr( p, &dlen );
if( dp == NULL || dlen != 132 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"dp(%p) == NULL || dlen(%d) != 132", dp, dlen );
ktest_reset_target();
}
}
/* no error occurs, free peer_buff and report PASS. */
free_peer_buff( p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_update_peer_buff_hdrE1
* Functionality:
* test update_peer_buff_hdr with the total size enlarged.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
* Note:
* this test case is not completed yet, and we want to detect the change of
* peer_buff's total size.
*****************************************************************************/
kal_int32 ktest_ipc_update_peer_buff_hdrE1( kal_uint32 argc, void *argv )
{
peer_buff_struct *p;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0x10;
p = construct_peer_buff( 100, 16, 16, 0 );
if( p == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"construct_peer_buff returns NULL" );
}
/* test update_peer_buff_hdr with total size enlarged */
{
void *dp;
kal_uint16 dlen;
/* enlarge peer_buff's size by 1 byte */
update_peer_buff_hdr( p, 0, 132 + 1, 0 );
dp = get_pdu_ptr( p, &dlen );
if( dp == NULL || dlen != 132 + 1 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"dp(%p) == NULL || dlen(%d) != 132 + 1", dp, dlen );
ktest_reset_target();
}
}
/* no error occurs, free peer_buff and report PASS. */
free_peer_buff( p );
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID,
"Suggest to detect total peer buffer size changed" );
}
/******************************************************************************
* for MAUI KAL USER MANUAL 5.4
* Task Communication APIs for special purposes ( NOT encourage ).
*****************************************************************************/
#define TESTQ_RECORDSIZE 22
#define TESTQ_SLOTS 16
/******************************************************************************
* Name:
* ktest_ipc_create_msgq
* Functionality:
* test the basic functionality of kal_create_msg_q and kal_get_queue_info.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_create_msgq( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_msgq_info msgq_info;
kal_bool r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
r = kal_get_queue_info( msgq, &msgq_info );
if( r != KAL_TRUE || msgq_info.pending_msgs != 0
|| msgq_info.max_msgs != TESTQ_SLOTS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_get_queue_info failed: ret=%d, pending=%d, max=%d",
r, msgq_info.pending_msgs, msgq_info.max_msgs );
return KTEST_FAIL;
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enqueue_msgq1
* Functionality:
* test kal_enque_msg: insert messages to a not-full queue in the pattern
* of KAL_NO_WAIT.
* Results:
* if no error occrus, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enqueue_msgq1( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_msgq_info msgq_info;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages to the queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
char buf[TESTQ_RECORDSIZE];
int j;
/* generate a message string */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
buf[j] = '0' + i + j % 32;
}
buf[j] = 0;
/* insert this message into the queue, use KAL_NO_WAIT. */
r = kal_enque_msg( msgq, buf, TESTQ_RECORDSIZE, KAL_NO_WAIT, KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
return KTEST_FAIL;
}
/* check whether the queue's information is correct */
r = kal_get_queue_info( msgq, &msgq_info );
if( r != KAL_TRUE || msgq_info.pending_msgs != (i + 1) )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_get_queue_info failed: ret = %d, pending = %d",
r, msgq_info.pending_msgs );
return KTEST_FAIL;
}
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enqueue_msgq2
* Functionality:
* test kal_enque_msg: insert messages to a not-full queue in the pattern
* of KAL_INFINITE_WAIT.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enqueue_msgq2( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_msgq_info msgq_info;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_BRIEF = "insert messages to a not-full queue with KAL_INFINITE_WAIT";
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages into the queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
char buf[TESTQ_RECORDSIZE];
int j;
/* generate a message string */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
buf[j] = '0' + i + j % 32;
}
buf[j] = 0;
/* insert this message into the queue, use KAL_INFINITE_WAIT. */
r = kal_enque_msg( msgq, buf, TESTQ_RECORDSIZE, KAL_INFINITE_WAIT, KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "kal_enque_msg failed: ret=%d", r );
return KTEST_FAIL;
}
/* check whether the queue's information is correct */
r = kal_get_queue_info( msgq, &msgq_info );
if( r != KAL_TRUE || msgq_info.pending_msgs != ( i+1 ) )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_get_queue_info failed: ret=%d, pending=%d",
r, msgq_info.pending_msgs );
}
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enqueue_msgq3
* Functionality:
* test kal_enque_msg: insert messages to a full queue in the pattern of
* KAL_NO_WAIT.
* Results:
* if kal_enqueue_msg returns KAL_Q_FULL, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enqueue_msgq3( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages to a queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
r = kal_enque_msg( msgq, "0123456789ABCDEF", TESTQ_RECORDSIZE,
KAL_NO_WAIT, KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
}
}
/* the queue is full now, and the insertion below will return KAL_Q_FULL */
for( i = 0; i < 4; i++ )
{
r = kal_enque_msg( msgq, "", TESTQ_RECORDSIZE, KAL_NO_WAIT, KAL_FALSE );
/* if the return value is not KAL_Q_FULL, then this is not what we
* expected, just report FAIL.*/
if( r != KAL_Q_FULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg(KAL_NO_WAIT) failed: ret=%d", r );
}
}
/* kal_enqueue_msg returns KAL_Q_FULL as we expected, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enqueue_msgq3a
* Functionality:
* test kal_enque_msg: insert messages to a full queue in the pattern of
* KAL_INFINITE_WAIT.
* Results:
* if suspension occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enqueue_msgq3a( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages to the queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
r = kal_enque_msg( msgq, "0123456789ABCDEF", TESTQ_RECORDSIZE,
KAL_NO_WAIT, KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
}
}
/* start a GPT timer to check suspension caused by kal_enque_msg below,
* if suspension occurs, report PASS. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* insert an extra message to a full queue in the pattern of
* KAL_INFINITE_WAIT, and a suspension is expected here. */
kal_enque_msg( msgq, "", TESTQ_RECORDSIZE, KAL_INFINITE_WAIT, KAL_FALSE );
/* if no suspension occurs, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_enque_msg shold not return" );
}
/******************************************************************************
* Name:
* ktest_ipc_enqueue_msgq4
* Functionality:
* test kal_enque_msg to a full queue from head in the pattern of
* KAL_NO_WAIT.
* Results:
* if returns KAL_Q_FULL, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enqueue_msgq4( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert to the queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
r = kal_enque_msg( msgq, "0123456789ABCDEF", TESTQ_RECORDSIZE,
KAL_NO_WAIT, KAL_TRUE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
}
}
/* the queue is full now, and insertion below will return KAL_Q_FULL. */
for( i = 0; i < 4; i++ )
{
r = kal_enque_msg( msgq, "", TESTQ_RECORDSIZE, KAL_NO_WAIT, KAL_TRUE );
/* if the return value is not KAL_Q_FULL, then this is not what we
* expected, just report FAIL. */
if( r != KAL_Q_FULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg(KAL_NO_WAIT) failed: ret=%d", r );
}
}
/* kal_enque_msg returns KAL_Q_FULL as we expected, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enqueue_msgq4a
* Functionality:
* test kal_enque_msg: insert messages to a full queue from head in the
* pattern of KAL_INFINITE_WAIT.
* Results:
* if suspension occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enqueue_msgq4a( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages into the queue from head until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
r = kal_enque_msg( msgq, "0123456789ABCDEF", TESTQ_RECORDSIZE,
KAL_NO_WAIT, KAL_TRUE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
}
}
/* start a GPT timer to check suspension caused by kal_enque_msg below,
* if suspension occurs, report PASS. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* insert an extra message to a full queue in the pattern of
* KAL_INFINITE_WAIT, and a suspension is expected here. */
kal_enque_msg( msgq, "", TESTQ_RECORDSIZE, KAL_INFINITE_WAIT, KAL_TRUE );
/* no suspension occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg should not return" );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgq1
* Functionality:
* test kal_deque_msg: dequeue a message from a non-empty queue whose
* messages are inserted from its tail.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgq1( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_msgq_info msgq_info;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages into the queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
char buf[TESTQ_RECORDSIZE];
int j;
/* generate a message string */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
buf[j] = '0' + i;
}
buf[j] = 0;
r = kal_enque_msg( msgq, buf, TESTQ_RECORDSIZE, KAL_NO_WAIT,
KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
ktest_reset_target();
return KTEST_FAIL;
}
}
/* the queue is full now, then we will test kal_deque_msg's functionality */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen;
int j;
/* test kal_deque_msg's functionality,
* if any error occurs, report FAIL. */
r = kal_deque_msg( msgq, buf, &mlen, KAL_NO_WAIT );
if( r != KAL_SUCCESS || mlen < TESTQ_RECORDSIZE )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_deque_msg failed: ret = %d, mlen = %d",
r, mlen );
ktest_reset_target();
return KTEST_FAIL;
}
/* test the content of the message,
* if it is not correct, report FAIL. */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
if( buf[j] != '0' + i )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue content corruption" );
}
}
if( buf[j] != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue content corruption" );
}
/* test the information about the queue after dequeue completed,
* if it's not correct, report FAIL. */
r = kal_get_queue_info( msgq, &msgq_info );
if( r != KAL_TRUE
|| msgq_info.pending_msgs != (TESTQ_SLOTS - (i + 1)) )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_get_queue_info failed: ret=%d, pending=%d", r,
msgq_info.pending_msgs );
ktest_reset_target();
return KTEST_FAIL;
}
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgq1a
* Functionality:
* test kal_dequeue_msgq: dequeue messages from a non-empty queue whose
* messages are inserted from its head.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgq1a( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_msgq_info msgq_info;
kal_status r;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages into the queue from its head until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
char buf[TESTQ_RECORDSIZE];
int j;
/* generate a message string */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
buf[j] = '0' + i;
}
buf[j] = 0;
/* insert this message to the queue from its head */
r = kal_enque_msg( msgq, buf, TESTQ_RECORDSIZE, KAL_NO_WAIT, KAL_TRUE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
ktest_reset_target();
return KTEST_FAIL;
}
}
/* test the basic functionality of kal_deque_msg */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen;
int j;
/* dequeue a message from the queue,
* if any error occurs, report FAIL. */
r = kal_deque_msg( msgq, buf, &mlen, KAL_NO_WAIT );
if( r != KAL_SUCCESS || mlen < TESTQ_RECORDSIZE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "kal_deque_msg failed: ret=%d", r );
ktest_reset_target();
return KTEST_FAIL;
}
/* test the content of the message, if it's not correct, report FAIL. */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
if( buf[j] != '0' + TESTQ_SLOTS - 1 - i )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue content corruption" );
}
}
if( buf[j] != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue content corruption" );
}
/* test the queue's information after dequeue completed,
* if it's not correct, report FAIL. */
r = kal_get_queue_info( msgq, &msgq_info );
if( r != KAL_TRUE || msgq_info.pending_msgs != (TESTQ_SLOTS - (i + 1)) )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_get_queue_info failed: ret=%d, pending=%d", r,
msgq_info.pending_msgs );
ktest_reset_target();
return KTEST_FAIL;
}
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, NULL );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgq2
* Functionality:
* test kal_deque_msg: dequeue messages from an empty queue after
* enqueue/dequeue operations in the pattern of
* KAL_NO_WAIT.
* Results:
* if returns KAL_Q_EMPTY, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgq2( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_msgq_info msgq_info;
kal_status r;
int i;
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* insert messages into the queue until it's full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
int j;
/* generate a message string */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
buf[j] = '0' + i;
}
buf[j] = 0;
/* insert this message into the queue, if not success, report FAIL. */
r = kal_enque_msg( msgq, buf, TESTQ_RECORDSIZE, KAL_NO_WAIT, KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_enque_msg failed: ret = %d", r );
ktest_reset_target();
return KTEST_FAIL;
}
}
/* dequeue messages from the queue,
* and test the functionality of kal_deque_msg */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
int j;
/* test the basic functionality of kal_deque_msg
* if any error occurs, report FAIL. */
r = kal_deque_msg( msgq, buf, &mlen, KAL_NO_WAIT );
if( r != KAL_SUCCESS || mlen < TESTQ_RECORDSIZE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "kal_deque_msg failed: ret=%d", r );
ktest_reset_target();
return KTEST_FAIL;
}
/* test the content of a message, if it's not correct, report FAIL. */
for( j = 0; j < TESTQ_RECORDSIZE - 1; j++ )
{
if( buf[j] != '0' + i )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue content corruption" );
}
}
if( buf[j] != 0 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue content corruption" );
}
/* test the queue's information after dequeue completed */
r = kal_get_queue_info( msgq, &msgq_info );
if( r != KAL_TRUE || msgq_info.pending_msgs != (TESTQ_SLOTS - (i + 1)) )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_get_queue_info failed: ret=%d, pending=%d",
r, msgq_info.pending_msgs );
ktest_reset_target();
return KTEST_FAIL;
}
}
/* the queue is empty now, so kal_deque_msg below will return KAL_Q_EMPTY,
* if not, report FAIL. */
{
r = kal_deque_msg( msgq, buf, &mlen, KAL_NO_WAIT );
if( r != KAL_Q_EMPTY )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue should be empty" );
}
}
/* kal_deque_msg returns KAL_Q_EMPTY as we expected, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgq3
* Functionality:
* test kal_deque_msg: dequeue messages in the pattern of KAL_NO_WAIT
* from an empty queue that is just created.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgq3( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* the queue is just created, and has no messages in it.
* so the dequeue operation below will cause KAL_Q_EMPTY returned.
* if not, report FAIL. */
{
r = kal_deque_msg( msgq, buf, &mlen, KAL_NO_WAIT );
if( r != KAL_Q_EMPTY )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "queue should be empty" );
}
}
/* kal_deque_msg returns KAL_Q_EMPTY as we expected, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgq4
* Functionality:
* test kal_deque_msg: dequeue messages from an empty queue in the pattern
* of KAL_INFINITE_WAIT.
* Results:
* if suspension occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgq4( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* create a GPT timer to check whether a suspension will occur when dequeue
* messages in the pattern of KAL_INFINITE_WAIT. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* the queue is just created and has no messages in it, so kal_deque_msg
* will cause a suspension. if not, report FAIL. */
r = kal_deque_msg( msgq, buf, &mlen, KAL_INFINITE_WAIT );
/* no suspension occurs, reporp FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_enque_msg shold not return" );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgqE1a
* Functionality:
* test kal_deque_msg: dequeue a message with the buffer pointer as NULL.
* Results:
* if a fatal error: KAL_ERROR_ITC_QDEQUE_NIL_FAILED occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgqE1a( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen = TESTQ_RECORDSIZE + 5;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_QDEQUE_NIL_FAILED;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* since the queue is just created and has no messages in it,
* so kal_deque_msg will cause a fatal error. if not, report FAIL. */
r = kal_deque_msg( msgq, NULL, &mlen, KAL_INFINITE_WAIT );
/* no fatal error occurs, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_enque_msg shold not return" );
}
/******************************************************************************
* Name:
* ktest_ipc_dequeue_msgqE1b
* Functionality:
* test kal_deque_msg: dequeue a message with qid as NULL.
* Results:
* if a fatal error: KAL_ERROR_ITC_QDEQUE_NIL_FAILED occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_dequeue_msgqE1b( kal_uint32 argc, void *argv )
{
kal_msgqid msgq;
kal_status r;
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen = TESTQ_RECORDSIZE + 5;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_QDEQUE_NIL_FAILED;
msgq = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( msgq == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* since the queue is just created and has no messages in it,
* so kal_deque_msg below will cause a fatal error. if not, report FAIL. */
r = kal_deque_msg( NULL, buf, &mlen, KAL_INFINITE_WAIT );
/* no fatal error occurs, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_enque_msg shold not return" );
}
/******************************************************************************
* Name:
* ktest_ipc_pre_testqueue_thread
* Functionality:
* the main function of a thread that enque or deque messages.
* Parameters:
* param_ptr: if it's "sender", do enqueue operations.
* else, do dequeue operations.
* Returns:
* void.
* Note:
* this function is not a test case, but it is used to support severial test
* cases below.
*****************************************************************************/
kal_msgqid _g_testqueue_msgq1;
void ktest_ipc_pre_testqueue_thread( void *param_ptr )
{
const char *str = (const char *) param_ptr;
char buf[TESTQ_RECORDSIZE];
kal_uint16 mlen;
kal_status r;
if( strcmp(str, "sender") == 0 )
{
/* this thread executes as a sender, do enqueue operations. */
while( 1 )
{
int i;
char ch = '0' + rand() % 64;
/* generate a message string */
for( i = 0; i < TESTQ_RECORDSIZE - 1; i++ )
{
buf[i] = ch;
}
buf[i] = 0;
/* insert this message into the queue */
r = kal_enque_msg( _g_testqueue_msgq1, buf, TESTQ_RECORDSIZE,
KAL_INFINITE_WAIT, KAL_FALSE );
if( r != KAL_SUCCESS )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "kal_enque_msg_q failed" );
}
/* sleep for a while */
if( rand() % 7 == 0 )
{
kal_sleep_task( 1 );
}
}
}
else {
/* this thread executes as a receiver, do dequeue operations. */
while( 1 )
{
int i;
char ch;
/* dequeue a message from the queue, if not success, report FAIL. */
memset( buf, 0, sizeof(buf) );
r = kal_deque_msg( _g_testqueue_msgq1, buf, &mlen, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "kal_deque_msg_q failed" );
}
/* test whether the content of a message is correct.
* if not, report FAIL. */
ch = buf[0];
for( i = 1; i < TESTQ_RECORDSIZE - 1; i++ )
{
if( buf[i] != ch )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "kal_deque_msg_q failed" );
}
}
if( buf[i] != 0 )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "kal_deque_msg_q failed" );
}
}
}
}
/******************************************************************************
* Name:
* ktest_ipc_testqueue1
* Functionality:
* test kal_enque_msg/kal_deque_msg in the environment with multiple tasks.
* note that the task with higher priority will send messages to the one
* with lower priority.
* Results:
* if the sender and receiver can run infinitly before the GPT timer
* expires (16 senconds), report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_testqueue1( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a queue for sender to insert messages to and reveiver to retrieve
* messages from */
_g_testqueue_msgq1 = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( _g_testqueue_msgq1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* create a task with higher priority
* to send messages to _g_test_queue_msgq1 infinitly */
ktest_lib_createtask( 61,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"sender" );
/* create a task with lower priority
* to receive messages from _g_test_queue_msgq1 infinitly */
ktest_lib_createtask( 62,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"receiver" );
/* start a GPT timer to check whether the sender and receiver are running
* infinitly. as we expected, they will always run before timer expires. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend current task, to make sender and receiver run. */
kal_sleep_task( KAL_SUSPEND );
/* we come here before timer expires, this is not what we expected,
* report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_testqueue2
* Functionality:
* test kal_enque_msg/kal_deque_msg in the environment with multiple tasks.
* note that the task with lower priority will send messages to the one
* with higher priority.
* Results:
* if the sender and receiver can run infinitly before the GPT timer
* expires (16 seconds), report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_testqueue2( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a queue for the sender to send messages to and the receiver
* retrieve messages from */
_g_testqueue_msgq1 = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( _g_testqueue_msgq1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* create a task with lower priority
* to send messages to _g_testqueue_msgq1 infinitly */
ktest_lib_createtask( 62,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"sender" );
/* create a task with higher priority
* to receive messages from _g_testqueue_msgq1 infinitly */
ktest_lib_createtask( 61,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"receiver" );
/* start a GPT timer to check whether the sender and receiver are running
* infinitly. as we expected, they will always run before timer expires */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend current task, to make sender and receiver to run */
kal_sleep_task( KAL_SUSPEND );
/* we come here before the timer expires, this is not what we expected,
* report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_testqueue3
* Functionality:
* test kal_enque_msg/kal_deque_msg in the environment with multiple tasks.
* note that more than one sender and reciver tasks will work on one queue.
* Results:
* if the sender and receiver tasks are running infinitly before the GPT
* timer expires (16 seconds), report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_testqueue3( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a queue for the sender and receiver tasks to work on */
_g_testqueue_msgq1 = kal_create_msg_q( "testmsgq", TESTQ_RECORDSIZE, TESTQ_SLOTS );
if( _g_testqueue_msgq1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* create 2 sender tasks and 2 receiver tasks. and note that their
* priorities from high to low is: receiver > sender > sender > receiver */
ktest_lib_createtask( 62,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"sender" );
ktest_lib_createtask( 61,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"receiver" );
ktest_lib_createtask( 63,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"sender" );
ktest_lib_createtask( 64,
(kal_task_func_ptr) ktest_ipc_pre_testqueue_thread,
"receiver" );
/* start a GPT timer to check whether the sender and receiver tasks are
* always running before the timer expires */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend current task, to make sender and receiver tasks to run. */
kal_sleep_task( KAL_SUSPEND );
/* we come here before the timer expires, this is not what we expected,
* report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* macros to access task_ext_qid and task_int_qid_ptr.
*****************************************************************************/
#define TEST_EXTQ ( task_info_g[mod_task_g[MOD_IDLE]].task_ext_qid )
#define TEST_INTQ ( task_info_g[mod_task_g[MOD_IDLE]].task_int_qid_ptr )
/******************************************************************************
* Name:
* create_queue
* Functionality:
* create an external queue and an internal queue.
* Parameters:
* void.
* Returns:
* KAL_TRUE to indicate it executes successfully.
*****************************************************************************/
static kal_bool create_queue( void )
{
kal_msgqid extq;
int_q_type *intq;
/* create an external queue, if not success, report FAIL. */
extq = kal_create_msg_q( "ilmqueue", sizeof(ilm_struct), TESTQ_SLOTS );
if( extq == NULL )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "kal_create_msg_q failed" );
}
/* create an internal queue, if not success, report FAIL. */
intq = kal_sys_mem_alloc( sizeof(int_q_type) + (TESTQ_SLOTS - 1) * sizeof(ilm_struct) );
if( intq == NULL )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "kal_sys_mem_alloc for intq failed" );
}
LCD_IP_CQUEUE_INIT_N( (*intq), TESTQ_SLOTS );
/* set task's ext_qid and int_qid_ptr */
TEST_EXTQ = extq;
TEST_INTQ = intq;
/* create external queue and internal queue successfully */
return KAL_TRUE;
}
/******************************************************************************
* Name:
* ktest_ipc_create_intext_queue
* Functionality:
* test the basic functionality of create external queue and internal queue.
* Results:
* if create queues successfully, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_create_intext_queue( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue.
* if not success, report FAIL in create_queue. */
create_queue();
/* create queues successfully, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_get_ext_queue_info
* Functionality:
* test the basic functionality of msg_get_ext_queue_info and
* msg_get_ext_queue_length.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_get_ext_queue_info( kal_uint32 argc, void *argv )
{
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* test the basic functionality of msg_get_ext_queue_info
* if not success, report FAIL. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 0 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 0 );
ktest_reset_target();
}
/* test the basic functionality of msg_get_ext_queue_length
* if not success, report FAIL. */
r = msg_get_ext_queue_length( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != TESTQ_SLOTS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_length failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, TESTQ_SLOTS );
ktest_reset_target();
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_ext_queue
* Functionality:
* test the basic functionality of msg_send_ext_queue.
* Results:
* if send messages and clear ILM allocation bit mask successfully,
* report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_ext_queue( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* get the information that how many messages in the external queue now.
* since it is just created, so the value must be 0. if not, report FAIL. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 0 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 0 );
ktest_reset_target();
}
/* get the information that how many messages can the queue contain, and the
* value should be TESTQ_SLOTS. if not, report FAIL. */
r = msg_get_ext_queue_length( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != TESTQ_SLOTS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_length failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, TESTQ_SLOTS );
ktest_reset_target();
}
/* allocate an ILM to send a message, if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the values of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
ilmp->local_para_ptr = NULL;
ilmp->peer_buff_ptr = NULL;
/* send ILM to the external queue. if not success, report FAIL. */
r = msg_send_ext_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
ktest_reset_target();
}
/* test whether the external queue's information is correct after sending
* an ILM to it. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 1 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 1 );
ktest_reset_target();
}
/* if send message successfully, the allocation bit mask will be cleared.
* so the allocate_ilm below will execute successfully.
* if not, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_ext_queue_to_head
* Functionality:
* test the basic functionality of msg_send_ext_queue_to_head.
* that is, use msg_send_ext_queue_to_head() to send an ILM to MOD_IDLE,
* and verify that it will clear the allocation bit mask.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_ext_queue_to_head( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* get that how many messages in the queue now.
* if not correct, report FAIL. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 0 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 0 );
ktest_reset_target();
}
/* get that how many messages the queue can contain.
* if it's not TESTQ_SLOTS, report FAIL. */
r = msg_get_ext_queue_length( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != TESTQ_SLOTS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_length failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, TESTQ_SLOTS );
ktest_reset_target();
}
/* allocate an ILM to send. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
ilmp->local_para_ptr = NULL;
ilmp->peer_buff_ptr = NULL;
/* send the ILM to external queue. if not success, report FAIL. */
r = msg_send_ext_queue_to_head( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
ktest_reset_target();
}
/* test whether the queue's information is correct after sending a message
* to external queue. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 1 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 1 );
ktest_reset_target();
}
/* since msg_send_ext_queue_to_head will clear the ILM's allocation bit
* mask, so allocate_ilm below will execute successfully.
* if not, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_int_queue
* Functionality:
* test the basic functionality of msg_send_int_queue.
* that is, use msg_send_int_queue() to send an ILM to MOD_IDLE, and verify
* it will clear the ILM's allocation bit mask.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_int_queue( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* allocate an ILM to send. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_IDLE );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_IDLE;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
ilmp->local_para_ptr = NULL;
ilmp->peer_buff_ptr = NULL;
/* send the ILM to internal queue. if not success, report FAIL. */
r = msg_send_int_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_int_queue failed" );
ktest_reset_target();
}
/* since msg_send_int_queue will clear the ILM's allocation bit mask, so
* allocate_ilm below will execute successfully. if not, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_receive_msg_ext_q
* Functionality:
* test receive_msg_ext_q on an empty external queue. as we expected, the
* task will be blocked forever.
* Results:
* we start a timer (16 seconds) to check whether the receiver task has been
* blocked.
* if the task is still blocked before the timer expires, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_receive_msg_ext_q( kal_uint32 argc, void *argv )
{
ilm_struct ilm;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* since the receiver task works on an empty queue, so it will be blocked
* forever. so we start a GPT timer (16 seconds), if the receiver task is
* still be blocked when the timer expires, then we think that the receiver
* task is in the status we expected. also, KTEST will report PASS in the
* timer handler. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* receive messages from an empty external queue */
r = receive_msg_ext_q( TEST_EXTQ, &ilm );
/* we come here before the timer expires, this is not what we expected,
* report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_receive_msg_int_q
* Functionality:
* test receive_msg_int_q on an empty internal queue. as expected, it will
* return KAL_FALSE.
* Results:
* if return KAL_FALSE, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_receive_msg_int_q( kal_uint32 argc, void *argv )
{
ilm_struct ilm;
kal_bool r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* start a timer to check this situation:
* if we can't receive any message from the internal queue until the
* timer expires, then we think that the receiver is blocked. at this
* case, report FAIL.
* but do we really need this ? */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* receive messages from an internal queue, note that the queue is empty. */
r = receive_msg_int_q( mod_task_g[MOD_IDLE], &ilm );
/* since the queue is empty, the receive_msg_int_q will return KAL_FALSE.
* if so, return PASS; else, return FAIL. */
if( r != KAL_FALSE )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"receive_msg_int_q return unexpected value" );
}
else
{
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_ext_queue2
* Functionality:
* test msg_send_ext_queue/receive_msg_ext_q.
* that is, send a message to MOD_IDLE, then receive the message and check
* its content.
* Results:
* if we can send and receive message successfully, and the content of the
* message is correct, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_ext_queue2( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
ilm_struct ilm;
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* allocate an ILM. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
ilmp->local_para_ptr = (local_para_struct *) 1;
ilmp->peer_buff_ptr = (peer_buff_struct *) 2;
/* send the ILM to an external queue. if not success, report FAIL. */
r = msg_send_ext_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
ktest_reset_target();
}
/* check whether the queue's information is correct after sending an ILM
* to it. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 1 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 1 );
ktest_reset_target();
}
/* since receive_msg_ext_q may be blocked on an empty queue, so we start a
* timer to check this situation. if we can't receive a message until the
* timer expires, then report FAIL. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* receive messages from the external queue. if not success, report FAIL. */
r = receive_msg_ext_q( TEST_EXTQ, &ilm );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "receive_msg_ext_q failed" );
}
/* we come here because we have received a message, now check its
* content. if it's not correct, report FAIL. */
if( ilmp->src_mod_id != MOD_USB
|| ilmp->dest_mod_id != MOD_IDLE
|| ilmp->sap_id != (sap_type)200
|| ilmp->msg_id != (msg_type)100
|| ilmp->local_para_ptr != (local_para_struct *) 1
|| ilmp->peer_buff_ptr != (peer_buff_struct *) 2 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "ilm content corruptted" );
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_ext_queue_to_head2
* Functionality:
* test msg_send_ext_queue_to_head/receive_msg_ext_q.
* that is, send a message to the head of MOD_IDLE's external queue, then
* try to get it back and check its conten.
* Results:
* if send and receive messages successfully, and its conent is correct,
* report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_ext_queue_to_head2( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
ilm_struct ilm;
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* allocate an ILM. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
ilmp->local_para_ptr = (local_para_struct *) 1;
ilmp->peer_buff_ptr = (peer_buff_struct *) 2;
/* send the message to the head of external queue.
* if not success, report FAIL. */
r = msg_send_ext_queue_to_head( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
ktest_reset_target();
}
/* since receive_msg_ext_q may be blocked on an empty queue, so we start a
* timer to check this situation. if we can't receive a message until the
* timer expires, report FAIL. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* try to receive a message from the external queue.
* if not success, report FAIL. */
r = receive_msg_ext_q( TEST_EXTQ, &ilm );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "receive_msg_ext_q failed" );
}
/* a message has been received, now check its content.
* if not correct, report FAIL. */
if( ilmp->src_mod_id != MOD_USB
|| ilmp->dest_mod_id != MOD_IDLE
|| ilmp->sap_id != (sap_type) 200
|| ilmp->msg_id != (msg_type) 100
|| ilmp->local_para_ptr != (local_para_struct *) 1
|| ilmp->peer_buff_ptr != (peer_buff_struct *) 2 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "ilm content corruptted" );
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_int_queue2
* Functionality:
* test msg_send_int_q/receive_msg_int_q.
* that is, send a message to MOD_IDLE's internal queue, then try to receive
* it back and check its content.
* Results:
* if send and receive messages successfully, and its content is correct,
* report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_int_queue2( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp, ilm;
kal_bool r;
kal_uint32 len;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue */
create_queue();
/* allocate an ILM to send. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
ilmp->local_para_ptr = (local_para_struct *) 1;
ilmp->peer_buff_ptr = (peer_buff_struct *) 2;
/* send the ILM to internal queue. if not success, report FAIL. */
r = msg_send_int_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
ktest_reset_target();
}
/* start a timer to check this situation:
* if we can't receive any message from the internal queue until the
* timer expires, then we think that the receiver is blocked. at this
* case, report FAIL.
* but do we really need this ? */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* receive messages from the internal queue.
* if not success, report FAIL. */
r = receive_msg_int_q( mod_task_g[MOD_IDLE], &ilm );
if( r != KAL_TRUE )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "receive_msg_ext_q failed" );
}
/* we have received an ILM now, then check its content.
* if not correct, report FAIL. */
if( ilmp->src_mod_id != MOD_USB
|| ilmp->dest_mod_id != MOD_IDLE
|| ilmp->sap_id != (sap_type) 200
|| ilmp->msg_id != (msg_type) 100
|| ilmp->local_para_ptr != (local_para_struct *) 1
|| ilmp->peer_buff_ptr != (peer_buff_struct *) 2 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "ilm content corruptted" );
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_ext_queue_full
* Functionality:
* test msg_send_ext_queue on a full queue. as we expected, this will cause
* a fatal error: KAL_ERROR_ITC_QENQUE_EXT_FAILED.
* Results:
* if a fatal error: KAL_ERROR_ITC_QENQUE_EXT_FAILED occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_ext_queue_full( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
kal_bool r;
kal_uint32 len;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue. */
create_queue();
/* check the queue's information, in order to check whether we have sent
* the message successfully. if not success, report FAIL. */
r = msg_get_ext_queue_info( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != 0 )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_info failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, 0 );
ktest_reset_target();
}
/* check the queue's max length, in order to check whether the queue is
* correct after sending a message to it. if not, report FAIL. */
r = msg_get_ext_queue_length( TEST_EXTQ, &len );
if( r != KAL_TRUE || len != TESTQ_SLOTS )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"msg_get_ext_queue_length failed: r = %d (expected %d), len = %u (expected %u)",
r, KAL_TRUE, len, TESTQ_SLOTS );
ktest_reset_target();
}
/* send messages to external queue until it is full */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
send_one:
/* allocate an ILM to send. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
/* send the ILM to external queue. if not success, report FAIL. */
r = msg_send_ext_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
ktest_reset_target();
}
}
/* the queue is full now. then we will send one more message to it, and as
* we expected, a fatal error will occur. */
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_QENQUE_EXT_FAILED;
goto send_one;
/* no fatal error occurs, this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_int_queue_full
* Functionality:
* test msg_send_int_queue to a full queue. as we expected, a fatal error:
* KAL_ERROR_ITC_QENQUE_INT_FAILED will occur.
* Results:
* if KAL_ERROR_ITC_QENQUE_INT_FAILED occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_int_queue_full( kal_uint32 argc, void *argv )
{
ilm_struct *ilmp;
kal_bool r;
kal_uint32 len;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue. */
create_queue();
/* send messages to internal queue until it is full. */
for( i = 0; i < TESTQ_SLOTS; i++ )
{
send_one:
/* allocate an ILM to send. if not success, report FAIL. */
ilmp = allocate_ilm( MOD_USB );
if( ilmp == NULL )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
ktest_reset_target();
}
/* set the value of ILM */
ilmp->src_mod_id = MOD_USB;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) 200;
ilmp->msg_id = (msg_type) 100;
/* send the ILM to internal queue. if not success, report FAIL. */
r = msg_send_int_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "msg_send_int_queue failed" );
ktest_reset_target();
}
}
/* the internal queue is full now. then we will send one more ILM to it, as
* we expected, this will cause a fatal error. */
KTEST_EXPECT_ERR_CODE = KAL_ERROR_ITC_QENQUE_INT_FAILED;
goto send_one;
/* no fatal error occurs. this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* kest_ipc_msg_send_ext_queue_thread
* Functionality:
* a task to send or receive messages on external queue.
* Parameters:
* role: if it is "hi-sender", the task will send messages.
* else if it is "lo-sender", the task will send messages.
* else, the task will receive messages.
* Returns:
* void.
* Note:
* this function is not a test case, it is to support severial test cases
* below.
*****************************************************************************/
static void ktest_ipc_msg_send_ext_queue_thread( const char *role )
{
int sender = 0;
int hisender = 0;
int index;
module_type srcmod;
kal_status r;
/* check if the role is "hi-sender" or "lo-sender".
* if so, this task will take the role as a sender.
* else, as a receiver. */
if( strncmp( role, "hi-sender", 9 ) == 0 )
{
sender = 1;
index = role[9] - '1';
srcmod = (module_type) ( MOD_MM + index );
hisender = 1;
}
else if( strncmp( role, "lo-sender", 9 ) == 0 )
{
sender = 1;
index = role[9] - '1';
srcmod = (module_type) ( MOD_BT + index );
hisender = 0;
}
if( sender )
{
/* this task is a sender */
ilm_struct *ilmp;
while( 1 )
{
int a, b;
a = rand();
b = rand();
/* allocate an ILM. if not success, report FAIL. */
ilmp = allocate_ilm( srcmod );
if( ilmp == NULL )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "allocate_ilm failed" );
}
/* set the value of ILM. */
ilmp->src_mod_id = srcmod;
ilmp->dest_mod_id = MOD_IDLE;
ilmp->sap_id = (sap_type) a;
ilmp->msg_id = (msg_type) a;
ilmp->local_para_ptr = (local_para_struct *) b;
ilmp->peer_buff_ptr = (peer_buff_struct *) b;
/* send the message into external queue.
* if not success, report FAIL. */
r = msg_send_ext_queue( ilmp );
if( r != KAL_TRUE )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "msg_send_ext_queue failed" );
}
/* the sender task with higher priority will suspend for a while,
* in order to give changes to other tasks to run. */
if( hisender )
{
kal_sleep_task( 1 );
}
}
}
else {
/* this task is a receiver. */
ilm_struct ilm;
while( 1 )
{
/* try to receive a message from external queue.
* if not success, report FAIL. */
r = receive_msg_ext_q( TEST_EXTQ, &ilm );
if( r != KAL_SUCCESS )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "receive_msg_ext_q failed" );
}
/* we have received a message, then check its content.
* if not correct, report FAIL. */
if( ilm.dest_mod_id != MOD_IDLE
|| (int) ilm.sap_id != (int) ilm.msg_id
|| (int) ilm.local_para_ptr != (int) ilm.peer_buff_ptr )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "ilm content corrupted" );
}
}
}
}
/******************************************************************************
* Name:
* ktest_ipc_msg_send_ext_queue_mt
* Functionality:
* test external queue using multiple tasks.
* note that, we create 4 tasks to send and 1 task to receive.
* and their priority from high to low is:
* hi-sender1 > hi-sender2 > receiver > lo-sender1 > lo-sender2
* Results:
* as we expected, the sender tasks and the receiver task will run
* infinitly. so we start a timer to check this, if the the sender and
* receiver is still running when the timer expires, then report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_msg_send_ext_queue_mt(kal_uint32 argc, void *argv)
{
ilm_struct *ilmp;
kal_bool r;
kal_uint32 len;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an external queue and an internal queue. */
create_queue();
/* create 4 sender tasks and 1 receiver task. note their priorities. */
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_ipc_msg_send_ext_queue_thread, "hi-sender1" );
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_ipc_msg_send_ext_queue_thread, "hi-sender2" );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_ipc_msg_send_ext_queue_thread, "receiver" );
ktest_lib_createtask( 64, (kal_task_func_ptr) ktest_ipc_msg_send_ext_queue_thread, "lo-sender1" );
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_ipc_msg_send_ext_queue_thread, "lo-sender2" );
/* as we expected, the sender tasks and the receiver task will run infinitly
* until the timer expires. so we report PASS in the timer handler. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend current task, to make the senders and receiver to run. */
kal_sleep_task( KAL_SUSPEND );
/* we come here before timer expires, and this is not what we expected,
* report FAIL.*/
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_pre_mutex1
* Functionality:
* test the basic functionality of kal_create_mutex.
* Results:
* if any error occurs, report FAIL.
* else, report PASS.
*****************************************************************************/
kal_int32 ktest_ipc_pre_mutex1( kal_uint32 argc, void *argv )
{
kal_mutexid mptr;
kal_uint32 i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create 24 mutexes using kal_create_mutex */
for( i = 0; i < 24; i++ )
{
mptr = kal_create_mutex( "tstmutex" );
/* if fail to create a mutex, report FAIL. */
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_mutex2
* Functionality:
* test the basic functionality of kal_take_mutex and kal_give_mutex
* in single task.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_mutex2( kal_uint32 argc, void *argv )
{
kal_mutexid mptr;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a mutex. if not success, report FAIL. */
mptr = kal_create_mutex( "tstmutex" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* take the mutex in this task. */
kal_take_mutex( mptr );
/* give the mutex in this task. */
kal_give_mutex( mptr );
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_pre_ipc_mutex3_thread
* Functionality:
* main function of a task that will be used in ktest_ipc_mutex3
* Parameters:
* noarg: argument transferred into the task.
* Returns:
* void.
* Note:
* this function is not a test case, and it's just to support
* ktest_ipc_mutex3 and ktest_ipc_mutex4.
*****************************************************************************/
kal_mutexid _g_testmutex3_ptr1;
kal_mutexid _g_testmutex3_ptr2;
kal_uint32 _g_testmutex3_owner;
void ktest_pre_ipc_mutex3_thread( void *noarg )
{
kal_uint32 prio = kal_get_mytask_priority();
while( 1 )
{
/* take the mutex. if not success, wait for it. */
kal_take_mutex( _g_testmutex3_ptr1 );
/* if _g_testmutex3_owner is not 0, that means the value has been
* modified by the other task. in our expectation, when one task has
* taken the mutex, the other one can not take it and modify the value
* of _g_testmutex3_owner. */
if( _g_testmutex3_owner != 0 )
{
ktest_report_reset( KTEST_FAIL );
}
/* set the value of _g_testmutex3_owner. */
_g_testmutex3_owner = prio;
/* suspend self, then let the other task to run. */
kal_sleep_task( rand2( 1, 5 ) );
/* reset the value of _g_testmutex3_owner to 0. */
_g_testmutex3_owner = 0;
/* give the mutex. */
kal_give_mutex( _g_testmutex3_ptr1 );
}
}
/******************************************************************************
* Name:
* ktest_ipc_mutex3
* Functionality:
* test kal_take_mutex/kal_give_mutex in 2 tasks. as we expected, the two
* tasks can not enter the mutex at the same time.
* Results:
* as we expected, the task with higher priority will always take the mutex,
* when it sleeps, the task with lower priority will try to take the mutex,
* but since the higher one has taken it, so the lower one will suspend and
* wait for the mutex. this will loop infinitly.
* so we start a timer (16 seconds) to check this, if they are still in loop
* when the timer expires, we think they work correctly, then report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_mutex3( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create the 1st mutex. if not success, report FAIL. */
_g_testmutex3_ptr1 = kal_create_mutex( "tstmutx1" );
if( _g_testmutex3_ptr1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create the 2nd mutex. if not success, report FAIL. */
_g_testmutex3_ptr2 = kal_create_mutex( "tstmutx2" );
if( _g_testmutex3_ptr2 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create 2 tasks. note their priorities. */
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_pre_ipc_mutex3_thread, NULL );
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_pre_ipc_mutex3_thread, NULL );
/* as we expected, the 2 tasks will loop infinitly. so we start a timer to
* check this, if they are still in loop when the timer expires, we think
* that they are working correctly, then report PASS. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend self, to let other tasks to run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means the 2 tasks don't run infinitly, so this is
* not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_mutex4
* Functionality:
* test kal_take_mutex/kal_give_mutex in 4 tasks. verify that no 2 tasks
* can enter the mutex at the same time.
* Resutls:
* as we expected, the 4 tasks will run infinitly. in order to check this,
* we start a timer, if the tasks are still running when the timer expires,
* then we think that they work correctly, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_mutex4( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create the 1st mutex. */
_g_testmutex3_ptr1 = kal_create_mutex( "tstmutx1" );
if( _g_testmutex3_ptr1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create the 2nd mutex. */
_g_testmutex3_ptr2 = kal_create_mutex( "tstmutx2" );
if( _g_testmutex3_ptr2 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create 4 tasks. as we expected, no 2 tasks can enter the mutex at the
* same time. */
ktest_lib_createtask( 62,
(kal_task_func_ptr) ktest_pre_ipc_mutex3_thread,
NULL );
ktest_lib_createtask( 61,
(kal_task_func_ptr) ktest_pre_ipc_mutex3_thread,
NULL );
ktest_lib_createtask( 64,
(kal_task_func_ptr) ktest_pre_ipc_mutex3_thread,
NULL );
ktest_lib_createtask( 63,
(kal_task_func_ptr) ktest_pre_ipc_mutex3_thread,
NULL );
/* start a timer to check whether the 4 tasks will run infinitly.
* if they are still running when the timer expires, then we think they
* work correctly, and report PASS in the timer handler. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* sleep self and let other tasks to run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means the 4 tasks are not running infinitly. and
* this is not what we expected. report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_pre_ipc_mutex5_thread
* Functionality:
* the main function of tasks that used in ktest_ipc_mutex5.
* Parameters:
* arg: arguments transferred into tasks.
* Returns:
* void.
* Note:
* this function is not a test case, it's just to support ktest_ipc_mutex5.
*****************************************************************************/
void ktest_pre_ipc_mutex5_thread( const char *arg )
{
if( strcmp( arg, "first" ) != 0 )
{
/* the "second" task will execute this flow. */
kal_sleep_task( 20 );
kal_take_mutex( _g_testmutex3_ptr1 );
kal_sleep_task( 20 );
kal_take_mutex( _g_testmutex3_ptr2 );
}
else
{
/* the "first" task will execute this flow. */
kal_sleep_task( 1 );
kal_take_mutex( _g_testmutex3_ptr2 );
kal_sleep_task( 30 );
kal_take_mutex( _g_testmutex3_ptr1 );
}
/* the task can not reach here, otherwise, report FAIL. */
ktest_report( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_mutex5
* Functionality:
* test mutex's deadlock behavior. that is, "first" task will take mutex2
* and "second" task will take mutex1, then "first" try to take mutex1 and
* "second" try to take mutex2, so a deadlock will happen.
* Results:
* we start a timer to check the deadlock. if the two tasks are not out of
* the deadlock when the timer (16 seconds) expires, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_mutex5( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create mutex1 */
_g_testmutex3_ptr1 = kal_create_mutex( "tstmutx1" );
if( _g_testmutex3_ptr1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create mutex2 */
_g_testmutex3_ptr2 = kal_create_mutex( "tstmutx2" );
if( _g_testmutex3_ptr2 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create 2 tasks, note that "first" has higher priority and "second" has
* lower priority. */
ktest_lib_createtask( 62,
(kal_task_func_ptr) ktest_pre_ipc_mutex5_thread,
"second" );
ktest_lib_createtask( 61,
(kal_task_func_ptr) ktest_pre_ipc_mutex5_thread,
"first" );
/* as we expected, a deadlock will happen. so we start a timer to check it,
* if the 2 tasks are not out of deadlock when the timer expires, we think
* the function is running correctly, report PASS in the timer handler. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend self, let other tasks to run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means no deadlock happens. and this is not what we
* expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_pre_sem1
* Functionality:
* test the basic functionality of kal_create_sem.
* Results:
* if create semaphores successfully, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_pre_sem1( kal_uint32 argc, void *argv )
{
kal_semid mptr;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create 24 semaphores. if any error occurs, report FAIL. */
for( i = 0; i < 24; i++ )
{
mptr = kal_create_sem( "tstsemph", i );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
}
/* create one more semaphore. if error occurs, report FAIL. */
mptr = kal_create_sem( "tstsemph", KTEST_MAX_SEM_CNT );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_sem2
* Functionality:
* test the basic functionality of kal_take_sem in single thread.
* that is, create a semphore with 3 count, then call kal_take_sem 3 times,
* there will be no error occurs as we expected.
* Results:
* if kal_take_sem return a correct value immediatly, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem2( kal_uint32 argc, void *argv )
{
kal_semid mptr;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a semaphore with count 3. */
mptr = kal_create_sem( "tstsemph", 3 );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* start a timer to check infinite wait. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* call kal_take_sem for the 1st time. if not success, report FAIL. */
r = kal_take_sem( mptr, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_take_sem failed" );
}
/* call kal_take_sem for the 2nd time. if not success, report FAIL. */
r = kal_take_sem( mptr, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_take_sem failed" );
}
/* call kal_take_sem for the 3rd time. if not success, report FAIL. */
r = kal_take_sem( mptr, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_take_sem failed" );
}
/* the semaphore's count will be 0 after take semaphore for 3 times.
* and we will report PASS here. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_sem2a
* Functionality:
* test kal_take_sem with KAL_NO_WAIT option.
* that is, create a semaphore with count 3, then call kal_take_sem for 3
* times, so the count will be 0 now. after this, we call
* kal_take_sem once more (with KAL_NO_WAIT option), as expected,
* it will return KAL_SEM_NOT_AVAILABLE immediately.
* Results:
* if the last kal_take_sem return KAL_SEM_NOT_AVAILABLE immediately,
* report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem2a(kal_uint32 argc, void *argv)
{
kal_semid mptr;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a semaphore with count 3. */
mptr = kal_create_sem( "tstsemph", 3 );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* start a timer to check infinite wait. but this will not happen here. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* take the semaphore for the 1st time. the count will be 2 after this. */
r = kal_take_sem( mptr, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_take_sem failed" );
}
/* take the semaphore for the 2nd time. the count will be 1 after this. */
r = kal_take_sem( mptr, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_take_sem failed" );
}
/* take the semaphore for the 3rd time. the count will be 0 after this. */
r = kal_take_sem( mptr, KAL_INFINITE_WAIT );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_take_sem failed" );
}
/* try to take the semaphore for the 4th time (use KAL_NO_WAIT option).
* since the count has been 0 now, so it will return KAL_SEM_NOT_AVAILABLE
* as we expected. if not, report FAIL. */
r = kal_take_sem( mptr, KAL_NO_WAIT );
if( r != KAL_SEM_NOT_AVAILABLE )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_take_sem failed: expected KAL_SEM_NOT_AVAILABLE(%u), got %u",
KAL_SEM_NOT_AVAILABLE, r );
return KTEST_FAIL;
}
/* it returns KAL_SEM_NOT_AVAILABLE as expected, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_sem3
* Functionality:
* test basic functionality of kal_take_sem with KAL_INFINITE_WAIT option.
* that is, create a semaphore with count 0, then call kal_take_sem with
* KAL_INFINITE_WAIT option. the task will be blocked as expected.
* Results:
* we start a timer to check whether the task is blocked. if the task is
* still blocked when the timer expires, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem3( kal_uint32 argc, void *argv )
{
kal_semid mptr;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a semaphore with count 0. */
mptr = kal_create_sem( "tstsemph", 0 );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* start a timer to check whether the task is blocked forever. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* try to take the semaphore with KAL_INFINITE_WAIT option. since the count
* is 0 now, so the task will be blocked forever. */
kal_take_sem( mptr, KAL_INFINITE_WAIT );
/* if we come here, that means the task is not blocked. and this is not
* what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreach" );
}
/******************************************************************************
* Name:
* ktest_ipc_sem3a
* Functionality:
* test basic functionality of kal_take_sem with KAL_NO_WAIT option.
* that is, create a semaphore with count 0, then call kal_take_sem with
* KAL_NO_WAIT option. it will return KAL_SEM_NOT_AVAILABLE as we
* expected.
* Results:
* if it returns KAL_SEM_NOT_AVAILABLE, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem3a( kal_uint32 argc, void *argv )
{
kal_semid mptr;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create a semaphore with count 0. */
mptr = kal_create_sem( "tstsemph", 0 );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* start a timer to check infinite wait. but this is not needed here. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* try to take the semaphore with KAL_NO_WAIT option.
* if it does not return KAL_SEM_NOT_AVAILABLE, report FAIL.*/
r = kal_take_sem( mptr, KAL_NO_WAIT );
if( r != KAL_SEM_NOT_AVAILABLE )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"kal_take_sem failed: expected KAL_SEM_NOT_AVAILABLE(%u), got %u",
KAL_SEM_NOT_AVAILABLE, r );
return KTEST_FAIL;
}
/* if it returns KAL_SEM_NOT_AVAILABLE, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_pre_ipc_sem4_thread
* Functionality:
* the main function of tasks used in ktest_ipc_sem4 and ktest_ipc_sem6.
* Parameters:
* arg: arguments transferred into the task.
* Returns:
* void.
*****************************************************************************/
kal_semid _g_test_sem1;
kal_mutexid _g_test_sem1_mutex;
int _g_test_sem1_count;
void ktest_pre_ipc_sem4_thread( void *arg )
{
int max_count = (int) arg;
int c;
while( 1 )
{
/* take the semaphore with KAL_INFINITE_WAIT option. */
kal_take_sem( _g_test_sem1, KAL_INFINITE_WAIT );
/* take the mutex. note that it will wait infinitely if not success. */
kal_take_mutex( _g_test_sem1_mutex );
c = ++_g_test_sem1_count;
/* give the mutex. */
kal_give_mutex( _g_test_sem1_mutex );
if( c < 0 || c > max_count )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "invalid count" );
}
/* suspend self, in order to let other tasks to run. */
kal_sleep_task( rand2( 1, 5 ) );
/* take the mutex again. if not success, it will wait infinitely. */
kal_take_mutex( _g_test_sem1_mutex );
c = --_g_test_sem1_count;
/* give the mutex again. */
kal_give_mutex( _g_test_sem1_mutex );
if( c < 0 || c > max_count )
{
ktest_report_reset3( KTEST_FAIL, KTEST_TCID, "invalid count" );
}
/* give the semaphore. */
kal_give_sem( _g_test_sem1 );
}
}
/******************************************************************************
* Name:
* ktest_ipc_sem4
* Functionality:
* test kal_take_sem/kal_give_sem in the environment with multiple tasks.
* create a semaphore with count 1, then create 6 tasks to compete for it.
* check the semaphore's owner counter is less than or equal to 1.
* Results:
* if the 6 tasks are still running when the timer expires, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem4( kal_uint32 argc, void *argv )
{
/* the semaphore's count is 1. */
int initial_count = 1;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create the 1st semaphore. */
_g_test_sem1 = kal_create_sem( "tstsemph", initial_count );
if( _g_test_sem1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create the 2nd semaphore. */
_g_test_sem1_mutex = kal_create_mutex( "amutex" );
if( _g_test_sem1_mutex == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create 6 tasks to compete for the semaphore. */
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 64, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 66, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
/* as we expected, the 6 tasks will run infinitely. so we start a timer to
* check this, if they are still running when the timer expires, then we
* report PASS in the timer handler.*/
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend self, in order to let other tasks to run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means the 6 tasks are not running infinitely. and
* this is not what we expected. report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_sem5
* Functionality:
* test kal_take_sem/kal_give_sem in the environment with multiple tasks.
* that is, create a semaphore with count 3, then create 6 tasks to compete
* for it. check the semaphore's owner counter is less than or
* equal to 3.
* Results:
* as we expected, the 6 tasks will run infinitely when the timer expires.
* if so, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem5( kal_uint32 argc, void *argv )
{
/* the semaphore's count is 3. */
int initial_count = 3;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create the 1st semaphore. */
_g_test_sem1 = kal_create_sem( "tstsemph", initial_count );
if( _g_test_sem1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create the 2nd semaphore. */
_g_test_sem1_mutex = kal_create_mutex( "amutex" );
if( _g_test_sem1_mutex == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create 6 tasks to compete for the semaphore. */
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 64, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 66, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
/* as expected, the 6 tasks will run infinitely until the timer expires.
* so we start a timer to check this case. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *)KTEST_PASS );
/* suspend self to let other tasks to run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means the 6 tasks are not running infinitely as
* we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_pre_ipc_sem6_thread
* Functionality:
* the main function of tasks that will be used in ktest_ipc_sem6.
* Parameters:
* arg: arguments transferred into the task.
* Returns:
* void.
* Note:
* this function is not a test case. it's just to support ktest_ipc_sem6.
*****************************************************************************/
void ktest_pre_ipc_sem6_thread( void *arg )
{
int initial_count = (int) arg;
int i;
/* give semaphore for severial times. */
for( i = 0; i < initial_count; i++ )
{
kal_give_sem( _g_test_sem1 );
}
/* suspend self to let other tasks to run. */
kal_sleep_task( KAL_SUSPEND );
}
/******************************************************************************
* Name:
* ktest_ipc_sem6
* Functionality:
* test give semaphore and take semaphore from different tasks.
* Results:
* if a timeout happens, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_sem6( kal_uint32 argc, void *argv )
{
/* the semaphore's count is 3. */
kal_uint32 initial_count = 3;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_BRIEF = "Test give sem and take sem can be from different tasks";
/* create a semaphore. and its count is 0 now. */
_g_test_sem1 = kal_create_sem( "tstsemph", 0 );
if( _g_test_sem1 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create a mutex. */
_g_test_sem1_mutex = kal_create_mutex( "amutex" );
if( _g_test_sem1_mutex == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* create a task to run ktest_pre_ipc_sem6_thread, note that it has the
* highest priority of all the tasks below. Also, it will set the
* semaphore's count to be 3 after it runs. */
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_pre_ipc_sem6_thread, (void *) initial_count );
/* create 6 tasks to compete for the semaphore. */
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 64, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 66, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
ktest_lib_createtask( 67, (kal_task_func_ptr) ktest_pre_ipc_sem4_thread, (void *) initial_count );
/* start a timer to check whether the 6 tasks will run infinitely.
* if so, report PASS in the timer handler when it expires. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means the 6 tasks are not running infinitely.
* and this is not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_pre_eg1
* Functionality:
* test basic functionality of kal_create_event_group.
* Results:
* if success, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_pre_eg1( kal_uint32 argc, void *argv )
{
kal_eventgrpid mptr;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create 24 event groups. if any error occurs, report FAIL. */
for( i = 0; i < 24; i++ )
{
mptr = kal_create_event_group( "tstevent" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_create_mutex failed" );
}
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_eg2
* Functionality:
* test kal_create_event_group. verify that no event has been set after
* it's just created, and any tasks who want to retrieve it will be blocked
* forever.
* Results:
* as we expected, a task that retrieve on an empty event group will be
* blocked forever. so we start a timer to check this, if it's blocked
* actually, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_eg2( kal_uint32 argc, void *argv )
{
kal_eventgrpid mptr;
kal_uint32 e;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an event group. */
mptr = kal_create_event_group( "tstevent" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* start a timer to check whether the task is blocked by retrieving from
* an empty event group. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* try to retrieve events with KAL_SUSPEND option from an empty event group.
* as expected, this will cause it be blocked forever. */
kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
/* we should not come here. otherwise, this means an error occurs,
* report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_eg3
* Functionality:
* test kal_retrieve_eg_events with KAL_OR option,
* verify that KAL_OR will retrieve all requested events.
* and KAL_OR_CONSUME will retrieve and consume all requested
* events.
* Results:
* if any error occurs, report FAIL.
* else, report PASS.
*****************************************************************************/
kal_int32 ktest_ipc_eg3( kal_uint32 argc, void *argv )
{
kal_eventgrpid mptr;
kal_uint32 e;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an event group. */
mptr = kal_create_event_group( "tstevent" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_create_event_group failed" );
}
/* set events on this event group. */
r = kal_set_eg_events( mptr, 0xe9113ef1, KAL_OR );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_set_eg_events failed" );
}
/* retrieve events from this event group with KAL_OR option.
* if not success, report FAIL. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
if( r != KAL_SUCCESS || e != 0xe9113ef1 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_retrieve_eg_events failed" );
}
/* retrieve events with KAL_OR option again. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
if( r != KAL_SUCCESS || e != 0xe9113ef1 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_retrieve_eg_events failed" );
}
/* as we expected, retrieve events with KAL_OR option will not clear the
* events. so we can still retrieve it. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR_CONSUME, &e,
KAL_SUSPEND );
if( r != KAL_SUCCESS || e != 0xe9113ef1 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_retrieve_eg_events failed" );
}
/* KAL_OR_CONSUME will clear the events. so if we try to retrieve events
* again, we will fail to retrieve it.
* here, we start a timer to check this case. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* try to retrieve events again, and this will cause a infinite wait. */
kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
/* we should not come here, otherwise, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_eg4
* Functionality:
* test kal_set_eg_events with KAL_OR option will add new events.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_eg4( kal_uint32 argc, void *argv )
{
kal_eventgrpid mptr;
kal_uint32 e;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an event group. */
mptr = kal_create_event_group( "tstevent" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_event_group failed" );
}
/* set events on this event group. */
r = kal_set_eg_events( mptr, 0xE9013EF0, KAL_OR );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_set_eg_events failed" );
}
/* add new events on this event group with KAL_OR option.
* after this, the events will be 0xE9113EF1. */
r = kal_set_eg_events( mptr, 0x00100081, KAL_OR );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_set_eg_events failed" );
}
/* retrieve events from the event group, and test whether the value is that
* we expected. if not correct, report FAIL. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
if( r != KAL_SUCCESS || e != 0xE9113EF1 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_retrieve_eg_events failed" );
}
/* retrieve events again from the event group. its behavior is just like the
* one above. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
if( r != KAL_SUCCESS || e != 0xE9113EF1 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_retrieve_eg_events failed" );
}
/* retrieve events with KAL_OR_CONSUME option.
* as we expected, this will get the new value of events, then clear it. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR_CONSUME, &e,
KAL_SUSPEND );
if( r != KAL_SUCCESS || e != 0xE9113EF1 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_retrieve_eg_events failed" );
}
/* since we have retrieved the events with KAL_OR_CONSUME option, so the
* events will be cleared. if we still retrieve events from the event group,
* it will not success. */
/* start a timer to check the whether the next kal_retrieve_eg_events with
* KAL_SUSPEND option will be blocked forever. if it's still blocked when
* the timer expires, we think it works correctly, report PASS in the timer
* handler. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* retrieve events with KAL_SUSPEND option. since the events have been
* consumed, so the action will not success, and the task will be blocked
* forever. */
kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_SUSPEND );
/* if we come here, that means the task is not blocked forever. and this is
* not what we expected, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_eg5
* Functionality:
* test kal_set_eg_events with KAL_AND option will mask out events.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_eg5( kal_uint32 argc, void *argv )
{
kal_eventgrpid mptr;
kal_uint32 e;
kal_status r;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an event group. */
mptr = kal_create_event_group( "tstevent" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_event_group failed" );
}
/* set events on this event group. after this, its value is 0xE9113EF1. */
r = kal_set_eg_events( mptr, 0xE9113EF1, KAL_OR );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_set_eg_events failed" );
}
/* set events with KAL_AND option. after this, its value is 0x00100081. */
r = kal_set_eg_events( mptr, 0x00100081, KAL_AND );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_set_eg_events failed" );
}
/* retrieve events with KAL_AND_CONSUME option. after this, its value is
* 0x00100000. */
r = kal_retrieve_eg_events( mptr, 0x00000081, KAL_AND_CONSUME, &e,
KAL_NO_SUSPEND );
if( r != KAL_SUCCESS || (e & 0x00000081) != 0x81 )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_retrieve_eg_events1 failed" );
}
/* the events is 0x00100000 now, so the retrieve below will get nothing. */
r = kal_retrieve_eg_events( mptr, ~0x00100000, KAL_OR_CONSUME, &e,
KAL_NO_SUSPEND );
if( r != KAL_NOT_PRESENT )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_retrieve_eg_events2 failed" );
}
/* the events is 0x00100000 now. so the retrieve below will get 0x00100000,
* then the events will be consumed. */
r = kal_retrieve_eg_events( mptr, 0x00100000, KAL_AND_CONSUME, &e, KAL_SUSPEND );
if( r != KAL_SUCCESS )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_retrieve_eg_events3 failed" );
}
/* the events have been cleared. so anyone want to retrieve it will get
* nothing. */
r = kal_retrieve_eg_events( mptr, 0xFFFFFFFF, KAL_OR, &e, KAL_NO_SUSPEND );
if( r != KAL_NOT_PRESENT )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_retrieve_eg_events4 failed" );
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_pre_enhmutex1
* Functionality:
* test basic functionality of kal_create_enh_mutex.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_pre_enhmutex1( kal_uint32 argc, void *argv )
{
kal_enhmutexid mptr;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create 128 enhanced mutexes. if any error occurs, report FAIL. */
for( i = 0; i < 128; i++ )
{
mptr = kal_create_enh_mutex( "tstenmtx" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_enh_mutex failed" );
}
}
/* no error occurs and report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex2
* Functionality:
* test kal_take_enh_mutex/kal_give_enh_mutex in single task.
* Results:
* if no error occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex2( kal_uint32 argc, void *argv )
{
kal_enhmutexid mptr;
int i;
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an enhanced mutex. */
mptr = kal_create_enh_mutex( "tstenmtx" );
if( mptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_create_enh_mutex failed" );
}
/* start a timer to check whether a deadlock happens. if so, report FAIL. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_FAIL );
/* take the enhanced mutex, then give it. do this for 128 times. */
for( i = 0; i < 128; i++ )
{
kal_take_enh_mutex( mptr );
kal_sleep_task( 10 );
kal_give_enh_mutex( mptr );
}
/* no error occurs, report PASS. */
MY_REPORT_RETURN3( KTEST_PASS, KTEST_TCID, "" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex3_thread
* Functionality:
* main function of tasks that will be used in ktest_ipc_enhmutex3 and
* ktest_ipc_enhmutex4.
* Parameters:
* noarg: arguments transferred into tasks. but we don't need it here.
* Returns:
* void.
* Note:
* this function is not a test case.
* it's just to support ktest_ipc_enhmutex3 and ktest_ipc_enhmutex4.
*****************************************************************************/
static kal_enhmutexid g_enhmutex3_ptr;
static int g_enhmutex3_owner;
void ktest_ipc_enhmutex3_thread( void *noarg )
{
kal_uint32 prio = kal_get_mytask_priority();
while( 1 )
{
/* take the enhanced mutex. */
kal_take_enh_mutex( g_enhmutex3_ptr );
/* we use g_enhmutex3_owner to check whether another task can enter
* the enhanced mutex. if it's not 0, that means another task has
* entered the enhanced mutex. but this is not what we expected, so if
* it happens, report FAIL. */
if( g_enhmutex3_owner != 0 )
{
ktest_report( KTEST_FAIL, KTEST_TCID, "error!" );
ktest_reset_target();
}
/* set g_enhmutex3_owner's value. our aim is to indicate that the task
* has entered the enhanced mutex. */
g_enhmutex3_owner = prio;
/* suspend self to let other tasks run. */
kal_sleep_task( rand2( 1, 3 ) );
/* before give the enhanced mutex, reset g_enhmutex3_owner's value. */
g_enhmutex3_owner = 0;
/* give the enhanced mutex. */
kal_give_enh_mutex( g_enhmutex3_ptr );
}
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex3
* Functionality:
* test kal_take_enh_mutex/kal_give_enh_mutex with 2 tasks.
* that is, use 2 tasks to take and give enhanced mutex, verify that no 2
* tasks can enter the critical section at the same time.
* Results:
* as we expected, no 2 tasks can enter the critical section at the same
* time, so the 2 tasks will run infinitely.
* for this reason, we start a timer, if the 2 tasks is still running when
* the timer expires, we think that they work correctly on the enhanced
* mutex, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex3( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an enhanced mutex. */
g_enhmutex3_ptr = kal_create_enh_mutex( "tstenmtx" );
if( g_enhmutex3_ptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_create_enh_mutex failed" );
}
/* create 2 tasks to compete the enhanced mutex, note that they have
* different priorities. */
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_ipc_enhmutex3_thread,
NULL );
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_ipc_enhmutex3_thread,
NULL );
/* start a timer to check whether the 2 tasks will run infinitely on the
* enhanced mutex. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend self to let the 2 tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* if we come here, that means the 2 tasks are not running infinitely on
* the enhanced mutex. this is not what we expected, then report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex4
* Functionality:
* test kal_take_enh_mutex/kal_give_enh_mutex with 4 tasks.
* that is, use 4 tasks to take and give enhanced mutex, verify that no 2
* tasks can enter the critical section at the same time.
* Results:
* as we expected, no 2 tasks can enter the critical section at the same
* time, so the 2 tasks will run infinitely.
* for this reason, we start a timer, if the 4 tasks is still running when
* the timer expires, we think that they work correctly on the enhanced
* mutex, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex4( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an enhanced mutex. */
g_enhmutex3_ptr = kal_create_enh_mutex( "tstenmtx" );
if( g_enhmutex3_ptr == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_enh_mutex failed" );
}
/* create 4 tasks to compete the enhanced mutex. */
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_ipc_enhmutex3_thread, NULL );
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_ipc_enhmutex3_thread, NULL );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_ipc_enhmutex3_thread, NULL );
ktest_lib_createtask( 64, (kal_task_func_ptr) ktest_ipc_enhmutex3_thread, NULL );
/* since no 2 tasks can enter the enhanced mutex at the same time, so they
* will run infinitely. we start a timer to check this case. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) ktest_report_reset,
(void *) KTEST_PASS );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* we should not come here, if so, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex5_thread
* Functionality:
* this function is to support ktest_ipc_enhmutex5.
* Parameters:
* arg: a value of "low", "mid" or "high".
* Returns:
* void.
* Note:
* this function is not a test case,
* it's just to support ktest_ipc_enhmutex5.
*****************************************************************************/
static int scenario5_test_mutex;
static int scenario5_requestor;
static int scenario5_low_count;
static int scenario5_high_count;
static int scenario5_pi_count;
static int scenario5_preempt_count;
static int scenario5_highblock_count;
static void *scenario5_mutex;
static void (*scenario5_take)( void * );
static void (*scenario5_give)( void * );
void ktest_ipc_enhmutex5_thread( const char *arg )
{
kal_uint32 prio = kal_get_mytask_priority();
if( strcmp( arg, "low" ) == 0 )
{
/* the task with lower priority will do this. */
while( 1 )
{
scenario5_requestor = prio;
(*scenario5_take)( scenario5_mutex );
scenario5_low_count++;
busyloop_delay( rand2( 30, 70 ) );
scenario5_requestor = 0;
(*scenario5_give)( scenario5_mutex );
kal_sleep_task( rand2( 10, 40 ) );
}
}
else if( strcmp( arg, "high" ) == 0 )
{
/* the task with higher priority will do this. */
kal_uint32 start_time, now;
while( 1 )
{
scenario5_requestor = prio;
kal_get_time( &start_time );
(*scenario5_take)( scenario5_mutex );
scenario5_high_count++;
kal_get_time( &now );
if( tick_diff( now, start_time ) >= 2 )
{
scenario5_highblock_count++;
}
busyloop_delay( rand2( 30, 70 ) );
(*scenario5_give)( scenario5_mutex );
scenario5_requestor = 0;
kal_sleep_task( rand2( 10, 40 ) );
}
}
else
{
/* the task with middle priority will do this. */
while( 1 )
{
int req;
kal_sleep_task( 1 );
req = scenario5_requestor;
if( req == 0 )
{
continue;
}
if( req > prio )
{
scenario5_preempt_count++;
}
if( req < prio )
{
scenario5_pi_count++;
if( scenario5_test_mutex == 0 )
{
ASSERT( scenario5_pi_count == 0 );
}
}
}
}
}
/******************************************************************************
* Name:
* monitor_enhmutex5
* Functionality:
* this function is the handler of a timer that used in ktest_ipc_enhmutex5.
* Parameters:
* arg: not used here.
* Returns:
* void.
* Note:
* this function is not a test case,
* it is just to support ktest_ipc_enhmutex5.
*****************************************************************************/
void monitor_enhmutex5( const char *arg )
{
/* timer handler for mutex. */
if( strcmp( arg, "mutex" ) == 0 )
{
if( scenario5_pi_count )
{
ktest_report( KTEST_PASS, KTEST_TCID,
"Priority Inversion detected" );
}
else
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"No Priority Inversion detected" );
}
}
/* timer handler for enhanced mutex. */
if( strcmp( arg, "enhmutex" ) == 0 )
{
if( scenario5_pi_count )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"Priority Inversion detected" );
}
else
{
ktest_report( KTEST_PASS, KTEST_TCID,
"No Priority Inversion detected" );
}
}
/* reset the target. */
ktest_reset_target();
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex5
* Functionality:
* detect that mutex can't avoid priority inversion.
* Results:
* if priority inversion occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex5( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an enhanced mutex. */
scenario5_mutex = kal_create_mutex( "tstmtx1" );
if( scenario5_mutex == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* the function will be kal_take_mutex and kal_give_mutex.
* note they are functions about mutex, not enhanced mutex. */
scenario5_take = (void (*)(void *)) kal_take_mutex;
scenario5_give = (void (*)(void *)) kal_give_mutex;
scenario5_test_mutex = 1;
busyloop_delay_base();
/* create 3 tasks to test priority inversion. */
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"low" );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"mid" );
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"high" );
/* start a timer to check whether priority inversion occurs. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) monitor_enhmutex5, "mutex" );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* we should not come here. otherwise, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex6
* Functionality:
* test that enhanced mutex can avoid priority inversion in the environment
* with 2 tasks.
* Results:
* if no priority inversion occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex6( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an enhanced mutex. */
scenario5_mutex = kal_create_enh_mutex( "tstemtx1" );
if( scenario5_mutex == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* use kal_take_enh_mutex and kal_give_enh_mutex.
* note they are functions about enhanced mutex, note common mutex. */
scenario5_take = (void (*)(void *)) kal_take_enh_mutex;
scenario5_give = (void (*)(void *)) kal_give_enh_mutex;
busyloop_delay_base();
/* create 3 tasks to compete the enhanced mutex. */
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"low" );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"mid" );
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"high" );
/* start a timer to check whether priority inversion occurs. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) monitor_enhmutex5, "enhmutex" );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* we should not come here. otherwise, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex7
* Functionality:
* test that enhanced mutex can avoid priority inversion in the environment
* with 5 tasks.
* Results:
* if no priority inversion occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex7( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create an enhanced mutex. */
scenario5_mutex = kal_create_enh_mutex( "tstemtx1" );
if( scenario5_mutex == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* use functions for enhanced mutex. */
scenario5_take = (void (*)(void *)) kal_take_enh_mutex;
scenario5_give = (void (*)(void *)) kal_give_enh_mutex;
busyloop_delay_base();
/* create 5 tasks to compete the enhanced mutex. */
ktest_lib_createtask( 65, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"low" );
ktest_lib_createtask( 64, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"mid1" );
ktest_lib_createtask( 63, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"mid" );
ktest_lib_createtask( 62, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"mid2" );
ktest_lib_createtask( 61, (kal_task_func_ptr) ktest_ipc_enhmutex5_thread,
"high" );
/* start a timer to check whether a priority inversion occurs. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) monitor_enhmutex5, "enhmutex" );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* we should not come here. otherwise, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* scenario8_func
* Functionality:
* main function of tasks that will be used in ktest_ipc_enhmutex8.
* Parameters:
* arg: a value of "low", "mid1", "mid2" or "high".
* Returns:
* void.
* Note:
* this function is not a test case.
* it's just to support ktest_ipc_enhmutex8.
*****************************************************************************/
static int scenario8_requestor;
static int scenario8_low_count;
static int scenario8_mid1_count;
static int scenario8_high_count;
static int scenario8_pi_count;
static int scenario8_preempt_count;
static int scenario8_highblock_count;
static void *scenario8_mutex1;
static void *scenario8_mutex2;
static void (*scenario8_take)( void * );
static void (*scenario8_give)( void * );
static void scenario8_func( const char *arg )
{
int prio = kal_get_mytask_priority();
if( strcmp( arg, "low" ) == 0 )
{
/* the task with lower priority will do this. */
while( 1 )
{
scenario8_requestor = prio;
(*scenario8_take)( scenario8_mutex2 );
scenario8_low_count++;
busyloop_delay( rand2( 40, 50 ) );
scenario8_requestor = 0;
(*scenario8_give)( scenario8_mutex2 );
kal_sleep_task( rand2( 5, 10 ) );
}
}
else if( strcmp( arg, "mid1" ) == 0 )
{
/* the task with "mid1" priority will do this. */
while( 1 )
{
scenario8_requestor = prio;
(*scenario8_take)( scenario8_mutex1 );
(*scenario8_take)( scenario8_mutex2 );
scenario8_mid1_count++;
busyloop_delay( rand2( 10, 40 ) );
scenario8_requestor = 0;
(*scenario8_give)( scenario8_mutex2 );
(*scenario8_give)( scenario8_mutex1 );
kal_sleep_task( rand2( 5, 10 ) );
}
}
else if( strcmp( arg, "high" ) == 0 )
{
/* the task with highest priority will do this. */
kal_uint32 start_time, now;
while( 1 )
{
scenario8_requestor = prio;
kal_get_time( &start_time );
(*scenario8_take)( scenario8_mutex1 );
scenario8_high_count++;
kal_get_time( &now );
if( tick_diff( now, start_time ) >= 2 )
{
scenario8_highblock_count++;
}
busyloop_delay( rand2( 10, 15 ) );
(*scenario8_give)( scenario8_mutex1 );
scenario8_requestor = 0;
kal_sleep_task( rand2( 50, 100 ) );
}
}
else if( strcmp( arg, "mid2" ) == 0 )
{
/* the task with priority "mid2" will do this. */
while( 1 )
{
int req;
kal_sleep_task( 1 );
req = scenario8_requestor;
if( req == 0 )
{
continue;
}
if( req > prio )
{
scenario8_preempt_count++;
}
if( req < prio )
{
scenario8_pi_count++;
}
}
}
else
{
/* invalid parameter. */
ASSERT( 0 );
}
}
/******************************************************************************
* Name:
* monitor_enhmutex8
* Functionality:
* timer handler used in ktest_ipc_enhmutex8.
* Parameters:
* arg: a value of "mutex" or "enhmutex", it indicates that the handler is
* for mutex or enhanced mutex.
* Returns:
* void.
* Note:
* this function is not a test case, it's to support ktest_ipc_enhmutex8.
*****************************************************************************/
void monitor_enhmutex8( const char *arg )
{
/* timer handler for mutex. */
if( strcmp( arg, "mutex" ) == 0 )
{
if( scenario8_pi_count )
{
ktest_report( KTEST_PASS, KTEST_TCID,
"Priority Inversion detected" );
}
else
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"No Priority Inversion detected" );
}
}
/* timer handler for enhanced mutex. */
if( strcmp( arg, "enhmutex" ) == 0 )
{
if( scenario8_pi_count )
{
ktest_report( KTEST_FAIL, KTEST_TCID,
"Priority Inversion detected" );
}
else
{
ktest_report( KTEST_PASS, KTEST_TCID,
"No Priority Inversion detected" );
}
}
/* reset the target. */
ktest_reset_target();
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex8
* Functionality:
* test that mutex can't avoid priority inversion in nested cases.
* Results:
* if priority inversion occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex8( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* create 2 mutexes. */
scenario8_mutex1 = kal_create_mutex( "tstemtx1" );
scenario8_mutex2 = kal_create_mutex( "tstemtx2" );
if( scenario8_mutex1 == NULL || scenario8_mutex2 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "kal_create_mutex failed" );
}
/* use functions about mutex. */
scenario8_take = (void (*)(void *)) kal_take_mutex;
scenario8_give = (void (*)(void *)) kal_give_mutex;
busyloop_delay_base();
/* create 4 tasks to compete mutex. */
ktest_lib_createtask( 65, (kal_task_func_ptr) scenario8_func, "low" );
ktest_lib_createtask( 64, (kal_task_func_ptr) scenario8_func, "mid1" );
ktest_lib_createtask( 63, (kal_task_func_ptr) scenario8_func, "mid2" );
ktest_lib_createtask( 61, (kal_task_func_ptr) scenario8_func, "high" );
/* start a timer to check whether priority inversion occurs. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) monitor_enhmutex8, "mutex" );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* we should not come here. otherwise, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
/******************************************************************************
* Name:
* ktest_ipc_enhmutex10
* Functionality:
* test that enhanced mutex can avoid priority inversion in nested case.
* Results:
* if no priority inversion occurs, report PASS.
* else, report FAIL.
*****************************************************************************/
kal_int32 ktest_ipc_enhmutex10( kal_uint32 argc, void *argv )
{
KTEST_TCID = KTEST_FUNCTION_NAME;
KTEST_EXPECT_ERR_CODE = 0;
/* creat 2 enhanced mutexes. */
scenario8_mutex1 = kal_create_enh_mutex( "tstemtx1" );
scenario8_mutex2 = kal_create_enh_mutex( "tstemtx2" );
if( scenario8_mutex1 == NULL || scenario8_mutex2 == NULL )
{
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID,
"kal_create_enh_mutex failed" );
}
/* use functions about enhanced mutex. */
scenario8_take = (void (*)(void *)) kal_take_enh_mutex;
scenario8_give = (void (*)(void *)) kal_give_enh_mutex;
busyloop_delay_base();
/* creat 4 tasks to compete enhanced mutex. */
ktest_lib_createtask( 65, (kal_task_func_ptr) scenario8_func, "low" );
ktest_lib_createtask( 64, (kal_task_func_ptr) scenario8_func, "mid1" );
ktest_lib_createtask( 62, (kal_task_func_ptr) scenario8_func, "mid2" );
ktest_lib_createtask( 61, (kal_task_func_ptr) scenario8_func, "high" );
/* start a timer to check whether priority inversion occurs. */
ktest_start_gpt_timer( GPT_TICKSPERSEC * 16,
(gpt_timer_handler) monitor_enhmutex8, "enhmutex" );
/* suspend self to let other tasks run. */
kal_sleep_task( KAL_SUSPEND );
/* we should not come here. otherwise, report FAIL. */
MY_REPORT_RETURN3( KTEST_FAIL, KTEST_TCID, "unreachable" );
}
#define TASK_PRIORITY_TEST_MUTEX_LOW 65
#define TASK_PRIORITY_TEST_MUTEX_MID1 64
#define TASK_PRIORITY_TEST_MUTEX_MID2 63
#define TASK_PRIORITY_TEST_MUTEX_MID3 62
#define TASK_PRIORITY_TEST_MUTEX_HIGH 61
/******************************************************************************
* a table that contains test cases in post-schedule stage of IPC module.
* note that the ones wrapped with FIX_OSCAR_FAIL will not run on MoDIS, but
* they will run on target.
*****************************************************************************/
const ktest_tc_struct ktest_tc_ipc_tbl[] =
{
{ktest_ipc_mutex2, 0, NULL},
{ktest_ipc_mutex3, 0, NULL},
{ktest_ipc_mutex4, 0, NULL},
{ktest_ipc_mutex5, 0, NULL},
{ktest_ipc_sem2, 0, NULL},
{ktest_ipc_sem2a, 0, NULL},
{ktest_ipc_sem3, 0, NULL},
{ktest_ipc_sem3a, 0, NULL},
{ktest_ipc_sem4, 0, NULL},
{ktest_ipc_sem5, 0, NULL},
{ktest_ipc_sem6, 0, NULL},
{ktest_ipc_eg2, 0, NULL},
{ktest_ipc_eg3, 0, NULL},
{ktest_ipc_eg4, 0, NULL},
{ktest_ipc_eg5, 0, NULL},
{ktest_ipc_enhmutex2, 0, NULL},
{ktest_ipc_enhmutex3, 0, NULL},
{ktest_ipc_enhmutex4, 0, NULL},
{ktest_ipc_enhmutex5, 0, NULL},
{ktest_ipc_enhmutex6, 0, NULL},
{ktest_ipc_enhmutex7, 0, NULL},
{ktest_ipc_enhmutex8, 0, NULL},
{ktest_ipc_enhmutex10, 0, NULL},
{ktest_ipc_allocate_ilm1, 0, NULL},
{ktest_ipc_allocate_ilm2, 0, NULL},
{ktest_ipc_allocate_ilm3, 0, NULL},
{ktest_ipc_allocate_ilm4, 0, NULL},
{ktest_ipc_allocate_ilm5, 0, NULL},
{ktest_ipc_construct_local_para, 0, NULL},
{ktest_ipc_hold_local_para, 0, NULL},
{ktest_ipc_hold_local_para2, 0, NULL},
{ktest_ipc_get_local_para_ptr, 0, NULL},
{ktest_ipc_construct_peer_buff, 0, NULL},
{ktest_ipc_hold_peer_buff, 0, NULL},
{ktest_ipc_hold_peer_buff2, 0, NULL},
{ktest_ipc_get_pdu_ptr, 0, NULL},
{ktest_ipc_prepend_to_peer_buff, 0, NULL},
{ktest_ipc_prepend_to_peer_buff2, 0, NULL},
{ktest_ipc_append_to_peer_buff, 0, NULL},
{ktest_ipc_append_to_peer_buff2, 0, NULL},
{ktest_ipc_update_peer_buff_hdr, 0, NULL},
{ktest_ipc_update_peer_buff_hdrE1, 0, NULL},
{ktest_ipc_create_msgq, 0, NULL},
{ktest_ipc_enqueue_msgq1, 0, NULL},
#ifdef FIX_OSCAR_FAIL
/* this case will fail on OSCAR, because it call kal_enque_msg with infinite
* wait option, but this is only supported on TARGET, not on OSCAR. */
{ktest_ipc_enqueue_msgq2, 0, NULL},
#endif
{ktest_ipc_enqueue_msgq3, 0, NULL},
#ifdef FIX_OSCAR_FAIL
/* this case will fail on OSCAR, because it call kal_enque_msg with infinite
* wait option, but this is only supported on TARGET, not on OSCAR. */
{ktest_ipc_enqueue_msgq3a, 0, NULL},
#endif
{ktest_ipc_enqueue_msgq4, 0, NULL},
#ifdef FIX_OSCAR_FAIL
/* this case will fail on OSCAR, because it call kal_enque_msg with infinite
* wait option, but this is only supported on TARGET, not on OSCAR. */
{ktest_ipc_enqueue_msgq4a, 0, NULL},
#endif
{ktest_ipc_dequeue_msgq1, 0, NULL},
{ktest_ipc_dequeue_msgq1a, 0, NULL},
{ktest_ipc_dequeue_msgq2, 0, NULL},
{ktest_ipc_dequeue_msgq3, 0, NULL},
{ktest_ipc_dequeue_msgq4, 0, NULL},
{ktest_ipc_dequeue_msgqE1a, 0, NULL},
{ktest_ipc_dequeue_msgqE1b, 0, NULL},
#ifdef FIX_OSCAR_FAIL
/* the 3 cases below will fail on OSCAR, because they call kal_enque_msg
* with infinite wait option, but this is only supported on TARGET, not on
* OSCAR. */
{ktest_ipc_testqueue1, 0, NULL},
{ktest_ipc_testqueue2, 0, NULL},
{ktest_ipc_testqueue3, 0, NULL},
#endif
{ktest_ipc_create_intext_queue, 0, NULL},
{ktest_ipc_msg_get_ext_queue_info, 0, NULL},
{ktest_ipc_msg_send_ext_queue, 0, NULL},
{ktest_ipc_msg_send_ext_queue_to_head, 0, NULL},
{ktest_ipc_msg_send_int_queue, 0, NULL},
{ktest_ipc_receive_msg_ext_q, 0, NULL},
{ktest_ipc_receive_msg_int_q, 0, NULL},
{ktest_ipc_msg_send_ext_queue2, 0, NULL},
{ktest_ipc_msg_send_ext_queue_to_head2, 0, NULL},
{ktest_ipc_msg_send_int_queue2, 0, NULL},
{ktest_ipc_msg_send_ext_queue_full, 0, NULL},
{ktest_ipc_msg_send_int_queue_full, 0, NULL},
{ktest_ipc_msg_send_ext_queue_mt, 0, NULL},
};
/******************************************************************************
* a table that contains test cases in pre-schedule stage of IPC module.
* note that the ones wrapped with FIX_OSCAR_FAIL will not run on MoDIS, but
* they will run on target.
*****************************************************************************/
const ktest_tc_struct ktest_pre_tc_ipc_tbl[] =
{
{ktest_ipc_pre_mutex1, 0, NULL},
{ktest_ipc_pre_sem1, 0, NULL},
{ktest_ipc_pre_eg1, 0, NULL},
{ktest_ipc_pre_enhmutex1, 0, NULL},
};
/******************************************************************************
* caculate the total number of all test cases of IPC moduel in post-schedule
* stage.
*****************************************************************************/
kal_uint32 ktest_tc_ipc_num( void )
{
return sizeof( ktest_tc_ipc_tbl ) / sizeof( ktest_tc_struct );
}
/******************************************************************************
* caculate the total number of all test cases of IPC module in pre-schedule
* stage.
*****************************************************************************/
kal_uint32 ktest_pre_tc_ipc_num( void )
{
return sizeof( ktest_pre_tc_ipc_tbl ) / sizeof( ktest_tc_struct );
}
/******************************************************************************
* register test case table (pre-schedule and post-schedule).
* set the total number of test cases in each stage of IPC module.
*****************************************************************************/
void ktest_ipc_init( kal_uint32 mod )
{
tc_all_tbls[mod] = ktest_tc_ipc_tbl;
pre_tc_all_tbls[mod] = ktest_pre_tc_ipc_tbl;
tc_modules_num[mod] = ktest_tc_ipc_num();
pre_tc_modules_num[mod] = ktest_pre_tc_ipc_num();
}
#endif /*__KTEST__*/