1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
/* this timeout is in effect with SGE commprocs */
#define SGE_COMMPROC_TIMEOUT 60*5
#include "japi/drmaa.h"
#include "japi/japi.h"
#include "japi/japiP.h"
#include "cull/cull_list.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_answer.h"
#include "uti/sge_rmon_monitoring_level.h"
#include "uti/sge_rmon.h"
#include "uti/sge_profiling.h"
#include "uti/sge_stdio.h"
#include "comm/commlib.h"
#include "gdi/sge_gdi_ctx.h"
#include "gdi/sge_gdi2.h"
#include "gdi/sge_gdi.h"
#include "show_job.h"
#include "msg_common.h"
#define JOB_CHUNK 8
#define NTHREADS 3
#define NBULKS 3
#define NEXT_ARGV(argc, argv) \
((*argc)--, (*argv)++, (*argv)[0])
enum {
ALL_TESTS = 0,
ST_SUBMIT_WAIT,
/* - one thread
- submit jobs
- wait for jobend */
ST_SUBMIT_NO_RUN_WAIT,
/* - one thread
- submit jobs that won't run
- wait for jobend */
MT_SUBMIT_WAIT,
/* - multiple submission threads
- wait is done by main thread */
MT_SUBMIT_BEFORE_INIT_WAIT,
/* - no drmaa_init() was called
- multiple threads try to submit but fail
- when drmaa_init() is called by main thread
submission proceed
- wait is done by main thread */
ST_MULT_INIT,
/* - drmaa_init() is called multiple times
- first time it must succeed - second time it must fail
- then drmaa_exit() is called */
ST_MULT_EXIT,
/* - drmaa_init() is called
- then drmaa_exit() is called multiple times
- first time it must succeed - second time it must fail */
MT_EXIT_DURING_SUBMIT,
/* - drmaa_init() is called
- multiple submission threads submitting (delayed) a series
of jobs
- during submission main thread does drmaa_exit() */
MT_SUBMIT_MT_WAIT,
/* - drmaa_init() is called
- multiple submission threads submit jobs and wait these jobs
- when all threads are finished main thread calls drmaa_exit() */
MT_EXIT_DURING_SUBMIT_OR_WAIT,
/* - drmaa_init() is called
- multiple submission threads submit jobs and wait these jobs
- while submission threads are waiting their jobs the main
thread calls drmaa_exit() */
ST_BULK_SUBMIT_WAIT,
/* - drmaa_init() is called
- a bulk job is submitted and waited
- then drmaa_exit() is called */
ST_BULK_SINGLESUBMIT_WAIT_INDIVIDUAL,
/* - drmaa_init() is called
- bulk and sequential jobs are submitted
- all jobs are waited individually
- then drmaa_exit() is called */
ST_SUBMITMIXTURE_SYNC_ALL_DISPOSE,
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose)
to wait for all jobs to finish
- then drmaa_exit() is called */
ST_SUBMITMIXTURE_SYNC_ALL_NODISPOSE,
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, no-dispose)
to wait for all jobs to finish
- do drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY) until
DRMAA_ERRNO_INVALID_JOB to reap all jobs
- then drmaa_exit() is called */
ST_SUBMITMIXTURE_SYNC_ALLIDS_DISPOSE,
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(all_jobids, dispose)
to wait for all jobs to finish
- then drmaa_exit() is called */
ST_SUBMITMIXTURE_SYNC_ALLIDS_NODISPOSE,
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(all_jobids, no-dispose)
to wait for all jobs to finish
- do drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY) until
DRMAA_ERRNO_INVALID_JOB to reap all jobs
- then drmaa_exit() is called */
ST_SUBMIT_PAUSE_SUBMIT_SYNC,
/* - drmaa_init() is called
- a job is submitted
- do a long sleep(SGE_COMMPROC_TIMEOUT+)
- another job is submitted
- do drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose)
- then drmaa_exit() is called */
ST_INPUT_FILE_FAILURE,
ST_OUTPUT_FILE_FAILURE,
ST_ERROR_FILE_FAILURE,
/* - drmaa_init() is called
- a job is submitted with input/output/error path specification
that must cause the job to fail
- use drmaa_synchronize() to ensure job was started
- drmaa_job_ps() must return DRMAA_PS_FAILED
- drmaa_wait() must report drmaa_wifaborted() -> true
- then drmaa_exit() is called */
ST_SUBMIT_IN_HOLD_RELEASE,
/* - drmaa_init() is called
- a job is submitted with a user hold
- use drmaa_job_ps() to verify user hold state
- hold state is released using drmaa_control()
- the job is waited
- then drmaa_exit() is called
(still requires manual testing)
*/
ST_SUBMIT_IN_HOLD_DELETE,
/* - drmaa_init() is called
- a job is submitted with a user hold
- use drmaa_job_ps() to verify user hold state
- job is terminated using drmaa_control()
- the job is waited
- then drmaa_exit() is called
(still requires manual testing)
*/
ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE,
/* - drmaa_init() is called
- a bulk job is submitted with a user hold
- hold state is released separately for each task using drmaa_control()
- the job ids are waited
- then drmaa_exit() is called
(still requires manual testing)
*/
ST_BULK_SUBMIT_IN_HOLD_SESSION_RELEASE,
/* - drmaa_init() is called
- a bulk job is submitted with a user hold
- hold state is released for the session using drmaa_control()
- the job ids are waited
- then drmaa_exit() is called
(still requires manual testing)
*/
ST_BULK_SUBMIT_IN_HOLD_SESSION_DELETE,
/* - drmaa_init() is called
- a bulk job is submitted with a user hold
- use drmaa_job_ps() to verify user hold state
- all session jobs are terminated using drmaa_control()
- the job ids are waited
- then drmaa_exit() is called
(still requires manual testing)
*/
ST_BULK_SUBMIT_IN_HOLD_SINGLE_DELETE,
/* - drmaa_init() is called
- a bulk job is submitted with a user hold
- use drmaa_job_ps() to verify user hold state
- all session jobs are terminated using drmaa_control()
- the job ids are waited
- then drmaa_exit() is called
(still requires manual testing)
*/
ST_INPUT_BECOMES_OUTPUT,
/* - drmaa_init() is called
- job input is prepared in local file
- a job is submitted that echoes it's input to output
- the job is waited
- then drmaa_exit() is called
- job output must be identical to job input
(this requires manual testing) */
ST_DRMAA_JOB_PS,
/* - drmaa_init() is called
- drmaa_job_ps() is used to retrieve DRMAA state
for each jobid passed *manually* in argv
- then drmaa_exit() is called
(requires manual testing)
*/
ST_DRMAA_CONTROL,
/* - drmaa_init() is called
- drmaa_control() is used to change DRMAA job state
for each jobid passed *manually* in argv
- drmaa_control() must return with the exit status passed in argv
- then drmaa_exit() is called
(still manual testing)
*/
ST_EXIT_STATUS,
/* - drmaa_init() is called
- 255 job are submitted
- job i returns i as exit status (8 bit)
- drmaa_wait() verifies each job returned the
correct exit status
- then drmaa_exit() is called */
ST_SUPPORTED_ATTR,
/* - drmaa_init() is called
- drmaa_get_attribute_names() is called
- the names of all supported non vector attributes are printed
- then drmaa_exit() is called */
ST_SUPPORTED_VATTR,
/* - drmaa_init() is called
- drmaa_get_vector_attribute_names() is called
- the names of all supported vector attributes are printed
- then drmaa_exit() is called */
ST_VERSION,
/* - drmaa_version() is called
- version information is printed */
ST_CONTACT,
/* - drmaa_get_contact() is called
- the contact string is printed
- drmaa_init() is called
- drmaa_get_contact() is called
- the contact string is printed
- then drmaa_exit() is called */
ST_DRM_SYSTEM,
/* - drmaa_get_DRM_system() is called
- the contact string is printed
- drmaa_init() is called
- drmaa_get_DRM_system() is called
- the DRM system name is printed
- then drmaa_exit() is called */
ST_DRMAA_IMPL,
/* - drmaa_get_DRM_system() is called
- the contact string is printed
- drmaa_init() is called
- drmaa_get_DRMAA_implementation() is called
- the DRMAA implemention name is printed
- then drmaa_exit() is called */
ST_EMPTY_SESSION_WAIT,
/* - drmaa_init() is called
- drmaa_wait() must return DRMAA_ERRNO_INVALID_JOB
- then drmaa_exit() is called */
ST_EMPTY_SESSION_SYNCHRONIZE_DISPOSE,
/* - drmaa_init() is called
- drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose=true) must return DRMAA_ERRNO_SUCCESS
- then drmaa_exit() is called */
ST_EMPTY_SESSION_SYNCHRONIZE_NODISPOSE,
/* - drmaa_init() is called
- drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose=false) must return DRMAA_ERRNO_SUCCESS
- then drmaa_exit() is called */
ST_EMPTY_SESSION_CONTROL,
/* - drmaa_init() is called
- drmaa_control(DRMAA_JOB_IDS_SESSION_ALL, <passed control operation>) must return DRMAA_ERRNO_SUCCESS
- then drmaa_exit() is called */
ST_SUBMIT_SUSPEND_RESUME_WAIT,
/* - drmaa_init() is called
- a single job is submitted
- drmaa_job_ps() is used to actively wait until job is running
- drmaa_control() is used to suspend the job
- drmaa_job_ps() is used to verify job was suspended
- drmaa_control() is used to resume the job
- drmaa_job_ps() is used to verify job was resumed
- drmaa_wait() is used to wait for the jobs regular end
- then drmaa_exit() is called */
ST_SUBMIT_POLLING_WAIT_TIMEOUT,
/* - drmaa_init() is called
- a single job is submitted
- repeatedly drmaa_wait() with a timeout is used until job is finished
- then drmaa_exit() is called */
ST_SUBMIT_POLLING_WAIT_ZEROTIMEOUT,
/* - drmaa_init() is called
- a single job is submitted
- repeatedly do drmaa_wait(DRMAA_TIMEOUT_NO_WAIT) + sleep() until job is finished
- then drmaa_exit() is called */
ST_SUBMIT_POLLING_SYNCHRONIZE_TIMEOUT,
/* - drmaa_init() is called
- a single job is submitted
- repeatedly drmaa_synchronize() with a timeout is used until job is finished
- then drmaa_exit() is called */
ST_SUBMIT_POLLING_SYNCHRONIZE_ZEROTIMEOUT,
/* - drmaa_init() is called
- a single job is submitted
- repeatedly do drmaa_synchronize(DRMAA_TIMEOUT_NO_WAIT) + sleep() until job is finished
- then drmaa_exit() is called */
ST_ATTRIBUTE_CHECK,
/* Need to test all DRMAA attributes:
DRMAA_REMOTE_COMMAND - implicit
DRMAA_JS_STATE
DRMAA_WD
DRMAA_JOB_NAME
DRMAA_INPUT_PATH
DRMAA_OUTPUT_PATH
DRMAA_ERROR_PATH
DRMAA_JOIN_FILES
DRMAA_JOB_CATEGORY
DRMAA_NATIVE_SPECIFICATION - test if it works and it if clashes
DRMAA_BLOCK_EMAIL
DRMAA_START_TIME
DRMAA_V_ARGV
DRMAA_V_EMAIL
DRMAA_V_ENV */
ST_USAGE_CHECK,
/* - one thread
- submit jobs
- wait for jobend
- print job usage */
ST_TRANSFER_FILES_SINGLE_JOB,
ST_TRANSFER_FILES_BULK_JOB,
/* Set Job InputHost:/InputPath, OutputHost:/OutputPath, ErrorHost:/ErrorPath */
ST_RESERVATION_FINISH_ORDER,
/* ensure three jobs finish in the order foreseen for reservation */
ST_BACKFILL_FINISH_ORDER,
/* ensure three jobs finish in the order foreseen for backfilling */
ST_WILD_PARALLEL,
/* ensure 7 jobs finish in the order foreseen for wildcard parallel jobs */
ST_UNSUPPORTED_ATTR,
/* - drmaa_init() is called
- drmaa_set_attribute() is called for an invalid attribute
- then drmaa_exit() is called */
ST_UNSUPPORTED_VATTR,
/* - drmaa_init() is called
- drmaa_set_vector_attribute() is called for an invalid attribute
- then drmaa_exit() is called */
ST_SYNCHRONIZE_NONEXISTANT,
/* - Init session.
- Create job template.
- Run job.
- Delete job template.
- Use job id to create unknown, valid job id.
- Synchronize against unknown id.
- Wait for real job to finish.
- Exit session. */
ST_RECOVERABLE_SESSION,
/* - Init session.
- Create job template.
- Run job.
- Delete job template.
- Exit session.
- Init session.
- Wait for job to finish.
- Exit session. */
ST_ERROR_CODES
/* - Test that each error code has the right value. */
};
const struct test_name2number_map {
char *test_name; /* name of the test */
int test_number; /* number the test is internally mapped to */
int nargs; /* number of test case arguments required */
char *opt_arguments; /* description of test case arguments for usage output */
} test_map[] = {
/* all automated tests - ST_* and MT_* tests */
{ "ALL_AUTOMATED", ALL_TESTS, 3, "<sleeper_job> <exit_arg_job> <email_addr>" },
/* one application thread - automated tests only */
{ "ST_ERROR_CODES", ST_ERROR_CODES, 0, "" },
{ "ST_MULT_INIT", ST_MULT_INIT, 0, "" },
{ "ST_MULT_EXIT", ST_MULT_EXIT, 0, "" },
{ "ST_SUPPORTED_ATTR", ST_SUPPORTED_ATTR, 0, "" },
{ "ST_SUPPORTED_VATTR", ST_SUPPORTED_VATTR, 0, "" },
{ "ST_VERSION", ST_VERSION, 0, "" },
{ "ST_DRM_SYSTEM", ST_DRM_SYSTEM, 0, "" },
{ "ST_DRMAA_IMPL", ST_DRMAA_IMPL, 0, "" },
{ "ST_CONTACT", ST_CONTACT, 0, "" },
{ "ST_EMPTY_SESSION_WAIT", ST_EMPTY_SESSION_WAIT, 0, "" },
{ "ST_EMPTY_SESSION_SYNCHRONIZE_DISPOSE", ST_EMPTY_SESSION_SYNCHRONIZE_DISPOSE, 0, "" },
{ "ST_EMPTY_SESSION_SYNCHRONIZE_NODISPOSE", ST_EMPTY_SESSION_SYNCHRONIZE_NODISPOSE, 0, "" },
{ "ST_EMPTY_SESSION_CONTROL", ST_EMPTY_SESSION_CONTROL, 1, "DRMAA_CONTROL_*" },
{ "ST_SUBMIT_WAIT", ST_SUBMIT_WAIT, 1, "<sleeper_job>" },
{ "ST_SUBMIT_NO_RUN_WAIT", ST_SUBMIT_NO_RUN_WAIT, 1, "<sleeper_job>" },
{ "ST_BULK_SUBMIT_WAIT", ST_BULK_SUBMIT_WAIT, 1, "<sleeper_job>" },
{ "ST_BULK_SINGLESUBMIT_WAIT_INDIVIDUAL", ST_BULK_SINGLESUBMIT_WAIT_INDIVIDUAL, 1, "<sleeper_job>" },
{ "ST_SUBMITMIXTURE_SYNC_ALL_DISPOSE", ST_SUBMITMIXTURE_SYNC_ALL_DISPOSE, 1, "<sleeper_job>" },
{ "ST_SUBMITMIXTURE_SYNC_ALL_NODISPOSE", ST_SUBMITMIXTURE_SYNC_ALL_NODISPOSE, 1, "<sleeper_job>" },
{ "ST_SUBMITMIXTURE_SYNC_ALLIDS_DISPOSE", ST_SUBMITMIXTURE_SYNC_ALLIDS_DISPOSE, 1, "<sleeper_job>" },
{ "ST_SUBMITMIXTURE_SYNC_ALLIDS_NODISPOSE", ST_SUBMITMIXTURE_SYNC_ALLIDS_NODISPOSE, 1, "<sleeper_job>" },
{ "ST_SUBMIT_PAUSE_SUBMIT_SYNC", ST_SUBMIT_PAUSE_SUBMIT_SYNC, 1, "<sleeper_job>" },
{ "ST_EXIT_STATUS", ST_EXIT_STATUS, 1, "<exit_arg_job>" },
{ "ST_INPUT_FILE_FAILURE", ST_INPUT_FILE_FAILURE, 1, "<sleeper_job>" },
{ "ST_OUTPUT_FILE_FAILURE", ST_OUTPUT_FILE_FAILURE, 1, "<sleeper_job>" },
{ "ST_ERROR_FILE_FAILURE", ST_ERROR_FILE_FAILURE, 1, "<sleeper_job>" },
{ "ST_SUBMIT_IN_HOLD_RELEASE", ST_SUBMIT_IN_HOLD_RELEASE, 1, "<sleeper_job>" },
{ "ST_SUBMIT_IN_HOLD_DELETE", ST_SUBMIT_IN_HOLD_DELETE, 1, "<sleeper_job>" },
{ "ST_BULK_SUBMIT_IN_HOLD_SESSION_RELEASE", ST_BULK_SUBMIT_IN_HOLD_SESSION_RELEASE, 1, "<sleeper_job>" },
{ "ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE", ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE, 1, "<sleeper_job>" },
{ "ST_BULK_SUBMIT_IN_HOLD_SESSION_DELETE", ST_BULK_SUBMIT_IN_HOLD_SESSION_DELETE, 1, "<sleeper_job>" },
{ "ST_BULK_SUBMIT_IN_HOLD_SINGLE_DELETE", ST_BULK_SUBMIT_IN_HOLD_SINGLE_DELETE, 1, "<sleeper_job>" },
{ "ST_SUBMIT_POLLING_WAIT_TIMEOUT", ST_SUBMIT_POLLING_WAIT_TIMEOUT, 1, "<sleeper_job>" },
{ "ST_SUBMIT_POLLING_WAIT_ZEROTIMEOUT", ST_SUBMIT_POLLING_WAIT_ZEROTIMEOUT, 1, "<sleeper_job>" },
{ "ST_SUBMIT_POLLING_SYNCHRONIZE_TIMEOUT", ST_SUBMIT_POLLING_SYNCHRONIZE_TIMEOUT, 1, "<sleeper_job>" },
{ "ST_SUBMIT_POLLING_SYNCHRONIZE_ZEROTIMEOUT", ST_SUBMIT_POLLING_SYNCHRONIZE_ZEROTIMEOUT, 1, "<sleeper_job>" },
{ "ST_UNSUPPORTED_ATTR", ST_UNSUPPORTED_ATTR, 0, "" },
{ "ST_UNSUPPORTED_VATTR", ST_UNSUPPORTED_VATTR, 0, "" },
{ "ST_SYNCHRONIZE_NONEXISTANT", ST_SYNCHRONIZE_NONEXISTANT, 1, "<sleeper_job>" },
{ "ST_RECOVERABLE_SESSION", ST_RECOVERABLE_SESSION, 1, "<sleeper_job>" },
/* multiple application threads - automated tests only */
{ "MT_SUBMIT_WAIT", MT_SUBMIT_WAIT, 1, "<sleeper_job>" },
{ "MT_SUBMIT_BEFORE_INIT_WAIT", MT_SUBMIT_BEFORE_INIT_WAIT, 1, "<sleeper_job>" },
{ "MT_EXIT_DURING_SUBMIT", MT_EXIT_DURING_SUBMIT, 1, "<sleeper_job>" },
{ "MT_SUBMIT_MT_WAIT", MT_SUBMIT_MT_WAIT, 1, "<sleeper_job>" },
{ "MT_EXIT_DURING_SUBMIT_OR_WAIT", MT_EXIT_DURING_SUBMIT_OR_WAIT, 1, "<sleeper_job>" },
/* ------------------------------------------------------------------------------------ */
/* tests that require test suite to be run in an automated fashion (file name creation) */
{ "ST_INPUT_BECOMES_OUTPUT", ST_INPUT_BECOMES_OUTPUT, 2, "<input_path> <output_path>" },
{ "ST_ATTRIBUTE_CHECK", ST_ATTRIBUTE_CHECK, 2, "<exit_arg_job> <email_addr>" },
{ "ST_SUBMIT_SUSPEND_RESUME_WAIT", ST_SUBMIT_SUSPEND_RESUME_WAIT, 1, "<sleeper_job>" },
/* tests that test_drmaa can't test in an automated fashion (so far) */
{ "ST_DRMAA_JOB_PS", ST_DRMAA_JOB_PS, 1, "<jobid> ..." },
{ "ST_DRMAA_CONTROL", ST_DRMAA_CONTROL, 3, "DRMAA_CONTROL_* DRMAA_ERRNO_* <jobid> ..." },
{ "ST_USAGE_CHECK", ST_USAGE_CHECK, 1, "<exit_job>" },
{ "ST_TRANSFER_FILES_SINGLE_JOB", ST_TRANSFER_FILES_SINGLE_JOB, 6, "<sleeper_job> <file_staging_flags "
"{\"i\"|\"o\"|\"e\" }> <merge_stderr {\"y\"|\"n\"}> <[inputhost]:/inputpath> <[outputhost]:/outputpath> <[errorhost]:/errorpath>" },
{ "ST_TRANSFER_FILES_BULK_JOB", ST_TRANSFER_FILES_BULK_JOB, 6, "<sleeper_job> <file_staging_flags "
"{\"i\"|\"o\"|\"e\" }> <<merge_stderr {\"y\"|\"n\"}> [inputhost]:/inputpath> <[outputhost]:/outputpath> <[errorhost]:/errorpath>" },
/* tests that have nothing to do with drmaa */
{ "ST_RESERVATION_FINISH_ORDER", ST_RESERVATION_FINISH_ORDER, 4, "<sleeper_job> <native_spec0> <native_spec1> <native_spec2>" },
{ "ST_BACKFILL_FINISH_ORDER", ST_BACKFILL_FINISH_ORDER, 4, "<sleeper_job> <native_spec0> <native_spec1> <native_spec2>" },
{ "ST_WILD_PARALLEL", ST_WILD_PARALLEL, 4, "<sleeper_job> <native_spec0> <native_spec1> <native_spec2>" },
{ NULL, 0 }
};
#define FIRST_NON_AUTOMATED_TEST ST_INPUT_BECOMES_OUTPUT
static int test(sge_gdi_ctx_class_t *ctx, int *argc, char **argv[], int parse_args);
static int submit_and_wait(int n);
static int submit_sleeper(int n);
static int submit_input_mirror(int n, const char *mirror_job,
const char *input_path, const char *output_path,
const char *error_path, int join, char* hostname);
static int do_submit(drmaa_job_template_t *jt, int n);
static int wait_all_jobs(int n);
static int wait_n_jobs(int n);
static drmaa_job_template_t *create_sleeper_job_template(int seconds,
int as_bulk_job,
int in_hold);
static drmaa_job_template_t *create_exit_job_template(const char *exit_job,
int as_bulk_job);
static void report_session_key(void);
static void *submit_and_wait_thread (void *v);
static void *submit_sleeper_thread (void *v);
int str2drmaa_state(const char *str);
static int str2drmaa_ctrl(const char *str);
static int str2drmaa_errno(const char *str);
static const char *drmaa_state2str(int state);
static const char *drmaa_ctrl2str(int control);
static const char *drmaa_errno2str(int ctrl);
static void array_job_run_sequence_adapt(int **sequence, int job_id, int count);
static int set_path_attribute_plus_colon(drmaa_job_template_t *jt,
const char *name, const char *value,
char *error_diagnosis,
size_t error_diag_len);
static int set_path_attribute_plus_colon(drmaa_job_template_t *jt,
const char *name, const char *value,
char *error_diagnosis,
size_t error_diag_len);
static bool test_error_code(char *name, int code, int expected);
static void report_wrong_job_finish(const char *comment, const char *jobid,
int stat);
typedef struct {
char *native;
int time;
} test_job_t;
static int test_dispatch_order_njobs(int n, test_job_t jobs[], char *jsr_str);
static int job_run_sequence_verify(int pos, const char *all_jobids[], int *order[]);
static int **job_run_sequence_parse(char *jrs_str);
static int test_case;
static int is_sun_grid_engine;
/* global test case parameters */
char *sleeper_job = NULL,
*exit_job = NULL,
*mirror_job = NULL,
*input_path = NULL,
*output_path = NULL,
*error_path = NULL,
*email_addr = NULL;
int ctrl_op = -1;
static void init_jobids(const char *jobids[], int size)
{
int i = 0;
for (i = 0; i < size; i++) {
jobids[i] = NULL;
}
}
static void free_jobids(const char *jobids[], int size)
{
int i = 0;
for (i = 0; i < size; i++) {
if (jobids[i] != NULL) {
sge_free(&(jobids[i]));
}
}
}
static void usage(void)
{
int i;
fprintf(stderr, "usage: test_drmaa <test_case>\n");
fprintf(stderr, " <test_case> is one of the keywords below including the enlisted test case arguments\n");
for (i=0; test_map[i].test_name; i++)
fprintf(stderr, "\t%-45.45s %s\n", test_map[i].test_name, test_map[i].opt_arguments);
fprintf(stderr, " <sleeper_job> is an executable job that sleeps <argv1> seconds\n");
fprintf(stderr, " the job must be executable at the target machine\n");
fprintf(stderr, " <mirror_job> is an executable job that returns it's stdin stream to stdout (e.g. /bin/cat)\n");
fprintf(stderr, " the job must be executable at the target machine\n\n");
fprintf(stderr, " <exit_arg_job> is an executable job that exits <argv1> as exit status\n");
fprintf(stderr, " the job must be executable at the target machine\n");
fprintf(stderr, " <input_path> is the path of an input file\n");
fprintf(stderr, " the user must have read access to this file at the target machine\n");
fprintf(stderr, " <output_path> is the path of an output file\n");
fprintf(stderr, " the user must have write access to this file at the target machine\n");
fprintf(stderr, " <email_addr> is an email address to which to send \n");
fprintf(stderr, " job completion notices\n");
fprintf(stderr, " <native_spec0> a native specification\n");
fprintf(stderr, " <native_spec1> a native specification\n");
fprintf(stderr, " <native_spec2> a native specification\n");
exit(1);
}
int main(int argc, char *argv[])
{
int failed = 0;
int i;
char diag[DRMAA_ERROR_STRING_BUFFER];
sge_gdi_ctx_class_t *ctx = NULL;
lList *alp = NULL;
DENTER_MAIN(TOP_LAYER, "qsub");
if (argc == 1)
usage();
/* Print out an adivsory */
printf ("The DRMAA test suite is now starting.\n");
/* figure out which DRM system we are using */
{
char drm_name[DRMAA_DRM_SYSTEM_BUFFER];
if (drmaa_get_DRM_system(drm_name, 255, diag, sizeof(diag)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_DRM_system() failed: %s\n", diag);
sge_prof_cleanup();
return 1;
}
printf("Connecting to DRM system \"%s\"\n", drm_name);
if (!strncmp(drm_name, "SGE", 3))
is_sun_grid_engine = 1;
else
is_sun_grid_engine = 0;
}
/*
** since drmaa doesn't give an explicit handle to the context and sge_gdi
** is used below, we provide our own context here
*/
if (sge_gdi2_setup(&ctx, JAPI, MAIN_THREAD, &alp) != AE_OK) {
answer_list_output(&alp);
SGE_EXIT((void**)&ctx, 1);
}
while (argc > 1) {
/* map test name to test number */
for (i=0; test_map[i].test_name; i++)
if (!strcasecmp(argv[1], test_map[i].test_name))
break;
if (!test_map[i].test_name) {
fprintf(stderr, "test_drmaa: %s is not a valid test name\n", argv[1]);
usage();
}
test_case = test_map[i].test_number;
argc--; argv++;
if ((argc-1) < test_map[i].nargs)
usage();
if (test_case == ALL_TESTS) {
int success = 1;
sleeper_job = NEXT_ARGV(&argc, &argv);
exit_job = NEXT_ARGV(&argc, &argv);
email_addr = NEXT_ARGV(&argc, &argv);
for (i=1; test_map[i].test_name && test_map[i].test_number != FIRST_NON_AUTOMATED_TEST && success; i++) {
test_case = test_map[i].test_number;
printf("---------------------\n");
printf("starting test #%d (%s)\n", i, test_map[i].test_name);
switch (test_case) {
case ST_EMPTY_SESSION_CONTROL:
{
int i;
const int ctrl_ops[] = { DRMAA_CONTROL_SUSPEND, DRMAA_CONTROL_RESUME,
DRMAA_CONTROL_HOLD, DRMAA_CONTROL_RELEASE, DRMAA_CONTROL_TERMINATE, -1 };
for (i=0; ctrl_ops[i] != -1; i++) {
ctrl_op = ctrl_ops[i];
if (test(ctx, &argc, &argv, 0)!=0) {
printf("test \"%s\" with \"%s\" failed\n",
test_map[i].test_name, drmaa_ctrl2str(ctrl_ops[i]));
failed = 1;
break;
} else
printf("successfully finished test \"%s\" with \"%s\"\n",
test_map[i].test_name, drmaa_ctrl2str(ctrl_ops[i]));
}
break;
}
default:
if (test(ctx, &argc, &argv, 0)!=0) {
printf("test #%d failed\n", i);
failed = 1;
break;
} else
printf("successfully finished test #%d\n", i);
break;
}
if (failed)
success = 0;
}
} else {
printf("starting test \"%s\"\n", test_map[i].test_name);
if (test(ctx, &argc, &argv, 1)!=0) {
printf("test \"%s\" failed\n", test_map[i].test_name);
failed = 1;
break;
} else {
printf("successfully finished test \"%s\"\n", test_map[i].test_name);
}
}
}
drmaa_exit(NULL, 0);
sge_gdi2_shutdown((void**)&ctx);
sge_gdi_ctx_class_destroy(&ctx);
sge_prof_cleanup();
return failed;
}
static int test(sge_gdi_ctx_class_t *ctx, int *argc, char **argv[], int parse_args)
{
bool bBulkJob = false;
int i;
int job_chunk = JOB_CHUNK;
char diagnosis[DRMAA_ERROR_STRING_BUFFER];
drmaa_job_template_t *jt = NULL;
int drmaa_errno=0;
int do_while_end = 0;
switch (test_case) {
case ST_ERROR_CODES:
{
if (test_error_code("DRMAA_ERRNO_SUCCESS", DRMAA_ERRNO_SUCCESS, 0) &&
test_error_code("DRMAA_ERRNO_INTERNAL_ERROR", DRMAA_ERRNO_INTERNAL_ERROR, 1) &&
test_error_code("DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE", DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE, 2) &&
test_error_code("DRMAA_ERRNO_AUTH_FAILURE", DRMAA_ERRNO_AUTH_FAILURE, 3) &&
test_error_code("DRMAA_ERRNO_INVALID_ARGUMENT", DRMAA_ERRNO_INVALID_ARGUMENT, 4) &&
test_error_code("DRMAA_ERRNO_NO_ACTIVE_SESSION", DRMAA_ERRNO_NO_ACTIVE_SESSION, 5) &&
test_error_code("DRMAA_ERRNO_NO_MEMORY", DRMAA_ERRNO_NO_MEMORY, 6) &&
test_error_code("DRMAA_ERRNO_INVALID_CONTACT_STRING", DRMAA_ERRNO_INVALID_CONTACT_STRING, 7) &&
test_error_code("DRMAA_ERRNO_DEFAULT_CONTACT_STRING_ERROR", DRMAA_ERRNO_DEFAULT_CONTACT_STRING_ERROR, 8) &&
test_error_code("DRMAA_ERRNO_NO_DEFAULT_CONTACT_STRING_SELECTED", DRMAA_ERRNO_NO_DEFAULT_CONTACT_STRING_SELECTED, 9) &&
test_error_code("DRMAA_ERRNO_DRMS_INIT_FAILED", DRMAA_ERRNO_DRMS_INIT_FAILED, 10) &&
test_error_code("DRMAA_ERRNO_ALREADY_ACTIVE_SESSION", DRMAA_ERRNO_ALREADY_ACTIVE_SESSION, 11) &&
test_error_code("DRMAA_ERRNO_DRMS_EXIT_ERROR", DRMAA_ERRNO_DRMS_EXIT_ERROR, 12) &&
test_error_code("DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT", DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT, 13) &&
test_error_code("DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE", DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, 14) &&
test_error_code("DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES", DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, 15) &&
test_error_code("DRMAA_ERRNO_TRY_LATER", DRMAA_ERRNO_TRY_LATER, 16) &&
test_error_code("DRMAA_ERRNO_DENIED_BY_DRM", DRMAA_ERRNO_DENIED_BY_DRM, 17) &&
test_error_code("DRMAA_ERRNO_INVALID_JOB", DRMAA_ERRNO_INVALID_JOB, 18) &&
test_error_code("DRMAA_ERRNO_RESUME_INCONSISTENT_STATE", DRMAA_ERRNO_RESUME_INCONSISTENT_STATE, 19) &&
test_error_code("DRMAA_ERRNO_SUSPEND_INCONSISTENT_STATE", DRMAA_ERRNO_SUSPEND_INCONSISTENT_STATE, 20) &&
test_error_code("DRMAA_ERRNO_HOLD_INCONSISTENT_STATE", DRMAA_ERRNO_HOLD_INCONSISTENT_STATE, 21) &&
test_error_code("DRMAA_ERRNO_RELEASE_INCONSISTENT_STATE", DRMAA_ERRNO_RELEASE_INCONSISTENT_STATE, 22) &&
test_error_code("DRMAA_ERRNO_EXIT_TIMEOUT", DRMAA_ERRNO_EXIT_TIMEOUT, 23) &&
test_error_code("DRMAA_ERRNO_NO_RUSAGE", DRMAA_ERRNO_NO_RUSAGE, 24) &&
test_error_code("DRMAA_ERRNO_NO_MORE_ELEMENTS", DRMAA_ERRNO_NO_MORE_ELEMENTS, 25)
) {
break;
}
else {
return 1;
}
}
case ST_MULT_INIT:
{
/* no test case arguments */
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_ALREADY_ACTIVE_SESSION) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_MULT_EXIT:
{
/* no test case arguments */
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit(1) failed: %s\n", diagnosis);
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_NO_ACTIVE_SESSION) {
fprintf(stderr, "drmaa_exit(2) failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SUBMIT_WAIT:
case ST_SUBMIT_NO_RUN_WAIT:
{
int n = (test_case == ST_SUBMIT_WAIT)?JOB_CHUNK:1;
char jobid[1024];
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
if (test_case == ST_SUBMIT_NO_RUN_WAIT) {
drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, "-l a=fantasy_os -now yes -w n", NULL, 0);
}
for (i=0; i<n; i++) {
if (drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
printf("submitted job \"%s\"\n", jobid);
}
drmaa_delete_job_template(jt, NULL, 0);
if (wait_all_jobs(n) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SUBMIT_POLLING_WAIT_TIMEOUT:
case ST_SUBMIT_POLLING_WAIT_ZEROTIMEOUT:
case ST_SUBMIT_POLLING_SYNCHRONIZE_TIMEOUT:
case ST_SUBMIT_POLLING_SYNCHRONIZE_ZEROTIMEOUT:
{
char jobid[1024];
const int timeout = 5;
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
if (drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
printf("submitted job \"%s\"\n", jobid);
drmaa_delete_job_template(jt, NULL, 0);
switch (test_case) {
case ST_SUBMIT_POLLING_WAIT_TIMEOUT:
while ((drmaa_errno=drmaa_wait(jobid, NULL, 0, NULL, timeout, NULL,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
if (drmaa_errno != DRMAA_ERRNO_EXIT_TIMEOUT) {
fprintf(stderr, "drmaa_wait(\"%s\", timeout = %d) failed: %s (%s)\n",
jobid, timeout, diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
printf("still waiting for job \"%s\" to finish\n", jobid);
}
break;
case ST_SUBMIT_POLLING_WAIT_ZEROTIMEOUT:
while ((drmaa_errno=drmaa_wait(jobid, NULL, 0, NULL, DRMAA_TIMEOUT_NO_WAIT, NULL,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
if (drmaa_errno != DRMAA_ERRNO_EXIT_TIMEOUT) {
fprintf(stderr, "drmaa_wait(\"%s\", no timeout) failed: %s (%s)\n",
jobid, diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
printf("still waiting for job \"%s\" to finish\n", jobid);
sleep(timeout);
printf("slept %d seconds\n", timeout);
}
break;
case ST_SUBMIT_POLLING_SYNCHRONIZE_TIMEOUT:
while ((drmaa_errno=drmaa_synchronize(session_all, timeout, 1,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
if (drmaa_errno != DRMAA_ERRNO_EXIT_TIMEOUT) {
fprintf(stderr, "drmaa_synchronize(\"%s\", timeout = %d) failed: %s (%s)\n",
jobid, timeout, diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
printf("still trying to synchronize with job \"%s\" to finish\n", jobid);
}
break;
case ST_SUBMIT_POLLING_SYNCHRONIZE_ZEROTIMEOUT:
while ((drmaa_errno=drmaa_synchronize(session_all, DRMAA_TIMEOUT_NO_WAIT, 1,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
if (drmaa_errno != DRMAA_ERRNO_EXIT_TIMEOUT) {
fprintf(stderr, "drmaa_synchronize(\"%s\", no timeout) failed: %s (%s)\n",
jobid, diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
printf("still trying to synchronize with job \"%s\" to finish\n", jobid);
sleep(timeout);
printf("slept %d seconds\n", timeout);
}
break;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case MT_SUBMIT_WAIT:
{
pthread_t submitter_threads[NTHREADS];
int n = -1;
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
for (i=0; i<NTHREADS; i++)
pthread_create(&submitter_threads[i], NULL, submit_sleeper_thread, &job_chunk);
for (i=0; i<NTHREADS; i++)
if (pthread_join(submitter_threads[i], NULL))
printf("pthread_join() returned != 0\n");
if (wait_all_jobs(n) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case MT_SUBMIT_BEFORE_INIT_WAIT:
{
pthread_t submitter_threads[NTHREADS];
int n = -1;
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
printf("sleeper_job = %s\n", sleeper_job);
for (i=0; i<NTHREADS; i++) {
pthread_create(&submitter_threads[i], NULL, submit_sleeper_thread, &job_chunk);
}
/* delay drmaa_init() */
sleep(5);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
for (i=0; i<NTHREADS; i++)
if (pthread_join(submitter_threads[i], NULL))
printf("pthread_join() returned != 0\n");
if (wait_all_jobs(n) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case MT_EXIT_DURING_SUBMIT:
{
pthread_t submitter_threads[NTHREADS];
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
putenv("SGE_DELAY_AFTER_SUBMIT=20");
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
for (i=0; i<NTHREADS; i++)
pthread_create(&submitter_threads[i], NULL, submit_sleeper_thread, &job_chunk);
sleep(1);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
printf("drmaa_exit() succeeded\n");
putenv("SGE_DELAY_AFTER_SUBMIT=0");
for (i=0; i<NTHREADS; i++)
if (pthread_join(submitter_threads[i], NULL))
printf("pthread_join() returned != 0\n");
}
break;
case MT_SUBMIT_MT_WAIT:
{
pthread_t submitter_threads[NTHREADS];
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
for (i=0; i<NTHREADS; i++)
pthread_create(&submitter_threads[i], NULL, submit_and_wait_thread, &job_chunk);
for (i=0; i<NTHREADS; i++)
if (pthread_join(submitter_threads[i], NULL))
printf("pthread_join() returned != 0\n");
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case MT_EXIT_DURING_SUBMIT_OR_WAIT:
{
pthread_t submitter_threads[NTHREADS];
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
for (i=0; i<NTHREADS; i++)
pthread_create(&submitter_threads[i], NULL, submit_and_wait_thread, &job_chunk);
sleep(20);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
printf("drmaa_exit() succeeded\n");
for (i=0; i<NTHREADS; i++)
if (pthread_join(submitter_threads[i], NULL))
printf("pthread_join() returned != 0\n");
}
break;
case ST_BULK_SUBMIT_WAIT:
{
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (!(jt = create_sleeper_job_template(5, 1, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<NBULKS; i++) {
char jobid[100];
drmaa_job_ids_t *jobids;
int j = 0 ;
int size = 0;
if ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
printf("failed submitting bulk job (%s): %s\n", drmaa_strerror(drmaa_errno), diagnosis);
return 1;
}
printf("submitted bulk job with jobids:\n");
drmaa_errno = drmaa_get_num_job_ids(jobids, &size);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "failed getting # job ids: %s\n", drmaa_strerror(drmaa_errno));
return 1;
}
for (j = 0; j < size; j++) {
drmaa_errno = drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
printf("failed getting job id: %s\n", drmaa_strerror(drmaa_errno));
}
printf("\t \"%s\"\n", jobid);
}
drmaa_errno = drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
if (drmaa_errno != DRMAA_ERRNO_NO_MORE_ELEMENTS) {
fprintf(stderr, "Got incorrect return value from drmaa_get_next_job_id()\n");
return 1;
}
drmaa_release_job_ids(jobids);
}
drmaa_delete_job_template(jt, NULL, 0);
if (wait_n_jobs(JOB_CHUNK*NBULKS) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_BULK_SINGLESUBMIT_WAIT_INDIVIDUAL:
{
const int size_all_jobids = NBULKS*JOB_CHUNK + JOB_CHUNK + 1;
const char *all_jobids[NBULKS*JOB_CHUNK + JOB_CHUNK + 1];
char jobid[100];
int pos = 0;
init_jobids(all_jobids, size_all_jobids);
if (parse_args) {
sleeper_job = NEXT_ARGV(argc, argv);
}
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit some bulk jobs
*/
if (!(jt = create_sleeper_job_template(5, 1, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i = 0; i < NBULKS; i++) {
drmaa_job_ids_t *jobids;
int j;
while ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis,
sizeof(diagnosis)-1))==DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j = 0; j < JOB_CHUNK; j++) {
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
all_jobids[pos++] = strdup(jobid);
printf("\t \"%s\"\n", jobid);
}
drmaa_release_job_ids(jobids);
sleep(1);
}
drmaa_delete_job_template(jt, NULL, 0);
/*
* submit some sequential jobs
*/
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
free_jobids(all_jobids, size_all_jobids);
return 1;
}
for (i=0; i<JOB_CHUNK; i++) {
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
all_jobids[pos++] = strdup(jobid);
printf("\t \"%s\"\n", jobid);
}
/* set string array end mark */
all_jobids[pos] = NULL;
drmaa_delete_job_template(jt, NULL, 0);
/*
* wait all those jobs
*/
for (pos=0; pos<NBULKS*JOB_CHUNK + JOB_CHUNK; pos++) {
do {
int stat;
drmaa_errno = drmaa_wait(all_jobids[pos], jobid, sizeof(jobid)-1,
&stat, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", all_jobids[pos], diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", all_jobids[pos], diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("waited job \"%s\"\n", all_jobids[pos]);
sge_free(&(all_jobids[pos]));
}
free_jobids(all_jobids, size_all_jobids);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SUBMITMIXTURE_SYNC_ALL_DISPOSE:
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose)
to wait for all jobs to finish
- then drmaa_exit() is called */
{
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
char jobid[100];
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit some bulk jobs
*/
if (!(jt = create_sleeper_job_template(5, 1, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<NBULKS; i++) {
drmaa_job_ids_t *jobids;
int j;
while ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis,
sizeof(diagnosis)-1))==DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s\n", diagnosis);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j=0; j<JOB_CHUNK; j++) {
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
printf("\t \"%s\"\n", jobid);
}
drmaa_release_job_ids(jobids);
sleep(1);
}
drmaa_delete_job_template(jt, NULL, 0);
/*
* submit some sequential jobs
*/
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<JOB_CHUNK; i++) {
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
printf("\t \"%s\"\n", jobid);
}
drmaa_delete_job_template(jt, NULL, 0);
/*
* synchronize with all jobs
*/
drmaa_errno = drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER, 1, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
return 1;
}
printf("waited all jobs\n");
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
break;
}
case ST_SUBMITMIXTURE_SYNC_ALL_NODISPOSE:
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, no-dispose)
to wait for all jobs to finish
- do drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY) until
DRMAA_ERRNO_INVALID_JOB to reap all jobs
- then drmaa_exit() is called */
{
int size_all_jobids = NBULKS*JOB_CHUNK + JOB_CHUNK + 1;
const char *all_jobids[NBULKS*JOB_CHUNK + JOB_CHUNK + 1];
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
char jobid[100];
int pos = 0;
init_jobids(all_jobids, size_all_jobids);
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit some bulk jobs
*/
if (!(jt = create_sleeper_job_template(5, 1, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<NBULKS; i++) {
drmaa_job_ids_t *jobids;
int j;
while ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis,
sizeof(diagnosis)-1))==DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j=0; j<JOB_CHUNK; j++) {
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
all_jobids[pos++] = strdup(jobid);
printf("\t \"%s\"\n", jobid);
}
drmaa_release_job_ids(jobids);
sleep(1);
}
drmaa_delete_job_template(jt, NULL, 0);
/*
* submit some sequential jobs
*/
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<JOB_CHUNK; i++) {
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("\t \"%s\"\n", jobid);
all_jobids[pos++] = strdup(jobid);
}
/* set string array end mark */
all_jobids[pos] = NULL;
drmaa_delete_job_template(jt, NULL, 0);
/*
* synchronize with all jobs
*/
drmaa_errno = drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER, 0, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("synchronized with all jobs\n");
/*
* wait all those jobs
*/
for (pos=0; pos<NBULKS*JOB_CHUNK + JOB_CHUNK; pos++) {
do {
int stat;
drmaa_errno = drmaa_wait(all_jobids[pos], jobid, sizeof(jobid)-1,
&stat, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", all_jobids[pos], diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", all_jobids[pos], diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("waited job \"%s\"\n", all_jobids[pos]);
sge_free(&(all_jobids[pos]));
}
free_jobids(all_jobids, size_all_jobids);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
break;
}
case ST_SUBMITMIXTURE_SYNC_ALLIDS_DISPOSE:
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(all_jobids, dispose)
to wait for all jobs to finish
- then drmaa_exit() is called */
{
int size_all_jobids = NBULKS*JOB_CHUNK + JOB_CHUNK + 1;
const char *all_jobids[NBULKS*JOB_CHUNK + JOB_CHUNK + 1];
char jobid[100];
int pos = 0;
init_jobids(all_jobids, size_all_jobids);
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit some bulk jobs
*/
if (!(jt = create_sleeper_job_template(5, 1, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<NBULKS; i++) {
drmaa_job_ids_t *jobids;
int j;
while ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis,
sizeof(diagnosis)-1))==DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j=0; j<JOB_CHUNK; j++) {
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
printf("\t \"%s\"\n", jobid);
all_jobids[pos++] = strdup(jobid);
}
drmaa_release_job_ids(jobids);
sleep(1);
}
drmaa_delete_job_template(jt, NULL, 0);
/*
* submit some sequential jobs
*/
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
free_jobids(all_jobids, size_all_jobids);
return 1;
}
for (i=0; i<JOB_CHUNK; i++) {
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("\t \"%s\"\n", jobid);
all_jobids[pos++] = strdup(jobid);
}
/* set string array end mark */
all_jobids[pos] = NULL;
drmaa_delete_job_template(jt, NULL, 0);
/*
* synchronize with all jobs
*/
drmaa_errno = drmaa_synchronize(all_jobids, DRMAA_TIMEOUT_WAIT_FOREVER, 1, diagnosis, sizeof(diagnosis)-1);
free_jobids(all_jobids, size_all_jobids);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
return 1;
}
printf("waited all jobs\n");
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
break;
}
case ST_SUBMITMIXTURE_SYNC_ALLIDS_NODISPOSE:
/* - drmaa_init() is called
- submit a mixture of single and bulk jobs
- do drmaa_synchronize(all_jobids, no-dispose)
to wait for all jobs to finish
- do drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY) until
DRMAA_ERRNO_INVALID_JOB to reap all jobs
- then drmaa_exit() is called */
{
int size_all_jobids = NBULKS*JOB_CHUNK + JOB_CHUNK+1;
const char *all_jobids[NBULKS*JOB_CHUNK + JOB_CHUNK+1];
char jobid[100];
int pos = 0;
init_jobids(all_jobids, size_all_jobids);
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit some bulk jobs
*/
if (!(jt = create_sleeper_job_template(5, 1, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<NBULKS; i++) {
drmaa_job_ids_t *jobids;
int j;
while ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis,
sizeof(diagnosis)-1))==DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j=0; j<JOB_CHUNK; j++) {
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
all_jobids[pos++] = strdup(jobid);
printf("\t \"%s\"\n", jobid);
}
drmaa_release_job_ids(jobids);
}
drmaa_delete_job_template(jt, NULL, 0);
/*
* submit some sequential jobs
*/
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
free_jobids(all_jobids, size_all_jobids);
return 1;
}
for (i=0; i<JOB_CHUNK; i++) {
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("\t \"%s\"\n", jobid);
all_jobids[pos++] = strdup(jobid);
}
/* set string array end mark */
all_jobids[pos] = NULL;
drmaa_delete_job_template(jt, NULL, 0);
/*
* synchronize with all jobs
*/
drmaa_errno = drmaa_synchronize(all_jobids, DRMAA_TIMEOUT_WAIT_FOREVER, 0, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("synchronized with all jobs\n");
/*
* wait all those jobs
*/
for (pos=0; pos<NBULKS*JOB_CHUNK + JOB_CHUNK; pos++) {
do {
int stat;
drmaa_errno = drmaa_wait(all_jobids[pos], jobid, sizeof(jobid)-1,
&stat, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", all_jobids[pos], diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", all_jobids[pos], diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("waited job \"%s\"\n", all_jobids[pos]);
}
free_jobids(all_jobids, size_all_jobids);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
break;
}
case ST_SUBMIT_PAUSE_SUBMIT_SYNC:
/* - drmaa_init() is called
- a job is submitted
- do a long sleep(ST_SUBMIT_PAUSE_SUBMIT_SYNC+)
- another job is submitted
- do drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose)
- then drmaa_exit() is called */
{
int size_all_jobids = 2 + 1;
const char *all_jobids[2 + 1];
char jobid[100];
int pos = 0;
init_jobids(all_jobids, size_all_jobids);
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit some sequential jobs
*/
if (!(jt = create_sleeper_job_template(5, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
for (i=0; i<2; i++) {
drmaa_errno = drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("\t \"%s\"\n", jobid);
all_jobids[pos++] = strdup(jobid);
/*
* enforce SGE commproc timeout
* this timeout must be handled transparently by DRMAA implementation
*/
if (i==0) {
printf("sleeping %d seconds\n", SGE_COMMPROC_TIMEOUT+30);
sleep(SGE_COMMPROC_TIMEOUT+30);
}
}
/* set string array end mark */
all_jobids[pos] = NULL;
drmaa_delete_job_template(jt, NULL, 0);
/*
* synchronize with all jobs
*/
drmaa_errno = drmaa_synchronize(all_jobids, DRMAA_TIMEOUT_WAIT_FOREVER, 1, diagnosis, sizeof(diagnosis)-1);
free_jobids(all_jobids, size_all_jobids);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
return 1;
}
printf("waited all jobs\n");
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_INPUT_FILE_FAILURE:
case ST_ERROR_FILE_FAILURE:
case ST_OUTPUT_FILE_FAILURE:
{
int aborted, stat, remote_ps;
char jobid[100];
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/* submit a job that must fail */
drmaa_allocate_job_template(&jt, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, sleeper_job, NULL, 0);
switch (test_case) {
case ST_OUTPUT_FILE_FAILURE:
drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "y", NULL, 0);
drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":/etc/passwd", NULL, 0);
break;
case ST_ERROR_FILE_FAILURE:
drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "n", NULL, 0);
drmaa_set_attribute(jt, DRMAA_ERROR_PATH, ":/etc/passwd", NULL, 0);
break;
case ST_INPUT_FILE_FAILURE:
drmaa_set_attribute(jt, DRMAA_INPUT_PATH, ":<not existing file>", NULL, 0);
break;
}
if ((drmaa_errno = drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
drmaa_delete_job_template(jt, NULL, 0);
printf("submitted job \"%s\"\n", jobid);
/* synchronize with job to finish but do not dispose job finish information */
if ((drmaa_errno = drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER, 0,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
return 1;
}
printf("synchronized with job finish\n");
/* get job state */
drmaa_errno = drmaa_job_ps(jobid, &remote_ps, diagnosis, sizeof(diagnosis)-1);
if (remote_ps != DRMAA_PS_FAILED) {
fprintf(stderr, "job \"%s\" is not in failed state: %s\n",
jobid, drmaa_state2str(remote_ps));
return 1;
}
/* wait job */
if ((drmaa_errno = drmaa_wait(jobid, NULL, 0, &stat, DRMAA_TIMEOUT_NO_WAIT, NULL,
diagnosis, sizeof(diagnosis)-1)) != DRMAA_ERRNO_SUCCESS) {
printf("drmaa_wait() failed %s: %s\n", drmaa_strerror(drmaa_errno), diagnosis);
return 1;
}
/* job finish information */
drmaa_wifaborted(&aborted, stat, diagnosis, sizeof(diagnosis)-1);
if (!aborted) {
fprintf(stderr, "job \"%s\" failed but drmaa_wifaborted() returns false\n",
jobid);
return 1;
}
printf("waited job \"%s\" that never ran\n", jobid);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SUPPORTED_ATTR:
case ST_SUPPORTED_VATTR:
/* - drmaa_init() is called
- drmaa_get_attribute_names()/drmaa_get_vector_attribute_names() is called
- the names of all supported non vector/vector attributes are printed
- then drmaa_exit() is called */
{
drmaa_attr_names_t *vector;
char attr_name[DRMAA_ATTR_BUFFER];
int size = 0;
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
if (test_case == ST_SUPPORTED_ATTR)
drmaa_errno = drmaa_get_attribute_names(&vector, diagnosis, sizeof(diagnosis)-1);
else
drmaa_errno = drmaa_get_vector_attribute_names(&vector, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_attribute_names()/drmaa_get_vector_attribute_names() failed: %s\n",
diagnosis);
return 1;
}
drmaa_errno = drmaa_get_num_attr_names(vector, &size);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_num_attr_names() failed: %s\n", drmaa_strerror(drmaa_errno));
return 1;
}
while ((drmaa_errno=drmaa_get_next_attr_name(vector, attr_name, sizeof(attr_name)-1))==DRMAA_ERRNO_SUCCESS) {
size--;
printf("%s\n", attr_name);
}
/* we don't need vector any longer - free it */
drmaa_release_attr_names(vector);
vector = NULL;
if (size != 0) {
fprintf(stderr, "Got incorrect size from drmaa_get_num_attr_names()\n");
return 1;
}
if (drmaa_errno != DRMAA_ERRNO_NO_MORE_ELEMENTS) {
fprintf(stderr, "Got incorrect return value from drmaa_get_next_attr_name()\n");
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_VERSION:
/* - drmaa_version() is called
- version information is printed */
{
unsigned int major, minor;
if (drmaa_version(&major, &minor, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_version() failed: %s\n", diagnosis);
return 1;
}
printf("version %d.%d\n", major, minor);
if ((major != 1) || (minor != 0)) {
fprintf(stderr, "drmaa_version() failed -- incorrect version number : %d.%d\n", major, minor);
return 1;
}
}
break;
case ST_CONTACT:
case ST_DRM_SYSTEM:
case ST_DRMAA_IMPL:
{
char output_string[1024];
if (test_case == ST_CONTACT)
drmaa_errno = drmaa_get_contact(output_string, sizeof(output_string)-1,
diagnosis, sizeof(diagnosis)-1);
else if (test_case == ST_DRM_SYSTEM)
drmaa_errno = drmaa_get_DRM_system(output_string, sizeof(output_string)-1,
diagnosis, sizeof(diagnosis)-1);
else if (test_case == ST_DRMAA_IMPL)
drmaa_errno = drmaa_get_DRMAA_implementation(output_string, sizeof(output_string)-1,
diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_contact()/drmaa_get_DRM_system() failed: %s\n", diagnosis);
return 1;
}
if (test_case == ST_CONTACT)
printf("drmaa_get_contact() returned \"%s\" before init\n", output_string);
else if (test_case == ST_DRM_SYSTEM)
printf("drmaa_get_DRM_system() returned \"%s\" before init\n", output_string);
else if (test_case == ST_DRMAA_IMPL)
printf("drmaa_get_DRMAA_implementation() returned \"%s\" before init\n", output_string);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
if (test_case == ST_CONTACT)
drmaa_errno = drmaa_get_contact(output_string, sizeof(output_string)-1,
diagnosis, sizeof(diagnosis)-1);
else if (test_case == ST_DRM_SYSTEM)
drmaa_errno = drmaa_get_DRM_system(output_string, sizeof(output_string)-1,
diagnosis, sizeof(diagnosis)-1);
else if (test_case == ST_DRMAA_IMPL)
drmaa_errno = drmaa_get_DRMAA_implementation(output_string, sizeof(output_string)-1,
diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_contact()/drmaa_get_DRM_system() failed: %s\n", diagnosis);
return 1;
}
if (test_case == ST_CONTACT)
printf("drmaa_get_contact() returned \"%s\" after init\n", output_string);
else if (test_case == ST_DRM_SYSTEM)
printf("drmaa_get_DRM_system() returned \"%s\" after init\n", output_string);
else if (test_case == ST_DRMAA_IMPL)
printf("drmaa_get_DRMAA_implementation() returned \"%s\" after init\n", output_string);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_INPUT_BECOMES_OUTPUT:
{
const char *mirror_job = "/bin/cat",
*input_path = NULL,
*output_path = NULL;
FILE *fp = NULL;
char buffer[1024];
const char *mirror_text = "thefoxjumps...";
char* local_host_name = NULL;
if (parse_args) {
input_path = NEXT_ARGV(argc, argv);
output_path = NEXT_ARGV(argc, argv);
}
if (!(fp = fopen(input_path, "w"))) {
fprintf(stderr, "fopen(w) failed: %s\n", strerror(errno));
return 1;
}
fprintf(fp, "%s\n", mirror_text);
FCLOSE(fp);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
cl_com_gethostname(&local_host_name, NULL, NULL, NULL);
if (local_host_name == NULL) {
fprintf(stderr, "can't get local hostname\n");
return 1;
}
if (submit_input_mirror(1, mirror_job, input_path, output_path,
NULL, 1, local_host_name)!=DRMAA_ERRNO_SUCCESS) {
return 1;
}
sge_free(&local_host_name);
if (wait_n_jobs(1) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (!(fp=fopen(output_path, "r"))) {
fprintf(stderr, "fopen(%s) failed: %s\n", output_path, strerror(errno));
return 1;
}
if (fscanf(fp, "%s", buffer) != 1) {
fprintf(stderr, "fscanf error\n");
return 1;
}
if (strcmp(buffer, mirror_text)) {
fprintf(stderr, "wrong output file: %s\n", buffer);
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SUBMIT_IN_HOLD_RELEASE:
case ST_SUBMIT_IN_HOLD_DELETE:
{
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
char jobid[1024];
int job_state;
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (!(jt = create_sleeper_job_template(5, 0, 1))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
if (drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
drmaa_delete_job_template(jt, NULL, 0);
printf("submitted job in hold state \"%s\"\n", jobid);
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\")) failed: %s\n", jobid, diagnosis);
return 1;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf(stderr, "job \"%s\" is not in user hold state: %s\n",
jobid, drmaa_state2str(job_state));
return 1;
}
printf("verified user hold state for job \"%s\"\n", jobid);
if (test_case == ST_SUBMIT_IN_HOLD_RELEASE) {
if (drmaa_control(jobid, DRMAA_CONTROL_RELEASE, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, DRMAA_CONTROL_RELEASE) failed: %s\n",
jobid, diagnosis);
return 1;
}
printf("released user hold state for job \"%s\"\n", jobid);
} else {
if (drmaa_control(jobid, DRMAA_CONTROL_TERMINATE, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, DRMAA_CONTROL_TERMINATE) failed: %s\n",
jobid, diagnosis);
return 1;
}
printf("terminated job in hold state \"%s\"\n", jobid);
}
/* synchronize with job to finish but do not dispose job finish information */
if ((drmaa_errno = drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER, 0,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
return 1;
}
printf("synchronized with job finish\n");
/* report job finish state */
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\")) failed: %s\n", jobid, diagnosis);
return 1;
}
printf("state of job \"%s\" is now %s\n", jobid, drmaa_state2str(job_state));
if ((test_case == ST_SUBMIT_IN_HOLD_RELEASE && job_state != DRMAA_PS_DONE) ||
(test_case != ST_SUBMIT_IN_HOLD_RELEASE && job_state != DRMAA_PS_FAILED)) {
fprintf(stderr, "job \"%s\" terminated with unexpected state \"%s\"\n", jobid, drmaa_state2str(job_state));
return 1;
}
if (wait_n_jobs(1) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_BULK_SUBMIT_IN_HOLD_SESSION_RELEASE:
case ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE:
case ST_BULK_SUBMIT_IN_HOLD_SESSION_DELETE:
case ST_BULK_SUBMIT_IN_HOLD_SINGLE_DELETE:
{
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
int size_all_jobids = JOB_CHUNK + 1;
const char *all_jobids[JOB_CHUNK + 1];
int job_state, pos = 0;
int ctrl_op;
init_jobids(all_jobids, size_all_jobids);
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (!(jt = create_sleeper_job_template(5, 1, 1))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
/*
* Submit a bulk job in hold and verify state using drmaa_job_ps()
*/
{
drmaa_job_ids_t *jobids;
int j;
if ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
printf("failed submitting bulk job (%s): %s\n", drmaa_strerror(drmaa_errno), diagnosis);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j=0; j<JOB_CHUNK; j++) {
char jobid[100];
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
printf("\t \"%s\"\n", jobid);
/* copy jobid into jobid array */
all_jobids[pos++] = strdup(jobid);
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\")) failed: %s\n", jobid, diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf(stderr, "job \"%s\" is not in user hold state: %s\n",
jobid, drmaa_state2str(job_state));
free_jobids(all_jobids, size_all_jobids);
return 1;
}
}
drmaa_release_job_ids(jobids);
}
drmaa_delete_job_template(jt, NULL, 0);
printf("verified user hold state for bulk job\n");
/*
* Release or terminate all jobs using drmaa_control() depending on the test case
* drmaa_control() is applied muliple times on all tasks or on the whole session
*/
if (test_case == ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE ||
test_case == ST_BULK_SUBMIT_IN_HOLD_SINGLE_DELETE) {
int ctrl_op;
if (test_case == ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE)
ctrl_op = DRMAA_CONTROL_RELEASE;
else
ctrl_op = DRMAA_CONTROL_TERMINATE;
for (pos=0; pos<JOB_CHUNK; pos++) {
if (drmaa_control(all_jobids[pos], ctrl_op, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
all_jobids[pos], drmaa_ctrl2str(ctrl_op), diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
}
} else {
if (test_case == ST_BULK_SUBMIT_IN_HOLD_SESSION_RELEASE)
ctrl_op = DRMAA_CONTROL_RELEASE;
else
ctrl_op = DRMAA_CONTROL_TERMINATE;
if (drmaa_control(DRMAA_JOB_IDS_SESSION_ALL, ctrl_op, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
DRMAA_JOB_IDS_SESSION_ALL, drmaa_ctrl2str(ctrl_op), diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
}
printf("released/terminated all jobs\n");
/* synchronize with job to finish but do not dispose job finish information */
if ((drmaa_errno = drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER, 0,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("synchronized with job finish\n");
/*
* Verify job state of all jobs in the job id array
*/
for (pos=0; pos<JOB_CHUNK; pos++) {
if (drmaa_job_ps(all_jobids[pos], &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\")) failed: %s\n", all_jobids[pos], diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("state of job \"%s\" is now %s\n", all_jobids[pos], drmaa_state2str(job_state));
if (((test_case == ST_BULK_SUBMIT_IN_HOLD_SINGLE_RELEASE ||
test_case == ST_BULK_SUBMIT_IN_HOLD_SESSION_RELEASE) && job_state != DRMAA_PS_DONE) ||
((test_case == ST_BULK_SUBMIT_IN_HOLD_SINGLE_DELETE ||
test_case == ST_BULK_SUBMIT_IN_HOLD_SESSION_DELETE) && job_state != DRMAA_PS_FAILED)) {
fprintf(stderr, "job \"%s\" terminated with unexpected state \"%s\"\n", all_jobids[pos], drmaa_state2str(job_state));
free_jobids(all_jobids, size_all_jobids);
return 1;
}
}
free_jobids(all_jobids, size_all_jobids);
if (wait_n_jobs(JOB_CHUNK) != DRMAA_ERRNO_SUCCESS) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SUBMIT_SUSPEND_RESUME_WAIT:
{
int job_state, stat, exited, exit_status;
char jobid[1024];
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
/* submit a job running long enough allowing it to be suspended and resumed */
if (!(jt = create_sleeper_job_template(30, 0, 0))) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
if (drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
printf("submitted job \"%s\"\n", jobid);
drmaa_delete_job_template(jt, NULL, 0);
/* wait until job is running */
do {
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps() failed: %s\n", diagnosis);
return 1;
}
if (job_state != DRMAA_PS_RUNNING)
sleep(1);
} while (job_state != DRMAA_PS_RUNNING);
printf("job \"%s\" is now running\n", jobid);
/* drmaa_control() is used to suspend the job */
if ((drmaa_errno=drmaa_control(jobid, DRMAA_CONTROL_SUSPEND, diagnosis,
sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(\"%s\", DRMAA_CONTROL_SUSPEND) failed: %s (%s)\n",
jobid, diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
printf("suspended job \"%s\"\n", jobid);
/* drmaa_job_ps() is used to verify job was suspended */
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps() failed: %s\n", diagnosis);
return 1;
}
if (job_state != DRMAA_PS_USER_SUSPENDED) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed returns unexpected job state after "
"job suspension: %s\n", jobid, drmaa_state2str(job_state));
return 1;
}
printf("verified suspend was done for job \"%s\"\n", jobid);
/* drmaa_control() is used to resume the job */
if ((drmaa_errno=drmaa_control(jobid, DRMAA_CONTROL_RESUME, diagnosis,
sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(\"%s\", DRMAA_CONTROL_RESUME) failed: %s (%s)\n",
jobid, diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
printf("resumed job \"%s\"\n", jobid);
/* drmaa_job_ps() is used to verify job was resumed */
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps() failed: %s\n", diagnosis);
return 1;
}
if (job_state != DRMAA_PS_RUNNING) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed returns unexpected job state after "
"job resume: %s\n", jobid, drmaa_state2str(job_state));
return 1;
}
printf("verified resume was done for job \"%s\"\n", jobid);
/* drmaa_wait() is used to wait for the jobs regular end */
if ((drmaa_errno=drmaa_wait(jobid, NULL, 0, &stat,
DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(\"%s\") failed: %s\n", jobid, diagnosis);
return 1;
}
drmaa_wifexited(&exited, stat, NULL, 0);
if (!exited || (drmaa_wexitstatus(&exit_status, stat, NULL, 0), exit_status != 0)) {
report_wrong_job_finish("expected regular job end", jobid, stat);
return 1;
}
printf("job \"%s\" finished as expected\n", jobid);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_EMPTY_SESSION_WAIT:
case ST_EMPTY_SESSION_SYNCHRONIZE_DISPOSE:
case ST_EMPTY_SESSION_SYNCHRONIZE_NODISPOSE:
{
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
switch (test_case) {
case ST_EMPTY_SESSION_WAIT:
/* drmaa_wait() must return DRMAA_ERRNO_INVALID_JOB */
if ((drmaa_errno=drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY, NULL, 0, NULL,
DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_INVALID_JOB) {
fprintf(stderr, "drmaa_wait(empty session) failed: %s\n", diagnosis);
return 1;
}
break;
case ST_EMPTY_SESSION_SYNCHRONIZE_DISPOSE:
case ST_EMPTY_SESSION_SYNCHRONIZE_NODISPOSE:
{
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
/* drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL) must return DRMAA_ERRNO_SUCCESS */
if ((drmaa_errno=drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER,
(test_case == ST_EMPTY_SESSION_SYNCHRONIZE_DISPOSE) ? 1 : 0,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(empty session) failed: %s\n", diagnosis);
return 1;
}
}
break;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_EMPTY_SESSION_CONTROL:
{
const char *s;
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
/* parse control operation */
if (parse_args) {
s = NEXT_ARGV(argc, argv);
if ((ctrl_op = str2drmaa_ctrl(s)) == -1) {
fprintf(stderr, "unknown DRMAA control operation \"%s\"\n", s);
usage();
}
}
if ((drmaa_errno=drmaa_control(DRMAA_JOB_IDS_SESSION_ALL, ctrl_op,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(empty_session, %s) failed: %s (%s)\n",
drmaa_ctrl2str(ctrl_op), diagnosis, drmaa_strerror(drmaa_errno));
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_DRMAA_JOB_PS:
{
char diagnosis[1024];
const char *jobid;
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
while ( *argc > 1) {
int state;
/* for this test args must always be parsed */
jobid = NEXT_ARGV(argc, argv);
if (drmaa_job_ps(jobid, &state, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed: %s\n", jobid, diagnosis);
return 1;
}
printf("%20s %s\n", jobid, drmaa_state2str(state));
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_DRMAA_CONTROL:
{
char diagnosis[1024];
const char *s, *jobid;
int drmaa_target_errno, drmaa_errno, drmaa_control_op = -1;
/* parse control operation */
s = NEXT_ARGV(argc, argv);
if ((drmaa_control_op = str2drmaa_ctrl(s)) == -1) {
fprintf(stderr, "unknown DRMAA control operation \"%s\"\n", s);
usage();
}
/* parse aspired errno value */
s = NEXT_ARGV(argc, argv);
if ((drmaa_target_errno = str2drmaa_errno(s)) == -1) {
fprintf(stderr, "unknown DRMAA errno constant \"%s\"\n", s);
usage();
}
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
while ( *argc > 1) {
jobid = NEXT_ARGV(argc, argv);
if ((drmaa_errno=drmaa_control(jobid, drmaa_control_op, diagnosis, sizeof(diagnosis)-1))
!= drmaa_target_errno) {
if (drmaa_target_errno == DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(\"%s\", %s) failed: %s (%s)\n", jobid,
drmaa_ctrl2str(drmaa_control_op), diagnosis, drmaa_strerror(drmaa_errno));
return 1;
} else {
fprintf(stderr, "drmaa_control(\"%s\", %s) returned with wrong errno "
"(%s) instead of %s: %s\n", jobid, drmaa_ctrl2str(drmaa_control_op),
drmaa_errno2str(drmaa_errno), drmaa_errno2str(drmaa_target_errno),
drmaa_errno==DRMAA_ERRNO_SUCCESS?"<no error>":diagnosis);
return 1;
}
}
printf("%20s %s\n", jobid, drmaa_ctrl2str(drmaa_control_op));
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_EXIT_STATUS:
/* - drmaa_init() is called
- 255 job are submitted
- job i returns i as exit status (8 bit)
- drmaa_wait() verifies each job returned the
correct exit status
- then drmaa_exit() is called */
{
char diagnosis[1024];
int size_all_jobids = 256;
const char *all_jobids[256];
const char *job_argv[2];
char jobid[1024];
char buffer[100];
init_jobids(all_jobids, size_all_jobids);
if (parse_args) {
exit_job = NEXT_ARGV(argc, argv);
}
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* submit sequential jobs
*/
if (!(jt = create_exit_job_template(exit_job, 0))) {
fprintf(stderr, "create_exit_job_template() failed\n");
return 1;
}
for (i=0; i<255; i++) {
/* parametrize exit job with job argument */
sprintf(buffer, "%d", i);
job_argv[0] = buffer;
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
printf("\t \"%s\"\n", jobid);
all_jobids[i] = strdup(jobid);
}
/* set string array end mark */
all_jobids[i] = NULL;
drmaa_delete_job_template(jt, NULL, 0);
/*
* wait for all jobs and verify exit status
*/
for (i=0; i<255; i++) {
int stat = 0;
int exit_status = 0;
int exited = 0;
do {
drmaa_errno = drmaa_wait(all_jobids[i], jobid, sizeof(jobid)-1,
&stat, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", all_jobids[i], diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("job %d with job id %s finished\n", i, all_jobids[i]);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", all_jobids[i], diagnosis);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
drmaa_wifexited(&exited, stat, NULL, 0);
if (!exited) {
fprintf(stderr, "job \"%s\" did not exit cleanly\n", all_jobids[i]);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
drmaa_wexitstatus(&exit_status, stat, NULL, 0);
if (exit_status != i) {
fprintf(stderr, "job \"%s\" returned wrong exit status %d instead of %d\n",
all_jobids[i], exit_status, i);
free_jobids(all_jobids, size_all_jobids);
return 1;
}
}
free_jobids(all_jobids, size_all_jobids);
printf("waited all jobs\n");
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
break;
}
case ST_ATTRIBUTE_CHECK:
/* Need to test all DRMAA attributes:
DRMAA_REMOTE_COMMAND
DRMAA_V_ARGV
- submit exit job
- wait for job and check status code
DRMAA_JS_STATE
DRMAA_JOB_NAME
- submit job in hold state with name
- use drmaa_ps_job to verify state
- use custom routine to verfiy name
- release hold
DRMAA_WD
DRMAA_INPUT_PATH
DRMAA_OUTPUT_PATH
- reuse ST_INPUT_BECOMES_OUTPUT with files in /tmp
DRMAA_ERROR_PATH
- submit tar job with error path set
- wait for job to finish
- check contents of error file
DRMAA_JOIN_FILES
- submit tar job to create a sample tar file
- wait for job to finish
- submit tar job with output path and join files set
- wait for job to finish
- check contents of output file
DRMAA_JOB_CATEGORY
- submit job with job category containing -h and -N
- use drmaa_ps_job to verify state
- use sge_gdi to verify name
- release hold
- submit job with job category containing -h and -N and DRMAA_JOB_NAME
- use sge_gdi to verify name
- use drmaa_ps_job to verify state
- release hold
- wait for job to complete
DRMAA_NATIVE_SPECIFICATION
- submit job with -h and -N
- use drmaa_ps_job to verify state
- use sge_gdi to verify name
- release hold
- submit job with -h and -N and DRMAA_JOB_NAME
- use sge_gdi to verify name
- use drmaa_ps_job to verify state
- release hold
- wait for job to complete
DRMAA_START_TIME
- store the time
- submit job with start time +1 min
- wait for job to complete
- compare the current time to stored time
DRMAA_V_ENV
- submit echo job with output path set
- wait for job to finish
- check output file
DRMAA_BLOCK_EMAIL
DRMAA_V_EMAIL */
{
int status, job_state, exit_status;
int failed_test = 0, test_failed = 0;
char diagnosis[1024];
const char *job_argv[4];
char jobid[1024], new_jobid[1024];
char buffer[100];
lList *alp, *job_lp;
lListElem *job_ep;
FILE *fp;
const char *mirror_text = "thefoxjumps...";
mirror_job = "/bin/cat";
input_path = "test.in";
output_path = "test.out";
error_path = "test.err";
if (parse_args) {
exit_job = NEXT_ARGV(argc, argv);
email_addr = NEXT_ARGV(argc, argv);
}
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/*
* test remote command and argv
*/
do {
printf ("Testing remote command and argv\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "5";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
drmaa_wexitstatus(&exit_status, status, NULL, 0);
if (exit_status != 5) {
fprintf(stderr, "job \"%s\" returned wrong exit status %d instead of 5\n",
jobid, exit_status);
failed_test = 1;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing job submission state and job name
*/
do {
printf ("Testing job submission state and job name\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "5";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
drmaa_set_attribute(jt, DRMAA_JS_STATE, DRMAA_SUBMISSION_STATE_HOLD, NULL, 0);
drmaa_set_attribute(jt, DRMAA_JOB_NAME, "ExitTest", NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Getting job name for job %lu from GDI\n", (unsigned long)atol(jobid));
{
lCondition* where = lWhere("%T(%I==%u)", JB_Type, JB_job_number, (u_long32)atol(jobid));
lEnumeration *what = lWhat("%T (%I %I)", JB_Type, JB_job_number, JB_job_name);
alp = ctx->gdi(ctx, SGE_JB_LIST, SGE_GDI_GET, &job_lp, where, what, false);
job_ep = lFirst(job_lp);
lFreeWhere(&where);
lFreeWhat(&what);
}
{
int tmp_ret = answer_list_print_err_warn(&alp, "GDI Critical", "GDI Error: ", "Message from GDI: ");
if (tmp_ret > 0) {
fprintf (stderr, "problem talking to gdi\n");
failed_test = 1;
}
}
lFreeList(&alp);
if (job_ep == NULL) {
printf ("No such job number.\n");
failed_test = 1;
}
else if ((job_ep != NULL) && (strcmp (lGetString (job_ep, JB_job_name), "ExitTest") != 0)) {
fprintf(stderr, "Job \"%s\" name was \"%s\" instead of \"ExitTest\"\n",
jobid, lGetString (job_ep, JB_job_name));
failed_test = 1;
}
lFreeList(&job_lp);
printf ("Checking job state\n");
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf (stderr, "Job \"%s\" was not in hold state\n", jobid);
failed_test = 1;
}
printf ("Releasing job\n");
if (drmaa_control(jobid, DRMAA_CONTROL_RELEASE, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
jobid, drmaa_ctrl2str(DRMAA_CONTROL_RELEASE), diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
}
if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing working directory, input stream and output stream
*/
do {
char abs_path[128];
printf ("Testing working directory, input stream and output stream\n");
printf ("Writing input file\n");
strcpy (abs_path, "/tmp/");
if (!(fp = fopen (strcat (abs_path, input_path), "w"))) {
fprintf(stderr, "fopen(%s, w) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
fprintf(fp, "%s\n", mirror_text);
FCLOSE(fp);
printf ("Clearing output file\n");
strcpy (abs_path, "/tmp/");
if ((unlink (strcat (abs_path, output_path)) == -1) && (errno != ENOENT)) {
fprintf(stderr, "unlink(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
drmaa_set_attribute(jt, DRMAA_WD, "/tmp", NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, mirror_job, NULL, 0);
set_path_attribute_plus_colon(jt, DRMAA_INPUT_PATH, input_path, NULL, 0);
set_path_attribute_plus_colon(jt, DRMAA_OUTPUT_PATH, output_path, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
strcpy (abs_path, "/tmp/");
if (!(fp=fopen(strcat (abs_path, output_path), "r"))) {
fprintf(stderr, "fopen(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
if (fscanf(fp, "%s", buffer) != 1) {
fprintf(stderr, "fscanf error\n");
failed_test = 1;
continue;
}
if (strcmp(buffer, mirror_text)) {
fprintf(stderr, "Wrong output file: %s\n", buffer);
failed_test = 1;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing error path
*/
do {
char abs_path[128];
printf ("Testing error stream\n");
printf ("Clearing error file\n");
strcpy (abs_path, "/tmp/");
if ((unlink (strcat (abs_path, error_path)) == -1) && (errno != ENOENT)) {
fprintf(stderr, "unlink(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
drmaa_set_attribute(jt, DRMAA_WD, "/tmp", NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, "tar", NULL, 0);
set_path_attribute_plus_colon(jt, DRMAA_ERROR_PATH, error_path, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
strcpy (abs_path, "/tmp/");
if (!(fp=fopen(strcat (abs_path, error_path), "r"))) {
fprintf(stderr, "fopen(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
if (fscanf(fp, "%10c", buffer) != 1) {
fprintf(stderr, "wrong output file: %s\n", buffer);
failed_test = 1;
}
buffer[10] = '\0';
if (strcmp("Usage: tar", buffer) != 0) {
fprintf(stderr, "wrong output file: %s\n", buffer);
failed_test = 1;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing join files
*/
do {
/* First submit job to create tar file */
char *tar_path = "test.tar";
char abs_path[128];
printf ("Testing join files\n");
printf ("Running job to prepare data\n");
printf ("Clearing output file\n");
strcpy (abs_path, "/tmp/");
if ((unlink (strcat (abs_path, output_path)) == -1) && (errno != ENOENT)) {
fprintf(stderr, "unlink(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
printf ("Clearing tar file\n");
strcpy (abs_path, "/tmp/");
if ((unlink (strcat (abs_path, tar_path)) == -1) && (errno != ENOENT)) {
fprintf(stderr, "unlink(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "cvf";
job_argv[1] = tar_path;
job_argv[2] = input_path;
job_argv[3] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_WD, "/tmp", NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, "tar", NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
drmaa_delete_job_template(jt, NULL, 0);
jt = NULL;
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
/* submit job to read tar file */
printf ("Running job to read data\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "tvf";
job_argv[1] = "test.tar";
job_argv[2] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_WD, "/tmp", NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, "tar", NULL, 0);
drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "y", NULL, 0);
set_path_attribute_plus_colon(jt, DRMAA_OUTPUT_PATH, output_path, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
strcpy (abs_path, "/tmp/");
if (!(fp=fopen(strcat (abs_path, output_path), "r"))) {
fprintf(stderr, "fopen(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
if (fscanf(fp, "%14c%*[^\n]\n", buffer) != 1) {
fprintf(stderr, "fscanf error\n");
failed_test = 1;
}
buffer[14] = '\0';
if (strcmp("tar: blocksize", buffer) != 0) {
fprintf(stderr, "missing stderr from output file: %s\n", buffer);
failed_test = 1;
}
if (fscanf(fp, "%4c\n", buffer) != 1) {
fprintf(stderr, "fscanf error\n");
failed_test = 1;
}
buffer[4] = '\0';
if (strcmp("-rw-", buffer) != 0) {
fprintf(stderr, "missing stdout from output file: %s\n", buffer);
failed_test = 1;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing job category
*/
do {
printf ("Testing job category\n");
printf ("$SGE_ROOT/$SGE_CELL/common/qtask should contain the following entry:\n");
printf ("test.cat -N ExitTest -h\n");
/* first test that it works */
printf ("Testing job category standalone\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "10";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
drmaa_set_attribute(jt, DRMAA_JOB_CATEGORY, "test.cat", NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
drmaa_delete_job_template(jt, NULL, 0);
jt = NULL;
printf ("Getting job name for job %lu from GDI\n", (unsigned long)atol(jobid));
{
lCondition *where = lWhere("%T(%I==%u)", JB_Type, JB_job_number, (u_long32)atol(jobid));
lEnumeration *what = lWhat("%T (%I %I)", JB_Type, JB_job_number, JB_job_name);
alp = ctx->gdi(ctx, SGE_JB_LIST, SGE_GDI_GET, &job_lp, where, what, false);
job_ep = lFirst(job_lp);
lFreeWhere(&where);
lFreeWhat(&what);
}
{
int tmp_ret = answer_list_print_err_warn(&alp, "GDI Critical", "GDI Error: ", "Message from GDI: ");
if (tmp_ret > 0) {
fprintf (stderr, "problem talking to gdi\n");
failed_test = 1;
continue;
}
}
lFreeList(&alp);
if (job_ep == NULL) {
printf ("No such job number.\n");
failed_test = 1;
}
else if ((job_ep != NULL) && (strcmp (lGetString (job_ep, JB_job_name), "ExitTest") != 0)) {
fprintf(stderr, "Job \"%s\" name was \"%s\" instead of \"ExitTest\"\n",
jobid, lGetString (job_ep, JB_job_name));
failed_test = 1;
}
lFreeList(&job_lp);
printf ("Checking job state\n");
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf (stderr, "Job \"%s\" was not in hold state\n", jobid);
failed_test = 1;
}
printf ("Releasing job\n");
if (drmaa_control(jobid, DRMAA_CONTROL_RELEASE, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
jobid, drmaa_ctrl2str(DRMAA_CONTROL_RELEASE), diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
/* then test that it doesn't override DRMAA attributes */
printf ("Testing job category v/s DRMAA attributes\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "10";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
drmaa_set_attribute(jt, DRMAA_JOB_NAME, "DRMAAExitTest", NULL, 0);
drmaa_set_attribute(jt, DRMAA_JOB_CATEGORY, "test.cat", NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Getting job name for job %lu from GDI\n", (unsigned long)atol(jobid));
{
lCondition *where = lWhere("%T(%I==%u)", JB_Type, JB_job_number, (u_long32)atol(jobid));
lEnumeration *what = lWhat("%T (%I %I)", JB_Type, JB_job_number, JB_job_name);
alp = ctx->gdi(ctx, SGE_JB_LIST, SGE_GDI_GET, &job_lp, where, what, false);
job_ep = lFirst(job_lp);
lFreeWhere(&where);
lFreeWhat(&what);
}
{
int tmp_ret = answer_list_print_err_warn(&alp, "GDI Critical", "GDI Error: ", "Message from GDI: ");
if (tmp_ret > 0) {
fprintf (stderr, "problem talking to gdi\n");
failed_test = 1;
}
}
lFreeList(&alp);
if (job_ep == NULL) {
printf ("No such job number.\n");
failed_test = 1;
}
else if ((job_ep != NULL) && (strcmp (lGetString (job_ep, JB_job_name), "DRMAAExitTest") != 0)) {
fprintf(stderr, "Job \"%s\" name was \"%s\" instead of \"DRMAAExitTest\"\n",
jobid, lGetString (job_ep, JB_job_name));
failed_test = 1;
}
lFreeList(&job_lp);
printf ("Checking job state\n");
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf (stderr, "job \"%s\" was not in hold state\n", jobid);
failed_test = 1;
}
printf ("Releasing job\n");
if (drmaa_control(jobid, DRMAA_CONTROL_RELEASE, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
jobid, drmaa_ctrl2str(DRMAA_CONTROL_RELEASE), diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing native specification
*/
do {
printf ("Testing native specification\n");
/* first test that it works */
printf ("Testing native specification standalone\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "10";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, "-h -N ExitTest", NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
drmaa_delete_job_template(jt, NULL, 0);
jt = NULL;
printf ("Getting job name for job %lu from GDI\n", (unsigned long)atol(jobid));
{
lCondition* where = lWhere("%T(%I==%u)", JB_Type, JB_job_number, (u_long32)atol(jobid));
lEnumeration *what = lWhat("%T (%I %I)", JB_Type, JB_job_number, JB_job_name);
alp = ctx->gdi(ctx, SGE_JB_LIST, SGE_GDI_GET, &job_lp, where, what, false);
job_ep = lFirst(job_lp);
lFreeWhere(&where);
lFreeWhat(&what);
}
{
int tmp_ret = answer_list_print_err_warn(&alp, "GDI Critical", "GDI Error: ", "Message from GDI: ");
if (tmp_ret > 0) {
fprintf (stderr, "problem talking to gdi\n");
failed_test = 1;
continue;
}
}
lFreeList(&alp);
if (job_ep == NULL) {
printf ("No such job number.\n");
failed_test = 1;
}
else if ((job_ep != NULL) && (strcmp (lGetString (job_ep, JB_job_name), "ExitTest") != 0)) {
fprintf(stderr, "Job \"%s\" name was \"%s\" instead of \"ExitTest\"\n",
jobid, lGetString (job_ep, JB_job_name));
failed_test = 1;
}
lFreeList(&job_lp);
printf ("Checking job state\n");
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf (stderr, "Job \"%s\" was not in hold state\n", jobid);
failed_test = 1;
}
printf ("Releasing job\n");
if (drmaa_control(jobid, DRMAA_CONTROL_RELEASE, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
jobid, drmaa_ctrl2str(DRMAA_CONTROL_RELEASE), diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
/* then test that it doesn't override DRMAA attributes */
printf ("Testing native specification v/s DRMAA attributes\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "10";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
drmaa_set_attribute(jt, DRMAA_JOB_NAME, "DRMAAExitTest", NULL, 0);
drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, "-h -N ExitTest", NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Getting job name for job %lu from GDI\n", (unsigned long)atol(jobid));
{
lCondition *where = lWhere ("%T(%I==%u)", JB_Type, JB_job_number, (u_long32)atol(jobid));
lEnumeration *what = lWhat("%T (%I %I)", JB_Type, JB_job_number, JB_job_name);
alp = ctx->gdi(ctx, SGE_JB_LIST, SGE_GDI_GET, &job_lp, where, what, false);
job_ep = lFirst(job_lp);
lFreeWhere(&where);
lFreeWhat(&what);
}
{
int tmp_ret = answer_list_print_err_warn(&alp, "GDI Critical", "GDI Error: ", "Message from GDI: ");
if (tmp_ret > 0) {
fprintf (stderr, "problem talking to gdi\n");
failed_test = 1;
}
}
lFreeList(&alp);
if (job_ep == NULL) {
printf ("No such job number.\n");
failed_test = 1;
}
else if ((job_ep != NULL) && (strcmp (lGetString (job_ep, JB_job_name), "DRMAAExitTest") != 0)) {
fprintf(stderr, "Job \"%s\" name was \"%s\" instead of \"DRMAAExitTest\"\n",
jobid, lGetString (job_ep, JB_job_name));
failed_test = 1;
}
lFreeList(&job_lp);
printf ("Checking job state\n");
if (drmaa_job_ps(jobid, &job_state, diagnosis, sizeof(diagnosis)-1)
!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_job_ps(\"%s\") failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
if (job_state != DRMAA_PS_USER_ON_HOLD && job_state != DRMAA_PS_USER_SYSTEM_ON_HOLD) {
fprintf (stderr, "job \"%s\" was not in hold state\n", jobid);
failed_test = 1;
}
printf ("Releasing job\n");
if (drmaa_control(jobid, DRMAA_CONTROL_RELEASE, diagnosis,
sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(%s, %s) failed: %s\n",
jobid, drmaa_ctrl2str(DRMAA_CONTROL_RELEASE), diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing start time
*/
do {
time_t now, later;
struct tm timenow;
struct tm timelater;
char timestr[32];
int time_diff;
printf ("Testing start time\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "0";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
time (&now);
localtime_r (&now, &timenow);
timenow.tm_min++;
/* This fails at midnight. */
if (timenow.tm_min == 0) {
timenow.tm_hour++;
}
sprintf (timestr, "%.4d/%.2d/%.2d %.2d:%.2d:%.2d", timenow.tm_year + 1900,
timenow.tm_mon + 1, timenow.tm_mday, timenow.tm_hour,
timenow.tm_min, timenow.tm_sec);
printf ("%s\n", timestr);
drmaa_set_attribute(jt, DRMAA_START_TIME, timestr, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
time (&later);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
localtime_r (&now, &timenow);
localtime_r (&later, &timelater);
time_diff = (((timelater.tm_hour * 60) + timelater.tm_min) * 60 + timelater.tm_sec) -
(((timenow.tm_hour * 60) + timenow.tm_min) * 60 + timenow.tm_sec);
/* Allow 10 seconds for scheduling and run time. This test will fail
* if run at midnight. */
if (time_diff > 80) {
printf ("Job took %d seconds longer than expected\n", time_diff - 60);
failed_test = 1;
}
else if (time_diff < 0) {
printf ("Job finished in %d seconds\n",
((timelater.tm_hour * 60) + timelater.tm_min) * 60 + timelater.tm_sec);
failed_test = 1;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing job environment
*/
do {
const char *job_env[2];
char abs_path[128];
printf ("Testing job environment\n");
printf ("Clearing output file\n");
strcpy (abs_path, "/tmp/");
if ((unlink (strcat (abs_path, output_path)) == -1) && (errno != ENOENT)) {
fprintf(stderr, "unlink(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
job_argv[0] = "$YOU_ARE_MY_SUNSHINE";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
job_env[0] = "YOU_ARE_MY_SUNSHINE=MyOnlySunshine";
job_env[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ENV, job_env, NULL, 0);
drmaa_set_attribute(jt, DRMAA_WD, "/tmp", NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, "/usr/bin/echo", NULL, 0);
drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, "-shell y", NULL, 0);
set_path_attribute_plus_colon(jt, DRMAA_OUTPUT_PATH, output_path, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
strcpy (abs_path, "/tmp/");
if (!(fp=fopen(strcat (abs_path, output_path), "r"))) {
fprintf(stderr, "fopen(%s) failed: %s\n", abs_path, strerror(errno));
failed_test = 1;
continue;
}
if (fscanf(fp, "%s", buffer) != 1) {
fprintf(stderr, "fscanf error\n");
failed_test = 1;
}
if (strcmp(buffer, "MyOnlySunshine")) {
fprintf(stderr, "Wrong output file: %s\n", buffer);
failed_test = 1;
}
else if (!failed_test) {
printf ("Test succeeded!\n");
}
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
printf("=====================\n");
/*
* testing email address
*/
do {
const char *email[3];
printf ("Testing email address\n");
printf ("$SGE_ROOT/$SGE_CELL/common/sge_request should contain the following entry:\n");
printf ("-m e\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
email[0] = email_addr;
email[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_EMAIL, email, NULL, 0);
job_argv[0] = "0";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
printf ("Check for email to find out if the test succeeded.\n");
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
failed_test = 0;
/*
* testing email supression
*/
printf("=====================\n");
do {
const char *email[2];
printf ("Testing email supression\n");
printf ("$SGE_ROOT/$SGE_CELL/common/sge_request should contain the following entry:\n");
printf ("-m e\n");
printf ("Getting job template\n");
drmaa_allocate_job_template(&jt, NULL, 0);
if (jt == NULL) {
fprintf(stderr, "drmaa_allocate_job_template() failed\n");
failed_test = 1;
continue;
}
printf ("Filling job template\n");
email[0] = email_addr;
email[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_EMAIL, email, NULL, 0);
job_argv[0] = "0";
job_argv[1] = NULL;
drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
drmaa_set_attribute(jt, DRMAA_BLOCK_EMAIL, "1", NULL, 0);
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
failed_test = 1;
continue;
}
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
failed_test = 1;
continue;
}
printf ("Check for email to find out if the test failed.\n");
} while (do_while_end);
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
if (failed_test) test_failed = 1;
/*
* shutdown session
*/
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
return test_failed;
}
case ST_USAGE_CHECK:
{
char jobid[1024], value[128], new_jobid[1024];
drmaa_attr_values_t *rusage = NULL;
int status;
int size = 0;
if (parse_args)
exit_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
jt = create_exit_job_template(exit_job, 0);
printf ("Running job\n");
while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) {
fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
sleep(1);
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
if (jt != NULL) { drmaa_delete_job_template(jt, NULL, 0); jt = NULL; }
printf ("Waiting for job to complete\n");
do {
drmaa_errno = drmaa_wait(jobid, new_jobid, sizeof(jobid)-1,
&status, DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed - retry: %s\n", jobid, diagnosis);
sleep(1);
}
} while (drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE);
printf("Job with job id %s finished\n", jobid);
if (drmaa_errno == DRMAA_ERRNO_NO_RUSAGE) {
fprintf(stderr, "drmaa_wait(%s) did not return usage information.\n", jobid);
return 1;
} else if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait(%s) failed: %s\n", jobid, diagnosis);
drmaa_release_attr_values(rusage);
return 1;
} else if (rusage == NULL) {
fprintf (stderr, "drmaa_wait(%s) did not return usage information and did not return DRMAA_ERRNO_NO_RUSAGE\n", jobid);
return 1;
}
drmaa_errno = drmaa_get_num_attr_values(rusage, &size);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_num_attr_values() failed: %s\n", drmaa_strerror(drmaa_errno));
drmaa_release_attr_values(rusage);
rusage = NULL;
return 1;
}
while ((drmaa_errno=drmaa_get_next_attr_value(rusage, value, 127))==DRMAA_ERRNO_SUCCESS) {
size--;
printf("%s\n", value);
}
drmaa_release_attr_values(rusage);
rusage = NULL;
if (size != 0) {
fprintf(stderr, "Got incorrect size from drmaa_get_num_attr_values()\n");
return 1;
}
if (drmaa_errno != DRMAA_ERRNO_NO_MORE_ELEMENTS) {
fprintf(stderr, "Got incorrect return value from drmaa_get_next_attr_value()\n");
return 1;
}
break;
}
case ST_TRANSFER_FILES_BULK_JOB:
bBulkJob = true;
case ST_TRANSFER_FILES_SINGLE_JOB:
{
int aborted, stat, remote_ps;
bool bFound=false;
char jobid[100];
char *szPath;
char *szTemp;
char attr_name[DRMAA_ATTR_BUFFER];
drmaa_attr_names_t *vector = NULL;
const char *session_all[] = { DRMAA_JOB_IDS_SESSION_ALL, NULL };
if (parse_args)
sleeper_job = NEXT_ARGV(argc, argv);
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
/* submit a working job from a local directory to the execution host */
drmaa_allocate_job_template(&jt, NULL, 0);
drmaa_errno = drmaa_get_attribute_names(&vector, diagnosis, sizeof(diagnosis)-1);
while((drmaa_errno=drmaa_get_next_attr_name(vector, attr_name,
sizeof(attr_name)-1)) == DRMAA_ERRNO_SUCCESS) {
if( strcmp( attr_name, "drmaa_transfer_files" )==0 ) {
bFound=true;
break;
}
}
/* we don't need vector any longer - free it */
drmaa_release_attr_names(vector);
vector = NULL;
if( !bFound ) {
fprintf( stderr, "DRMAA_TRANSFER_FILES is not supported!\n" );
return 1;
}
drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, sleeper_job, NULL, 0);
szTemp = NEXT_ARGV(argc,argv);
drmaa_set_attribute(jt, DRMAA_TRANSFER_FILES, szTemp, NULL, 0);
szTemp = NEXT_ARGV(argc,argv);
drmaa_set_attribute(jt, DRMAA_JOIN_FILES, szTemp, NULL, 0);
if( !strcmp( (szPath=NEXT_ARGV(argc,argv)), "NULL" )) {
szPath="";
}
drmaa_set_attribute(jt, DRMAA_INPUT_PATH, szPath, NULL, 0);
if( !strcmp( (szPath=NEXT_ARGV(argc,argv)), "NULL" )) {
szPath="";
}
drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH,szPath, NULL, 0);
if( !strcmp( (szPath=NEXT_ARGV(argc,argv)), "NULL" )) {
szPath="";
}
drmaa_set_attribute(jt, DRMAA_ERROR_PATH, szPath, NULL, 0);
if( bBulkJob ) {
drmaa_job_ids_t *jobids;
int j;
if((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, 3, 1,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
printf("failed submitting bulk job (%s): %s\n", drmaa_strerror(drmaa_errno), diagnosis);
return 1;
}
printf("submitted bulk job with jobids:\n");
for (j=0; j<3; j++) {
drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
printf("\t \"%s\"\n", jobid);
}
drmaa_release_job_ids(jobids);
} else {
/* synchronize with job to finish but do not dispose job finish information */
if((drmaa_errno = drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
sizeof(diagnosis)-1)) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
}
drmaa_delete_job_template(jt, NULL, 0);
/* synchronize with job to finish but do not dispose job finish information */
if ((drmaa_errno = drmaa_synchronize(session_all, DRMAA_TIMEOUT_WAIT_FOREVER, 0,
diagnosis, sizeof(diagnosis)-1))!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n", diagnosis);
return 1;
}
printf("synchronized with job finish\n");
/* get job state */
drmaa_errno = drmaa_job_ps(jobid, &remote_ps, diagnosis, sizeof(diagnosis)-1);
if (remote_ps == DRMAA_PS_FAILED) {
fprintf(stderr, "job \"%s\" is not in failed state: %s\n",
jobid, drmaa_state2str(remote_ps));
return 1;
}
/* wait job */
if ((drmaa_errno = drmaa_wait(jobid, NULL, 0, &stat, DRMAA_TIMEOUT_WAIT_FOREVER, NULL,
diagnosis, sizeof(diagnosis)-1)) != DRMAA_ERRNO_SUCCESS) {
printf("drmaa_wait() failed %s: %s\n", drmaa_strerror(drmaa_errno), diagnosis);
return 1;
}
/* job finish information */
drmaa_wifaborted(&aborted, stat, diagnosis, sizeof(diagnosis)-1);
if(!aborted) {
fprintf(stderr,
"job \"%s\" failed but drmaa_wifaborted() returns false\n", jobid);
return 1;
}
printf("waited job \"%s\" that never ran\n", jobid);
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_RESERVATION_FINISH_ORDER:
case ST_BACKFILL_FINISH_ORDER:
{
test_job_t job_spec[3];
if (parse_args) {
sleeper_job = NEXT_ARGV(argc, argv);
job_spec[0].native = NEXT_ARGV(argc, argv);
job_spec[0].time = 10;
job_spec[1].native = NEXT_ARGV(argc, argv);
job_spec[1].time = 10;
job_spec[2].native = NEXT_ARGV(argc, argv);
job_spec[2].time = 10;
}
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (test_dispatch_order_njobs(3, job_spec, test_case==ST_RESERVATION_FINISH_ORDER?"0-1-2":"0,2-1")) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_WILD_PARALLEL:
{
test_job_t job_spec[7];
if (parse_args) {
sleeper_job = NEXT_ARGV(argc, argv);
job_spec[0].native = NEXT_ARGV(argc, argv);
job_spec[0].time = 20;
job_spec[1].native = job_spec[0].native;
job_spec[1].time = 20;
job_spec[2].native = job_spec[0].native;
job_spec[2].time = 20;
job_spec[3].native = job_spec[0].native;
job_spec[3].time = 20;
job_spec[4].native = NEXT_ARGV(argc, argv);
job_spec[4].time = 20;
job_spec[5].native = job_spec[4].native;
job_spec[5].time = 20;
job_spec[6].native = NEXT_ARGV(argc, argv);
job_spec[6].time = 20;
}
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
if (test_dispatch_order_njobs(7, job_spec, "6-4,5-0,1,2,3")) {
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_UNSUPPORTED_ATTR:
case ST_UNSUPPORTED_VATTR:
{
drmaa_job_template_t *jt = NULL;
const char *values[2];
values[0] = "blah";
values[1] = NULL;
if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
/* submit a working job from a local directory to the execution host */
drmaa_allocate_job_template(&jt, NULL, 0);
if (test_case == ST_UNSUPPORTED_ATTR) {
drmaa_errno = drmaa_set_attribute(jt, "blah", "blah", diagnosis, sizeof(diagnosis)-1);
} else {
drmaa_errno = drmaa_set_vector_attribute(jt, "blah", (const char**)values, diagnosis, sizeof(diagnosis)-1);
}
drmaa_delete_job_template(jt, NULL, 0);
jt = NULL;
if (drmaa_errno != DRMAA_ERRNO_INVALID_ARGUMENT) {
fprintf(stderr, "drmaa_set_attribute()/drmaa_set_vector_attribute() allowed invalid attribute\n");
return 1;
}
if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_SYNCHRONIZE_NONEXISTANT:
{
char jobid[1024];
const char *all_jobids[2];
int new_id = 0;
int drmaa_errno = DRMAA_ERRNO_SUCCESS;
if (parse_args) {
sleeper_job = NEXT_ARGV(argc, argv);
}
drmaa_errno = drmaa_init(NULL, diagnosis, sizeof(diagnosis) - 1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
report_session_key();
jt = create_sleeper_job_template(5, 0, 0);
if (jt == NULL) {
fprintf(stderr, "create_sleeper_job_template() failed\n");
return 1;
}
drmaa_errno = drmaa_run_job(jobid, sizeof(jobid) - 1, jt, diagnosis,
sizeof(diagnosis) - 1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
return 1;
}
printf("submitted job \"%s\"\n", jobid);
drmaa_delete_job_template(jt, NULL, 0);
/* Convert job id into a number and add 1. */
new_id = strtol(jobid, NULL, 10) + 1;
printf ("Last job id is %s. Using %d.\n", jobid, new_id);
/* Build job id list. */
sprintf(jobid, "%d", new_id);
all_jobids[0] = jobid;
all_jobids[1] = NULL;
/* Synchronize on the new job id. */
drmaa_errno = drmaa_synchronize(all_jobids, DRMAA_TIMEOUT_WAIT_FOREVER,
0, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "Synchronize on non-existant job id failed\n");
return 1;
}
drmaa_errno = wait_all_jobs(1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
return 1;
}
drmaa_errno = drmaa_exit(diagnosis, sizeof(diagnosis) - 1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
}
break;
case ST_RECOVERABLE_SESSION:
{
char jobid1[DRMAA_JOBNAME_BUFFER + 1];
char jobid2[DRMAA_JOBNAME_BUFFER + 1];
char jobid3[DRMAA_JOBNAME_BUFFER + 1];
char jobid4[DRMAA_JOBNAME_BUFFER + 1];
char buffer[DRMAA_JOBNAME_BUFFER + 1];
char contact[DRMAA_CONTACT_BUFFER + 1];
int drmaa_errno = DRMAA_ERRNO_SUCCESS;
int exit_code = 0;
int stat = 0;
drmaa_job_ids_t *bulk_job_ids = NULL;
drmaa_attr_values_t *rusage = NULL;
if (parse_args) {
sleeper_job = NEXT_ARGV(argc, argv);
}
if (drmaa_init("", diagnosis, DRMAA_ERROR_STRING_BUFFER) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
if (drmaa_get_contact(contact, DRMAA_CONTACT_BUFFER, diagnosis,
DRMAA_ERROR_STRING_BUFFER) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_get_contact() failed: %s\n", diagnosis);
return 1;
}
printf ("Contact string is \"%s\"\n", contact);
/* Run long job. */
jt = create_sleeper_job_template(120, 0, 0);
if (jt == NULL) {
fprintf(stderr, "create_job_template() failed\n");
exit_code = 1;
goto error;
}
drmaa_errno = drmaa_run_job(jobid1, DRMAA_JOBNAME_BUFFER, jt, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s %s\n", diagnosis,
drmaa_strerror(drmaa_errno));
exit_code = 1;
goto error;
}
drmaa_delete_job_template(jt, diagnosis, DRMAA_ERROR_STRING_BUFFER);
/* Run short job. */
jt = create_sleeper_job_template(10, 0, 0);
if (jt == NULL) {
fprintf(stderr, "create_job_template() failed\n");
exit_code = 1;
goto error;
}
drmaa_errno = drmaa_run_job(jobid2, DRMAA_JOBNAME_BUFFER, jt, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s %s\n", diagnosis,
drmaa_strerror(drmaa_errno));
exit_code = 1;
goto error;
}
drmaa_delete_job_template(jt, diagnosis, DRMAA_ERROR_STRING_BUFFER);
/* Run bulk job. */
jt = create_sleeper_job_template(10, 1, 1);
if (jt == NULL) {
fprintf(stderr, "create_job_template() failed\n");
exit_code = 1;
goto error;
}
drmaa_errno = drmaa_run_bulk_jobs(&bulk_job_ids, jt, 1, 2, 1,
diagnosis,
DRMAA_ERROR_STRING_BUFFER);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s %s\n", diagnosis,
drmaa_strerror(drmaa_errno));
exit_code = 1;
goto error;
}
drmaa_delete_job_template(jt, diagnosis, DRMAA_ERROR_STRING_BUFFER);
/* Release one of the bulk jobs */
drmaa_get_next_job_id(bulk_job_ids, jobid3, DRMAA_JOBNAME_BUFFER);
drmaa_get_next_job_id(bulk_job_ids, jobid4, DRMAA_JOBNAME_BUFFER);
drmaa_release_job_ids(bulk_job_ids);
drmaa_errno = drmaa_control(jobid3, DRMAA_CONTROL_RELEASE, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control() failed: %s %s\n", diagnosis,
drmaa_strerror(drmaa_errno));
exit_code = 1;
goto error;
}
/* Stop and restart the session. */
if (drmaa_exit(diagnosis, DRMAA_ERROR_STRING_BUFFER) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
return 1;
}
/* Sleep long enough for the short jobs to finish. */
printf ("Sleeping for 60 seconds\n");
sleep(60);
printf ("Done sleeping\n");
if (drmaa_init(contact, diagnosis, DRMAA_ERROR_STRING_BUFFER) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
return 1;
}
/* Wait for the long job to finish. */
drmaa_errno = drmaa_wait(jobid1, buffer, DRMAA_JOBNAME_BUFFER, &stat,
DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
/* we don't use rusage here - free it! */
drmaa_release_attr_values(rusage);
rusage = NULL;
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_wait() failed: %s\n", diagnosis);
exit_code = 1;
goto error;
}
/* Wait for the short job to finish. */
drmaa_errno = drmaa_wait(jobid2, buffer, DRMAA_JOBNAME_BUFFER, &stat,
DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
/* we don't use rusage here - free it! */
drmaa_release_attr_values(rusage);
rusage = NULL;
if ((drmaa_errno != DRMAA_ERRNO_INVALID_JOB) &&
(drmaa_errno != DRMAA_ERRNO_NO_RUSAGE)) {
fprintf(stderr, "drmaa_wait() did not fail as expected: %s\n",
diagnosis);
exit_code = 1;
goto error;
}
/* Wait for the bulk jobs to finish. */
drmaa_errno = drmaa_wait(jobid3, buffer, DRMAA_JOBNAME_BUFFER, &stat,
DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
/* we don't use rusage here - free it! */
drmaa_release_attr_values(rusage);
rusage = NULL;
/* This one must be found, because another task in this job is still
* held. The only option is to complain about no rusage info. */
if (drmaa_errno != DRMAA_ERRNO_NO_RUSAGE) {
fprintf(stderr, "drmaa_wait() did not fail as expected: %s\n",
diagnosis);
exit_code = 1;
goto error;
}
drmaa_errno = drmaa_wait(jobid4, buffer, DRMAA_JOBNAME_BUFFER, &stat,
DRMAA_TIMEOUT_NO_WAIT, &rusage, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
/* we don't use rusage here - free it! */
drmaa_release_attr_values(rusage);
rusage = NULL;
if (drmaa_errno != DRMAA_ERRNO_EXIT_TIMEOUT) {
fprintf(stderr, "drmaa_wait() did not fail as expected: %s\n",
diagnosis);
exit_code = 1;
goto error;
}
drmaa_errno = drmaa_control(jobid4, DRMAA_CONTROL_TERMINATE, diagnosis,
DRMAA_ERROR_STRING_BUFFER);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control() failed: %s %s\n", diagnosis,
drmaa_strerror(drmaa_errno));
exit_code = 1;
goto error;
}
error:
if (drmaa_exit(diagnosis, DRMAA_ERROR_STRING_BUFFER) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
exit_code = 1;
}
if (exit_code != 0) {
return exit_code;
}
}
break;
default:
break;
}
return 0;
FCLOSE_ERROR:
fprintf(stderr, MSG_FILE_NOCLOSE_SS, input_path, strerror(errno));
return 1;
}
static void *submit_and_wait_thread (void *vp) {
int n;
if (vp != NULL) {
n = *(int *)vp;
}
else {
n = 1;
}
submit_and_wait (n);
return (void *)NULL;
}
static int submit_and_wait(int n)
{
int ret = DRMAA_ERRNO_SUCCESS;
ret = submit_sleeper(n);
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = wait_all_jobs(n);
}
return ret;
}
static void *submit_sleeper_thread (void *vp) {
int n;
if (vp != NULL) {
n = *(int *)vp;
}
else {
n = 1;
}
submit_sleeper(n);
return (void *)NULL;
}
static drmaa_job_template_t *create_exit_job_template(const char *exit_job, int as_bulk_job)
{
const char *job_argv[2];
drmaa_job_template_t *jt = NULL;
int ret = DRMAA_ERRNO_SUCCESS;
ret = drmaa_allocate_job_template(&jt, NULL, 0);
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_WD, DRMAA_PLACEHOLDER_HD, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, exit_job, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
job_argv[0] = "0";
job_argv[1] = NULL;
ret = drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "y", NULL, 0);
}
#if 0
if (!as_bulk_job) {
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":"DRMAA_PLACEHOLDER_HD"/DRMAA_JOB.$JOB_ID", NULL, 0);
}
else {
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":"DRMAA_PLACEHOLDER_HD"/DRMAA_JOB.$JOB_ID."DRMAA_PLACEHOLDER_INCR, NULL, 0);
}
#else
if (ret == DRMAA_ERRNO_SUCCESS) {
/* no output please */
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":/dev/null", NULL, 0);
}
#endif
if (ret == DRMAA_ERRNO_SUCCESS) {
return jt;
} else {
drmaa_delete_job_template(jt, NULL, 0);
return NULL;
}
}
static drmaa_job_template_t *create_sleeper_job_template(int seconds, int as_bulk_job, int in_hold)
{
const char *job_argv[2];
drmaa_job_template_t *jt = NULL;
char buffer[100];
int ret = DRMAA_ERRNO_SUCCESS;
ret = drmaa_allocate_job_template(&jt, NULL, 0);
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_WD, DRMAA_PLACEHOLDER_HD, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, sleeper_job, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
sprintf(buffer, "%d", seconds);
job_argv[0] = buffer;
job_argv[1] = NULL;
ret = drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "y", NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
#if 0
if (!as_bulk_job) {
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":"DRMAA_PLACEHOLDER_HD"/DRMAA_JOB.$JOB_ID", NULL, 0);
}
else {
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":"DRMAA_PLACEHOLDER_HD"/DRMAA_JOB.$JOB_ID."DRMAA_PLACEHOLDER_INCR, NULL, 0);
}
#else
/* no output please */
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":/dev/null", NULL, 0);
#endif
}
if (ret == DRMAA_ERRNO_SUCCESS) {
if (in_hold) {
ret = drmaa_set_attribute(jt, DRMAA_JS_STATE, DRMAA_SUBMISSION_STATE_HOLD, NULL, 0);
}
}
if (ret == DRMAA_ERRNO_SUCCESS) {
return jt;
} else {
drmaa_delete_job_template(jt, NULL, 0);
return NULL;
}
}
static int submit_sleeper(int n)
{
drmaa_job_template_t *jt;
int ret = DRMAA_ERRNO_SUCCESS;
jt = create_sleeper_job_template(10, 0, 0);
if (jt != NULL) {
ret = do_submit(jt, n);
/* We don't care about the error code from this one. It doesn't affect
* anything. */
drmaa_delete_job_template(jt, NULL, 0);
jt = NULL;
}
return ret;
}
static int submit_input_mirror(int n, const char *mirror_job,
const char *input_path, const char *output_path,
const char *error_path, int join, char* hostname)
{
drmaa_job_template_t *jt = NULL;
char buffer[10000];
int ret = DRMAA_ERRNO_SUCCESS;
ret = drmaa_allocate_job_template(&jt, NULL, 0);
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_WD, DRMAA_PLACEHOLDER_HD, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, mirror_job, NULL, 0);
}
/*
* we use the local host for the cat job, because when job is running
* on other hosts there my be NFS problems when reading the input_path file
*/
if (ret == DRMAA_ERRNO_SUCCESS && hostname != NULL) {
snprintf(buffer, 10000, "-l h=%s", hostname);
ret = drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, buffer, NULL, 0);
}
if (ret == DRMAA_ERRNO_SUCCESS) {
if (join) {
ret = drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "y", NULL, 0);
}
else {
ret = drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "n", NULL, 0);
}
}
if (ret == DRMAA_ERRNO_SUCCESS) {
if (input_path) {
strcpy(buffer, ":");
strcat(buffer, input_path);
ret = drmaa_set_attribute(jt, DRMAA_INPUT_PATH, buffer, NULL, 0);
}
}
if (ret == DRMAA_ERRNO_SUCCESS) {
if (output_path) {
strcpy(buffer, ":");
strcat(buffer, output_path);
ret = drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, buffer, NULL, 0);
}
}
if (ret == DRMAA_ERRNO_SUCCESS) {
if (error_path) {
strcpy(buffer, ":");
strcat(buffer, error_path);
ret = drmaa_set_attribute(jt, DRMAA_ERROR_PATH, buffer, NULL, 0);
}
}
if (ret == DRMAA_ERRNO_SUCCESS) {
ret = do_submit(jt, n);
/* We don't care about the error code here because it doesn't affect
* anything. */
drmaa_delete_job_template(jt, NULL, 0);
}
return ret;
}
static int do_submit(drmaa_job_template_t *jt, int n)
{
int i;
char diagnosis[1024];
char jobid[100];
int drmaa_errno = DRMAA_ERRNO_SUCCESS;
int error = DRMAA_ERRNO_SUCCESS;
bool done;
for (i=0; i<n; i++) {
/* submit job */
done = false;
while (!done) {
drmaa_errno = drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis, sizeof(diagnosis)-1);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
printf("failed submitting job (%s)\n", drmaa_strerror(drmaa_errno));
}
/* Only retry on "try again" error. */
if (drmaa_errno == DRMAA_ERRNO_TRY_LATER) {
printf("retry: %s\n", diagnosis);
sleep(1);
} else {
done = true;
break; /* while */
}
}
if (drmaa_errno == DRMAA_ERRNO_SUCCESS) {
printf("submitted job \"%s\"\n", jobid);
} else {
printf("unable to submit job\n");
}
if (((test_case == MT_EXIT_DURING_SUBMIT_OR_WAIT) ||
(test_case == MT_EXIT_DURING_SUBMIT)) &&
(drmaa_errno == DRMAA_ERRNO_NO_ACTIVE_SESSION)) {
/* It's supposed to do that. */
drmaa_errno = DRMAA_ERRNO_SUCCESS;
}
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
/* If there is ever an error, we will return an error. */
error = drmaa_errno;
}
}
return error;
}
static int wait_all_jobs(int n)
{
char jobid[100];
int drmaa_errno = DRMAA_ERRNO_SUCCESS;
int stat;
drmaa_attr_values_t *rusage = NULL;
do {
drmaa_errno = drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY, jobid, sizeof(jobid)-1, &stat, DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, NULL, 0);
/* we don't use rusage here - free it! */
drmaa_release_attr_values(rusage);
rusage = NULL;
if (drmaa_errno == DRMAA_ERRNO_SUCCESS) {
printf("waited job \"%s\"\n", jobid);
if (n != -1) {
if (--n == 0) {
printf("waited for last job\n");
break;
}
}
} else if (drmaa_errno != DRMAA_ERRNO_INVALID_JOB) {
printf("drmaa_wait() returned %s\n", drmaa_strerror(drmaa_errno));
}
} while (drmaa_errno == DRMAA_ERRNO_SUCCESS);
/* that means we got all */
if (drmaa_errno == DRMAA_ERRNO_INVALID_JOB) {
printf("no more jobs to wait\n");
drmaa_errno = DRMAA_ERRNO_SUCCESS;
}
else if (((drmaa_errno == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE) &&
(test_case == MT_EXIT_DURING_SUBMIT_OR_WAIT)) ||
((drmaa_errno == DRMAA_ERRNO_NO_RUSAGE) &&
(test_case == ST_SUBMIT_NO_RUN_WAIT))) {
/* It's supposed to do that. */
drmaa_errno = DRMAA_ERRNO_SUCCESS;
}
return drmaa_errno;
}
static int wait_n_jobs(int n)
{
char jobid[100];
int i, stat;
int drmaa_errno = DRMAA_ERRNO_SUCCESS;
int error = DRMAA_ERRNO_SUCCESS;
bool done;
for (i=0; i<n; i++) {
done = false;
while (!done) {
drmaa_errno = drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY, jobid,
sizeof(jobid)-1, &stat,
DRMAA_TIMEOUT_WAIT_FOREVER, NULL, NULL, 0);
if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
printf("failed waiting for job (%s)\n", drmaa_strerror(drmaa_errno));
}
/* Only retry on "try again" error. */
if (drmaa_errno == DRMAA_ERRNO_TRY_LATER) {
printf("retry...\n");
sleep(1);
} else {
done = true;
break;
}
}
if (drmaa_errno == DRMAA_ERRNO_SUCCESS) {
printf("waited job \"%s\"\n", jobid);
} else {
/* If there is ever an error, we will return an error. */
error = drmaa_errno;
}
}
return error;
}
static void report_session_key(void)
{
if (is_sun_grid_engine) {
const char *session_key = getenv("SGE_SESSION_KEY");
if (session_key)
printf("got \"%s\" as session key\n", session_key);
else
printf("no session key set\n");
}
}
#if 0
static init_signal_handling()
{
struct sigaction nact;
nact.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, NULL);
}
#endif
const struct drmaa_errno_descr_s {
char *descr;
int drmaa_errno;
} errno_vector[] = {
{ "DRMAA_ERRNO_SUCCESS", DRMAA_ERRNO_SUCCESS },
{ "DRMAA_ERRNO_INTERNAL_ERROR", DRMAA_ERRNO_INTERNAL_ERROR },
{ "DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE", DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE },
{ "DRMAA_ERRNO_AUTH_FAILURE", DRMAA_ERRNO_AUTH_FAILURE },
{ "DRMAA_ERRNO_INVALID_ARGUMENT", DRMAA_ERRNO_INVALID_ARGUMENT },
{ "DRMAA_ERRNO_NO_ACTIVE_SESSION", DRMAA_ERRNO_NO_ACTIVE_SESSION },
{ "DRMAA_ERRNO_NO_MEMORY", DRMAA_ERRNO_NO_MEMORY },
{ "DRMAA_ERRNO_INVALID_CONTACT_STRING", DRMAA_ERRNO_INVALID_CONTACT_STRING },
{ "DRMAA_ERRNO_DEFAULT_CONTACT_STRING_ERROR", DRMAA_ERRNO_DEFAULT_CONTACT_STRING_ERROR },
{ "DRMAA_ERRNO_DRMS_INIT_FAILED", DRMAA_ERRNO_DRMS_INIT_FAILED },
{ "DRMAA_ERRNO_ALREADY_ACTIVE_SESSION", DRMAA_ERRNO_ALREADY_ACTIVE_SESSION },
{ "DRMAA_ERRNO_DRMS_EXIT_ERROR", DRMAA_ERRNO_DRMS_EXIT_ERROR },
{ "DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT", DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT },
{ "DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE", DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE },
{ "DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES", DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES },
{ "DRMAA_ERRNO_TRY_LATER", DRMAA_ERRNO_TRY_LATER },
{ "DRMAA_ERRNO_DENIED_BY_DRM", DRMAA_ERRNO_DENIED_BY_DRM },
{ "DRMAA_ERRNO_INVALID_JOB", DRMAA_ERRNO_INVALID_JOB },
{ "DRMAA_ERRNO_RESUME_INCONSISTENT_STATE", DRMAA_ERRNO_RESUME_INCONSISTENT_STATE },
{ "DRMAA_ERRNO_SUSPEND_INCONSISTENT_STATE", DRMAA_ERRNO_SUSPEND_INCONSISTENT_STATE },
{ "DRMAA_ERRNO_HOLD_INCONSISTENT_STATE", DRMAA_ERRNO_HOLD_INCONSISTENT_STATE },
{ "DRMAA_ERRNO_RELEASE_INCONSISTENT_STATE", DRMAA_ERRNO_RELEASE_INCONSISTENT_STATE },
{ "DRMAA_ERRNO_EXIT_TIMEOUT", DRMAA_ERRNO_EXIT_TIMEOUT },
{ "DRMAA_ERRNO_NO_RUSAGE", DRMAA_ERRNO_NO_RUSAGE },
{ NULL, 0 }
};
/****** test_drmaa/str2drmaa_errno() ********************************************
* NAME
* str2drmaa_errno() -- Map string into DRMAA errno constant
*
* SYNOPSIS
* static int str2drmaa_errno(const char *str)
*
* FUNCTION
* Map string into DRMAA errno constant.
*
* INPUTS
* const char *str - ???
*
* RESULT
* static int - DRMAA_ERRNO_* constant or -1 on failre
*******************************************************************************/
static int str2drmaa_errno(const char *str)
{
int i;
for (i=0; errno_vector[i].descr != NULL; i++)
if (!strcmp(errno_vector[i].descr, str))
return errno_vector[i].drmaa_errno;
return -1;
}
/****** test_drmaa/drmaa_errno2str() *******************************************
* NAME
* drmaa_errno2str() -- Map DRMAA errno constant into string
*
* SYNOPSIS
* static const char* drmaa_errno2str(int drmaa_errno)
*
* FUNCTION
* Map DRMAA errno constant into string
*
* INPUTS
* int drmaa_errno - Any DRMAA errno
*
* RESULT
* static const char* - String representation
*******************************************************************************/
static const char *drmaa_errno2str(int drmaa_errno)
{
int i;
for (i=0; errno_vector[i].descr != NULL; i++)
if (errno_vector[i].drmaa_errno == drmaa_errno)
return errno_vector[i].descr;
return "DRMAA_ERRNO_???UNKNOWN???";
}
const struct ctrl_descr_s {
char *descr;
int ctrl;
} ctrl_vector[] = {
{ "DRMAA_CONTROL_SUSPEND", DRMAA_CONTROL_SUSPEND },
{ "DRMAA_CONTROL_RESUME", DRMAA_CONTROL_RESUME },
{ "DRMAA_CONTROL_HOLD", DRMAA_CONTROL_HOLD },
{ "DRMAA_CONTROL_RELEASE", DRMAA_CONTROL_RELEASE },
{ "DRMAA_CONTROL_TERMINATE", DRMAA_CONTROL_TERMINATE },
{ NULL, 0 }
};
/****** test_drmaa/drmaa_ctrl2str() ********************************************
* NAME
* drmaa_ctrl2str() -- Map DRMAA control constant into string
*
* SYNOPSIS
* static const char* drmaa_ctrl2str(int ctrl)
*
* FUNCTION
* Map DRMAA control constant into string
*
* INPUTS
* int ctrl - Any DRMAA_CONTROL_* value
*
* RESULT
* static const char* - DRMAA constant name or "unknown" string
*
*******************************************************************************/
static const char *drmaa_ctrl2str(int ctrl)
{
int i;
for (i=0; ctrl_vector[i].descr != NULL; i++)
if (ctrl_vector[i].ctrl == ctrl)
return ctrl_vector[i].descr;
return "DRMAA_CONTROL_???UNKNOWN???";
}
/****** test_drmaa/str2drmaa_ctrl() ********************************************
* NAME
* str2drmaa_ctrl() -- Map string into DRMAA control constant
*
* SYNOPSIS
* static int str2drmaa_ctrl(const char *str)
*
* FUNCTION
* Map string into DRMAA control constant.
*
* INPUTS
* const char *str - ???
*
* RESULT
* static int - DRMAA_CONTROL_* constant or -1 on failure
*******************************************************************************/
static int str2drmaa_ctrl(const char *str)
{
int i;
for (i=0; ctrl_vector[i].descr != NULL; i++) {
if (!strcmp(ctrl_vector[i].descr, str))
return ctrl_vector[i].ctrl;
}
return -1;
}
const struct state_descr_s {
char *descr;
int state;
} state_vector[] = {
{ "DRMAA_PS_UNDETERMINED", DRMAA_PS_UNDETERMINED },
{ "DRMAA_PS_QUEUED_ACTIVE", DRMAA_PS_QUEUED_ACTIVE },
{ "DRMAA_PS_SYSTEM_ON_HOLD", DRMAA_PS_SYSTEM_ON_HOLD },
{ "DRMAA_PS_USER_ON_HOLD ", DRMAA_PS_USER_ON_HOLD },
{ "DRMAA_PS_USER_SYSTEM_ON_HOLD", DRMAA_PS_USER_SYSTEM_ON_HOLD },
{ "DRMAA_PS_RUNNING", DRMAA_PS_RUNNING },
{ "DRMAA_PS_SYSTEM_SUSPENDED", DRMAA_PS_SYSTEM_SUSPENDED },
{ "DRMAA_PS_USER_SUSPENDED", DRMAA_PS_USER_SUSPENDED },
{ "DRMAA_PS_USER_SYSTEM_SUSPENDED", DRMAA_PS_USER_SYSTEM_SUSPENDED },
{ "DRMAA_PS_DONE", DRMAA_PS_DONE },
{ "DRMAA_PS_FAILED", DRMAA_PS_FAILED },
{ NULL, 0 }
};
/****** test_drmaa/drmaa_state2str() *******************************************
* NAME
* drmaa_state2str() -- Map DRMAA state constant into string
*
* SYNOPSIS
* static const char* drmaa_state2str(int state)
*
* FUNCTION
* Map DRMAA state constant into string
*
* INPUTS
* int state - Any DRMAA_PS_* value.
*
* RESULT
* static const char* -
*******************************************************************************/
static const char *drmaa_state2str(int state)
{
int i;
for (i=0; state_vector[i].descr != NULL; i++)
if (state_vector[i].state == state)
return state_vector[i].descr;
return "DRMAA_PS_???UNKNOWN???";
}
/****** test_drmaa/str2drmaa_state() *******************************************
* NAME
* str2drmaa_state() -- Map string into DRMAA state constant
*
* SYNOPSIS
* int str2drmaa_state(const char *str)
*
* FUNCTION
* Map string into DRMAA state constant.
*
* INPUTS
* const char *str -
*
* RESULT
* static int -
*******************************************************************************/
int str2drmaa_state(const char *str)
{
int i;
for (i=0; state_vector[i].descr != NULL; i++)
if (!strcmp(state_vector[i].descr, str))
return state_vector[i].state;
return -1;
}
/****** test_drmaa/report_wrong_job_finish() ***********************************
* NAME
* report_wrong_job_finish() -- Report how job finished
*
* SYNOPSIS
* static void report_wrong_job_finish(const char *comment, const char
* *jobid, int stat)
*
* FUNCTION
* Report how job finished based on the stat value returned by drmaa_wait().
* The information is printed to stderr.
*
* INPUTS
* const char *comment - provided by the caller
* const char *jobid - provided by the caller
* int stat - stat value as returned by drmaa_wait()
*******************************************************************************/
static void report_wrong_job_finish(const char *comment, const char *jobid, int stat)
{
int aborted, exited, exit_status, signaled;
drmaa_wifaborted(&aborted, stat, NULL, 0);
if (aborted)
fprintf(stderr, "%s: job \"%s\" never ran\n", comment, jobid);
else {
drmaa_wifexited(&exited, stat, NULL, 0);
if (exited) {
drmaa_wexitstatus(&exit_status, stat, NULL, 0);
fprintf(stderr, "%s: job \"%s\" finished regularly with exit status %d\n",
comment, jobid, exit_status);
} else {
drmaa_wifsignaled(&signaled, stat, NULL, 0);
if (signaled) {
char termsig[DRMAA_SIGNAL_BUFFER+1];
drmaa_wtermsig(termsig, DRMAA_SIGNAL_BUFFER, stat, NULL, 0);
fprintf(stderr, "%s: job \"%s\" finished due to signal %s\n",
comment, jobid, termsig);
} else
fprintf(stderr, "%s: job \"%s\" finished with unclear conditions\n",
comment, jobid);
}
}
}
static bool extract_array_command(char *command_line, int *start, int *end, int *incr)
{
bool ret = false;
char *t_option = NULL;
char *start_value = NULL;
char *end_value = NULL;
char *incr_value = NULL;
char *end_t_option = NULL;
*start = 1;
*end = 1;
*incr = 1;
t_option = strstr(command_line, "-t");
if (t_option != NULL) {
ret = true;
start_value = t_option + 3;
*start = atoi(start_value);
if (*start <= 0) {
goto error;
}
end_t_option = strstr(start_value, " ");
end_value = strstr(start_value, "-");
incr_value = strstr(start_value, ":");
if ((end_value != NULL) && (end_value < end_t_option)) {
*end = atoi(end_value+1);
if (*end <= 0) {
goto error;
}
if ((incr_value != NULL) && (incr_value < end_t_option)) {
*incr = atoi(incr_value+1);
if (*incr <= 0) {
*incr = 1;
}
}
}
else {
goto error;
}
if (end_t_option != NULL) {
strcpy(t_option, end_t_option+1);
}
else {
t_option = '\0';
}
}/* end if */
return ret;
error:
if (end_t_option != NULL) {
strcpy(t_option, end_t_option);
}
else {
t_option = '\0';
}
*start = 1;
*end = 1;
*incr = 1;
ret = false;
fprintf(stderr, "could not parse \"%s\" for -t option\n", command_line);
if (end_t_option != NULL) {
strcpy(t_option, end_t_option);
}
else {
t_option = '\0';
}
return ret;
}
static void free_order(int **order)
{
int i = 0;
while (order[i] != NULL) {
sge_free(&(order[i]));
i++;
}
sge_free(&order);
}
static int test_dispatch_order_njobs(int njobs, test_job_t job[], char *jsr_str)
{
char diagnosis[DRMAA_ERROR_STRING_BUFFER];
const char *all_jobids[10];
char jobid[100];
drmaa_job_template_t *jt;
int drmaa_errno, i, pos = 0;
int stat;
int **order = job_run_sequence_parse(jsr_str);
int nwait = njobs;
if (order == NULL) {
fprintf(stderr, "failed parsing job run sequence string\n");
return -1;
}
init_jobids(all_jobids, njobs);
/* submit jobs in hold */
for (i = 0; i < njobs; i++) {
int start = 0;
int end = 0;
int incr = 1;
bool bulk_job = false;
bulk_job = extract_array_command(job[i].native, &start, &end, &incr);
jt = create_sleeper_job_template(job[i].time, 0, 1);
drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, job[i].native, NULL, 0);
if (bulk_job) {
int counter = 0;
drmaa_job_ids_t *bulkJobId;
if (drmaa_run_bulk_jobs(&bulkJobId, jt, start, end, incr,
diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_order(order);
drmaa_delete_job_template(jt, NULL, 0);
return -1;
}
while (drmaa_get_next_job_id(bulkJobId, jobid, sizeof(jobid)-1) == DRMAA_ERRNO_SUCCESS) {
all_jobids[pos++] = strdup(jobid);
printf("submitted job \"%s\"\n", jobid);
counter++;
}
array_job_run_sequence_adapt(order,i,counter);
drmaa_release_job_ids(bulkJobId);
} else {
if (drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
free_order(order);
free_jobids(all_jobids, njobs);
drmaa_delete_job_template(jt, NULL, 0);
return -1;
}
printf("submitted job \"%s\"\n", jobid);
all_jobids[pos++] = strdup(jobid);
}
drmaa_delete_job_template(jt, NULL, 0);
}
all_jobids[pos] = NULL;
nwait = pos;
njobs = pos;
/* release all three jobs in one operation to ensure they get runnable at once for scheduler */
if (drmaa_control(DRMAA_JOB_IDS_SESSION_ALL, DRMAA_CONTROL_RELEASE, diagnosis, sizeof(diagnosis)-1)!=DRMAA_ERRNO_SUCCESS) {
fprintf(stderr, "drmaa_control(DRMAA_JOB_IDS_SESSION_ALL, DRMAA_CONTROL_RELEASE) failed: %s\n", diagnosis);
free_order(order);
free_jobids(all_jobids, njobs);
return -1;
}
do {
drmaa_errno = drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY, jobid, sizeof(jobid)-1, &stat,
DRMAA_TIMEOUT_WAIT_FOREVER, NULL, NULL, 0);
if (drmaa_errno == DRMAA_ERRNO_SUCCESS) {
printf("waited job \"%s\"\n", jobid);
/* map jobid to job index */
pos = -1;
for (i = 0; i < njobs; i++) {
if (all_jobids[i] != NULL && strcmp(jobid, all_jobids[i]) == 0) {
pos = i;
break;
}
}
if (pos == -1) {
fprintf(stderr, "drmaa_wait() returned unexpected job: %s\n", jobid);
free_jobids(all_jobids, njobs);
free_order(order);
return -1;
}
if (job_run_sequence_verify(pos, all_jobids, order)) {
free_jobids(all_jobids, njobs);
free_order(order);
return -1;
}
/* NULL-ify finished ones */
sge_free(&(all_jobids[pos]));
if (--nwait == 0) {
printf("waited for last job\n");
break;
}
} else if (drmaa_errno != DRMAA_ERRNO_INVALID_JOB) {
printf("drmaa_wait() returned %s\n", drmaa_strerror(drmaa_errno));
}
} while (drmaa_errno == DRMAA_ERRNO_SUCCESS);
free_jobids(all_jobids, njobs);
free_order(order);
return 0;
}
static int job_run_sequence_verify(int pos, const char *all_jobids[], int *order[])
{
int test_index, i, j;
int found_group = 0;
int *group;
/* search the group this job belongs to */
for (i=0; order[i]; i++) {
group = order[i];
for (j=0; group[j] != -1; j++) {
if (group[j] == pos) {
found_group = 1;
break;
}
}
if (found_group)
break;
}
if (!found_group) {
fprintf(stderr, "test broken: could not find job index %d in finish order scheme\n", pos);
return -1;
}
/* complain about previous group job that did not finish earlier */
while (i>0) {
i--;
for (j=0; order[i][j] != -1; j++) {
test_index = order[i][j];
if (all_jobids[test_index] != NULL) {
fprintf(stderr, "order broken: job \"%s\" [%d] did not finish before job \"%s\" [%d]\n",
all_jobids[test_index], test_index, all_jobids[pos], pos);
return -1;
}
}
}
return 0;
}
/****** test_drmaa/job_run_sequence_parse() ************************************
* NAME
* job_run_sequence_parse() -- ???
*
* SYNOPSIS
* static int** job_run_sequence_parse(char *jrs_str)
*
* FUNCTION
* Parse job run sequence strings into order data structures.
*
* INPUTS
* char *jrs_str - ???
*
* RESULT
* static int** -
*
* EXAMPLE
* For exmples the strings "0-1-2", "0,2-1" and "0,1-2-3" are parsed
* into data structures like the following ones:
*
* int rr0[] = { 0, -1 };
* int rr1[] = { 1, -1 };
* int rr2[] = { 2, -1 };
* int *rr_order[] = { rr0, rr1, rr2, NULL };
*
* int bf0[] = { 0, 2, -1 };
* int bf1[] = { 1, -1 };
* int *bf_order[] = { bf0, bf1, NULL };
*
* int st0[] = { 0, 1, -1 };
* int st1[] = { 2, -1 };
* int st2[] = { 3, -1 };
* int *st_order[] = { st0, st1, st2, NULL };
*******************************************************************************/
#define GROUP_CHUNK 5
#define NUMBER_CHUNK 10
static int **job_run_sequence_parse(char *jrs_str)
{
char *s = NULL, *group_str = NULL;
/* control outer loop */
char *jrs_str_cp = strdup(jrs_str);
char *iter_dash = NULL;
int **sequence = NULL;
int groups_total = GROUP_CHUNK;
int groups_used = 0;
int i = 0;
printf("parsing sequence: \"%s\"\n", jrs_str_cp);
sequence = malloc(sizeof(int *)*(GROUP_CHUNK+1));
/* groups are delimited by dashes '-' */
for (group_str=strtok_r(jrs_str_cp, "-", &iter_dash); group_str; group_str=strtok_r(NULL, "-", &iter_dash)) {
char *iter_comma = NULL;
int *group;
int numbers_total;
int numbers_used;
int j = 0;
if (++groups_used > groups_total) {
groups_total += GROUP_CHUNK;
sequence = sge_realloc(sequence, groups_total + 1, 1);
}
numbers_total = NUMBER_CHUNK;
numbers_used = 0;
group = malloc(sizeof(int *)*(NUMBER_CHUNK+1));
/* sequence numbers within a group are delimited by comma ',' */
for (s=strtok_r(group_str, ",", &iter_comma); s; s=strtok_r(NULL, ",", &iter_comma)) {
if (++numbers_used > numbers_total) {
numbers_total += NUMBER_CHUNK;
group = sge_realloc(group, numbers_total + 1, 1);
}
printf("%s ", s);
group[j] = atoi(s);
j++;
}
printf("\n");
group[j] = -1;
sequence[i] = group;
i++;
}
sequence[i] = NULL;
sge_free(&jrs_str_cp);
return sequence;
}
static void array_job_run_sequence_adapt(int **sequence, int job_id, int count)
{
int x = 0;
int y = 0;
if (count <= 1) {
return;
}
printf("modify finish order:\n");
while (sequence[x] != NULL) {
y = 0;
while (sequence[x][y] != -1) {
if (sequence[x][y] == job_id) {
int dy = 0;
printf("%d ", sequence[x][y]);
while (sequence[x][y] != -1) {
y++;
}
for (; dy < (count-1); dy++) {
sequence[x][y+dy] = job_id + dy + 1;
sequence[x][y+dy+1] = -1;
printf("[%d] ", sequence[x][y+dy]);
}
y += dy - 1;
}
else if (sequence[x][y] > job_id) {
sequence[x][y] += (count-1);
printf("(%d) ", sequence[x][y]);
}
else {
printf("%d ", sequence[x][y]);
}
y++;
}
printf("\n");
x++;
}
}
static int set_path_attribute_plus_colon(drmaa_job_template_t *jt,
const char *name, const char *value,
char *error_diagnosis,
size_t error_diag_len)
{
char path_buffer[10000];
strcpy(path_buffer, ":");
strcat(path_buffer, value);
return drmaa_set_attribute(jt, name, path_buffer, error_diagnosis,
error_diag_len);
}
static bool test_error_code(char *name, int code, int expected)
{
if (code != expected) {
fprintf(stderr, "%s = %d; should be %d\n", name, code, expected);
return false;
}
else {
return true;
}
}
|