diff options
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index b9f0fb538..c35500c35 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -784,6 +784,87 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
784 | case SP_START_DONE: | 784 | case SP_START_DONE: |
785 | GNUNET_break (0); | 785 | GNUNET_break (0); |
786 | break; | 786 | break; |
787 | case SP_SERVICE_START: | ||
788 | /* confirm gnunet-arm exited */ | ||
789 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
790 | { | ||
791 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
792 | 0) | ||
793 | { | ||
794 | cb = d->cb; | ||
795 | d->cb = NULL; | ||
796 | if (NULL != cb) | ||
797 | cb (d->cb_cls, | ||
798 | NULL, | ||
799 | d->cfg, | ||
800 | d, | ||
801 | (NULL == d->hostname) | ||
802 | ? _("`gnunet-arm' does not seem to terminate.\n") | ||
803 | : _("`ssh' does not seem to terminate.\n")); | ||
804 | return; | ||
805 | } | ||
806 | /* wait some more */ | ||
807 | d->task | ||
808 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
809 | &start_fsm, d); | ||
810 | return; | ||
811 | } | ||
812 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
813 | { | ||
814 | cb = d->cb; | ||
815 | d->cb = NULL; | ||
816 | if (NULL != cb) | ||
817 | cb (d->cb_cls, | ||
818 | NULL, | ||
819 | d->cfg, | ||
820 | d, | ||
821 | (NULL == d->hostname) | ||
822 | ? _("`gnunet-arm' does not seem to terminate.\n") | ||
823 | : _("`ssh' does not seem to terminate.\n")); | ||
824 | return; | ||
825 | } | ||
826 | #if DEBUG_TESTING | ||
827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n"); | ||
828 | #endif | ||
829 | cb = d->cb; | ||
830 | d->cb = NULL; | ||
831 | d->phase = SP_START_DONE; | ||
832 | if (NULL != cb) | ||
833 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); | ||
834 | break; | ||
835 | case SP_SERVICE_SHUTDOWN_START: | ||
836 | /* confirm copying complete */ | ||
837 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | ||
838 | { | ||
839 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == | ||
840 | 0) | ||
841 | { | ||
842 | if (NULL != d->dead_cb) | ||
843 | d->dead_cb (d->dead_cb_cls, | ||
844 | _ | ||
845 | ("either `gnunet-arm' or `ssh' does not seem to terminate.\n")); | ||
846 | return; | ||
847 | } | ||
848 | /* wait some more */ | ||
849 | d->task | ||
850 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, | ||
851 | &start_fsm, d); | ||
852 | return; | ||
853 | } | ||
854 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) | ||
855 | { | ||
856 | if (NULL != d->dead_cb) | ||
857 | d->dead_cb (d->dead_cb_cls, | ||
858 | _ | ||
859 | ("shutdown (either `gnunet-arm' or `ssh') did not complete cleanly.\n")); | ||
860 | return; | ||
861 | } | ||
862 | #if DEBUG_TESTING | ||
863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); | ||
864 | #endif | ||
865 | if (NULL != d->dead_cb) | ||
866 | d->dead_cb (d->dead_cb_cls, NULL); | ||
867 | break; | ||
787 | case SP_SHUTDOWN_START: | 868 | case SP_SHUTDOWN_START: |
788 | /* confirm copying complete */ | 869 | /* confirm copying complete */ |
789 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) | 870 | if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) |
@@ -958,6 +1039,94 @@ GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon) | |||
958 | 1039 | ||
959 | 1040 | ||
960 | /** | 1041 | /** |
1042 | * Stops a GNUnet daemon. | ||
1043 | * | ||
1044 | * @param d the daemon for which the service should be started | ||
1045 | * @param service the name of the service to start | ||
1046 | * @param timeout how long to wait for process for shutdown to complete | ||
1047 | * @param cb function called once the daemon was stopped | ||
1048 | * @param cb_cls closure for cb | ||
1049 | */ | ||
1050 | void | ||
1051 | GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, | ||
1052 | char *service, | ||
1053 | struct GNUNET_TIME_Relative timeout, | ||
1054 | GNUNET_TESTING_NotifyDaemonRunning cb, void *cb_cls) | ||
1055 | { | ||
1056 | char *arg; | ||
1057 | d->cb = cb; | ||
1058 | d->cb_cls = cb_cls; | ||
1059 | |||
1060 | GNUNET_assert(d->running == GNUNET_YES); | ||
1061 | |||
1062 | if (d->phase == SP_CONFIG_UPDATE) | ||
1063 | { | ||
1064 | GNUNET_SCHEDULER_cancel (d->task); | ||
1065 | d->phase = SP_START_DONE; | ||
1066 | } | ||
1067 | |||
1068 | #if DEBUG_TESTING | ||
1069 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1070 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); | ||
1071 | #endif | ||
1072 | if (d->churned_services == NULL) | ||
1073 | { | ||
1074 | d->dead_cb(d->dead_cb_cls, "No service has been churned off yet!!"); | ||
1075 | return; | ||
1076 | } | ||
1077 | d->phase = SP_SERVICE_START; | ||
1078 | GNUNET_free(d->churned_services); | ||
1079 | |||
1080 | /* Check if this is a local or remote process */ | ||
1081 | if (NULL != d->hostname) | ||
1082 | { | ||
1083 | #if DEBUG_TESTING | ||
1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1085 | "Starting gnunet-arm with config `%s' on host `%s'.\n", | ||
1086 | d->cfgfile, d->hostname); | ||
1087 | #endif | ||
1088 | |||
1089 | if (d->username != NULL) | ||
1090 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | ||
1091 | else | ||
1092 | arg = GNUNET_strdup (d->hostname); | ||
1093 | |||
1094 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | ||
1095 | #if !DEBUG_TESTING | ||
1096 | "-q", | ||
1097 | #endif | ||
1098 | arg, "gnunet-arm", | ||
1099 | #if DEBUG_TESTING | ||
1100 | "-L", "DEBUG", | ||
1101 | #endif | ||
1102 | "-c", d->cfgfile, "-i", service, "-q", | ||
1103 | NULL); | ||
1104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1105 | "Starting gnunet-arm with command ssh %s gnunet-arm -c %s -i %s -q\n", | ||
1106 | arg, "gnunet-arm", d->cfgfile, service); | ||
1107 | GNUNET_free (arg); | ||
1108 | } | ||
1109 | else | ||
1110 | { | ||
1111 | #if DEBUG_TESTING | ||
1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1113 | "Starting gnunet-arm with config `%s' locally.\n", | ||
1114 | d->cfgfile); | ||
1115 | #endif | ||
1116 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | ||
1117 | "gnunet-arm", | ||
1118 | #if DEBUG_TESTING | ||
1119 | "-L", "DEBUG", | ||
1120 | #endif | ||
1121 | "-c", d->cfgfile, "-i", service, "-q", | ||
1122 | NULL); | ||
1123 | } | ||
1124 | |||
1125 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
1126 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | ||
1127 | } | ||
1128 | |||
1129 | /** | ||
961 | * Start a peer that has previously been stopped using the daemon_stop | 1130 | * Start a peer that has previously been stopped using the daemon_stop |
962 | * call (and files weren't deleted and the allow restart flag) | 1131 | * call (and files weren't deleted and the allow restart flag) |
963 | * | 1132 | * |
@@ -1333,6 +1502,99 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
1333 | * Stops a GNUnet daemon. | 1502 | * Stops a GNUnet daemon. |
1334 | * | 1503 | * |
1335 | * @param d the daemon that should be stopped | 1504 | * @param d the daemon that should be stopped |
1505 | * @param service the name of the service to stop | ||
1506 | * @param timeout how long to wait for process for shutdown to complete | ||
1507 | * @param cb function called once the daemon was stopped | ||
1508 | * @param cb_cls closure for cb | ||
1509 | * @param delete_files GNUNET_YES to remove files, GNUNET_NO | ||
1510 | * to leave them | ||
1511 | * @param allow_restart GNUNET_YES to restart peer later (using this API) | ||
1512 | * GNUNET_NO to kill off and clean up for good | ||
1513 | */ | ||
1514 | void | ||
1515 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, | ||
1516 | char *service, | ||
1517 | struct GNUNET_TIME_Relative timeout, | ||
1518 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) | ||
1519 | { | ||
1520 | char *arg; | ||
1521 | d->dead_cb = cb; | ||
1522 | d->dead_cb_cls = cb_cls; | ||
1523 | |||
1524 | GNUNET_assert(d->running == GNUNET_YES); | ||
1525 | |||
1526 | if (d->phase == SP_CONFIG_UPDATE) | ||
1527 | { | ||
1528 | GNUNET_SCHEDULER_cancel (d->task); | ||
1529 | d->phase = SP_START_DONE; | ||
1530 | } | ||
1531 | |||
1532 | #if DEBUG_TESTING | ||
1533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1534 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); | ||
1535 | #endif | ||
1536 | if (d->churned_services != NULL) | ||
1537 | { | ||
1538 | d->dead_cb(d->dead_cb_cls, "A service has already been turned off!!"); | ||
1539 | return; | ||
1540 | } | ||
1541 | d->phase = SP_SERVICE_SHUTDOWN_START; | ||
1542 | d->churned_services = GNUNET_strdup(service); | ||
1543 | |||
1544 | /* Check if this is a local or remote process */ | ||
1545 | if (NULL != d->hostname) | ||
1546 | { | ||
1547 | #if DEBUG_TESTING | ||
1548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1549 | "Stopping gnunet-arm with config `%s' on host `%s'.\n", | ||
1550 | d->cfgfile, d->hostname); | ||
1551 | #endif | ||
1552 | |||
1553 | if (d->username != NULL) | ||
1554 | GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); | ||
1555 | else | ||
1556 | arg = GNUNET_strdup (d->hostname); | ||
1557 | |||
1558 | d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", | ||
1559 | #if !DEBUG_TESTING | ||
1560 | "-q", | ||
1561 | #endif | ||
1562 | arg, "gnunet-arm", | ||
1563 | #if DEBUG_TESTING | ||
1564 | "-L", "DEBUG", | ||
1565 | #endif | ||
1566 | "-c", d->cfgfile, "-k", service, "-q", | ||
1567 | NULL); | ||
1568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1569 | "Stopping gnunet-arm with command ssh %s gnunet-arm -c %s -k %s -q\n", | ||
1570 | arg, "gnunet-arm", d->cfgfile, service); | ||
1571 | GNUNET_free (arg); | ||
1572 | } | ||
1573 | else | ||
1574 | { | ||
1575 | #if DEBUG_TESTING | ||
1576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1577 | "Stopping gnunet-arm with config `%s' locally.\n", | ||
1578 | d->cfgfile); | ||
1579 | #endif | ||
1580 | d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", | ||
1581 | "gnunet-arm", | ||
1582 | #if DEBUG_TESTING | ||
1583 | "-L", "DEBUG", | ||
1584 | #endif | ||
1585 | "-c", d->cfgfile, "-k", service, "-q", | ||
1586 | NULL); | ||
1587 | } | ||
1588 | |||
1589 | d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
1590 | d->task = GNUNET_SCHEDULER_add_now (&start_fsm, d); | ||
1591 | } | ||
1592 | |||
1593 | |||
1594 | /** | ||
1595 | * Stops a GNUnet daemon. | ||
1596 | * | ||
1597 | * @param d the daemon that should be stopped | ||
1336 | * @param timeout how long to wait for process for shutdown to complete | 1598 | * @param timeout how long to wait for process for shutdown to complete |
1337 | * @param cb function called once the daemon was stopped | 1599 | * @param cb function called once the daemon was stopped |
1338 | * @param cb_cls closure for cb | 1600 | * @param cb_cls closure for cb |