Example #1
0
Test(control_cmds, test_reset_stats)
{
  StatsCounterItem *counter = NULL;
  const gchar *response;

  stats_init();

  stats_lock();
  StatsClusterKey sc_key;
  stats_cluster_logpipe_key_set(&sc_key, SCS_CENTER, "id", "received" );
  stats_register_counter(0, &sc_key, SC_TYPE_PROCESSED, &counter);
  stats_counter_set(counter, 666);
  stats_unlock();

  _run_command("RESET_STATS", &response);
  cr_assert(first_line_eq(response, "OK The statistics of syslog-ng have been reset to 0."), "Bad reply");

  _run_command("STATS", &response);
  cr_assert_str_eq(response,
                   "SourceName;SourceId;SourceInstance;State;Type;Number\ncenter;id;received;a;processed;0\n.\n",
                   "Bad reply");
  stats_destroy();
}
// check for new user input
bool
Menu::check_input(void)
{
	if (_port == NULL) {
		// default to main serial port
		_port = hal.console;
	}

    _allocate_buffers();

    if (_check_for_input()) {
        return _run_command(true);
    }    

    return false;
}
Example #3
0
Test(control_cmds, test_stats)
{
  StatsCounterItem *counter = NULL;
  gchar **stats_result;
  const gchar *response;

  stats_init();

  stats_lock();
  StatsClusterKey sc_key;
  stats_cluster_logpipe_key_set(&sc_key, SCS_CENTER, "id", "received" );
  stats_register_counter(0, &sc_key, SC_TYPE_PROCESSED, &counter);
  stats_unlock();

  _run_command("STATS", &response);

  stats_result = g_strsplit(response, "\n", 2);
  cr_assert_str_eq(stats_result[0], "SourceName;SourceId;SourceInstance;State;Type;Number",
                   "Bad reply");
  g_strfreev(stats_result);
  stats_destroy();
}
// run the menu
void
Menu::run(void)
{
	if (_port == NULL) {
		// default to main serial port
		_port = hal.console;
	}

    _allocate_buffers();

    _display_prompt();

    // loop performing commands
    for (;;) {

        // run the pre-prompt function, if one is defined
        if (_ppfunc) {
            if (!_ppfunc())
                return;
            _display_prompt();
        }

        // loop reading characters from the input
        _input_len = 0;

        for (;; ) {
            if (_check_for_input()) {
                break;
            }
            hal.scheduler->delay(20);
        }

        // we have a full command to run
        if (_run_command(false)) break;

        _display_prompt();
    }    
}
Example #5
0
Test(control_cmds, test_log)
{
  const gchar *response;

  _run_command("LOG", &response);
  cr_assert(first_line_eq(response, "Invalid arguments received, expected at least one argument"),
            "Bad reply: [%s]", response);

  _run_command("LOG fakelog", &response);
  cr_assert(first_line_eq(response, "FAIL Invalid arguments received"),
            "Bad reply: [%s]", response);

  verbose_flag = 0;
  debug_flag = 1;
  trace_flag = 1;
  _run_command("LOG VERBOSE", &response);
  cr_assert(first_line_eq(response, "OK VERBOSE=0"),
            "Bad reply: [%s]", response);

  _run_command("LOG VERBOSE ON", &response);
  cr_assert(first_line_eq(response, "OK VERBOSE=1"),
            "Bad reply: [%s]", response);
  cr_assert_eq(verbose_flag, 1, "Flag isn't changed");

  _run_command("LOG VERBOSE OFF", &response);
  cr_assert(first_line_eq(response, "OK VERBOSE=0"),
            "Bad reply: [%s]", response);
  cr_assert_eq(verbose_flag, 0, "Flag isn't changed");


  debug_flag = 0;
  verbose_flag = 1;
  trace_flag = 1;
  _run_command("LOG DEBUG", &response);
  cr_assert(first_line_eq(response, "OK DEBUG=0"),
            "Bad reply: [%s]", response);

  _run_command("LOG DEBUG ON", &response);
  cr_assert(first_line_eq(response, "OK DEBUG=1"),
            "Bad reply: [%s]", response);
  cr_assert_eq(debug_flag, 1, "Flag isn't changed");

  _run_command("LOG DEBUG OFF", &response);
  cr_assert(first_line_eq(response, "OK DEBUG=0"),
            "Bad reply: [%s]", response);
  cr_assert_eq(debug_flag, 0, "Flag isn't changed");

  debug_flag = 1;
  verbose_flag = 1;
  trace_flag = 0;
  _run_command("LOG TRACE", &response);
  cr_assert(first_line_eq(response, "OK TRACE=0"),
            "Bad reply: [%s]", response);

  _run_command("LOG TRACE ON", &response);
  cr_assert(first_line_eq(response, "OK TRACE=1"),
            "Bad reply: [%s]", response);
  cr_assert_eq(trace_flag, 1, "Flag isn't changed");

  _run_command("LOG TRACE OFF", &response);
  cr_assert(first_line_eq(response, "OK TRACE=0"),
            "Bad reply: [%s]", response);
  cr_assert_eq(trace_flag, 0, "Flag isn't changed");

}