1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2014 Fujitsu Ltd. 4f08c3bdfSopenharmony_ci * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com> 5f08c3bdfSopenharmony_ci * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Verify that, fetching and changing the capacity of a pipe works as 12f08c3bdfSopenharmony_ci * expected with fcntl(2) syscall using F_GETPIPE_SZ, F_SETPIPE_SZ arguments. 13f08c3bdfSopenharmony_ci */ 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci#include "tst_test.h" 16f08c3bdfSopenharmony_ci#include "lapi/fcntl.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic int fds[2]; 19f08c3bdfSopenharmony_cistatic int max_size_unpriv; 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic void run(void) 22f08c3bdfSopenharmony_ci{ 23f08c3bdfSopenharmony_ci SAFE_PIPE(fds); 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci TST_EXP_POSITIVE(fcntl(fds[1], F_GETPIPE_SZ)); 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci TST_EXP_POSITIVE(fcntl(fds[1], F_SETPIPE_SZ, max_size_unpriv)); 28f08c3bdfSopenharmony_ci TST_EXP_POSITIVE(fcntl(fds[1], F_GETPIPE_SZ)); 29f08c3bdfSopenharmony_ci TST_EXP_EXPR(TST_RET >= max_size_unpriv, 30f08c3bdfSopenharmony_ci "new pipe size (%ld) >= requested size (%d)", 31f08c3bdfSopenharmony_ci TST_RET, max_size_unpriv); 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci SAFE_CLOSE(fds[0]); 34f08c3bdfSopenharmony_ci SAFE_CLOSE(fds[1]); 35f08c3bdfSopenharmony_ci} 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_cistatic void setup(void) 38f08c3bdfSopenharmony_ci{ 39f08c3bdfSopenharmony_ci SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &max_size_unpriv); 40f08c3bdfSopenharmony_ci} 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_cistatic void cleanup(void) 43f08c3bdfSopenharmony_ci{ 44f08c3bdfSopenharmony_ci if (fds[0] > 0) 45f08c3bdfSopenharmony_ci SAFE_CLOSE(fds[0]); 46f08c3bdfSopenharmony_ci if (fds[1] > 0) 47f08c3bdfSopenharmony_ci SAFE_CLOSE(fds[1]); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic struct tst_test test = { 51f08c3bdfSopenharmony_ci .test_all = run, 52f08c3bdfSopenharmony_ci .setup = setup, 53f08c3bdfSopenharmony_ci .cleanup = cleanup 54f08c3bdfSopenharmony_ci}; 55