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 if (clock == CLOCK_PROCESS_CPUTIME_ID ||
34 clock == CLOCK_THREAD_CPUTIME_ID) {
35 if (!have_cputime_timers())
36 continue;
37 }
38
39 tst_res(TINFO, "Testing %s", get_clock_str(clock));
40
41 TEST(tst_syscall(__NR_timer_create, clock, NULL, &timer_id));
42 if (TST_RET != 0) {
43 if (possibly_unsupported(clock) &&
44 (TST_ERR == EINVAL || TST_ERR == ENOTSUP)) {
45 tst_res(TCONF | TTERRNO, "%s unsupported",
46 get_clock_str(clock));
47 } else {
48 tst_res(TFAIL | TTERRNO,
49 "Aborting test - timer_create(%s) failed",
50 get_clock_str(clock));
51 }
52 continue;
53 }
54
55 TEST(tst_syscall(__NR_timer_delete, timer_id));
56 if (TST_RET == 0)
57 tst_res(TPASS, "Timer deleted successfully!");
58 else
59 tst_res(TFAIL | TTERRNO, "Timer deletion failed!");
60 }
61 }
62
63 static struct tst_test test = {
64 .test_all = run,
65 .needs_root = 1,
66 .tags = (const struct tst_tag[]) {
67 {"linux-git", "f18ddc13af98"},
68 {}
69 }
70 };
71