xref: /dpdk/app/test/test_alarm.c (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
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 static volatile int flag;
14 
15 static void
16 test_alarm_callback(void *cb_arg)
17 {
18 	flag = 1;
19 	printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
20 }
21 
22 static int
23 test_alarm(void)
24 {
25 #ifdef RTE_EXEC_ENV_FREEBSD
26 	printf("The alarm API is not supported on FreeBSD\n");
27 	return 0;
28 #endif
29 
30 	/* check if it will fail to set alarm with wrong us value */
31 	printf("check if it will fail to set alarm with wrong ms values\n");
32 	if (rte_eal_alarm_set(0, test_alarm_callback,
33 						NULL) >= 0) {
34 		printf("should not be successful with 0 us value\n");
35 		return -1;
36 	}
37 	if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback,
38 						NULL) >= 0) {
39 		printf("should not be successful with (UINT64_MAX-1) us value\n");
40 		return -1;
41 	}
42 
43 	/* check if it will fail to set alarm with null callback parameter */
44 	printf("check if it will fail to set alarm with null callback parameter\n");
45 	if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) {
46 		printf("should not be successful to set alarm with null callback parameter\n");
47 		return -1;
48 	}
49 
50 	/* check if it will fail to remove alarm with null callback parameter */
51 	printf("check if it will fail to remove alarm with null callback parameter\n");
52 	if (rte_eal_alarm_cancel(NULL, NULL) == 0) {
53 		printf("should not be successful to remove alarm with null callback parameter");
54 		return -1;
55 	}
56 
57 	return 0;
58 }
59 
60 REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);
61