コード例 #1
0
ファイル: chibach.c プロジェクト: aigamo/trema
static void
finalize_chibach() {
  die_unless_initialized();

  debug( "Terminating chibach..." );

  maybe_finalize_openflow_switch_interface();

  finalize_messenger();
  finalize_stat();
  finalize_timer();
  chibach_started = false;
  unlink_pid( get_chibach_pid(), get_chibach_name() );

  unset_chibach_home();
  unset_chibach_tmp();

  xfree( chibach_name );
  chibach_name = NULL;

  xfree( chibach_log );
  chibach_log = NULL;

  initialized = false;
}
コード例 #2
0
ファイル: timer_test.c プロジェクト: TakumiKomada/trema
static void
test_delete_timer_event() {
  init_timer();

  will_return_count( mock_clock_gettime, 0, -1 );

  char user_data_1[] = "1";
  char user_data_2[] = "2";

  struct itimerspec interval;
  interval.it_value.tv_sec = 1;
  interval.it_value.tv_nsec = 0;
  interval.it_interval.tv_sec = 1;
  interval.it_interval.tv_nsec = 0;
  assert_true( add_timer_event_callback( &interval, mock_timer_event_callback, user_data_1 ) );
  interval.it_value.tv_sec = 2;
  interval.it_interval.tv_sec = 2;
  assert_true( add_timer_event_callback( &interval, mock_timer_event_callback, user_data_2 ) );

  delete_timer_event( mock_timer_event_callback, user_data_1 );

  timer_callback_info *callback = find_timer_callback( mock_timer_event_callback );
  assert_true( callback != NULL );
  assert_true( callback->user_data == user_data_2 );

  delete_timer_event( mock_timer_event_callback, user_data_2 );
  assert_true( find_timer_callback( mock_timer_event_callback ) == NULL );

  finalize_timer();
}
コード例 #3
0
ファイル: timer_test.c プロジェクト: TakumiKomada/trema
static void
test_timer_event_callback() {
  init_timer();

  will_return_count( mock_clock_gettime, 0, -1 );

  char user_data[] = "It's time!!!";
  struct itimerspec interval;
  interval.it_value.tv_sec = 1;
  interval.it_value.tv_nsec = 1000;
  interval.it_interval.tv_sec = 2;
  interval.it_interval.tv_nsec = 2000;
  assert_true( add_timer_event_callback( &interval, mock_timer_event_callback, user_data ) );

  timer_callback_info *callback = find_timer_callback( mock_timer_event_callback );
  assert_true( callback != NULL );
  assert_true( callback->function == mock_timer_event_callback );
  assert_string_equal( callback->user_data, "It's time!!!" );
  assert_int_equal( callback->interval.tv_sec, 2 );
  assert_int_equal( callback->interval.tv_nsec, 2000 );

  delete_timer_event( mock_timer_event_callback, user_data );
  assert_true( find_timer_callback( mock_timer_event_callback ) == NULL );

  finalize_timer();
}
コード例 #4
0
ファイル: timer_test.c プロジェクト: TakumiKomada/trema
static void
test_clock_gettime_fail_einval() {
  init_timer();

  char user_data[] = "It's time!!!";
  will_return_count( mock_clock_gettime, -1, -1 );
  assert_false( add_periodic_event_callback( 1, mock_timer_event_callback, user_data ) );

  finalize_timer();
}
コード例 #5
0
ファイル: timer_test.c プロジェクト: TakumiKomada/trema
static void
test_add_timer_event_callback_fail_with_invalid_timespec() {
  init_timer();

  will_return_count( mock_clock_gettime, 0, -1 );

  char user_data[] = "It's time!!!";
  struct itimerspec interval;
  interval.it_value.tv_sec = 0;
  interval.it_value.tv_nsec = 0;
  interval.it_interval.tv_sec = 0;
  interval.it_interval.tv_nsec = 0;
  assert_false( add_timer_event_callback( &interval, mock_timer_event_callback, user_data ) );

  finalize_timer();
}
コード例 #6
0
ファイル: timer_test.c プロジェクト: TakumiKomada/trema
static void
test_periodic_event_callback() {
  init_timer();

  char user_data[] = "It's time!!!";
  will_return_count( mock_clock_gettime, 0, -1 );
  assert_true( add_periodic_event_callback( 1, mock_timer_event_callback, user_data ) );

  timer_callback_info *callback = find_timer_callback( mock_timer_event_callback );
  assert_true( callback != NULL );
  assert_true( callback->function == mock_timer_event_callback );
  assert_string_equal( callback->user_data, "It's time!!!" );
  assert_int_equal( callback->interval.tv_sec, 1 );
  assert_int_equal( callback->interval.tv_nsec, 0 );

  delete_timer_event( mock_timer_event_callback, user_data );
  assert_true( find_timer_callback( mock_timer_event_callback ) == NULL );

  finalize_timer();
}