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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=C0302
"""
VirtualBox Validation Kit - Guest Control Tests.
"""
__copyright__ = \
"""
Copyright (C) 2010-2019 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
you can redistribute it and/or modify it under the terms of the GNU
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
__version__ = "$Revision: 127855 $"
# Disable bitching about too many arguments per function.
# pylint: disable=R0913
# Disable bitching about semicolons at the end of lines.
# pylint: disable=W0301
## @todo Convert map() usage to a cleaner alternative Python now offers.
# pylint: disable=W0141
## @todo Convert the context/test classes into named tuples. Not in the mood right now, so
# disabling it.
# pylint: disable=R0903
# Standard Python imports.
from array import array
import errno
import os
import random
import string # pylint: disable=W0402
import struct
import sys
import time
# Only the main script needs to modify the path.
try: __file__
except: __file__ = sys.argv[0];
g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
sys.path.append(g_ksValidationKitDir);
# Validation Kit imports.
from testdriver import reporter;
from testdriver import base;
from testdriver import vbox;
from testdriver import vboxcon;
from testdriver import vboxwrappers;
# Python 3 hacks:
if sys.version_info[0] >= 3:
long = int # pylint: disable=W0622,C0103
class GuestStream(bytearray):
"""
Class for handling a guest process input/output stream.
"""
def appendStream(self, stream, convertTo='<b'):
"""
Appends and converts a byte sequence to this object;
handy for displaying a guest stream.
"""
self.extend(struct.pack(convertTo, stream));
class tdCtxTest(object):
"""
Provides the actual test environment. Should be kept
as generic as possible.
"""
def __init__(self, oSession, oTxsSession, oTestVm): # pylint: disable=W0613
## The desired Main API result.
self.fRc = False;
## IGuest reference.
self.oGuest = oSession.o.console.guest;
# Rest not used (yet).
class tdCtxCreds(object):
"""
Provides credentials to pass to the guest.
"""
def __init__(self, sUser = None, sPassword = None, sDomain = None, oTestVm = None):
# If no user is specified, select the default user and
# password for the given test VM.
if sUser is None:
assert sPassword is None;
assert sDomain is None;
assert oTestVm is not None;
## @todo fix this so all VMs have several usable test users with the same passwords (or none).
sUser = 'test';
sPassword = 'password';
if oTestVm.isWindows():
#sPassword = ''; # stupid config mistake.
sPassword = 'password';
sUser = 'Administrator';
sDomain = '';
self.sUser = sUser;
self.sPassword = sPassword if sPassword is not None else '';
self.sDomain = sDomain if sDomain is not None else '';
class tdTestGuestCtrlBase(object):
"""
Base class for all guest control tests.
Note: This test ASSUMES that working Guest Additions
were installed and running on the guest to be tested.
"""
def __init__(self):
self.oTest = None;
self.oCreds = None;
self.timeoutMS = 30 * 1000; # 30s timeout
## IGuestSession reference or None.
self.oGuestSession = None;
def setEnvironment(self, oSession, oTxsSession, oTestVm):
"""
Sets the test environment required for this test.
"""
self.oTest = tdCtxTest(oSession, oTxsSession, oTestVm);
return self.oTest;
def createSession(self, sName):
"""
Creates (opens) a guest session.
Returns (True, IGuestSession) on success or (False, None) on failure.
"""
if self.oGuestSession is None:
if sName is None:
sName = "<untitled>";
try:
reporter.log('Creating session "%s" ...' % (sName,));
self.oGuestSession = self.oTest.oGuest.createSession(self.oCreds.sUser,
self.oCreds.sPassword,
self.oCreds.sDomain,
sName);
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Creating a guest session "%s" failed; sUser="%s", pw="%s", sDomain="%s":'
% (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain));
return (False, None);
try:
reporter.log('Waiting for session "%s" to start within %dms...' % (sName, self.timeoutMS));
fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
waitResult = self.oGuestSession.waitForArray(fWaitFor, self.timeoutMS);
#
# Be nice to Guest Additions < 4.3: They don't support session handling and
# therefore return WaitFlagNotSupported.
#
if waitResult != vboxcon.GuestSessionWaitResult_Start \
and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.log('Session did not start successfully, returned wait result: %d' \
% (waitResult,));
return (False, None);
reporter.log('Session "%s" successfully started' % (sName,));
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Waiting for guest session "%s" (usr=%s;pw=%s;dom=%s) to start failed:'
% (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain,));
return (False, None);
else:
reporter.log('Warning: Session already set; this is probably not what you want');
return (True, self.oGuestSession);
def setSession(self, oGuestSession):
"""
Sets the current guest session and closes
an old one if necessary.
"""
if self.oGuestSession is not None:
self.closeSession();
self.oGuestSession = oGuestSession;
return self.oGuestSession;
def closeSession(self):
"""
Closes the guest session.
"""
if self.oGuestSession is not None:
sName = self.oGuestSession.name;
try:
reporter.log('Closing session "%s" ...' % (sName,));
self.oGuestSession.close();
self.oGuestSession = None;
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Closing guest session "%s" failed:' % (sName,));
return False;
return True;
class tdTestCopyFrom(tdTestGuestCtrlBase):
"""
Test for copying files from the guest to the host.
"""
def __init__(self, sSrc = "", sDst = "", sUser = "", sPassword = "", aFlags = None):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sSrc = sSrc;
self.sDst = sDst;
self.aFlags = aFlags;
class tdTestCopyTo(tdTestGuestCtrlBase):
"""
Test for copying files from the host to the guest.
"""
def __init__(self, sSrc = "", sDst = "", sUser = "", sPassword = "", aFlags = None):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sSrc = sSrc;
self.sDst = sDst;
self.aFlags = aFlags;
class tdTestDirCreate(tdTestGuestCtrlBase):
"""
Test for directoryCreate call.
"""
def __init__(self, sDirectory = "", sUser = "", sPassword = "", fMode = 0, aFlags = None):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sDirectory = sDirectory;
self.fMode = fMode;
self.aFlags = aFlags;
class tdTestDirCreateTemp(tdTestGuestCtrlBase):
"""
Test for the directoryCreateTemp call.
"""
def __init__(self, sDirectory = "", sTemplate = "", sUser = "", sPassword = "", fMode = 0, fSecure = False):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sDirectory = sDirectory;
self.sTemplate = sTemplate;
self.fMode = fMode;
self.fSecure = fSecure;
class tdTestDirOpen(tdTestGuestCtrlBase):
"""
Test for the directoryOpen call.
"""
def __init__(self, sDirectory = "", sUser = "", sPassword = "",
sFilter = "", aFlags = None):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sDirectory = sDirectory;
self.sFilter = sFilter;
self.aFlags = aFlags or [];
class tdTestDirRead(tdTestDirOpen):
"""
Test for the opening, reading and closing a certain directory.
"""
def __init__(self, sDirectory = "", sUser = "", sPassword = "",
sFilter = "", aFlags = None):
tdTestDirOpen.__init__(self, sDirectory, sUser, sPassword, sFilter, aFlags);
class tdTestExec(tdTestGuestCtrlBase):
"""
Specifies exactly one guest control execution test.
Has a default timeout of 5 minutes (for safety).
"""
def __init__(self, sCmd = "", aArgs = None, aEnv = None, \
aFlags = None, timeoutMS = 5 * 60 * 1000, \
sUser = "", sPassword = "", sDomain = "", \
fWaitForExit = True):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);
self.sCmd = sCmd;
self.aArgs = aArgs if aArgs is not None else [sCmd,];
self.aEnv = aEnv;
self.aFlags = aFlags or [];
self.timeoutMS = timeoutMS;
self.fWaitForExit = fWaitForExit;
self.uExitStatus = 0;
self.iExitCode = 0;
self.cbStdOut = 0;
self.cbStdErr = 0;
self.sBuf = '';
class tdTestFileExists(tdTestGuestCtrlBase):
"""
Test for the file exists API call (fileExists).
"""
def __init__(self, sFile = "", sUser = "", sPassword = ""):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sFile = sFile;
class tdTestFileRemove(tdTestGuestCtrlBase):
"""
Test querying guest file information.
"""
def __init__(self, sFile = "", sUser = "", sPassword = ""):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sFile = sFile;
class tdTestFileStat(tdTestGuestCtrlBase):
"""
Test querying guest file information.
"""
def __init__(self, sFile = "", sUser = "", sPassword = "", cbSize = 0, eFileType = 0):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sFile = sFile;
self.cbSize = cbSize;
self.eFileType = eFileType;
class tdTestFileIO(tdTestGuestCtrlBase):
"""
Test for the IGuestFile object.
"""
def __init__(self, sFile = "", sUser = "", sPassword = ""):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sFile = sFile;
class tdTestFileQuerySize(tdTestGuestCtrlBase):
"""
Test for the file size query API call (fileQuerySize).
"""
def __init__(self, sFile = "", sUser = "", sPassword = ""):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sFile = sFile;
class tdTestFileReadWrite(tdTestGuestCtrlBase):
"""
Tests reading from guest files.
"""
def __init__(self, sFile = "", sUser = "", sPassword = "",
sOpenMode = "r", sDisposition = "",
sSharingMode = "",
lCreationMode = 0, cbOffset = 0, cbToReadWrite = 0,
aBuf = None):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
self.sFile = sFile;
self.sOpenMode = sOpenMode;
self.sDisposition = sDisposition;
self.sSharingMode = sSharingMode;
self.lCreationMode = lCreationMode;
self.cbOffset = cbOffset;
self.cbToReadWrite = cbToReadWrite;
self.aBuf = aBuf;
def getOpenAction(self):
""" Converts string disposition to open action enum. """
if self.sDisposition == 'oe': return vboxcon.FileOpenAction_OpenExisting;
if self.sDisposition == 'oc': return vboxcon.FileOpenAction_OpenOrCreate;
if self.sDisposition == 'ce': return vboxcon.FileOpenAction_CreateNew;
if self.sDisposition == 'ca': return vboxcon.FileOpenAction_CreateOrReplace;
if self.sDisposition == 'ot': return vboxcon.FileOpenAction_OpenExistingTruncated;
if self.sDisposition == 'oa': return vboxcon.FileOpenAction_AppendOrCreate;
raise base.GenError(self.sDisposition);
def getAccessMode(self):
""" Converts open mode to access mode enum. """
if self.sOpenMode == 'r': return vboxcon.FileOpenMode_ReadOnly;
if self.sOpenMode == 'w': return vboxcon.FileOpenMode_WriteOnly;
if self.sOpenMode == 'w+': return vboxcon.FileOpenMode_ReadWrite;
if self.sOpenMode == 'r+': return vboxcon.FileOpenMode_ReadWrite;
raise base.GenError(self.sOpenMode);
def getSharingMode(self):
""" Converts the sharing mode. """
return vboxcon.FileSharingMode_All;
class tdTestSession(tdTestGuestCtrlBase):
"""
Test the guest session handling.
"""
def __init__(self, sUser = "", sPassword = "", sDomain = "", \
sSessionName = ""):
tdTestGuestCtrlBase.__init__(self);
self.sSessionName = sSessionName;
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);
def getSessionCount(self, oVBoxMgr):
"""
Helper for returning the number of currently
opened guest sessions of a VM.
"""
if self.oTest.oGuest is None:
return 0;
aoSession = oVBoxMgr.getArray(self.oTest.oGuest, 'sessions')
return len(aoSession);
class tdTestSessionEx(tdTestGuestCtrlBase):
"""
Test the guest session.
"""
def __init__(self, aoSteps = None, enmUser = None):
tdTestGuestCtrlBase.__init__(self);
assert enmUser is None; # For later.
self.enmUser = enmUser;
self.aoSteps = aoSteps if aoSteps is not None else [];
def execute(self, oTstDrv, oVmSession, oTxsSession, oTestVm, sMsgPrefix):
"""
Executes the test.
"""
#
# Create a session.
#
assert self.enmUser is None; # For later.
self.oCreds = tdCtxCreds(oTestVm = oTestVm);
self.setEnvironment(oVmSession, oTxsSession, oTestVm);
reporter.log2('%s: %s steps' % (sMsgPrefix, len(self.aoSteps),));
fRc, oCurSession = self.createSession(sMsgPrefix);
if fRc is True:
#
# Execute the tests.
#
try:
fRc = self.executeSteps(oTstDrv, oCurSession, sMsgPrefix);
except:
reporter.errorXcpt('%s: Unexpected exception executing test steps' % (sMsgPrefix,));
fRc = False;
fRc2 = self.closeSession();
if fRc2 is False:
reporter.error('%s: Session could not be closed' % (sMsgPrefix,));
fRc = False;
else:
reporter.error('%s: Session creation failed' % (sMsgPrefix,));
fRc = False;
return fRc;
def executeSteps(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Executes just the steps.
Returns True on success, False on test failure.
"""
fRc = True;
for (i, oStep) in enumerate(self.aoSteps):
fRc2 = oStep.execute(oTstDrv, oGstCtrlSession, sMsgPrefix + ', step #%d' % i);
if fRc2 is True:
pass;
elif fRc2 is None:
reporter.log('skipping remaining %d steps' % (len(self.aoSteps) - i - 1,));
break;
else:
fRc = False;
return fRc;
@staticmethod
def executeListTestSessions(aoTests, oTstDrv, oVmSession, oTxsSession, oTestVm, sMsgPrefix):
"""
Works thru a list of tdTestSessionEx object.
"""
fRc = True;
for (i, oCurTest) in enumerate(aoTests):
try:
fRc2 = oCurTest.execute(oTstDrv, oVmSession, oTxsSession, oTestVm, '%s, test %#d' % (sMsgPrefix, i,));
if fRc2 is not True:
fRc = False;
except:
reporter.errorXcpt('Unexpected exception executing test #%d' % (i,));
fRc = False;
return (fRc, oTxsSession);
class tdSessionStepBase(object):
"""
Base class for the guest control session test steps.
"""
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Executes the test step.
Returns True on success.
Returns False on failure (must be reported as error).
Returns None if to skip the remaining steps.
"""
reporter.error('%s: Missing execute implementation: %s' % (sMsgPrefix, self,));
_ = oTstDrv;
_ = oGstCtrlSession;
return False;
class tdStepRequireMinimumApiVer(tdSessionStepBase):
"""
Special test step which will cause executeSteps to skip the remaining step
if the VBox API is too old:
"""
def __init__(self, fpMinApiVer):
self.fpMinApiVer = fpMinApiVer;
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
""" Returns None if API version is too old, otherwise True. """
if oTstDrv.fpApiVer >= self.fpMinApiVer:
return True;
_ = oGstCtrlSession;
_ = sMsgPrefix;
return None; # Special return value. Don't use elsewhere.
#
# Scheduling Environment Changes with the Guest Control Session.
#
class tdStepSessionSetEnv(tdSessionStepBase):
"""
Guest session environment: schedule putenv
"""
def __init__(self, sVar, sValue, hrcExpected = 0):
self.sVar = sVar;
self.sValue = sValue;
self.hrcExpected = hrcExpected;
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Executes the step.
Returns True on success, False on test failure.
"""
reporter.log2('tdStepSessionSetEnv: sVar=%s sValue=%s hrcExpected=%#x' % (self.sVar, self.sValue, self.hrcExpected,));
try:
if oTstDrv.fpApiVer >= 5.0:
oGstCtrlSession.environmentScheduleSet(self.sVar, self.sValue);
else:
oGstCtrlSession.environmentSet(self.sVar, self.sValue);
except vbox.ComException as oXcpt:
# Is this an expected failure?
if vbox.ComError.equal(oXcpt, self.hrcExpected):
return True;
reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (setenv %s=%s)'
% (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
vbox.ComError.getXcptResult(oXcpt),
vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
self.sVar, self.sValue,));
return False;
except:
reporter.errorXcpt('%s: Unexpected exception in tdStepSessionSetEnv::execute (%s=%s)'
% (sMsgPrefix, self.sVar, self.sValue,));
return False;
# Should we succeed?
if self.hrcExpected != 0:
reporter.error('%s: Expected hrcExpected=%#x, got S_OK (putenv %s=%s)'
% (sMsgPrefix, self.hrcExpected, self.sVar, self.sValue,));
return False;
return True;
class tdStepSessionUnsetEnv(tdSessionStepBase):
"""
Guest session environment: schedule unset.
"""
def __init__(self, sVar, hrcExpected = 0):
self.sVar = sVar;
self.hrcExpected = hrcExpected;
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Executes the step.
Returns True on success, False on test failure.
"""
reporter.log2('tdStepSessionUnsetEnv: sVar=%s hrcExpected=%#x' % (self.sVar, self.hrcExpected,));
try:
if oTstDrv.fpApiVer >= 5.0:
oGstCtrlSession.environmentScheduleUnset(self.sVar);
else:
oGstCtrlSession.environmentUnset(self.sVar);
except vbox.ComException as oXcpt:
# Is this an expected failure?
if vbox.ComError.equal(oXcpt, self.hrcExpected):
return True;
reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (unsetenv %s)'
% (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
vbox.ComError.getXcptResult(oXcpt),
vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
self.sVar,));
return False;
except:
reporter.errorXcpt('%s: Unexpected exception in tdStepSessionUnsetEnv::execute (%s)'
% (sMsgPrefix, self.sVar,));
return False;
# Should we succeed?
if self.hrcExpected != 0:
reporter.error('%s: Expected hrcExpected=%#x, got S_OK (unsetenv %s)'
% (sMsgPrefix, self.hrcExpected, self.sVar,));
return False;
return True;
class tdStepSessionBulkEnv(tdSessionStepBase):
"""
Guest session environment: Bulk environment changes.
"""
def __init__(self, asEnv = None, hrcExpected = 0):
self.asEnv = asEnv if asEnv is not None else [];
self.hrcExpected = hrcExpected;
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Executes the step.
Returns True on success, False on test failure.
"""
reporter.log2('tdStepSessionBulkEnv: asEnv=%s hrcExpected=%#x' % (self.asEnv, self.hrcExpected,));
try:
if oTstDrv.fpApiVer >= 5.0:
oTstDrv.oVBoxMgr.setArray(oGstCtrlSession, 'environmentChanges', self.asEnv);
else:
oTstDrv.oVBoxMgr.setArray(oGstCtrlSession, 'environment', self.asEnv);
except vbox.ComException as oXcpt:
# Is this an expected failure?
if vbox.ComError.equal(oXcpt, self.hrcExpected):
return True;
reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (asEnv=%s)'
% (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
vbox.ComError.getXcptResult(oXcpt),
vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
self.asEnv,));
return False;
except:
reporter.errorXcpt('%s: Unexpected exception writing the environmentChanges property (asEnv=%s).'
% (sMsgPrefix, self.asEnv));
return False;
return True;
class tdStepSessionClearEnv(tdStepSessionBulkEnv):
"""
Guest session environment: clears the scheduled environment changes.
"""
def __init__(self):
tdStepSessionBulkEnv.__init__(self);
class tdStepSessionCheckEnv(tdSessionStepBase):
"""
Check the currently scheduled environment changes of a guest control session.
"""
def __init__(self, asEnv = None):
self.asEnv = asEnv if asEnv is not None else [];
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Executes the step.
Returns True on success, False on test failure.
"""
reporter.log2('tdStepSessionCheckEnv: asEnv=%s' % (self.asEnv,));
#
# Get the environment change list.
#
try:
if oTstDrv.fpApiVer >= 5.0:
asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environmentChanges');
else:
asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environment');
except:
reporter.errorXcpt('%s: Unexpected exception reading the environmentChanges property.' % (sMsgPrefix,));
return False;
#
# Compare it with the expected one by trying to remove each expected value
# and the list anything unexpected.
#
fRc = True;
asCopy = list(asCurEnv); # just in case asCurEnv is immutable
for sExpected in self.asEnv:
try:
asCopy.remove(sExpected);
except:
reporter.error('%s: Expected "%s" to be in the resulting environment' % (sMsgPrefix, sExpected,));
fRc = False;
for sUnexpected in asCopy:
reporter.error('%s: Unexpected "%s" in the resulting environment' % (sMsgPrefix, sUnexpected,));
fRc = False;
if fRc is not True:
reporter.log2('%s: Current environment: %s' % (sMsgPrefix, asCurEnv));
return fRc;
#
# File system object statistics (i.e. stat()).
#
class tdStepStat(tdSessionStepBase):
"""
Stats a file system object.
"""
def __init__(self, sPath, hrcExpected = 0, fFound = True, fFollowLinks = True, enmType = None):
self.sPath = sPath;
self.hrcExpected = hrcExpected;
self.fFound = fFound;
self.fFollowLinks = fFollowLinks;
self.enmType = enmType if enmType is not None else vboxcon.FsObjType_File;
self.cbExactSize = None;
self.cbMinSize = None;
def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
"""
Execute the test step.
"""
reporter.log2('tdStepStat: sPath=%s enmType=%s hrcExpected=%s fFound=%s fFollowLinks=%s'
% (self.sPath, self.enmType, self.hrcExpected, self.fFound, self.fFollowLinks,));
# Don't execute non-file tests on older VBox version.
if oTstDrv.fpApiVer >= 5.0 or self.enmType == vboxcon.FsObjType_File or not self.fFound:
#
# Call the API.
#
try:
if oTstDrv.fpApiVer >= 5.0:
oFsInfo = oGstCtrlSession.fsObjQueryInfo(self.sPath, self.fFollowLinks);
else:
oFsInfo = oGstCtrlSession.fileQueryInfo(self.sPath);
except vbox.ComException as oXcpt:
## @todo: The error reporting in the API just plain sucks! Most of the errors are
## VBOX_E_IPRT_ERROR and there seems to be no way to distinguish between
## non-existing files/path and a lot of other errors. Fix API and test!
if not self.fFound:
return True;
if vbox.ComError.equal(oXcpt, self.hrcExpected): # Is this an expected failure?
return True;
return reporter.errorXcpt('%s: Unexpected exception for exiting path "%s" (enmType=%s, hrcExpected=%s):'
% (sMsgPrefix, self.sPath, self.enmType, self.hrcExpected,));
except:
return reporter.errorXcpt('%s: Unexpected exception in tdStepStat::execute (%s)'
% (sMsgPrefix, self.sPath,));
if oFsInfo is None:
return reporter.error('%s: "%s" got None instead of IFsObjInfo instance!' % (sMsgPrefix, self.sPath,));
#
# Check type expectations.
#
try:
enmType = oFsInfo.type;
except:
return reporter.errorXcpt('%s: Unexpected exception in reading "IFsObjInfo::type"' % (sMsgPrefix,));
if enmType != self.enmType:
return reporter.error('%s: "%s" has type %s, expected %s'
% (sMsgPrefix, self.sPath, enmType, self.enmType));
#
# Check size expectations.
# Note! This is unicode string here on windows, for some reason.
# long long mapping perhaps?
#
try:
cbObject = long(oFsInfo.objectSize);
except:
return reporter.errorXcpt('%s: Unexpected exception in reading "IFsObjInfo::objectSize"'
% (sMsgPrefix,));
if self.cbExactSize is not None \
and cbObject != self.cbExactSize:
return reporter.error('%s: "%s" has size %s bytes, expected %s bytes'
% (sMsgPrefix, self.sPath, cbObject, self.cbExactSize));
if self.cbMinSize is not None \
and cbObject < self.cbMinSize:
return reporter.error('%s: "%s" has size %s bytes, expected as least %s bytes'
% (sMsgPrefix, self.sPath, cbObject, self.cbMinSize));
return True;
class tdStepStatDir(tdStepStat):
""" Checks for an existing directory. """
def __init__(self, sDirPath):
tdStepStat.__init__(self, sPath = sDirPath, enmType = vboxcon.FsObjType_Directory);
class tdStepStatFile(tdStepStat):
""" Checks for an existing file """
def __init__(self, sFilePath):
tdStepStat.__init__(self, sPath = sFilePath, enmType = vboxcon.FsObjType_File);
class tdStepStatFileSize(tdStepStat):
""" Checks for an existing file of a given expected size.. """
def __init__(self, sFilePath, cbExactSize = 0):
tdStepStat.__init__(self, sPath = sFilePath, enmType = vboxcon.FsObjType_File);
self.cbExactSize = cbExactSize;
class tdStepStatFileNotFound(tdStepStat):
""" Checks for an existing directory. """
def __init__(self, sPath):
tdStepStat.__init__(self, sPath = sPath, fFound = False);
class tdStepStatPathNotFound(tdStepStat):
""" Checks for an existing directory. """
def __init__(self, sPath):
tdStepStat.__init__(self, sPath = sPath, fFound = False);
#
#
#
class tdTestSessionFileRefs(tdTestGuestCtrlBase):
"""
Tests session file (IGuestFile) reference counting.
"""
def __init__(self, cRefs = 0):
tdTestGuestCtrlBase.__init__(self);
self.cRefs = cRefs;
class tdTestSessionDirRefs(tdTestGuestCtrlBase):
"""
Tests session directory (IGuestDirectory) reference counting.
"""
def __init__(self, cRefs = 0):
tdTestGuestCtrlBase.__init__(self);
self.cRefs = cRefs;
class tdTestSessionProcRefs(tdTestGuestCtrlBase):
"""
Tests session process (IGuestProcess) reference counting.
"""
def __init__(self, cRefs = 0):
tdTestGuestCtrlBase.__init__(self);
self.cRefs = cRefs;
class tdTestUpdateAdditions(tdTestGuestCtrlBase):
"""
Test updating the Guest Additions inside the guest.
"""
def __init__(self, sSrc = "", aArgs = None, aFlags = None,
sUser = "", sPassword = "", sDomain = ""):
tdTestGuestCtrlBase.__init__(self);
self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);
self.sSrc = sSrc;
self.aArgs = aArgs;
self.aFlags = aFlags;
class tdTestResult(object):
"""
Base class for test results.
"""
def __init__(self, fRc = False):
## The overall test result.
self.fRc = fRc;
class tdTestResultDirRead(tdTestResult):
"""
Test result for reading guest directories.
"""
def __init__(self, fRc = False,
numFiles = 0, numDirs = 0):
tdTestResult.__init__(self, fRc = fRc);
self.numFiles = numFiles;
self.numDirs = numDirs;
class tdTestResultExec(tdTestResult):
"""
Holds a guest process execution test result,
including the exit code, status + aFlags.
"""
def __init__(self, fRc = False, \
uExitStatus = 500, iExitCode = 0, \
sBuf = None, cbBuf = 0, \
cbStdOut = 0, cbStdErr = 0):
tdTestResult.__init__(self);
## The overall test result.
self.fRc = fRc;
## Process exit stuff.
self.uExitStatus = uExitStatus;
self.iExitCode = iExitCode;
## Desired buffer length returned back from stdout/stderr.
self.cbBuf = cbBuf;
## Desired buffer result from stdout/stderr. Use with caution!
self.sBuf = sBuf;
self.cbStdOut = cbStdOut;
self.cbStdErr = cbStdErr;
class tdTestResultFileStat(tdTestResult):
"""
Test result for stat'ing guest files.
"""
def __init__(self, fRc = False,
cbSize = 0, eFileType = 0):
tdTestResult.__init__(self, fRc = fRc);
self.cbSize = cbSize;
self.eFileType = eFileType;
## @todo Add more information.
class tdTestResultFileReadWrite(tdTestResult):
"""
Test result for reading + writing guest directories.
"""
def __init__(self, fRc = False,
cbProcessed = 0, cbOffset = 0, aBuf = None):
tdTestResult.__init__(self, fRc = fRc);
self.cbProcessed = cbProcessed;
self.cbOffset = cbOffset;
self.aBuf = aBuf;
class tdTestResultSession(tdTestResult):
"""
Test result for guest session counts.
"""
def __init__(self, fRc = False, cNumSessions = 0):
tdTestResult.__init__(self, fRc = fRc);
self.cNumSessions = cNumSessions;
class SubTstDrvAddGuestCtrl(base.SubTestDriverBase):
"""
Sub-test driver for executing guest control (VBoxService, IGuest) tests.
"""
def __init__(self, oTstDrv):
base.SubTestDriverBase.__init__(self, 'add-guest-ctrl', oTstDrv);
## @todo base.TestBase.
self.asTestsDef = \
[
'session_basic', 'session_env', 'session_file_ref', 'session_dir_ref', 'session_proc_ref',
'exec_basic', 'exec_errorlevel', 'exec_timeout',
'dir_create', 'dir_create_temp', 'dir_read',
'file_remove', 'file_stat', 'file_read', 'file_write',
'copy_to', 'copy_from',
'update_additions'
];
self.asTests = self.asTestsDef;
self.asRsrcs = ['5.3/guestctrl/50mb_rnd.dat', ];
def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
if asArgs[iArg] == '--add-guest-ctrl-tests':
iArg += 1;
if asArgs[iArg] == 'all': # Nice for debugging scripts.
self.asTests = self.asTestsDef;
return iArg + 1;
iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
self.asTests = asArgs[iArg].split(':');
for s in self.asTests:
if s not in self.asTestsDef:
raise base.InvalidOption('The "--add-guest-ctrl-tests" value "%s" is not valid; valid values are: %s' \
% (s, ' '.join(self.asTestsDef)));
return iNext;
return iArg;
def showUsage(self):
base.SubTestDriverBase.showUsage(self);
reporter.log(' --add-guest-ctrl-tests <s1[:s2[:]]>');
reporter.log(' Default: %s (all)' % (':'.join(self.asTestsDef)));
return True;
def testIt(self, oTestVm, oSession, oTxsSession):
"""
Executes the test.
Returns fRc, oTxsSession. The latter may have changed.
"""
reporter.log("Active tests: %s" % (self.asTests,));
fRc = True;
# Do the testing.
reporter.testStart('Session Basics');
fSkip = 'session_basic' not in self.asTests;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlSession(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Session Environment');
fSkip = 'session_env' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlSessionEnvironment(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Session File References');
fSkip = 'session_file_ref' not in self.asTests;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlSessionFileRefs(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
## @todo Implement this.
#reporter.testStart('Session Directory References');
#fSkip = 'session_dir_ref' not in self.asTests;
#if fSkip is False:
# fRc, oTxsSession = self.testGuestCtrlSessionDirRefs(oSession, oTxsSession, oTestVm);
#reporter.testDone(fSkip);
reporter.testStart('Session Process References');
fSkip = 'session_proc_ref' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlSessionProcRefs(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Execution');
fSkip = 'exec_basic' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlExec(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Execution Error Levels');
fSkip = 'exec_errorlevel' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlExecErrorLevel(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Execution Timeouts');
fSkip = 'exec_timeout' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlExecTimeout(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Creating directories');
fSkip = 'dir_create' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlDirCreate(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Creating temporary directories');
fSkip = 'dir_create_temp' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlDirCreateTemp(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Reading directories');
fSkip = 'dir_read' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlDirRead(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Copy to guest');
fSkip = 'copy_to' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlCopyTo(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Copy from guest');
fSkip = 'copy_from' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlCopyFrom(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Removing files');
fSkip = 'file_remove' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlFileRemove(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
reporter.testStart('Querying file information (stat)');
fSkip = 'file_stat' not in self.asTests or fRc is False;
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlFileStat(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
# FIXME: Failing tests.
# reporter.testStart('File read');
# fSkip = 'file_read' not in self.asTests or fRc is False;
# if fSkip is False:
# fRc, oTxsSession = self.testGuestCtrlFileRead(oSession, oTxsSession, oTestVm);
# reporter.testDone(fSkip);
# reporter.testStart('File write');
# fSkip = 'file_write' not in self.asTests or fRc is False;
# if fSkip is False:
# fRc, oTxsSession = self.testGuestCtrlFileWrite(oSession, oTxsSession, oTestVm);
# reporter.testDone(fSkip);
reporter.testStart('Updating Guest Additions');
fSkip = 'update_additions' not in self.asTests or fRc is False;
# Skip test for updating Guest Additions if we run on a too old (Windows) guest.
fSkip = oTestVm.sKind in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003');
if fSkip is False:
fRc, oTxsSession = self.testGuestCtrlUpdateAdditions(oSession, oTxsSession, oTestVm);
reporter.testDone(fSkip);
return (fRc, oTxsSession);
def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, aFlags):
"""
Helper function to copy a single file from the guest to the host.
"""
fRc = True; # Be optimistic.
try:
reporter.log2('Copying guest file "%s" to host "%s"' % (sSrc, sDst));
if self.oTstDrv.fpApiVer >= 5.0:
curProgress = oGuestSession.fileCopyFromGuest(sSrc, sDst, aFlags);
else:
curProgress = oGuestSession.copyFrom(sSrc, sDst, aFlags);
if curProgress is not None:
oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlFileCopyFrom");
try:
oProgress.wait();
if not oProgress.isSuccess():
oProgress.logResult(fIgnoreErrors = True);
fRc = False;
except:
reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
fRc = False;
else:
reporter.error('No progress object returned');
fRc = False;
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Copy from exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
fRc = False;
return fRc;
def gctrlCopyFileTo(self, oGuestSession, sSrc, sDst, aFlags):
"""
Helper function to copy a single file from host to the guest.
"""
fRc = True; # Be optimistic.
try:
reporter.log2('Copying host file "%s" to guest "%s" (flags %s)' % (sSrc, sDst, aFlags));
if self.oTstDrv.fpApiVer >= 5.0:
curProgress = oGuestSession.fileCopyToGuest(sSrc, sDst, aFlags);
else:
curProgress = oGuestSession.copyTo(sSrc, sDst, aFlags);
if curProgress is not None:
oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlCopyFileTo");
try:
oProgress.wait();
if not oProgress.isSuccess():
oProgress.logResult(fIgnoreErrors = True);
fRc = False;
except:
reporter.logXcpt('Wait exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
fRc = False;
else:
reporter.error('No progress object returned');
fRc = False;
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Copy to exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
fRc = False;
return fRc;
def gctrlCreateDir(self, oTest, oRes, oGuestSession):
"""
Helper function to create a guest directory specified in
the current test.
"""
fRc = True; # Be optimistic.
reporter.log2('Creating directory "%s"' % (oTest.sDirectory,));
try:
oGuestSession.directoryCreate(oTest.sDirectory, \
oTest.fMode, oTest.aFlags);
if self.oTstDrv.fpApiVer >= 5.0:
fDirExists = oGuestSession.directoryExists(oTest.sDirectory, False);
else:
fDirExists = oGuestSession.directoryExists(oTest.sDirectory);
if fDirExists is False \
and oRes.fRc is True:
# Directory does not exist but we want it to.
fRc = False;
except:
reporter.logXcpt('Directory create exception for directory "%s":' % (oTest.sDirectory,));
if oRes.fRc is True:
# Just log, don't assume an error here (will be done in the main loop then).
fRc = False;
# Directory creation failed, which was the expected result.
return fRc;
def gctrlReadDir(self, oTest, oRes, oGuestSession, subDir = ''): # pylint: disable=R0914
"""
Helper function to read a guest directory specified in
the current test.
"""
sDir = oTest.sDirectory;
sFilter = oTest.sFilter;
aFlags = oTest.aFlags;
fRc = True; # Be optimistic.
cDirs = 0; # Number of directories read.
cFiles = 0; # Number of files read.
try:
sCurDir = os.path.join(sDir, subDir);
#reporter.log2('Directory="%s", filter="%s", aFlags="%s"' % (sCurDir, sFilter, aFlags));
oCurDir = oGuestSession.directoryOpen(sCurDir, sFilter, aFlags);
while fRc:
try:
oFsObjInfo = oCurDir.read();
if oFsObjInfo.name == "." \
or oFsObjInfo.name == "..":
#reporter.log2('\tSkipping "%s"' % oFsObjInfo.name);
continue; # Skip "." and ".." entries.
if oFsObjInfo.type is vboxcon.FsObjType_Directory:
#reporter.log2('\tDirectory "%s"' % oFsObjInfo.name);
cDirs += 1;
sSubDir = oFsObjInfo.name;
if subDir != "":
sSubDir = os.path.join(subDir, oFsObjInfo.name);
fRc, cSubDirs, cSubFiles = self.gctrlReadDir(oTest, oRes, oGuestSession, sSubDir);
cDirs += cSubDirs;
cFiles += cSubFiles;
elif oFsObjInfo.type is vboxcon.FsObjType_File:
#reporter.log2('\tFile "%s"' % oFsObjInfo.name);
cFiles += 1;
elif oFsObjInfo.type is vboxcon.FsObjType_Symlink:
#reporter.log2('\tSymlink "%s" -- not tested yet' % oFsObjInfo.name);
pass;
else:
reporter.error('\tDirectory "%s" contains invalid directory entry "%s" (type %d)' % \
(sCurDir, oFsObjInfo.name, oFsObjInfo.type));
fRc = False;
except Exception as oXcpt:
# No necessarily an error -- could be VBOX_E_OBJECT_NOT_FOUND. See reference.
if vbox.ComError.equal(oXcpt, vbox.ComError.VBOX_E_OBJECT_NOT_FOUND):
#reporter.log2('\tNo more directory entries for "%s"' % (sCurDir,));
break
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('\tDirectory open exception for directory="%s":' % (sCurDir,));
fRc = False;
break;
oCurDir.close();
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('\tDirectory open exception for directory="%s":' % (sCurDir,));
fRc = False;
return (fRc, cDirs, cFiles);
def gctrlExecDoTest(self, i, oTest, oRes, oGuestSession):
"""
Wrapper function around gctrlExecute to provide more sanity checking
when needed in actual execution tests.
"""
reporter.log('Testing #%d, cmd="%s" ...' % (i, oTest.sCmd));
fRc = self.gctrlExecute(oTest, oGuestSession);
if fRc is oRes.fRc:
if fRc is True:
# Compare exit status / code on successful process execution.
if oTest.uExitStatus != oRes.uExitStatus \
or oTest.iExitCode != oRes.iExitCode:
reporter.error('Test #%d failed: Got exit status + code %d,%d, expected %d,%d'
% (i, oTest.uExitStatus, oTest.iExitCode, oRes.uExitStatus, oRes.iExitCode));
return False;
if fRc is True:
# Compare test / result buffers on successful process execution.
if oTest.sBuf is not None \
and oRes.sBuf is not None:
if bytes(oTest.sBuf) != bytes(oRes.sBuf):
reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)'
% (i, map(hex, map(ord, oTest.sBuf)), len(oTest.sBuf), \
map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf)));
return False;
else:
reporter.log2('Test #%d passed: Buffers match (%d bytes)' % (i, len(oRes.sBuf)));
elif oRes.sBuf is not None \
and oRes.sBuf:
reporter.error('Test #%d failed: Got no buffer data, expected\n%s (%dbytes)' %
(i, map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf)));
return False;
elif oRes.cbStdOut > 0 \
and oRes.cbStdOut != oTest.cbStdOut:
reporter.error('Test #%d failed: Got %d stdout data, expected %d'
% (i, oTest.cbStdOut, oRes.cbStdOut));
return False;
else:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, oRes.fRc));
return False;
return True;
def gctrlExecute(self, oTest, oGuestSession):
"""
Helper function to execute a program on a guest, specified in
the current test.
"""
fRc = True; # Be optimistic.
## @todo Compare execution timeouts!
#tsStart = base.timestampMilli();
reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d' \
% (oGuestSession.user, oGuestSession.domain, \
oGuestSession.name, oGuestSession.timeout));
reporter.log2('Executing sCmd=%s, aFlags=%s, timeoutMS=%d, aArgs=%s, aEnv=%s' \
% (oTest.sCmd, oTest.aFlags, oTest.timeoutMS, \
oTest.aArgs, oTest.aEnv));
try:
curProc = oGuestSession.processCreate(oTest.sCmd,
oTest.aArgs if self.oTstDrv.fpApiVer >= 5.0 else oTest.aArgs[1:],
oTest.aEnv, oTest.aFlags, oTest.timeoutMS);
if curProc is not None:
reporter.log2('Process start requested, waiting for start (%dms) ...' % (oTest.timeoutMS,));
fWaitFor = [ vboxcon.ProcessWaitForFlag_Start ];
waitResult = curProc.waitForArray(fWaitFor, oTest.timeoutMS);
reporter.log2('Wait result returned: %d, current process status is: %d' % (waitResult, curProc.status));
if curProc.status == vboxcon.ProcessStatus_Started:
fWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ];
if vboxcon.ProcessCreateFlag_WaitForStdOut in oTest.aFlags:
fWaitFor.append(vboxcon.ProcessWaitForFlag_StdOut);
if vboxcon.ProcessCreateFlag_WaitForStdErr in oTest.aFlags:
fWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr);
## @todo Add vboxcon.ProcessWaitForFlag_StdIn.
reporter.log2('Process (PID %d) started, waiting for termination (%dms), waitFlags=%s ...' \
% (curProc.PID, oTest.timeoutMS, fWaitFor));
while True:
waitResult = curProc.waitForArray(fWaitFor, oTest.timeoutMS);
reporter.log2('Wait returned: %d' % (waitResult,));
try:
# Try stdout.
if waitResult == vboxcon.ProcessWaitResult_StdOut \
or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
reporter.log2('Reading stdout ...');
abBuf = curProc.Read(1, 64 * 1024, oTest.timeoutMS);
if abBuf:
reporter.log2('Process (PID %d) got %d bytes of stdout data' % (curProc.PID, len(abBuf)));
oTest.cbStdOut += len(abBuf);
oTest.sBuf = abBuf; # Appending does *not* work atm, so just assign it. No time now.
# Try stderr.
if waitResult == vboxcon.ProcessWaitResult_StdErr \
or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
reporter.log2('Reading stderr ...');
abBuf = curProc.Read(2, 64 * 1024, oTest.timeoutMS);
if abBuf:
reporter.log2('Process (PID %d) got %d bytes of stderr data' % (curProc.PID, len(abBuf)));
oTest.cbStdErr += len(abBuf);
oTest.sBuf = abBuf; # Appending does *not* work atm, so just assign it. No time now.
# Use stdin.
if waitResult == vboxcon.ProcessWaitResult_StdIn \
or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
pass; #reporter.log2('Process (PID %d) needs stdin data' % (curProc.pid,));
# Termination or error?
if waitResult == vboxcon.ProcessWaitResult_Terminate \
or waitResult == vboxcon.ProcessWaitResult_Error \
or waitResult == vboxcon.ProcessWaitResult_Timeout:
reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' \
% (curProc.PID, waitResult, curProc.status));
break;
except:
# Just skip reads which returned nothing.
pass;
reporter.log2('Final process status (PID %d) is: %d' % (curProc.PID, curProc.status));
reporter.log2('Process (PID %d) %d stdout, %d stderr' % (curProc.PID, oTest.cbStdOut, oTest.cbStdErr));
oTest.uExitStatus = curProc.status;
oTest.iExitCode = curProc.exitCode;
reporter.log2('Process (PID %d) has exit code: %d' % (curProc.PID, oTest.iExitCode));
except KeyboardInterrupt:
reporter.error('Process (PID %d) execution interrupted' % (curProc.PID,));
if curProc is not None:
curProc.close();
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Execution exception for command "%s":' % (oTest.sCmd,));
fRc = False;
return fRc;
def testGuestCtrlSessionEnvironment(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests the guest session environment changes.
"""
aoTests = [
# Check basic operations.
tdTestSessionEx([ # Initial environment is empty.
tdStepSessionCheckEnv(),
# Check clearing empty env.
tdStepSessionClearEnv(),
tdStepSessionCheckEnv(),
# Check set.
tdStepSessionSetEnv('FOO', 'BAR'),
tdStepSessionCheckEnv(['FOO=BAR',]),
tdStepRequireMinimumApiVer(5.0), # 4.3 can't cope with the remainder.
tdStepSessionClearEnv(),
tdStepSessionCheckEnv(),
# Check unset.
tdStepSessionUnsetEnv('BAR'),
tdStepSessionCheckEnv(['BAR']),
tdStepSessionClearEnv(),
tdStepSessionCheckEnv(),
# Set + unset.
tdStepSessionSetEnv('FOO', 'BAR'),
tdStepSessionCheckEnv(['FOO=BAR',]),
tdStepSessionUnsetEnv('FOO'),
tdStepSessionCheckEnv(['FOO']),
# Bulk environment changes (via attrib) (shall replace existing 'FOO').
tdStepSessionBulkEnv( ['PATH=/bin:/usr/bin', 'TMPDIR=/var/tmp', 'USER=root']),
tdStepSessionCheckEnv(['PATH=/bin:/usr/bin', 'TMPDIR=/var/tmp', 'USER=root']),
]),
tdTestSessionEx([ # Check that setting the same value several times works.
tdStepSessionSetEnv('FOO','BAR'),
tdStepSessionCheckEnv([ 'FOO=BAR',]),
tdStepSessionSetEnv('FOO','BAR2'),
tdStepSessionCheckEnv([ 'FOO=BAR2',]),
tdStepSessionSetEnv('FOO','BAR3'),
tdStepSessionCheckEnv([ 'FOO=BAR3',]),
tdStepRequireMinimumApiVer(5.0), # 4.3 can't cope with the remainder.
# Add a little unsetting to the mix.
tdStepSessionSetEnv('BAR', 'BEAR'),
tdStepSessionCheckEnv([ 'FOO=BAR3', 'BAR=BEAR',]),
tdStepSessionUnsetEnv('FOO'),
tdStepSessionCheckEnv([ 'FOO', 'BAR=BEAR',]),
tdStepSessionSetEnv('FOO','BAR4'),
tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR',]),
# The environment is case sensitive.
tdStepSessionSetEnv('foo','BAR5'),
tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR', 'foo=BAR5']),
tdStepSessionUnsetEnv('foo'),
tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR', 'foo']),
]),
tdTestSessionEx([ # Bulk settings merges stuff, last entry standing.
tdStepSessionBulkEnv(['FOO=bar', 'foo=bar', 'FOO=doofus', 'TMPDIR=/tmp', 'foo=bar2']),
tdStepSessionCheckEnv(['FOO=doofus', 'TMPDIR=/tmp', 'foo=bar2']),
tdStepRequireMinimumApiVer(5.0), # 4.3 is buggy!
tdStepSessionBulkEnv(['2=1+1', 'FOO=doofus2', ]),
tdStepSessionCheckEnv(['2=1+1', 'FOO=doofus2' ]),
]),
# Invalid variable names.
tdTestSessionEx([
tdStepSessionSetEnv('', 'FOO', vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
tdStepRequireMinimumApiVer(5.0), # 4.3 is too relaxed checking input!
tdStepSessionSetEnv('=', '===', vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
tdStepSessionSetEnv('FOO=', 'BAR', vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
tdStepSessionSetEnv('=FOO', 'BAR', vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
tdStepRequireMinimumApiVer(5.0), # 4.3 is buggy and too relaxed!
tdStepSessionBulkEnv(['', 'foo=bar'], vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
tdStepSessionBulkEnv(['=', 'foo=bar'], vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
tdStepSessionBulkEnv(['=FOO', 'foo=bar'], vbox.ComError.E_INVALIDARG),
tdStepSessionCheckEnv(),
]),
# A bit more weird keys/values.
tdTestSessionEx([ tdStepSessionSetEnv('$$$', ''),
tdStepSessionCheckEnv([ '$$$=',]), ]),
tdTestSessionEx([ tdStepSessionSetEnv('$$$', '%%%'),
tdStepSessionCheckEnv([ '$$$=%%%',]),
]),
tdTestSessionEx([ tdStepRequireMinimumApiVer(5.0), # 4.3 is buggy!
tdStepSessionSetEnv(u'ß$%ß&', ''),
tdStepSessionCheckEnv([ u'ß$%ß&=',]),
]),
# Misc stuff.
tdTestSessionEx([ tdStepSessionSetEnv('FOO', ''),
tdStepSessionCheckEnv(['FOO=',]),
]),
tdTestSessionEx([ tdStepSessionSetEnv('FOO', 'BAR'),
tdStepSessionCheckEnv(['FOO=BAR',])
],),
tdTestSessionEx([ tdStepSessionSetEnv('FOO', 'BAR'),
tdStepSessionSetEnv('BAR', 'BAZ'),
tdStepSessionCheckEnv([ 'FOO=BAR', 'BAR=BAZ',]),
]),
];
return tdTestSessionEx.executeListTestSessions(aoTests, self.oTstDrv, oSession, oTxsSession, oTestVm, 'SessionEnv');
def testGuestCtrlSession(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests the guest session handling.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
aaTests = [
# Invalid parameters.
[ tdTestSession(),
tdTestResultSession(fRc = False) ],
[ tdTestSession(sUser = ''),
tdTestResultSession(fRc = False) ],
[ tdTestSession(sPassword = 'bar'),
tdTestResultSession(fRc = False) ],
[ tdTestSession(sDomain = 'boo'),
tdTestResultSession(fRc = False) ],
[ tdTestSession(sPassword = 'bar', sDomain = 'boo'),
tdTestResultSession(fRc = False) ],
# User account without a passwort - forbidden.
[ tdTestSession(sUser = sUser),
tdTestResultSession(fRc = False) ],
# Wrong credentials.
# Note: On Guest Additions < 4.3 this always succeeds because these don't
# support creating dedicated sessions. Instead, guest process creation
# then will fail. See note below.
[ tdTestSession(sUser = 'foo', sPassword = 'bar', sDomain = 'boo'),
tdTestResultSession(fRc = False) ],
# Correct credentials.
[ tdTestSession(sUser = sUser, sPassword = sPassword),
tdTestResultSession(fRc = True, cNumSessions = 1) ]
];
# Parameters.
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestSession, use an index, later.
curRes = aTest[1]; # tdTestResult
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
reporter.log('Testing #%d, user="%s", sPassword="%s", sDomain="%s" ...' \
% (i, curTest.oCreds.sUser, curTest.oCreds.sPassword, curTest.oCreds.sDomain));
curGuestSessionName = 'testGuestCtrlSession: Test #%d' % (i);
fRc2, curGuestSession = curTest.createSession(curGuestSessionName);
# See note about < 4.3 Guest Additions above.
if curGuestSession is not None \
and curGuestSession.protocolVersion >= 2 \
and fRc2 is not curRes.fRc:
reporter.error('Test #%d failed: Session creation failed: Got %s, expected %s' \
% (i, fRc2, curRes.fRc));
fRc = False;
if fRc2:
# On Guest Additions < 4.3 getSessionCount() always will return 1, so skip the
# check then.
if curGuestSession.protocolVersion >= 2:
curSessionCount = curTest.getSessionCount(self.oTstDrv.oVBoxMgr);
if curSessionCount is not curRes.cNumSessions:
reporter.error('Test #%d failed: Session count does not match: Got %d, expected %d' \
% (i, curSessionCount, curRes.cNumSessions));
fRc = False;
break;
if curGuestSession is not None \
and curGuestSession.name != curGuestSessionName:
reporter.error('Test #%d failed: Session name does not match: Got "%s", expected "%s"' \
% (i, curGuestSession.name, curGuestSessionName));
fRc = False;
break;
fRc2 = curTest.closeSession();
if fRc2 is False:
reporter.error('Test #%d failed: Session could not be closed' % (i,));
fRc = False;
break;
if fRc is False:
return (False, oTxsSession);
# Multiple sessions.
iMaxGuestSessions = 31; # Maximum number of concurrent guest session allowed.
# Actually, this is 32, but we don't test session 0.
multiSession = {};
reporter.log2('Opening multiple guest tsessions at once ...');
for i in range(iMaxGuestSessions + 1):
multiSession[i] = tdTestSession(sUser = sUser, sPassword = sPassword, sSessionName = 'MultiSession #%d' % (i,));
multiSession[i].setEnvironment(oSession, oTxsSession, oTestVm);
curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
reporter.log2('MultiSession test #%d count is %d' % (i, curSessionCount));
if curSessionCount is not i:
reporter.error('MultiSession count #%d must be %d, got %d' % (i, i, curSessionCount));
fRc = False;
break;
fRc2, _ = multiSession[i].createSession('MultiSession #%d' % (i,));
if fRc2 is not True:
if i < iMaxGuestSessions:
reporter.error('MultiSession #%d test failed' % (i,));
fRc = False;
else:
reporter.log('MultiSession #%d exceeded concurrent guest session count, good' % (i,));
break;
curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
if curSessionCount is not iMaxGuestSessions:
reporter.error('Final MultiSession count must be %d, got %d'
% (iMaxGuestSessions, curSessionCount));
return (False, oTxsSession);
reporter.log2('Closing MultiSessions ...');
iLastSession = iMaxGuestSessions - 1;
for i in range(iLastSession): # Close all but the last opened session.
fRc2 = multiSession[i].closeSession();
reporter.log2('MultiSession #%d count is %d' % (i, multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr),));
if fRc2 is False:
reporter.error('Closing MultiSession #%d failed' % (i,));
fRc = False;
break;
curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
if curSessionCount is not 1:
reporter.error('Final MultiSession count #2 must be 1, got %d' % (curSessionCount,));
fRc = False;
try:
# r=bird: multiSession[0].oGuestSession is None! Why don't you just use 'assert' or 'if' to check
# the functioning of the __testcase__?
# Make sure that accessing the first opened guest session does not work anymore because we just removed (closed) it.
curSessionName = multiSession[0].oGuestSession.name;
reporter.error('Accessing first removed MultiSession should not be possible, got name="%s"' % (curSessionName,));
fRc = False;
except:
reporter.logXcpt('Could not access first removed MultiSession object, good:');
try:
# Try Accessing last opened session which did not get removed yet.
curSessionName = multiSession[iLastSession].oGuestSession.name;
reporter.log('Accessing last standing MultiSession worked, got name="%s"' % (curSessionName,));
multiSession[iLastSession].closeSession();
curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
if curSessionCount is not 0:
reporter.error('Final MultiSession count #3 must be 0, got %d' % (curSessionCount,));
fRc = False;
except:
reporter.logXcpt('Could not access last standing MultiSession object:');
fRc = False;
## @todo Test session timeouts.
return (fRc, oTxsSession);
def testGuestCtrlSessionFileRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests the guest session file reference handling.
"""
if oTestVm.isWindows():
sUser = "Administrator";
sPassword = "password";
sDomain = "";
sFile = "C:\\windows\\system32\\kernel32.dll";
# Number of stale guest files to create.
cStaleFiles = 10;
fRc = True;
try:
oGuest = oSession.o.console.guest;
oGuestSession = oGuest.createSession(sUser, sPassword, sDomain, \
"testGuestCtrlSessionFileRefs");
fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
waitResult = oGuestSession.waitForArray(fWaitFor, 30 * 1000);
#
# Be nice to Guest Additions < 4.3: They don't support session handling and
# therefore return WaitFlagNotSupported.
#
if waitResult != vboxcon.GuestSessionWaitResult_Start \
and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.log('Session did not start successfully, returned wait result: %d' \
% (waitResult));
return (False, oTxsSession);
reporter.log('Session successfully started');
#
# Open guest files and "forget" them (stale entries).
# For them we don't have any references anymore intentionally.
#
reporter.log2('Opening stale files');
for i in range(0, cStaleFiles):
try:
if self.oTstDrv.fpApiVer >= 5.0:
oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly, vboxcon.FileOpenAction_OpenExisting, 0);
else:
oGuestSession.fileOpen(sFile, "r", "oe", 0);
# Note: Use a timeout in the call above for not letting the stale processes
# hanging around forever. This can happen if the installed Guest Additions
# do not support terminating guest processes.
except:
reporter.errorXcpt('Opening stale file #%d failed:' % (i,));
fRc = False;
break;
if fRc:
cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
if cFiles != cStaleFiles:
reporter.error('Test failed: Got %d stale files, expected %d' % (cFiles, cStaleFiles));
fRc = False;
if fRc:
#
# Open non-stale files and close them again.
#
reporter.log2('Opening non-stale files');
aaFiles = [];
for i in range(0, cStaleFiles):
try:
if self.oTstDrv.fpApiVer >= 5.0:
oCurFile = oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly,
vboxcon.FileOpenAction_OpenExisting, 0);
else:
oCurFile = oGuestSession.fileOpen(sFile, "r", "oe", 0);
aaFiles.append(oCurFile);
except:
reporter.errorXcpt('Opening non-stale file #%d failed:' % (i,));
fRc = False;
break;
if fRc:
cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
if cFiles != cStaleFiles * 2:
reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles * 2));
fRc = False;
if fRc:
reporter.log2('Closing all non-stale files again ...');
for i in range(0, cStaleFiles):
try:
aaFiles[i].close();
except:
reporter.errorXcpt('Waiting for non-stale file #%d failed:' % (i,));
fRc = False;
break;
cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
# Here we count the stale files (that is, files we don't have a reference
# anymore for) and the opened and then closed non-stale files (that we still keep
# a reference in aaFiles[] for).
if cFiles != cStaleFiles:
reporter.error('Test failed: Got %d total files, expected %d' \
% (cFiles, cStaleFiles));
fRc = False;
if fRc:
#
# Check if all (referenced) non-stale files now are in "closed" state.
#
reporter.log2('Checking statuses of all non-stale files ...');
for i in range(0, cStaleFiles):
try:
curFilesStatus = aaFiles[i].status;
if curFilesStatus != vboxcon.FileStatus_Closed:
reporter.error('Test failed: Non-stale file #%d has status %d, expected %d' \
% (i, curFilesStatus, vboxcon.FileStatus_Closed));
fRc = False;
except:
reporter.errorXcpt('Checking status of file #%d failed:' % (i,));
fRc = False;
break;
if fRc:
reporter.log2('All non-stale files closed');
cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
reporter.log2('Final guest session file count: %d' % (cFiles,));
# Now try to close the session and see what happens.
reporter.log2('Closing guest session ...');
oGuestSession.close();
except:
reporter.errorXcpt('Testing for stale processes failed:');
fRc = False;
return (fRc, oTxsSession);
#def testGuestCtrlSessionDirRefs(self, oSession, oTxsSession, oTestVm):
# """
# Tests the guest session directory reference handling.
# """
# fRc = True;
# return (fRc, oTxsSession);
def testGuestCtrlSessionProcRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests the guest session process reference handling.
"""
if oTestVm.isWindows():
sUser = "Administrator";
sPassword = "password";
sDomain = "";
sCmd = "C:\\windows\\system32\\cmd.exe";
aArgs = [sCmd,];
# Number of stale guest processes to create.
cStaleProcs = 10;
fRc = True;
try:
oGuest = oSession.o.console.guest;
oGuestSession = oGuest.createSession(sUser, sPassword, sDomain, \
"testGuestCtrlSessionProcRefs");
fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
waitResult = oGuestSession.waitForArray(fWaitFor, 30 * 1000);
#
# Be nice to Guest Additions < 4.3: They don't support session handling and
# therefore return WaitFlagNotSupported.
#
if waitResult != vboxcon.GuestSessionWaitResult_Start \
and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.log('Session did not start successfully, returned wait result: %d' \
% (waitResult));
return (False, oTxsSession);
reporter.log('Session successfully started');
#
# Fire off forever-running processes and "forget" them (stale entries).
# For them we don't have any references anymore intentionally.
#
reporter.log2('Starting stale processes');
for i in range(0, cStaleProcs):
try:
oGuestSession.processCreate(sCmd,
aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], [],
[ vboxcon.ProcessCreateFlag_WaitForStdOut ], \
30 * 1000);
# Note: Use a timeout in the call above for not letting the stale processes
# hanging around forever. This can happen if the installed Guest Additions
# do not support terminating guest processes.
except:
reporter.logXcpt('Creating stale process #%d failed:' % (i,));
fRc = False;
break;
if fRc:
cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
if cProcs != cStaleProcs:
reporter.error('Test failed: Got %d stale processes, expected %d' % (cProcs, cStaleProcs));
fRc = False;
if fRc:
#
# Fire off non-stale processes and wait for termination.
#
if oTestVm.isWindows():
aArgs = [ sCmd, '/C', 'dir', '/S', 'C:\\Windows\\system'];
reporter.log2('Starting non-stale processes');
aaProcs = [];
for i in range(0, cStaleProcs):
try:
oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
[], [], 0); # Infinite timeout.
aaProcs.append(oCurProc);
except:
reporter.logXcpt('Creating non-stale process #%d failed:' % (i,));
fRc = False;
break;
if fRc:
reporter.log2('Waiting for non-stale processes to terminate');
for i in range(0, cStaleProcs):
try:
aaProcs[i].waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000);
curProcStatus = aaProcs[i].status;
if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
reporter.error('Test failed: Waiting for non-stale processes #%d'
' resulted in status %d, expected %d' \
% (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
fRc = False;
except:
reporter.logXcpt('Waiting for non-stale process #%d failed:' % (i,));
fRc = False;
break;
cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
# Here we count the stale processes (that is, processes we don't have a reference
# anymore for) and the started + terminated non-stale processes (that we still keep
# a reference in aaProcs[] for).
if cProcs != (cStaleProcs * 2):
reporter.error('Test failed: Got %d total processes, expected %d' \
% (cProcs, cStaleProcs));
fRc = False;
if fRc:
#
# Check if all (referenced) non-stale processes now are in "terminated" state.
#
for i in range(0, cStaleProcs):
curProcStatus = aaProcs[i].status;
if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
reporter.error('Test failed: Non-stale processes #%d has status %d, expected %d' \
% (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
fRc = False;
if fRc:
reporter.log2('All non-stale processes terminated');
# Fire off blocking processes which are terminated via terminate().
if oTestVm.isWindows():
aArgs = [ sCmd, '/C', 'dir', '/S', 'C:\\Windows'];
reporter.log2('Starting blocking processes');
aaProcs = [];
for i in range(0, cStaleProcs):
try:
oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
[], [], 30 * 1000);
# Note: Use a timeout in the call above for not letting the stale processes
# hanging around forever. This can happen if the installed Guest Additions
# do not support terminating guest processes.
aaProcs.append(oCurProc);
except:
reporter.logXcpt('Creating blocking process failed:');
fRc = False;
break;
if fRc:
reporter.log2('Terminating blocking processes');
for i in range(0, cStaleProcs):
try:
aaProcs[i].terminate();
except: # Termination might not be supported, just skip and log it.
reporter.logXcpt('Termination of blocking process failed, skipped:');
cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
if cProcs != (cStaleProcs * 2): # Still should be 20 processes because we terminated the 10 newest ones.
reporter.error('Test failed: Got %d total processes, expected %d' % (cProcs, cStaleProcs * 2));
fRc = False;
cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
reporter.log2('Final guest session processes count: %d' % (cProcs,));
# Now try to close the session and see what happens.
reporter.log2('Closing guest session ...');
oGuestSession.close();
except:
reporter.logXcpt('Testing for stale processes failed:');
fRc = False;
return (fRc, oTxsSession);
def testGuestCtrlExec(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914,R0915
"""
Tests the basic execution feature.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
if oTestVm.isWindows():
# Outputting stuff.
sImageOut = "C:\\windows\\system32\\cmd.exe";
else:
reporter.error('Implement me!'); ## @todo Implement non-Windows bits.
return (False, oTxsSession);
aaInvalid = [
# Invalid parameters.
[ tdTestExec(sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = False) ],
# Non-existent / invalid image.
[ tdTestExec(sCmd = "non-existent", sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = False) ],
[ tdTestExec(sCmd = "non-existent2", sUser = sUser, sPassword = sPassword, fWaitForExit = True),
tdTestResultExec(fRc = False) ],
# Use an invalid format string.
[ tdTestExec(sCmd = "%$%%%&", sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = False) ],
# More stuff.
[ tdTestExec(sCmd = u"ƒ‰‹ˆ÷‹¸", sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = False) ],
[ tdTestExec(sCmd = "???://!!!", sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = False) ],
[ tdTestExec(sCmd = "<>!\\", sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = False) ]
# Enable as soon as ERROR_BAD_DEVICE is implemented.
#[ tdTestExec(sCmd = "CON", sUser = sUser, sPassword = sPassword),
# tdTestResultExec(fRc = False) ]
];
if oTestVm.isWindows():
sVBoxControl = "C:\\Program Files\\Oracle\\VirtualBox Guest Additions\\VBoxControl.exe";
aaExec = [
# Basic executon.
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True) ],
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32\\kernel32.dll' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True) ],
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32\\nonexist.dll' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ],
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', '/wrongparam' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ],
# Paths with spaces.
## @todo Get path of installed Guest Additions. Later.
[ tdTestExec(sCmd = sVBoxControl, aArgs = [ sVBoxControl, 'version' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True) ],
# StdOut.
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True) ],
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdout-non-existing' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ],
# StdErr.
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True) ],
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stderr-non-existing' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ],
# StdOut + StdErr.
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True) ],
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdouterr-non-existing' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ]
# FIXME: Failing tests.
# Environment variables.
# [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_NONEXIST' ],
# sUser = sUser, sPassword = sPassword),
# tdTestResultExec(fRc = True, iExitCode = 1) ]
# [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'windir' ],
# sUser = sUser, sPassword = sPassword,
# aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, sBuf = 'windir=C:\\WINDOWS\r\n') ],
# [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ],
# sUser = sUser, sPassword = sPassword,
# aEnv = [ 'TEST_FOO=BAR' ],
# aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ],
# [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ],
# sUser = sUser, sPassword = sPassword,
# aEnv = [ 'TEST_FOO=BAR', 'TEST_BAZ=BAR' ],
# aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ]
## @todo Create some files (or get files) we know the output size of to validate output length!
## @todo Add task which gets killed at some random time while letting the guest output something.
];
# Manual test, not executed automatically.
aaManual = [
[ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir /S C:\\Windows' ],
sUser = sUser, sPassword = sPassword,
aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
tdTestResultExec(fRc = True, cbStdOut = 497917) ] ];
else:
reporter.log('No OS-specific tests for non-Windows yet!');
# Build up the final test array for the first batch.
aaTests = [];
aaTests.extend(aaInvalid);
if aaExec is not None:
aaTests.extend(aaExec);
fRc = True;
#
# Single execution stuff. Nice for debugging.
#
fManual = False;
if fManual:
curTest = aaTests[1][0]; # tdTestExec, use an index, later.
curRes = aaTests[1][1]; # tdTestResultExec
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Single test 1');
if fRc is False:
reporter.error('Single test failed: Could not create session');
else:
fRc = self.gctrlExecDoTest(0, curTest, curRes, curGuestSession);
curTest.closeSession();
curTest = aaTests[2][0]; # tdTestExec, use an index, later.
curRes = aaTests[2][1]; # tdTestResultExec
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Single test 2');
if fRc is False:
reporter.error('Single test failed: Could not create session');
else:
fRc = self.gctrlExecDoTest(0, curTest, curRes, curGuestSession);
curTest.closeSession();
curTest = aaTests[3][0]; # tdTestExec, use an index, later.
curRes = aaTests[3][1]; # tdTestResultExec
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Single test 3');
if fRc is False:
reporter.error('Single test failed: Could not create session');
else:
fRc = self.gctrlExecDoTest(0, curTest, curRes, curGuestSession);
curTest.closeSession();
return (fRc, oTxsSession);
else:
aaManual = aaManual; # Workaround for pylint #W0612.
if fRc is False:
return (fRc, oTxsSession);
#
# First batch: One session per guest process.
#
reporter.log('One session per guest process ...');
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResultExec
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);
if fRc is False:
break;
fRc = curTest.closeSession();
if fRc is False:
break;
# No sessions left?
if fRc is True:
aSessions = self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions');
cSessions = len(aSessions);
if cSessions is not 0:
reporter.error('Found %d stale session(s), expected 0:' % (cSessions,));
for (i, aSession) in enumerate(aSessions):
reporter.log('\tStale session #%d ("%s")' % (aSession.id, aSession.name));
fRc = False;
if fRc is False:
return (fRc, oTxsSession);
reporter.log('Now using one guest session for all tests ...');
#
# Second batch: One session for *all* guest processes.
#
oGuest = oSession.o.console.guest;
try:
reporter.log('Creating session for all tests ...');
curGuestSession = oGuest.createSession(sUser, sPassword, '', 'testGuestCtrlExec: One session for all tests');
try:
fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
waitResult = curGuestSession.waitForArray(fWaitFor, 30 * 1000);
if waitResult != vboxcon.GuestSessionWaitResult_Start \
and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
reporter.error('Session did not start successfully, returned wait result: %d' \
% (waitResult));
return (False, oTxsSession);
reporter.log('Session successfully started');
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Waiting for guest session to start failed:');
return (False, oTxsSession);
# Note: Not waiting for the guest session to start here
# is intentional. This must be handled by the process execution
# call then.
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResultExec
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);
if fRc is False:
break;
try:
reporter.log2('Closing guest session ...');
curGuestSession.close();
curGuestSession = None;
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Closing guest session failed:');
fRc = False;
except:
reporter.logXcpt('Could not create one session:');
# No sessions left?
if fRc is True:
cSessions = len(self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions'));
if cSessions is not 0:
reporter.error('Found %d stale session(s), expected 0' % (cSessions,));
fRc = False;
return (fRc, oTxsSession);
def testGuestCtrlExecErrorLevel(self, oSession, oTxsSession, oTestVm):
"""
Tests handling of error levels from started guest processes.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
if oTestVm.isWindows():
# Outputting stuff.
sImage = "C:\\windows\\system32\\cmd.exe";
else:
reporter.error('Implement me!'); ## @todo Implement non-Windows bits.
return (False, oTxsSession);
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Simple.
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'wrongcommand' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'exit', '22' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 22) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'set', 'ERRORLEVEL=234' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 0) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'echo', '%WINDIR%' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 0) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'set', 'ERRORLEVEL=0' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 0) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 0) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32\\kernel32.dll' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 0) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ],
[ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
sUser = sUser, sPassword = sPassword),
tdTestResultExec(fRc = True, iExitCode = 1) ]
# FIXME: Failing tests.
# With stdout.
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
# sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
# tdTestResultExec(fRc = True, iExitCode = 0) ],
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
# sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
# tdTestResultExec(fRc = True, iExitCode = 1) ],
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
# sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
# tdTestResultExec(fRc = True, iExitCode = 1) ],
# With stderr.
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
# sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, iExitCode = 0) ],
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
# sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, iExitCode = 1) ],
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
# sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, iExitCode = 1) ],
# With stdout/stderr.
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
# sUser = sUser, sPassword = sPassword,
# aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, iExitCode = 0) ],
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
# sUser = sUser, sPassword = sPassword,
# aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, iExitCode = 1) ],
# [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
# sUser = sUser, sPassword = sPassword,
# aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
# tdTestResultExec(fRc = True, iExitCode = 1) ]
## @todo Test stdin!
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlExecErrorLevel: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);
curTest.closeSession();
if fRc is False:
break;
return (fRc, oTxsSession);
def testGuestCtrlExecTimeout(self, oSession, oTxsSession, oTestVm):
"""
Tests handling of timeouts of started guest processes.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
sDomain = "";
if oTestVm.isWindows():
# Outputting stuff.
sImage = "C:\\windows\\system32\\cmd.exe";
else:
reporter.error('Implement me!'); ## @todo Implement non-Windows bits.
return (False, oTxsSession);
fRc = True;
try:
oGuest = oSession.o.console.guest;
oGuestSession = oGuest.createSession(sUser, sPassword, sDomain, "testGuestCtrlExecTimeout");
oGuestSession.waitForArray([ vboxcon.GuestSessionWaitForFlag_Start ], 30 * 1000);
# Create a process which never terminates and should timeout when
# waiting for termination.
try:
curProc = oGuestSession.processCreate(sImage, [sImage,] if self.oTstDrv.fpApiVer >= 5.0 else [], \
[], [], 30 * 1000);
reporter.log('Waiting for process 1 being started ...');
waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
if waitRes != vboxcon.ProcessWaitResult_Start:
reporter.error('Waiting for process 1 to start failed, got status %d');
fRc = False;
if fRc:
reporter.log('Waiting for process 1 to time out within 1ms ...');
waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 1);
if waitRes != vboxcon.ProcessWaitResult_Timeout:
reporter.error('Waiting for process 1 did not time out when it should (1)');
fRc = False;
else:
reporter.log('Waiting for process 1 timed out (1), good');
if fRc:
reporter.log('Waiting for process 1 to time out within 5000ms ...');
waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 5000);
if waitRes != vboxcon.ProcessWaitResult_Timeout:
reporter.error('Waiting for process 1 did not time out when it should, got wait result %d' % (waitRes,));
fRc = False;
else:
reporter.log('Waiting for process 1 timed out (5000), good');
## @todo Add curProc.terminate() as soon as it's implemented.
except:
reporter.errorXcpt('Exception for process 1:');
fRc = False;
# Create a lengthly running guest process which will be killed by VBoxService on the
# guest because it ran out of execution time (5 seconds).
if fRc:
try:
curProc = oGuestSession.processCreate(sImage, [sImage,] if self.oTstDrv.fpApiVer >= 5.0 else [], \
[], [], 5 * 1000);
reporter.log('Waiting for process 2 being started ...');
waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
if waitRes != vboxcon.ProcessWaitResult_Start:
reporter.error('Waiting for process 1 to start failed, got status %d');
fRc = False;
if fRc:
reporter.log('Waiting for process 2 to get killed because it ran out of execution time ...');
waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000);
if waitRes != vboxcon.ProcessWaitResult_Timeout:
reporter.error('Waiting for process 2 did not time out when it should, got wait result %d' \
% (waitRes,));
fRc = False;
if fRc:
reporter.log('Waiting for process 2 indicated an error, good');
if curProc.status != vboxcon.ProcessStatus_TimedOutKilled:
reporter.error('Status of process 2 wrong; excepted %d, got %d' \
% (vboxcon.ProcessStatus_TimedOutKilled, curProc.status));
fRc = False;
else:
reporter.log('Status of process 2 correct (%d)' % (vboxcon.ProcessStatus_TimedOutKilled,));
## @todo Add curProc.terminate() as soon as it's implemented.
except:
reporter.errorXcpt('Exception for process 2:');
fRc = False;
oGuestSession.close();
except:
reporter.errorXcpt('Could not handle session:');
fRc = False;
return (fRc, oTxsSession);
def testGuestCtrlDirCreate(self, oSession, oTxsSession, oTestVm):
"""
Tests creation of guest directories.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
if oTestVm.isWindows():
sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlDirCreate\\";
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Invalid stuff.
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '' ),
tdTestResult(fRc = False) ],
# More unusual stuff.
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '..\\..\\' ),
tdTestResult(fRc = False) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '../../' ),
tdTestResult(fRc = False) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = 'z:\\' ),
tdTestResult(fRc = False) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '\\\\uncrulez\\foo' ),
tdTestResult(fRc = False) ],
# Creating directories.
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = sScratch ),
tdTestResult(fRc = False) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = os.path.join(sScratch, 'foo\\bar\\baz'),
aFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ),
tdTestResult(fRc = True) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = os.path.join(sScratch, 'foo\\bar\\baz'),
aFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ),
tdTestResult(fRc = True) ],
# Long (+ random) stuff.
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
sDirectory = os.path.join(sScratch,
"".join(random.choice(string.ascii_lowercase) for i in range(32))) ),
tdTestResult(fRc = True) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
sDirectory = os.path.join(sScratch,
"".join(random.choice(string.ascii_lowercase) for i in range(128))) ),
tdTestResult(fRc = True) ],
# Following two should fail on Windows (paths too long). Both should timeout.
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
sDirectory = os.path.join(sScratch,
"".join(random.choice(string.ascii_lowercase) for i in range(255))) ),
tdTestResult(fRc = False) ],
[ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
sDirectory = os.path.join(sScratch,
"".join(random.choice(string.ascii_lowercase) for i in range(1024)))
),
tdTestResult(fRc = False) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sDirectory="%s" ...' % (i, curTest.sDirectory));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlDirCreate: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
fRc = self.gctrlCreateDir(curTest, curRes, curGuestSession);
curTest.closeSession();
if fRc is False:
reporter.error('Test #%d failed' % (i,));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlDirCreateTemp(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests creation of temporary directories.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
# if oTestVm.isWindows():
# sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlDirCreateTemp\\";
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Invalid stuff.
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sDirectory = ''),
tdTestResult(fRc = False) ],
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sDirectory = 'C:\\Windows',
fMode = 1234),
tdTestResult(fRc = False) ],
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = '',
sDirectory = 'C:\\Windows', fMode = 1234),
tdTestResult(fRc = False) ],
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'xXx',
sDirectory = 'C:\\Windows', fMode = 0o700),
tdTestResult(fRc = False) ],
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'xxx',
sDirectory = 'C:\\Windows', fMode = 0o700),
tdTestResult(fRc = False) ],
# More unusual stuff.
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'foo',
sDirectory = 'z:\\'),
tdTestResult(fRc = False) ],
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'foo',
sDirectory = '\\\\uncrulez\\foo'),
tdTestResult(fRc = False) ],
# Non-existing stuff.
[ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'bar',
sDirectory = 'c:\\Apps\\nonexisting\\foo'),
tdTestResult(fRc = False) ],
# FIXME: Failing test. Non Windows path
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'bar',
# sDirectory = '/tmp/non/existing'),
# tdTestResult(fRc = False) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
# FIXME: Failing tests.
# aaTests.extend([
# Non-secure variants.
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'X',
# sDirectory = sScratch),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'X',
# sDirectory = sScratch),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fMode = 0o700),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fMode = 0o700),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fMode = 0o755),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fMode = 0o755),
# tdTestResult(fRc = True) ],
# Secure variants.
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch, fSecure = True),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch, fSecure = True),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch, fSecure = True),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch, fSecure = True),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fSecure = True, fMode = 0o700),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fSecure = True, fMode = 0o700),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fSecure = True, fMode = 0o755),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
# sDirectory = sScratch,
# fSecure = True, fMode = 0o755),
# tdTestResult(fRc = True) ],
# Random stuff.
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword,
# sTemplate = "XXX-".join(random.choice(string.ascii_lowercase) for i in range(32)),
# sDirectory = sScratch,
# fSecure = True, fMode = 0o755),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = "".join('X' for i in range(32)),
# sDirectory = sScratch,
# fSecure = True, fMode = 0o755),
# tdTestResult(fRc = True) ],
# [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = "".join('X' for i in range(128)),
# sDirectory = sScratch,
# fSecure = True, fMode = 0o755),
# tdTestResult(fRc = True) ]
# ]);
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sTemplate="%s", fMode=%#o, path="%s", secure="%s" ...' %
(i, curTest.sTemplate, curTest.fMode, curTest.sDirectory, curTest.fSecure));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlDirCreateTemp: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
sDirTemp = "";
try:
sDirTemp = curGuestSession.directoryCreateTemp(curTest.sTemplate, curTest.fMode,
curTest.sDirectory, curTest.fSecure);
except:
if curRes.fRc is True:
reporter.errorXcpt('Creating temp directory "%s" failed:' % (curTest.sDirectory,));
fRc = False;
break;
else:
reporter.logXcpt('Creating temp directory "%s" failed expectedly, skipping:' % (curTest.sDirectory,));
curTest.closeSession();
if sDirTemp != "":
reporter.log2('Temporary directory is: %s' % (sDirTemp,));
if self.oTstDrv.fpApiVer >= 5.0:
fExists = curGuestSession.directoryExists(sDirTemp, False);
else:
fExists = curGuestSession.directoryExists(sDirTemp);
if fExists is False:
reporter.error('Test #%d failed: Temporary directory "%s" does not exists' % (i, sDirTemp));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlDirRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests opening and reading (enumerating) guest directories.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Invalid stuff.
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = ''),
tdTestResultDirRead(fRc = False) ],
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'C:\\Windows', aFlags = [ 1234 ]),
tdTestResultDirRead(fRc = False) ],
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'C:\\Windows', sFilter = '*.foo'),
tdTestResultDirRead(fRc = False) ],
# More unusual stuff.
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'z:\\'),
tdTestResultDirRead(fRc = False) ],
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = '\\\\uncrulez\\foo'),
tdTestResultDirRead(fRc = False) ],
# Non-existing stuff.
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Apps\\nonexisting'),
tdTestResultDirRead(fRc = False) ],
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Apps\\testDirRead'),
tdTestResultDirRead(fRc = False) ]
]);
if oTestVm.sVmName == 'tst-xppro':
aaTests.extend([
# Reading directories.
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = '../../Windows/Fonts'),
tdTestResultDirRead(fRc = True, numFiles = 191) ],
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Windows\\Help'),
tdTestResultDirRead(fRc = True, numDirs = 13, numFiles = 569) ],
[ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Windows\\Web'),
tdTestResultDirRead(fRc = True, numDirs = 3, numFiles = 55) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, dir="%s" ...' % (i, curTest.sDirectory));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlDirRead: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
(fRc2, cDirs, cFiles) = self.gctrlReadDir(curTest, curRes, curGuestSession);
curTest.closeSession();
reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles));
if fRc2 is curRes.fRc:
if fRc2 is True:
if curRes.numFiles != cFiles:
reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, curRes.numFiles));
fRc = False;
break;
if curRes.numDirs != cDirs:
reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, curRes.numDirs));
fRc = False;
break;
else:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlFileRemove(self, oSession, oTxsSession, oTestVm):
"""
Tests removing guest files.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Invalid stuff.
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = ''),
tdTestResult(fRc = False) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows'),
tdTestResult(fRc = False) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows'),
tdTestResult(fRc = False) ],
# More unusual stuff.
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'z:\\'),
tdTestResult(fRc = False) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\foo'),
tdTestResult(fRc = False) ],
# Non-existing stuff.
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Apps\\nonexisting'),
tdTestResult(fRc = False) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Apps\\testFileRemove'),
tdTestResult(fRc = False) ],
# Try to delete system files.
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\pagefile.sys'),
tdTestResult(fRc = False) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\kernel32.sys'),
tdTestResult(fRc = False) ]
]);
if oTestVm.sVmName == 'tst-xppro':
aaTests.extend([
# Try delete some unimportant media stuff.
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chimes.wav'),
tdTestResult(fRc = True) ],
# Second attempt should fail.
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chimes.wav'),
tdTestResult(fRc = False) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chord.wav'),
tdTestResult(fRc = True) ],
[ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chord.wav'),
tdTestResult(fRc = False) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, file="%s" ...' % (i, curTest.sFile));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlFileRemove: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
try:
if self.oTstDrv.fpApiVer >= 5.0:
curGuestSession.fsObjRemove(curTest.sFile);
else:
curGuestSession.fileRemove(curTest.sFile);
except:
if curRes.fRc is True:
reporter.errorXcpt('Removing file "%s" failed:' % (curTest.sFile,));
fRc = False;
break;
else:
reporter.logXcpt('Removing file "%s" failed expectedly, skipping:' % (curTest.sFile,));
curTest.closeSession();
return (fRc, oTxsSession);
def testGuestCtrlFileStat(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests querying file information through stat.
"""
# Basic stuff, existing stuff.
aoTests = [
tdTestSessionEx([ tdStepStatDir('.'),
tdStepStatDir('..'),
]),
];
if oTestVm.isWindows():
aoTests += [ tdTestSessionEx([ tdStepStatDir('C:\\Windows'),
tdStepStatDir('C:\\Windows\\System32'),
tdStepStatDir('C:\\Windows\\System32\\'),
tdStepStatDir('C:\\Windows\\System32\\.'),
tdStepStatDir('C:\\Windows\\System32\\.\\'),
tdStepStatDir('C:\\Windows\\System32\\..'),
tdStepStatDir('C:\\Windows\\System32\\..\\'),
tdStepStatDir('C:\\Windows\\System32\\..\\\\'),
tdStepStatDir('C:\\Windows\\System32\\\\..\\\\'),
tdStepStatDir('C:/Windows/System32'),
tdStepStatDir('C:/Windows/System32/'),
tdStepStatDir('c:/winDowS/sYsTeM32/'),
tdStepStatDir('C:/Windows/System32/.'),
tdStepStatDir('C:/Windows/System32/./'),
tdStepStatDir('C:/Windows/System32/..'),
tdStepStatDir('C:/Windows/System32/../'),
tdStepStatDir('C:/Windows/System32/..//'),
tdStepStatDir('C:/Windows/System32//..//'),
tdStepStatFile('C:\\Windows\\System32\\kernel32.dll'),
tdStepStatFile('C:/Windows/System32/kernel32.dll')
]) ];
elif oTestVm.isOS2():
aoTests += [ tdTestSessionEx([ tdStepStatDir('C:\\OS2'),
tdStepStatDir('C:\\OS2\\DLL'),
tdStepStatDir('C:\\OS2\\DLL\\'),
tdStepStatDir('C:/OS2/DLL'),
tdStepStatDir('c:/OS2/DLL'),
tdStepStatDir('c:/OS2/DLL/'),
tdStepStatFile('C:\\CONFIG.SYS'),
tdStepStatFile('C:\\OS2\\DLL\\DOSCALL1.DLL'),
]) ];
else: # generic unix.
aoTests += [ tdTestSessionEx([ tdStepStatDir('/'),
tdStepStatDir('///'),
tdStepStatDir('/usr/bin/.'),
tdStepStatDir('/usr/bin/./'),
tdStepStatDir('/usr/bin/..'),
tdStepStatDir('/usr/bin/../'),
tdStepStatFile('/bin/ls'),
tdStepStatFile('/bin/cp'),
tdStepStatFile('/bin/date'),
]) ];
# None existing stuff.
if oTestVm.isWindows() or oTestVm.isOS2():
aoTests += [ tdTestSessionEx([ tdStepStatFileNotFound('C:\\NoSuchFileOrDirectory', ),
tdStepStatPathNotFound('C:\\NoSuchDirectory\\'),
tdStepStatPathNotFound('C:/NoSuchDirectory/'),
tdStepStatPathNotFound('C:\\NoSuchDirectory\\.'),
tdStepStatPathNotFound('C:/NoSuchDirectory/.'),
tdStepStatPathNotFound('C:\\NoSuchDirectory\\NoSuchFileOrDirectory'),
tdStepStatPathNotFound('C:/NoSuchDirectory/NoSuchFileOrDirectory'),
tdStepStatPathNotFound('C:/NoSuchDirectory/NoSuchFileOrDirectory/'),
tdStepStatPathNotFound('N:\\'), # ASSUMES nothing mounted on N:!
tdStepStatPathNotFound('\\\\NoSuchUncServerName\\NoSuchShare'),
]) ];
else: # generic unix.
aoTests += [ tdTestSessionEx([ tdStepStatFileNotFound('/NoSuchFileOrDirectory', ),
tdStepStatFileNotFound('/bin/NoSuchFileOrDirectory'),
tdStepStatPathNotFound('/NoSuchDirectory/'),
tdStepStatPathNotFound('/NoSuchDirectory/.'),
]) ];
# Invalid parameter check.
aoTests += [ tdTestSessionEx([ tdStepStat('', vbox.ComError.E_INVALIDARG), ]), ];
# Some test VM specific tests.
if oTestVm.sVmName == 'tst-xppro':
aoTests += [ tdTestSessionEx([ tdStepStatFileSize('c:\\Windows\\system32\\kernel32.dll', 926720), ]) ];
#
# Execute the tests.
#
return tdTestSessionEx.executeListTestSessions(aoTests, self.oTstDrv, oSession, oTxsSession, oTestVm, 'FsStat');
def testGuestCtrlFileRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests reading from guest files.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlFileRead') is False:
reporter.error('Could not create scratch directory on guest');
return (False, oTxsSession);
aaTests = [];
aaTests.extend([
# Invalid stuff.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, cbToReadWrite = 0),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = ''),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file'),
tdTestResultFileReadWrite(fRc = False) ],
# Wrong open mode.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file', \
sOpenMode = 'rt', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\non-existing.file', \
sOpenMode = 'tr', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '../../non-existing.file', \
sOpenMode = 'wr', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = False) ],
# Wrong disposition.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file', \
sOpenMode = 'r', sDisposition = 'e'),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\non-existing.file', \
sOpenMode = 'r', sDisposition = 'o'),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '../../non-existing.file', \
sOpenMode = 'r', sDisposition = 'c'),
tdTestResultFileReadWrite(fRc = False) ],
# Opening non-existing file when it should exist.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file', \
sOpenMode = 'r', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\non-existing.file', \
sOpenMode = 'r', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = False) ],
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '../../non-existing.file', \
sOpenMode = 'r', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = False) ]
]);
if oTestVm.isWindows():
aaTests.extend([
# Create a file which must not exist (but it hopefully does).
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\calc.exe', \
sOpenMode = 'w', sDisposition = 'ce'),
tdTestResultFileReadWrite(fRc = False) ],
# Open a file which must exist.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\kernel32.dll', \
sOpenMode = 'r', sDisposition = 'oe'),
tdTestResultFileReadWrite(fRc = True) ],
# Try truncating a file which already is opened with a different sharing mode (and thus should fail).
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\kernel32.dll', \
sOpenMode = 'w', sDisposition = 'ot'),
tdTestResultFileReadWrite(fRc = False) ]
]);
if oTestVm.sKind == "WindowsXP":
aaTests.extend([
# Reading from beginning.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\eula.txt', \
sOpenMode = 'r', sDisposition = 'oe', cbToReadWrite = 33),
tdTestResultFileReadWrite(fRc = True, aBuf = 'Microsoft Windows XP Professional', \
cbProcessed = 33, cbOffset = 33) ],
# Reading from offset.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\eula.txt', \
sOpenMode = 'r', sDisposition = 'oe', cbOffset = 17782, cbToReadWrite = 26),
tdTestResultFileReadWrite(fRc = True, aBuf = 'LINKS TO THIRD PARTY SITES', \
cbProcessed = 26, cbOffset = 17782 + 26) ]
]);
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' % \
(i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlFileRead: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
try:
if curTest.cbOffset > 0: # The offset parameter is gone.
if self.oTstDrv.fpApiVer >= 5.0:
curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
curTest.getSharingMode(), curTest.lCreationMode, []);
curFile.seek(curTest.cbOffset, vboxcon.FileSeekOrigin_Begin);
else:
curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.sOpenMode, curTest.sDisposition, \
curTest.sSharingMode, curTest.lCreationMode, curTest.cbOffset);
curOffset = long(curFile.offset);
resOffset = long(curTest.cbOffset);
if curOffset != resOffset:
reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \
% (i, curOffset, resOffset));
fRc = False;
else:
if self.oTstDrv.fpApiVer >= 5.0:
curFile = curGuestSession.fileOpen(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
curTest.lCreationMode);
else:
curFile = curGuestSession.fileOpen(curTest.sFile, curTest.sOpenMode, curTest.sDisposition, \
curTest.lCreationMode);
if fRc \
and curTest.cbToReadWrite > 0:
## @todo Split this up in 64K reads. Later.
## @todo Test timeouts.
aBufRead = curFile.read(curTest.cbToReadWrite, 30 * 1000);
if curRes.cbProcessed > 0 \
and curRes.cbProcessed is not len(aBufRead):
reporter.error('Test #%d failed: Read buffer length does not match: Got %d, expected %d' \
% (i, len(aBufRead), curRes.cbProcessed));
fRc = False;
if fRc:
if curRes.aBuf is not None \
and bytes(curRes.aBuf) != bytes(aBufRead):
reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)' \
% (i, map(hex, map(ord, aBufRead)), len(aBufRead), \
map(hex, map(ord, curRes.aBuf)), len(curRes.aBuf)));
reporter.error('Test #%d failed: Got buffer\n%s, expected\n%s' \
% (i, aBufRead, curRes.aBuf));
fRc = False;
# Test final offset.
curOffset = long(curFile.offset);
resOffset = long(curRes.cbOffset);
if curOffset != resOffset:
reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \
% (i, curOffset, resOffset));
fRc = False;
curFile.close();
except:
reporter.logXcpt('Opening "%s" failed:' % (curTest.sFile,));
fRc = False;
curTest.closeSession();
if fRc != curRes.fRc:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlFileWrite(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests writing to guest files.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
if oTestVm.isWindows():
sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlFileWrite\\";
if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlFileWrite') is False:
reporter.error('Could not create scratch directory on guest');
return (False, oTxsSession);
aaTests = [];
cScratchBuf = 512;
aScratchBuf = array('b', [random.randint(-128, 127) for i in range(cScratchBuf)]);
aaTests.extend([
# Write to a non-existing file.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = sScratch + 'testGuestCtrlFileWrite.txt', \
sOpenMode = 'w+', sDisposition = 'ce', cbToReadWrite = cScratchBuf,
aBuf = aScratchBuf),
tdTestResultFileReadWrite(fRc = True, aBuf = aScratchBuf, \
cbProcessed = cScratchBuf, cbOffset = cScratchBuf) ]
]);
aScratchBuf2 = array('b', [random.randint(-128, 127) for i in range(cScratchBuf)]);
aaTests.extend([
# Append the same amount of data to the just created file.
[ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = sScratch + 'testGuestCtrlFileWrite.txt', \
sOpenMode = 'w+', sDisposition = 'oa', cbToReadWrite = cScratchBuf,
cbOffset = cScratchBuf, aBuf = aScratchBuf2),
tdTestResultFileReadWrite(fRc = True, aBuf = aScratchBuf2, \
cbProcessed = cScratchBuf, cbOffset = cScratchBuf * 2) ],
]);
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' %
(i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlFileWrite: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
try:
if curTest.cbOffset > 0: # The offset parameter is gone.
if self.oTstDrv.fpApiVer >= 5.0:
curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
curTest.getSharingMode(), []);
curFile.seek(curTest.cbOffset, vboxcon.FileSeekOrigin_Begin);
else:
curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.sOpenMode, curTest.sDisposition,
curTest.sSharingMode, curTest.lCreationMode, curTest.cbOffset);
curOffset = long(curFile.offset);
resOffset = long(curTest.cbOffset);
if curOffset != resOffset:
reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d'
% (i, curOffset, resOffset));
fRc = False;
else:
if self.oTstDrv.fpApiVer >= 5.0:
curFile = curGuestSession.fileOpen(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
curTest.lCreationMode);
else:
curFile = curGuestSession.fileOpen(curTest.sFile, curTest.sOpenMode, curTest.sDisposition,
curTest.lCreationMode);
if fRc and curTest.cbToReadWrite > 0:
## @todo Split this up in 64K writes. Later.
## @todo Test timeouts.
cBytesWritten = curFile.write(curTest.aBuf, 30 * 1000);
if curRes.cbProcessed > 0 \
and curRes.cbProcessed != cBytesWritten:
reporter.error('Test #%d failed: Written buffer length does not match: Got %d, expected %d'
% (i, cBytesWritten, curRes.cbProcessed));
fRc = False;
if fRc:
# Verify written content by seeking back to the initial offset and
# re-read & compare the written data.
try:
if self.oTstDrv.fpApiVer >= 5.0:
curFile.seek(-(curTest.cbToReadWrite), vboxcon.FileSeekOrigin_Current);
else:
curFile.seek(-(curTest.cbToReadWrite), vboxcon.FileSeekType_Current);
except:
reporter.logXcpt('Seeking back to initial write position failed:');
fRc = False;
if fRc and long(curFile.offset) != curTest.cbOffset:
reporter.error('Test #%d failed: Initial write position does not match current position, '
'got %d, expected %d' % (i, long(curFile.offset), curTest.cbOffset));
fRc = False;
if fRc:
aBufRead = curFile.read(curTest.cbToReadWrite, 30 * 1000);
if len(aBufRead) != curTest.cbToReadWrite:
reporter.error('Test #%d failed: Got buffer length %d, expected %d'
% (i, len(aBufRead), curTest.cbToReadWrite));
fRc = False;
if fRc \
and curRes.aBuf is not None \
and curRes.aBuf != aBufRead:
reporter.error('Test #%d failed: Got buffer\n%s, expected\n%s'
% (i, aBufRead, curRes.aBuf));
fRc = False;
# Test final offset.
curOffset = long(curFile.offset);
resOffset = long(curRes.cbOffset);
if curOffset != resOffset:
reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d'
% (i, curOffset, resOffset));
fRc = False;
curFile.close();
except:
reporter.logXcpt('Opening "%s" failed:' % (curTest.sFile,));
fRc = False;
curTest.closeSession();
if fRc != curRes.fRc:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlCopyTo(self, oSession, oTxsSession, oTestVm):
"""
Tests copying files from host to the guest.
"""
if oTestVm.isWindows():
sUser = "Administrator";
sScratchGst = "C:\\Temp\\vboxtest\\testGuestCtrlCopyTo\\";
sScratchGstNotExist = "C:\\does-not-exist\\";
sScratchGstInvalid = "?*|invalid-name?*|";
else:
sUser = "vbox";
sScratchGst = "/tmp/testGuestCtrlCopyTo/";
sScratchGstNotExist = "/tmp/does-not-exist/";
sScratchGstInvalid = "/";
sPassword = "password";
if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlCopyTo') is False:
reporter.error('Could not create scratch directory on guest');
return (False, oTxsSession);
## @todo r=klaus It's not good to use files with unpredictable size
# for testing. Causes all sorts of weird failures as things grow,
# exceeding the free space of the test VMs. Especially as this used
# the very big (and quickly growing) validation kit ISO originally.
sTestFileBig = self.oTstDrv.getFullResourceName('5.3/guestctrl/50mb_rnd.dat');
if not os.path.isfile(sTestFileBig):
sTestFileBig = self.oTstDrv.getGuestAdditionsIso();
if sTestFileBig == '' or not os.path.isfile(sTestFileBig):
sTestFileBig = self.oTstDrv.sVBoxValidationKitIso;
if os.path.isfile(sTestFileBig):
reporter.log('Test file for big copy found at: %s' % (sTestFileBig,));
else:
reporter.log('Warning: Test file for big copy not found -- some tests might fail');
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Destination missing.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = ''),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = '/placeholder',
aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Source missing.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sDst = ''),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sDst = '/placeholder',
aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Testing DirectoryCopyFlag flags.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGstInvalid, aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Testing FileCopyFlag flags.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGstInvalid, aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Nothing to copy (source and/or destination is empty).
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'z:\\'),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = '\\\\uncrulez\\foo'),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'non-exist',
sDst = os.path.join(sScratchGst, 'non-exist.dll')),
tdTestResult(fRc = False) ]
]);
#
# Single file handling.
#
if self.oTstDrv.fpApiVer > 5.2:
aaTests.extend([
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGstInvalid),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGstNotExist),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGstNotExist),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = os.path.join(sScratchGstNotExist, 'renamedfile.dll')),
tdTestResult(fRc = False) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = os.path.join(sScratchGst, 'HostGABig.dat')),
tdTestResult(fRc = True) ],
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = os.path.join(sScratchGst, 'HostGABig.dat')),
tdTestResult(fRc = True) ],
# Note: Copying files into directories via Main is supported only in versions > 5.2.
# Destination is a directory.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGst),
tdTestResult(fRc = True) ],
# Copy over file again into same directory (overwrite).
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = sScratchGst),
tdTestResult(fRc = True) ]
]);
aaTests.extend([
# Copy the same file over to the guest, but this time store the file into the former
# file's ADS (Alternate Data Stream). Only works on Windows, of course.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sTestFileBig,
sDst = os.path.join(sScratchGst, 'HostGABig.dat:ADS-Test')),
tdTestResult(fRc = True) ]
]);
#
# Directory handling.
#
## @todo r=michaln disabled completely, can fill up the guest disk or fail without giving a reason
if self.oTstDrv.fpApiVer > 6.0: # Copying directories via Main is supported only in versions > 5.2.
if self.oTstDrv.sHost == "win":
sSystemRoot = os.getenv('SystemRoot', 'C:\\Windows')
aaTests.extend([
# Copying directories with contain files we don't have read access to.
## @todo r=klaus disabled, because this can fill up the guest disk, making other tests fail,
## additionally it's not really clear if this fails reliably on all Windows versions, even
## the old ones like XP with a "proper" administrator.
#[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = os.path.join(sSystemRoot, 'security'),
# sDst = sScratchGst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
# tdTestResult(fRc = False) ],
# Copying directories with regular files.
[ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = os.path.join(sSystemRoot, 'Help'),
sDst = sScratchGst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
tdTestResult(fRc = True) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sSrc=%s, sDst=%s, aFlags=%s ...' % \
(i, curTest.sSrc, curTest.sDst, curTest.aFlags));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlCopyTo: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
fRc2 = False;
if os.path.isdir(curTest.sSrc):
try:
curProgress = curGuestSession.directoryCopyToGuest(curTest.sSrc, curTest.sDst, curTest.aFlags);
if curProgress is not None:
oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \
"gctrlDirCopyTo");
try:
oProgress.wait();
if not oProgress.isSuccess():
oProgress.logResult(fIgnoreErrors = True);
fRc = False;
except:
reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst));
fRc2 = False;
else:
reporter.error('No progress object returned');
fRc2 = False;
except:
fRc2 = False;
else:
fRc2 = self.gctrlCopyFileTo(curGuestSession, curTest.sSrc, curTest.sDst, curTest.aFlags);
curTest.closeSession();
if fRc2 is curRes.fRc:
## @todo Verify the copied results (size, checksum?).
pass;
else:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlCopyFrom(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests copying files from guest to the host.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
sScratchHst = os.path.join(self.oTstDrv.sScratchPath, "testGctrlCopyFrom");
if self.oTstDrv.sHost == "win":
sScratchHstNotExist = sScratchHst + "\\does-not-exist\\";
sScratchHstNotExistChain = sScratchHst + "\\does\\not\\exist\\";
sScratchHstInvalid = "?*|invalid-name?*|";
else:
sScratchHstNotExist = sScratchHst + "/does-not-exist/";
sScratchHstNotExistChain = sScratchHst + "/does/not/exist/";
sScratchHstInvalid = "/";
try:
os.makedirs(sScratchHst);
except OSError as e:
if e.errno != errno.EEXIST:
reporter.error('Failed: Unable to create scratch directory \"%s\"' % (sScratchHst,));
return (False, oTxsSession);
reporter.log('Scratch path is: %s' % (sScratchHst,));
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Destination missing.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = ''),
tdTestResult(fRc = False) ],
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'Something',
aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Source missing.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sDst = ''),
tdTestResult(fRc = False) ],
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sDst = 'Something',
aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Testing DirectoryCopyFlag flags.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32',
sDst = sScratchHstInvalid, aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Testing FileCopyFlag flags.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = sScratchHstInvalid, aFlags = [ 80 ] ),
tdTestResult(fRc = False) ],
# Nothing to copy (sDst is empty / unreachable).
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'z:\\'),
tdTestResult(fRc = False) ],
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = '\\\\uncrulez\\foo'),
tdTestResult(fRc = False) ],
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'non-exist',
sDst = os.path.join(sScratchHst, 'non-exist.dll')),
tdTestResult(fRc = False) ]
]);
#
# Single file handling.
#
if self.oTstDrv.fpApiVer > 5.2:
aaTests.extend([
# Copying single files.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = sScratchHstInvalid),
tdTestResult(fRc = False) ],
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = os.path.join(sScratchHstInvalid, 'renamedfile.dll')),
tdTestResult(fRc = False) ],
# Copy over file using a different destination name.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = os.path.join(sScratchHst, 'renamedfile.dll')),
tdTestResult(fRc = True) ],
# Copy over same file (and overwrite existing one).
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = os.path.join(sScratchHst, 'renamedfile.dll')),
tdTestResult(fRc = True) ],
# Note: Copying files into directories via Main is supported only in versions > 5.2.
# Destination is a directory with a trailing slash (should work).
# See "cp" syntax.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = sScratchHst + "/"),
tdTestResult(fRc = True) ],
# Destination is a directory (without a trailing slash, should also work).
# See "cp" syntax.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = sScratchHst),
tdTestResult(fRc = True) ],
# Destination is a non-existing directory.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
sDst = sScratchHstNotExist),
tdTestResult(fRc = False) ]
]);
#
# Directory handling.
#
if self.oTstDrv.fpApiVer > 5.2: # Copying directories via Main is supported only in versions > 5.2.
aaTests.extend([
# Copying entire directories (destination is "<sScratchHst>\Web").
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
sDst = sScratchHst),
tdTestResult(fRc = True) ],
# Repeat -- this time it should fail, as the destination directory already exists (and
# DirectoryCopyFlag_CopyIntoExisting is not specified).
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
sDst = sScratchHst + "/"),
tdTestResult(fRc = False) ],
# Next try with the DirectoryCopyFlag_CopyIntoExisting flag being set.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
sDst = sScratchHst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
tdTestResult(fRc = True) ],
# Ditto, with trailing slash.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
tdTestResult(fRc = True) ],
# Copying contents of directories into a non-existing directory chain on the host which fail.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\',
sDst = sScratchHstNotExistChain,
aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
tdTestResult(fRc = False) ],
# Copying contents of directories into a non-existing directory on the host, which should succeed.
[ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\',
sDst = sScratchHstNotExist,
aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
tdTestResult(fRc = True) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sSrc="%s", sDst="%s", aFlags="%s" ...' % \
(i, curTest.sSrc, curTest.sDst, curTest.aFlags));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, curGuestSession = curTest.createSession('testGuestCtrlCopyFrom: Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
fRc2 = True;
try:
if self.oTstDrv.fpApiVer >= 5.0:
oFsInfo = curGuestSession.fsObjQueryInfo(curTest.sSrc, True); # fFollowSymlinks
else:
oFsInfo = curGuestSession.fileQueryInfo(curTest.sSrc);
if oFsInfo.type is vboxcon.FsObjType_Directory:
curProgress = curGuestSession.directoryCopyFromGuest(curTest.sSrc, curTest.sDst, curTest.aFlags);
if curProgress is not None:
oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \
"gctrlDirCopyFrom");
try:
oProgress.wait();
if not oProgress.isSuccess():
oProgress.logResult(fIgnoreErrors = True);
fRc2 = False;
except:
reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst));
fRc2 = False;
else:
reporter.error('No progress object returned');
fRc2 = False;
elif oFsInfo.type is vboxcon.FsObjType_File:
fRc2 = self.gctrlCopyFileFrom(curGuestSession, curTest.sSrc, curTest.sDst, curTest.aFlags);
else:
reporter.log2('Element "%s" not handled (yet), skipping' % oFsInfo.name);
except:
reporter.logXcpt('Query information exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst));
fRc2 = False;
curTest.closeSession();
if fRc2 is curRes.fRc:
## @todo Verify the copied results (size, checksum?).
pass;
else:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));
fRc = False;
break;
return (fRc, oTxsSession);
def testGuestCtrlUpdateAdditions(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
"""
Tests updating the Guest Additions inside the guest.
"""
if oTestVm.isWindows():
sUser = "Administrator";
else:
sUser = "vbox";
sPassword = "password";
# Some stupid trickery to guess the location of the iso.
sVBoxValidationKitISO = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
if not os.path.isfile(sVBoxValidationKitISO):
sVBoxValidationKitISO = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
if not os.path.isfile(sVBoxValidationKitISO):
sCur = os.getcwd();
for i in range(0, 10):
sVBoxValidationKitISO = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
if os.path.isfile(sVBoxValidationKitISO):
break;
sVBoxValidationKitISO = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
if os.path.isfile(sVBoxValidationKitISO):
break;
sCur = os.path.abspath(os.path.join(sCur, '..'));
if i is None: pass; # shut up pychecker/pylint.
if os.path.isfile(sVBoxValidationKitISO):
reporter.log('Validation Kit .ISO found at: %s' % (sVBoxValidationKitISO,));
else:
reporter.log('Warning: Validation Kit .ISO not found -- some tests might fail');
sScratch = os.path.join(self.oTstDrv.sScratchPath, "testGctrlUpdateAdditions");
try:
os.makedirs(sScratch);
except OSError as e:
if e.errno != errno.EEXIST:
reporter.error('Failed: Unable to create scratch directory \"%s\"' % (sScratch,));
return (False, oTxsSession);
reporter.log('Scratch path is: %s' % (sScratch,));
aaTests = [];
if oTestVm.isWindows():
aaTests.extend([
# Source is missing.
[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = ''),
tdTestResult(fRc = False) ],
# Wrong aFlags.
[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = self.oTstDrv.getGuestAdditionsIso(),
aFlags = [ 1234 ]),
tdTestResult(fRc = False) ],
# Non-existing .ISO.
[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = "non-existing.iso"),
tdTestResult(fRc = False) ],
# Wrong .ISO.
[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO),
tdTestResult(fRc = False) ],
# The real thing.
[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = self.oTstDrv.getGuestAdditionsIso()),
tdTestResult(fRc = True) ],
# Test the (optional) installer arguments. This will extract the
# installer into our guest's scratch directory.
[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = self.oTstDrv.getGuestAdditionsIso(),
aArgs = [ '/extract', '/D=' + sScratch ]),
tdTestResult(fRc = True) ]
# Some debg ISO. Only enable locally.
#[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword,
# sSrc = "V:\\Downloads\\VBoxGuestAdditions-r80354.iso"),
# tdTestResult(fRc = True) ]
]);
else:
reporter.log('No OS-specific tests for non-Windows yet!');
fRc = True;
for (i, aTest) in enumerate(aaTests):
curTest = aTest[0]; # tdTestExec, use an index, later.
curRes = aTest[1]; # tdTestResult
reporter.log('Testing #%d, sSrc="%s", aFlags="%s" ...' % \
(i, curTest.sSrc, curTest.aFlags));
curTest.setEnvironment(oSession, oTxsSession, oTestVm);
fRc, _ = curTest.createSession('Test #%d' % (i,));
if fRc is False:
reporter.error('Test #%d failed: Could not create session' % (i,));
break;
try:
curProgress = curTest.oTest.oGuest.updateGuestAdditions(curTest.sSrc, curTest.aArgs, curTest.aFlags);
if curProgress is not None:
oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlUpGA");
try:
oProgress.wait();
if not oProgress.isSuccess():
oProgress.logResult(fIgnoreErrors = True);
fRc = False;
except:
reporter.logXcpt('Waiting exception for updating Guest Additions:');
fRc = False;
else:
reporter.error('No progress object returned');
fRc = False;
except:
# Just log, don't assume an error here (will be done in the main loop then).
reporter.logXcpt('Updating Guest Additions exception for sSrc="%s", aFlags="%s":' \
% (curTest.sSrc, curTest.aFlags));
fRc = False;
curTest.closeSession();
if fRc is curRes.fRc:
if fRc:
## @todo Verify if Guest Additions were really updated (build, revision, ...).
pass;
else:
reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));
fRc = False;
break;
return (fRc, oTxsSession);
class tdAddGuestCtrl(vbox.TestDriver): # pylint: disable=R0902,R0904
"""
Guest control using VBoxService on the guest.
"""
def __init__(self):
vbox.TestDriver.__init__(self);
self.oTestVmSet = self.oTestVmManager.getSmokeVmSet('nat');
self.asRsrcs = None;
self.fQuick = False; # Don't skip lengthly tests by default.
self.addSubTestDriver(SubTstDrvAddGuestCtrl(self));
#
# Overridden methods.
#
def showUsage(self):
"""
Shows the testdriver usage.
"""
rc = vbox.TestDriver.showUsage(self);
reporter.log('');
reporter.log('tdAddGuestCtrl Options:');
reporter.log(' --quick');
reporter.log(' Same as --virt-modes hwvirt --cpu-counts 1.');
return rc;
def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
"""
Parses the testdriver arguments from the command line.
"""
if asArgs[iArg] == '--quick':
self.parseOption(['--virt-modes', 'hwvirt'], 0);
self.parseOption(['--cpu-counts', '1'], 0);
self.fQuick = True;
else:
return vbox.TestDriver.parseOption(self, asArgs, iArg);
return iArg + 1;
def actionConfig(self):
if not self.importVBoxApi(): # So we can use the constant below.
return False;
eNic0AttachType = vboxcon.NetworkAttachmentType_NAT;
sGaIso = self.getGuestAdditionsIso();
return self.oTestVmSet.actionConfig(self, eNic0AttachType = eNic0AttachType, sDvdImage = sGaIso);
def actionExecute(self):
return self.oTestVmSet.actionExecute(self, self.testOneCfg);
#
# Test execution helpers.
#
def testOneCfg(self, oVM, oTestVm): # pylint: disable=R0915
"""
Runs the specified VM thru the tests.
Returns a success indicator on the general test execution. This is not
the actual test result.
"""
self.logVmInfo(oVM);
fRc = True;
oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = False);
reporter.log("TxsSession: %s" % (oTxsSession,));
if oSession is not None:
self.addTask(oTxsSession);
fManual = False; # Manual override for local testing. (Committed version shall be False.)
if not fManual:
fRc, oTxsSession = self.aoSubTstDrvs[0].testIt(oTestVm, oSession, oTxsSession);
else:
fRc, oTxsSession = self.testGuestCtrlManual(oSession, oTxsSession, oTestVm);
# Cleanup.
self.removeTask(oTxsSession);
if not fManual:
self.terminateVmBySession(oSession);
else:
fRc = False;
return fRc;
def gctrlReportError(self, progress):
"""
Helper function to report an error of a
given progress object.
"""
if progress is None:
reporter.log('No progress object to print error for');
else:
errInfo = progress.errorInfo;
if errInfo:
reporter.log('%s' % (errInfo.text,));
return False;
def gctrlGetRemainingTime(self, msTimeout, msStart):
"""
Helper function to return the remaining time (in ms)
based from a timeout value and the start time (both in ms).
"""
if msTimeout is 0:
return 0xFFFFFFFE; # Wait forever.
msElapsed = base.timestampMilli() - msStart;
if msElapsed > msTimeout:
return 0; # No time left.
return msTimeout - msElapsed;
def testGuestCtrlManual(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914,R0915,W0613,W0612
"""
For manually testing certain bits.
"""
reporter.log('Manual testing ...');
fRc = True;
sUser = 'Administrator';
sPassword = 'password';
oGuest = oSession.o.console.guest;
oGuestSession = oGuest.createSession(sUser,
sPassword,
"", "Manual Test");
aWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
_ = oGuestSession.waitForArray(aWaitFor, 30 * 1000);
sCmd = 'c:\\windows\\system32\\cmd.exe';
aArgs = [ sCmd, '/C', 'dir', '/S', 'c:\\windows' ];
aEnv = [];
aFlags = [];
for _ in range(100):
oProc = oGuestSession.processCreate(sCmd, aArgs if self.fpApiVer >= 5.0 else aArgs[1:],
aEnv, aFlags, 30 * 1000);
aWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ];
_ = oProc.waitForArray(aWaitFor, 30 * 1000);
oGuestSession.close();
oGuestSession = None;
time.sleep(5);
oSession.o.console.PowerDown();
return (fRc, oTxsSession);
if __name__ == '__main__':
sys.exit(tdAddGuestCtrl().main(sys.argv));
|