/**
 * Main point of test execution
 */
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct TestingContext *test_ctx;
  char *emsg;
  struct GNUNET_PeerIdentity id;
  struct GNUNET_TESTING_SharedService ss[] = {
    {"peerinfo", cfg, 2},
    {NULL, NULL, 0}
  };
  struct GNUNET_TESTING_Peer *peer;
  unsigned int cnt;

  test_ctx = GNUNET_new (struct TestingContext);
  test_ctx->system =
      GNUNET_TESTING_system_create ("test-gnunet-testing",
                                    "127.0.0.1", NULL, ss);
  emsg = NULL;
  if (NULL == test_ctx->system)
    goto end;
  test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg);
  for (cnt = 0; cnt < NUM_PEERS; cnt++)
  {
    peer = GNUNET_TESTING_peer_configure (test_ctx->system,
                                          test_ctx->cfg,
                                          0, &id, &emsg);
    if (NULL == peer)
    {
      if (NULL != emsg)
        printf ("Test failed upon error: %s", emsg);
      goto end;
    }
    if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
    {
      GNUNET_TESTING_peer_destroy (peer);
      goto end;
    }
    test_ctx->peers[cnt] = peer;
  }
  status = GNUNET_OK;
  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
                                &do_shutdown, test_ctx);
  return;

 end:
  GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx);
  GNUNET_free_non_null (emsg);
}
예제 #2
0
/**
 * shutdown the given peer
 * @param tth testing handle
 * @param p the peer
 */
void
GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
                                    struct PeerContext *p)
{
  GNUNET_assert (p != NULL);
  if (p->ghh != NULL)
  {
    GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
    p->ghh = NULL;
  }
  if (p->th != NULL)
  {
    GNUNET_TRANSPORT_disconnect (p->th);
    p->th = NULL;
  }

  if (p->peer != NULL)
  {
    if (GNUNET_OK != GNUNET_TESTING_peer_stop (p->peer))
    {
      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
                       "Testing lib failed to stop peer %u (`%s') \n", p->no,
                       GNUNET_i2s (&p->id));
    }
    GNUNET_TESTING_peer_destroy (p->peer);
    p->peer = NULL;
  }

  if (p->hello != NULL)
  {
    GNUNET_free (p->hello);
    p->hello = NULL;
  }
  if (p->cfg != NULL)
  {
    GNUNET_CONFIGURATION_destroy (p->cfg);
    p->cfg = NULL;
  }
  GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p);
  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
                   "Peer %u (`%s') stopped \n", p->no,
                   GNUNET_i2s (&p->id));
  GNUNET_free (p);
}
예제 #3
0
/**
 * Function to destroy a peer
 *
 * @param peer the peer structure to destroy
 */
void
GST_destroy_peer (struct Peer *peer)
{
  GNUNET_break (0 == peer->reference_cnt);
  if (GNUNET_YES == peer->is_remote)
  {
    peer_list_remove (peer);
    GNUNET_free (peer);
    return;
  }
  if (GNUNET_YES == peer->details.local.is_running)
  {
    GNUNET_TESTING_peer_stop (peer->details.local.peer);
    peer->details.local.is_running = GNUNET_NO;
  }
  GNUNET_TESTING_peer_destroy (peer->details.local.peer);
  GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
  peer_list_remove (peer);
  GNUNET_free (peer);
}
/**
 * Task for shutdown
 *
 * @param cls the testing context
 * @param tc the tast context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct TestingContext *test_ctx = cls;
  struct GNUNET_TESTING_Peer *peer;
  unsigned int cnt;

  GNUNET_assert (NULL != test_ctx);
  for (cnt = 0; cnt < NUM_PEERS; cnt++)
  {
    peer = test_ctx->peers[cnt];
    if (NULL == peer)
      continue;
    (void) GNUNET_TESTING_peer_stop (peer);
    GNUNET_TESTING_peer_destroy (peer);
  }
  if (NULL != test_ctx->cfg)
    GNUNET_CONFIGURATION_destroy (test_ctx->cfg);
  if (NULL != test_ctx->system)
    GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES);
  GNUNET_free (test_ctx);
}