示例#1
0
static void
handle_smoothtime(CMD_Request *rx_message, CMD_Reply *tx_message)
{
  struct timeval now;
  int option;

  if (!SMT_IsEnabled()) {
    tx_message->status = htons(STT_NOTENABLED);
    return;
  }

  option = ntohl(rx_message->data.smoothtime.option);
  SCH_GetLastEventTime(&now, NULL, NULL);

  switch (option) {
    case REQ_SMOOTHTIME_RESET:
      SMT_Reset(&now);
      break;
    case REQ_SMOOTHTIME_ACTIVATE:
      SMT_Activate(&now);
      break;
    default:
      tx_message->status = htons(STT_INVALID);
      break;
  }
}
示例#2
0
文件: smooth.c 项目: mlichvar/chrony
void
test_unit(void)
{
  int i, j;
  struct timespec ts;
  double offset, freq, wander;
  char conf[] = "smoothtime 300 0.01";

  CNF_Initialise(0, 0);
  CNF_ParseLine(NULL, 1, conf);

  LCL_Initialise();
  SMT_Initialise();
  locked = 0;

  for (i = 0; i < 500; i++) {
    UTI_ZeroTimespec(&ts);
    SMT_Reset(&ts);

    DEBUG_LOG("iteration %d", i);

    offset = (random() % 1000000 - 500000) / 1.0e6;
    freq = (random() % 1000000 - 500000) / 1.0e9;
    update_smoothing(&ts, offset, freq);

    for (j = 0; j < 10000; j++) {
      update_smoothing(&ts, 0.0, 0.0);
      UTI_AddDoubleToTimespec(&ts, 16.0, &ts);
      get_smoothing(&ts, &offset, &freq, &wander);
    }

    TEST_CHECK(fabs(offset) < 1e-12);
    TEST_CHECK(fabs(freq) < 1e-12);
    TEST_CHECK(fabs(wander) < 1e-12);
  }

  SMT_Finalise();
  LCL_Finalise();
  CNF_Finalise();
}