1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2003. All Rights Reserved.
4 *
5 * Author: Aniruddha Marathe <aniruddha.marathe@wipro.com>
6 *
7 * Ported to new library:
8 * 07/2019 Christian Amann <camann@suse.com>
9 */
10 /*
11 * Basic test for timer_delete(2)
12 *
13 * Creates a timer for each available clock and then tries
14 * to delete them again.
15 *
16 * This is also regression test for commit:
17 * f18ddc13af98 ("alarmtimer: Use EOPNOTSUPP instead of ENOTSUPP")
18 */
19
20 #include <errno.h>
21 #include <time.h>
22 #include "tst_test.h"
23 #include "lapi/common_timers.h"
24
run(void)25 static void run(void)
26 {
27 unsigned int i;
28 kernel_timer_t timer_id;
29
30 for (i = 0; i < CLOCKS_DEFINED; ++i) {
31 clock_t clock = clock_list[i];
32
33 tst_res(TINFO, "Testing %s", get_clock_str(clock));
34
35 TEST(tst_syscall(__NR_timer_create, clock, NULL, &timer_id));
36 if (TST_RET != 0) {
37 if (possibly_unsupported(clock) &&
38 (TST_ERR == EINVAL || TST_ERR == ENOTSUP)) {
39 tst_res(TCONF | TTERRNO, "%s unsupported",
40 get_clock_str(clock));
41 } else {
42 tst_res(TFAIL | TTERRNO,
43 "Aborting test - timer_create(%s) failed",
44 get_clock_str(clock));
45 }
46 continue;
47 }
48
49 TEST(tst_syscall(__NR_timer_delete, timer_id));
50 if (TST_RET == 0)
51 tst_res(TPASS, "Timer deleted successfully!");
52 else
53 tst_res(TFAIL | TTERRNO, "Timer deletion failed!");
54 }
55 }
56
57 static struct tst_test test = {
58 .test_all = run,
59 .needs_root = 1,
60 .tags = (const struct tst_tag[]) {
61 {"linux-git", "f18ddc13af98"},
62 {}
63 }
64 };
65