70e97a3109af505a48014185106c81b9abb500fa
[dpdk.git] / app / test / test_alarm.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <stdint.h>
7
8 #include <rte_common.h>
9 #include <rte_alarm.h>
10
11 #include "test.h"
12
13 #ifndef RTE_EXEC_ENV_WINDOWS
14 static volatile int flag;
15
16 static void
17 test_alarm_callback(void *cb_arg)
18 {
19         flag = 1;
20         printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
21 }
22 #endif
23
24 static int
25 test_alarm(void)
26 {
27 #ifdef RTE_EXEC_ENV_FREEBSD
28         printf("The alarm API is not supported on FreeBSD\n");
29         return 0;
30 #endif
31
32 #ifndef RTE_EXEC_ENV_WINDOWS
33         /* check if it will fail to set alarm with wrong us value */
34         printf("check if it will fail to set alarm with wrong ms values\n");
35         if (rte_eal_alarm_set(0, test_alarm_callback,
36                                                 NULL) >= 0) {
37                 printf("should not be successful with 0 us value\n");
38                 return -1;
39         }
40         if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback,
41                                                 NULL) >= 0) {
42                 printf("should not be successful with (UINT64_MAX-1) us value\n");
43                 return -1;
44         }
45 #endif
46
47         /* check if it will fail to set alarm with null callback parameter */
48         printf("check if it will fail to set alarm with null callback parameter\n");
49         if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) {
50                 printf("should not be successful to set alarm with null callback parameter\n");
51                 return -1;
52         }
53
54         /* check if it will fail to remove alarm with null callback parameter */
55         printf("check if it will fail to remove alarm with null callback parameter\n");
56         if (rte_eal_alarm_cancel(NULL, NULL) == 0) {
57                 printf("should not be successful to remove alarm with null callback parameter");
58                 return -1;
59         }
60
61         return 0;
62 }
63
64 REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);