1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4 *
5 * Description:
6 * Cross verify the _high fields being set to 0 by the kernel.
7 */
8 #include "lapi/sembuf.h"
9 #include "lapi/sem.h"
10 #include "tst_test.h"
11 #include "libnewipc.h"
12
13 #ifdef HAVE_SEMID64_DS_TIME_HIGH
14
run(void)15 static void run(void)
16 {
17 struct semid64_ds buf_ds = {
18 .sem_otime_high = 0x0A0A,
19 .sem_ctime_high = 0x0A0A,
20 };
21 int semid;
22 union semun arg;
23 key_t key;
24
25 /* get an IPC resource key */
26 key = GETIPCKEY();
27
28 semid = semget(key, 1, SEM_RA | IPC_CREAT);
29 if (semid == -1)
30 tst_brk(TBROK | TERRNO, "couldn't create semaphore");
31
32 arg.buf = (struct semid_ds *)&buf_ds;
33 TEST(semctl(semid, 0, IPC_STAT, arg));
34 if (TST_RET == -1)
35 tst_brk(TFAIL | TTERRNO, "semctl() failed");
36
37 if (buf_ds.sem_otime_high || buf_ds.sem_ctime_high)
38 tst_res(TFAIL, "time_high fields aren't cleared by the kernel");
39 else
40 tst_res(TPASS, "time_high fields cleared by the kernel");
41
42 if (semctl(semid, 0, IPC_RMID, arg) == -1)
43 tst_res(TINFO, "WARNING: semaphore deletion failed.");
44 }
45
46 static struct tst_test test = {
47 .test_all = run,
48 .needs_tmpdir = 1,
49 };
50 #else
51 TST_TEST_TCONF("test requires struct semid64_ds to have the time_high fields");
52 #endif
53