Skip to content

Commit

Permalink
Refactor ptem01 test
Browse files Browse the repository at this point in the history
Fix test failure when running inside a new session via setsid() and
start spliting its internal tests cases implementations into multiple
files.

Fixes: linux-test-project/kirk#28
Reviewed-by: Petr Vorel <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Andrea Cervesato <[email protected]>
  • Loading branch information
acerv committed Jan 17, 2025
1 parent cf77adb commit 6a0c1f6
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 419 deletions.
68 changes: 68 additions & 0 deletions testcases/kernel/pty/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
*/

#ifndef PTEM_H
#define PTEM_H

#define _GNU_SOURCE

#include "tst_test.h"

#define MASTERCLONE "/dev/ptmx"

static inline int open_master(void)
{
int masterfd;

if (access(MASTERCLONE, F_OK))
tst_brk(TCONF, "%s device doesn't exist", MASTERCLONE);

tst_res(TINFO, "opening master %s", MASTERCLONE);

masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);

if (grantpt(masterfd) == -1)
tst_brk(TBROK | TERRNO, "grantpt() error");

if (unlockpt(masterfd) == -1)
tst_brk(TBROK | TERRNO, "unlockpt() error");

return masterfd;
}

static inline int open_slave(const int masterfd)
{
int slavefd;
char *slavename;

slavename = SAFE_PTSNAME(masterfd);

tst_res(TINFO, "opening slave %s", slavename);

#ifndef __BIONIC__
/* grantpt() is a no-op in bionic. */
struct stat st;

SAFE_STAT(slavename, &st);

uid_t uid = getuid();

if (st.st_uid != uid) {
tst_brk(TBROK, "uid mismatch st.st_uid(%d) != getuid(%d)",
st.st_uid, uid);
}

if (st.st_mode != (S_IFCHR | 0620)) {
tst_brk(TBROK, "unexpected slave device permission: %o",
st.st_mode);
}
#endif

slavefd = SAFE_OPEN(slavename, O_RDWR);

return slavefd;
}

#endif
Loading

0 comments on commit 6a0c1f6

Please sign in to comment.