Пример #1
0
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
static void
test_foreach_stat_fails_if_callback_function_is_NULL() {
  assert_true( init_stat() );

  expect_assert_failure( foreach_stat( NULL, NULL ) );

  assert_true( finalize_stat() );
}
Пример #3
0
static void
test_foreach_stat_succeeds_without_entries() {
  assert_true( init_stat() );

  foreach_stat( mock_callback, NULL );

  assert_true( finalize_stat() );
}
Пример #4
0
static void
test_increment_stat_fails_if_key_is_NULL() {
  assert_true( init_stat() );

  expect_assert_failure( increment_stat( NULL ) );

  assert_true( finalize_stat() );
}
Пример #5
0
static void
test_init_stat_reinitializes_if_already_initialized() {
  assert_true( init_stat() );
  assert_true( init_stat() );
  assert_true( stats != NULL );

  assert_true( finalize_stat() );
}
Пример #6
0
static void
test_dump_stats_succeeds_without_entries() {
  assert_true( init_stat() );

  expect_string( mock_info, message, "Statistics:" );
  expect_string( mock_info, message, "No statistics found." );
  dump_stats();

  assert_true( finalize_stat() );
}
Пример #7
0
static void
test_add_stat_entry_fails_with_duplicated_key() {
  assert_true( init_stat() );

  const char *key = "key";
  assert_true( add_stat_entry( key ) );
  assert_false( add_stat_entry( key ) );

  assert_true( finalize_stat() );
}
Пример #8
0
static void
test_dump_stats_succeeds() {
  assert_true( init_stat() );

  const char *key = "key";
  increment_stat( key );

  expect_string( mock_info, message, "Statistics:" );
  expect_string( mock_info, message, "key: 1" );
  dump_stats();

  assert_true( finalize_stat() );
}
Пример #9
0
static void
test_add_stat_entry_succeeds() {
  assert_true( init_stat() );

  const char *key = "key";
  assert_true( add_stat_entry( key ) );
  stat_entry *entry = lookup_hash_entry( stats, key );
  assert_string_equal( entry->key, key );
  uint64_t expected_value = 0;
  assert_memory_equal( &entry->value, &expected_value, sizeof( uint64_t ) );

  assert_true( finalize_stat() );
}
Пример #10
0
static void
test_increment_stat_succeeds_with_undefined_key() {
  assert_true( init_stat() );

  const char *key = "key";
  increment_stat( key );

  stat_entry *entry = lookup_hash_entry( stats, key );
  assert_string_equal( entry->key, key );
  uint64_t expected_value = 1;
  assert_memory_equal( &entry->value, &expected_value, sizeof( uint64_t ) );

  assert_true( finalize_stat() );
}
Пример #11
0
Файл: stat.c Проект: nhst/trema
/**
 * Primiary routine which initializes a Statistics holding database/table (of hash_table type).
 * @param None
 * @return bool Always returns True
 */
bool
init_stat() {
  debug( "Initializing statistics collector." );

  if ( stats != NULL ) {
    warn( "Statistics collector is already initialized. Reinitializing." );
    finalize_stat();
  }

  pthread_mutex_lock( &stats_table_mutex );
  create_stats_table();
  pthread_mutex_unlock( &stats_table_mutex );

  return true;
}
Пример #12
0
static void
test_reset_stats_succeeds_without_entries() {
  assert_true( init_stat() );

  reset_stats();

  hash_iterator iter;
  hash_entry *e = NULL;
  init_hash_iterator( stats, &iter );
  int n_entries = 0;
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    n_entries++;
  }
  assert_int_equal( n_entries, 0 );

  assert_true( finalize_stat() );
}
Пример #13
0
static void
test_reset_stats_succeeds_with_single_entry() {
  assert_true( init_stat() );

  const char *key = "key";
  increment_stat( key );

  reset_stats();

  hash_iterator iter;
  hash_entry *e = NULL;
  init_hash_iterator( stats, &iter );
  int n_entries = 0;
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    n_entries++;
  }
  assert_int_equal( n_entries, 0 );

  assert_true( finalize_stat() );
}
Пример #14
0
static void
test_foreach_stat_succeeds() {
  assert_true( init_stat() );

  const char *keys[] = { "key0", "key1" };
  increment_stat( keys[ 0 ] );
  increment_stat( keys[ 1 ] );
  increment_stat( keys[ 1 ] );

  void *user_data = ( void * ) ( intptr_t ) 0x1;

  expect_string( mock_callback, key, keys[ 1 ] );
  expect_value( mock_callback, value, 2 );
  expect_value( mock_callback, user_data, user_data );

  expect_string( mock_callback, key, keys[ 0 ] );
  expect_value( mock_callback, value, 1 );
  expect_value( mock_callback, user_data, user_data );

  foreach_stat( mock_callback, user_data );

  assert_true( finalize_stat() );
}
Пример #15
0
static void
test_init_stat_succeeds() {
  assert_true( init_stat() );
  assert_true( stats != NULL );
  assert_true( finalize_stat() );
}
Пример #16
0
static void
test_finalize_stat_fails_if_not_initialized() {
  expect_assert_failure( finalize_stat() );
}