/* This test outputs TAP syntax: http://testanything.org/ */
int
main (int argc, char *argv[])
{
  long start_tv_sec, start_tv_usec;
  long end_tv_sec, end_tv_usec;
  int i;
  DBusMessage *method;
  DBusConnection *conn;
  DBusError error;

  /* Time each iteration and make sure it doesn't take more than 5 seconds
     to complete.  Outside influences may cause connections to take longer
     but if it does and we are stuck in a poll call then we know the 
     stuck in poll bug has come back to haunt us */

  printf ("# Testing stuck in poll\n");

  dbus_error_init (&error);

  conn = dbus_bus_get (DBUS_BUS_SESSION, &error);

  /* run 100 times to make sure */
  for (i = 0; i < 100; i++)
    {
      long delta;
      
      _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec);
      _run_iteration (conn);
      _dbus_get_monotonic_time (&end_tv_sec, &end_tv_usec);

      /* we just care about seconds */
      delta = end_tv_sec - start_tv_sec;
      printf ("ok %d - %lis\n", i + 1, delta);
      if (delta >= 5)
        {
	  printf ("Bail out! Looks like we might have been be stuck in poll ***\n");
	  exit (1);
	}
    }
 
  method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
                                         "/org/freedesktop/TestSuite",
                                         "org.freedesktop.TestSuite",
                                         "Exit");
  dbus_connection_send (conn, method, NULL);
  dbus_message_unref (method);

  printf ("# Testing completed\n1..%d\n", i);
  exit (0);
}
Ejemplo n.º 2
0
/* This test outputs TAP syntax: http://testanything.org/ */
int
main (int argc, char *argv[])
{
    long start_tv_sec, start_tv_usec;
    long end_tv_sec, end_tv_usec;
    int i;
    DBusMessage *method;
    DBusConnection *conn;
    DBusError error;

    printf ("# Testing pending call timeouts\n");

    dbus_error_init (&error);

    conn = dbus_bus_get (DBUS_BUS_SESSION, &error);

    /* run 100 times to make sure */
    for (i = 0; i < 100; i++)
    {
        long delta;

        _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec);
        _run_iteration (conn);
        _dbus_get_monotonic_time (&end_tv_sec, &end_tv_usec);

        /* we just care about seconds */
        delta = end_tv_sec - start_tv_sec;
        printf ("ok %d - %lis\n", i + 1, delta);
    }

    method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
                                           "/org/freedesktop/TestSuite",
                                           "org.freedesktop.TestSuite",
                                           "Exit");
    dbus_connection_send (conn, method, NULL);
    dbus_message_unref (method);

    printf ("# Testing completed\n1..%d\n", i);
    exit (0);
}
Ejemplo n.º 3
0
static TimeoutCallback*
timeout_callback_new (DBusTimeout         *timeout)
{
  TimeoutCallback *cb;

  cb = dbus_new (TimeoutCallback, 1);
  if (cb == NULL)
    return NULL;

  cb->timeout = timeout;
  _dbus_get_monotonic_time (&cb->last_tv_sec,
                            &cb->last_tv_usec);
  return cb;
}
Ejemplo n.º 4
0
static void
bus_expirelist_expire (BusExpireList *list)
{
  int next_interval;

  next_interval = -1;

  if (list->items != NULL)
    {
      long tv_sec, tv_usec;

      _dbus_get_monotonic_time (&tv_sec, &tv_usec);

      next_interval = do_expiration_with_monotonic_time (list, tv_sec, tv_usec);
    }

  bus_expire_timeout_set_interval (list->timeout, next_interval);
}
Ejemplo n.º 5
0
dbus_bool_t
bus_expire_list_test (const DBusString *test_data_dir)
{
  DBusLoop *loop;
  BusExpireList *list;
  long tv_sec, tv_usec;
  long tv_sec_not_expired, tv_usec_not_expired;
  long tv_sec_expired, tv_usec_expired;
  long tv_sec_past, tv_usec_past;
  TestExpireItem *item;
  int next_interval;
  dbus_bool_t result = FALSE;


  loop = _dbus_loop_new ();
  _dbus_assert (loop != NULL);

#define EXPIRE_AFTER 100
  
  list = bus_expire_list_new (loop, EXPIRE_AFTER,
                              test_expire_func, NULL);
  _dbus_assert (list != NULL);

  _dbus_get_monotonic_time (&tv_sec, &tv_usec);

  tv_sec_not_expired = tv_sec;
  tv_usec_not_expired = tv_usec;
  time_add_milliseconds (&tv_sec_not_expired,
                         &tv_usec_not_expired, EXPIRE_AFTER - 1);

  tv_sec_expired = tv_sec;
  tv_usec_expired = tv_usec;
  time_add_milliseconds (&tv_sec_expired,
                         &tv_usec_expired, EXPIRE_AFTER);
  

  tv_sec_past = tv_sec - 1;
  tv_usec_past = tv_usec;

  item = dbus_new0 (TestExpireItem, 1);

  if (item == NULL)
    goto oom;

  item->item.added_tv_sec = tv_sec;
  item->item.added_tv_usec = tv_usec;
  if (!bus_expire_list_add (list, &item->item))
    _dbus_assert_not_reached ("out of memory");

  next_interval =
    do_expiration_with_monotonic_time (list, tv_sec_not_expired,
                                       tv_usec_not_expired);
  _dbus_assert (item->expire_count == 0);
  _dbus_verbose ("next_interval = %d\n", next_interval);
  _dbus_assert (next_interval == 1);
  
  next_interval =
    do_expiration_with_monotonic_time (list, tv_sec_expired,
                                       tv_usec_expired);
  _dbus_assert (item->expire_count == 1);
  _dbus_verbose ("next_interval = %d\n", next_interval);
  _dbus_assert (next_interval == -1);

  next_interval =
    do_expiration_with_monotonic_time (list, tv_sec_past,
                                       tv_usec_past);
  _dbus_assert (item->expire_count == 1);
  _dbus_verbose ("next_interval = %d\n", next_interval);
  _dbus_assert (next_interval == 1000 + EXPIRE_AFTER);

  bus_expire_list_remove (list, &item->item);
  dbus_free (item);
  
  bus_expire_list_free (list);
  _dbus_loop_unref (loop);
  
  result = TRUE;

 oom:
  return result;
}