2017-12-19 15:49:05 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2012-09-04 12:54:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <rte_common.h>
|
|
|
|
#include <rte_alarm.h>
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
2022-01-26 05:10:40 +00:00
|
|
|
#ifndef RTE_EXEC_ENV_WINDOWS
|
2012-09-04 12:54:00 +00:00
|
|
|
static volatile int flag;
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_alarm_callback(void *cb_arg)
|
|
|
|
{
|
|
|
|
flag = 1;
|
|
|
|
printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
|
|
|
|
}
|
2022-01-26 05:10:40 +00:00
|
|
|
#endif
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2014-08-18 11:29:23 +00:00
|
|
|
static int
|
2012-09-04 12:54:00 +00:00
|
|
|
test_alarm(void)
|
|
|
|
{
|
2019-03-06 16:22:40 +00:00
|
|
|
#ifdef RTE_EXEC_ENV_FREEBSD
|
2018-09-19 14:39:10 +00:00
|
|
|
printf("The alarm API is not supported on FreeBSD\n");
|
|
|
|
return 0;
|
|
|
|
#endif
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2022-01-26 05:10:40 +00:00
|
|
|
#ifndef RTE_EXEC_ENV_WINDOWS
|
2012-09-04 12:54:00 +00:00
|
|
|
/* check if it will fail to set alarm with wrong us value */
|
|
|
|
printf("check if it will fail to set alarm with wrong ms values\n");
|
|
|
|
if (rte_eal_alarm_set(0, test_alarm_callback,
|
|
|
|
NULL) >= 0) {
|
|
|
|
printf("should not be successful with 0 us value\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback,
|
|
|
|
NULL) >= 0) {
|
|
|
|
printf("should not be successful with (UINT64_MAX-1) us value\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2022-01-26 05:10:40 +00:00
|
|
|
#endif
|
2012-09-04 12:54:00 +00:00
|
|
|
|
|
|
|
/* check if it will fail to set alarm with null callback parameter */
|
|
|
|
printf("check if it will fail to set alarm with null callback parameter\n");
|
2021-06-03 15:22:34 +00:00
|
|
|
if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) {
|
2012-09-04 12:54:00 +00:00
|
|
|
printf("should not be successful to set alarm with null callback parameter\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if it will fail to remove alarm with null callback parameter */
|
|
|
|
printf("check if it will fail to remove alarm with null callback parameter\n");
|
|
|
|
if (rte_eal_alarm_cancel(NULL, NULL) == 0) {
|
|
|
|
printf("should not be successful to remove alarm with null callback parameter");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-13 12:38:13 +00:00
|
|
|
REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);
|