Skip to content

Commit

Permalink
Add pty09 test
Browse files Browse the repository at this point in the history
Verify that slave pseudo-terminal can be opened multiple times
in parallel.

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Andrea Cervesato <[email protected]>
  • Loading branch information
acerv committed Jan 17, 2025
1 parent b2399a3 commit 20aa13d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtest/pty
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pty05 pty05
pty06 pty06
pty07 pty07
pty08 pty08
pty09 pty09
ptem01 ptem01
ptem02 ptem02
ptem03 ptem03
Expand Down
1 change: 1 addition & 0 deletions testcases/kernel/pty/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/pty06
/pty07
/pty08
/pty09
74 changes: 74 additions & 0 deletions testcases/kernel/pty/pty09.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) International Business Machines Corp., 2002
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
*/

/*\
* [Description]
*
* Verify that slave pseudo-terminal can be opened multiple times in parallel.
*/

#define _GNU_SOURCE

#include "common.h"

static int masterfd = -1;

static unsigned int count_avail_pid(void)
{
DIR *dir;
struct dirent *ent;
struct rlimit limit;
unsigned int count = 0;
unsigned int max_pid_num;

SAFE_GETRLIMIT(RLIMIT_NOFILE, &limit);

dir = SAFE_OPENDIR("/proc/self/fd");
while ((ent = SAFE_READDIR(dir)))
count++;

SAFE_CLOSEDIR(dir);

max_pid_num = limit.rlim_cur - count;

tst_res(TINFO, "Available number of pids: %u", max_pid_num);

return max_pid_num;
}

static void run(void)
{
unsigned int max_pid_num;

max_pid_num = count_avail_pid();

int slavefd[max_pid_num];

for (uint32_t i = 0; i < max_pid_num; i++)
slavefd[i] = open_slave(masterfd);

tst_res(TPASS, "pty has been opened %d times", max_pid_num);

for (uint32_t i = 0; i < max_pid_num; i++)
SAFE_CLOSE(slavefd[i]);
}

static void setup(void)
{
masterfd = open_master();
}

static void cleanup(void)
{
if (masterfd != -1)
SAFE_CLOSE(masterfd);
}

static struct tst_test test = {
.test_all = run,
.setup = setup,
.cleanup = cleanup,
};

0 comments on commit 20aa13d

Please sign in to comment.