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