1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4 */
5
6 /*\
7 * [Description]
8 *
9 * Cross verify the _high fields being set to 0 by the kernel.
10 */
11
12 #include <sys/shm.h>
13 #include "lapi/shmbuf.h"
14 #include "libnewipc.h"
15 #include "tst_test.h"
16 #include "tst_safe_sysv_ipc.h"
17
18 #ifdef HAVE_SHMID64_DS_TIME_HIGH
19
run(void)20 static void run(void)
21 {
22 struct shmid64_ds buf_ds = {
23 .shm_atime_high = 0x0A0A,
24 .shm_dtime_high = 0x0A0A,
25 .shm_ctime_high = 0x0A0A,
26 };
27 int shmid;
28 key_t key;
29
30 /* get an IPC resource key */
31 key = GETIPCKEY();
32
33 shmid = shmget(key, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW);
34 if (shmid == -1)
35 tst_brk(TBROK | TERRNO, "couldn't create shared memory segment");
36
37 TEST(shmctl(shmid, IPC_STAT, (struct shmid_ds *)&buf_ds));
38 if (TST_RET == -1)
39 tst_brk(TFAIL | TTERRNO, "shmctl() failed");
40
41 if (buf_ds.shm_atime_high || buf_ds.shm_dtime_high || buf_ds.shm_ctime_high)
42 tst_res(TFAIL, "time_high fields aren't cleared by the kernel");
43 else
44 tst_res(TPASS, "time_high fields cleared by the kernel");
45
46 SAFE_SHMCTL(shmid, IPC_RMID, NULL);
47 }
48
49 static struct tst_test test = {
50 .test_all = run,
51 .needs_tmpdir = 1,
52 };
53 #else
54 TST_TEST_TCONF("test requires struct shmid64_ds to have the time_high fields");
55 #endif
56