{"id":2220089,"url":"http://patchwork.ozlabs.org/api/patches/2220089/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/patch/20260406100311.79619-1-abdulla1@linux.ibm.com/","project":{"id":59,"url":"http://patchwork.ozlabs.org/api/projects/59/?format=json","name":"Linux Test Project development","link_name":"ltp","list_id":"ltp.lists.linux.it","list_email":"ltp@lists.linux.it","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260406100311.79619-1-abdulla1@linux.ibm.com>","list_archive_url":null,"date":"2026-04-06T10:03:11","name":"syscalls/ioctl02: Move TTY discovery from shell to C","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6a1eadd0caf1deea4290e04268cb62d30d9a1343","submitter":{"id":93068,"url":"http://patchwork.ozlabs.org/api/people/93068/?format=json","name":"Abdulla","email":"abdulla1@linux.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ltp/patch/20260406100311.79619-1-abdulla1@linux.ibm.com/mbox/","series":[{"id":498834,"url":"http://patchwork.ozlabs.org/api/series/498834/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/list/?series=498834","date":"2026-04-06T10:03:11","name":"syscalls/ioctl02: Move TTY discovery from shell to C","version":1,"mbox":"http://patchwork.ozlabs.org/series/498834/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2220089/comments/","check":"warning","checks":"http://patchwork.ozlabs.org/api/patches/2220089/checks/","tags":{},"related":[],"headers":{"Return-Path":"<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>","X-Original-To":["incoming@patchwork.ozlabs.org","ltp@lists.linux.it"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","ltp@picard.linux.it"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256\n header.s=pp1 header.b=TNZb38nZ;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=2001:1418:10:5::2; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)"],"Received":["from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fq4fB6rVBz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 06 Apr 2026 20:03:28 +1000 (AEST)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id B9CB63D2269\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  6 Apr 2026 12:03:25 +0200 (CEST)","from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1))\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id 3FF1D3C2B7E\n for <ltp@lists.linux.it>; Mon,  6 Apr 2026 12:03:21 +0200 (CEST)","from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n [148.163.158.5])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 09E0A600131\n for <ltp@lists.linux.it>; Mon,  6 Apr 2026 12:03:20 +0200 (CEST)","from pps.filterd (m0356516.ppops.net [127.0.0.1])\n by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 635JP1Hq3413620\n for <ltp@lists.linux.it>; Mon, 6 Apr 2026 10:03:19 GMT","from ppma13.dal12v.mail.ibm.com\n (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221])\n by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dar2gdt4k-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT)\n for <ltp@lists.linux.it>; Mon, 06 Apr 2026 10:03:19 +0000 (GMT)","from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1])\n by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id\n 6366id1f014784\n for <ltp@lists.linux.it>; Mon, 6 Apr 2026 10:03:18 GMT","from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228])\n by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dbf6jv26u-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT)\n for <ltp@lists.linux.it>; Mon, 06 Apr 2026 10:03:18 +0000","from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com\n [10.20.54.102])\n by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id\n 636A3EVD29557432\n (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK);\n Mon, 6 Apr 2026 10:03:14 GMT","from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id 7A0922004D;\n Mon,  6 Apr 2026 10:03:14 +0000 (GMT)","from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id C4EBE2004B;\n Mon,  6 Apr 2026 10:03:13 +0000 (GMT)","from localhost.localdomain (unknown [9.109.228.243])\n by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP;\n Mon,  6 Apr 2026 10:03:13 +0000 (GMT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc\n :content-transfer-encoding:date:from:message-id:mime-version\n :subject:to; s=pp1; bh=WFFV88/qt2KLnd7mp/4PpYQ/3GlG6ct9sk14FTV6s\n 9c=; b=TNZb38nZ2i3dqHP9gWARQ22xPcW6p/JN2tVRCr5k02i3iUi1zv9eFEZJ6\n aDzhZ78uJ363TPOScfr7wrP4x29S2YaDIkUahB2OnlDFcytTlTwThoH2wkBcvWxn\n d0hwsR8yU/xz2ns9mxUdHwn61yDTLe8s+hx7wGArVoOC9V4R59OVIIDvfWJt+13Q\n 8IsrnSwSzNIE4Uk8DMVt1ngzxie7b/6Dv6L8+8Ef+3akgqLsIR4fK3AjM+vLzXzq\n ahDiqSnHYVHnghFQ0yDWLtOSNWio7PHFnV749NOwBh83soEF6PHRzsD7GVm+edjv\n AJ6vZVDeMWXKIHKpY7s8TvBA4hVZA==","From":"Abdulla <abdulla1@linux.ibm.com>","To":"ltp@lists.linux.it","Date":"Mon,  6 Apr 2026 15:33:11 +0530","Message-Id":"<20260406100311.79619-1-abdulla1@linux.ibm.com>","X-Mailer":"git-send-email 2.39.5 (Apple Git-154)","MIME-Version":"1.0","X-TM-AS-GCONF":"00","X-Proofpoint-GUID":"rh1c7wD0AtfMqwbAd0cYzfDb5STlW9jK","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDA2MDA5NiBTYWx0ZWRfX0SUeGs7ayA5U\n aq0IoGxjwkfDYwvEOhxWX0PRm7AkVHKam940GYmcRW7u8jsXWyTUprOAL9PY8nfbV78hMgwQrc1\n 9Y8jyyUkV3c2iKGJz45awrOnIOJL6HKSTOvyaPQ+tsBifK0Ok9y22xMF0Av7uIn7y6lzV6t4AsK\n FkIvrhrOBCDBVThlrSyyr3sARUdQ6BnbOwSvrTqgK1TG2Ev9L7xJWzhX0M4Sc3jYhHOFp4UOl+P\n 9C5i8ZQbdNlvIDIG5CG19eiNTePsEZVJ10sLo/qNFyAbg8dAiE2hNUkswCKwzitJ1OTaTriPtpl\n +OlXdzTaM6WhyvhX0RRI3Qg2defIMSD2JjCGQmTZy6hCJs7HbKSnhrnV3svPtgWpONkbXvQjhY3\n Sz2zN3nT11sfeNTWwN0FCwUlLSAducCUR9eu1+Bzw3W85ZCHl57hmSmK9xVQ7xnSR6bg5fr2WU8\n AAmLHUT4TuDSUYZoWWg==","X-Authority-Analysis":"v=2.4 cv=b+u/I9Gx c=1 sm=1 tr=0 ts=69d384e7 cx=c_pps\n a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17\n a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22\n a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=BqmSNwtJosOcRg9k20kA:9","X-Proofpoint-ORIG-GUID":"rh1c7wD0AtfMqwbAd0cYzfDb5STlW9jK","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-06_02,2026-04-03_01,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0\n impostorscore=0 malwarescore=0 spamscore=0 priorityscore=1501 clxscore=1011\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2604060096","X-Spam-Status":"No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DMARC_PASS,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled\n version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on in-2.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-2.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"[LTP] [PATCH] syscalls/ioctl02: Move TTY discovery from shell to C","X-BeenThere":"ltp@lists.linux.it","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"Linux Test Project <ltp.lists.linux.it>","List-Unsubscribe":"<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>","List-Archive":"<http://lists.linux.it/pipermail/ltp/>","List-Post":"<mailto:ltp@lists.linux.it>","List-Help":"<mailto:ltp-request@lists.linux.it?subject=help>","List-Subscribe":"<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it","Sender":"\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>"},"content":"The test previously required a shell wrapper to discover and validate\nTTY devices. This modernization moves all TTY discovery logic into C,\neliminating the shell dependency.\n\nKey changes:\n- Added is_valid_tty_name() for pattern matching tty[0-9]*\n- Added is_valid_tty_device() for ioctl-based validation\n- Added find_valid_ttys() for /dev directory scanning\n- Made device parameter optional with auto-discovery mode\n- Extracted test_single_device() for code reusability\n\nThe test now supports two modes:\n1. Single device: ./ioctl02 -d /dev/tty1 (backward compatible)\n2. Auto-discovery: ./ioctl02 (discovers all valid TTY devices)\n\nSigned-off-by: Shaik Abdulla <abdulla1@linux.ibm.com>\n---\n .../syscalls/ioctl/ioctl02_modernized.c       | 431 ++++++++++++++++++\n 1 file changed, 431 insertions(+)\n create mode 100644 testcases/kernel/syscalls/ioctl/ioctl02_modernized.c","diff":"diff --git a/testcases/kernel/syscalls/ioctl/ioctl02_modernized.c b/testcases/kernel/syscalls/ioctl/ioctl02_modernized.c\nnew file mode 100644\nindex 000000000..44b43db19\n--- /dev/null\n+++ b/testcases/kernel/syscalls/ioctl/ioctl02_modernized.c\n@@ -0,0 +1,431 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ * Copyright (c) International Business Machines  Corp., 2001\n+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>\n+ * Copyright (c) 2023 Marius Kittler <mkittler@suse.de>\n+ * Copyright (c) 2026 Modernization - TTY discovery moved from shell to C\n+ */\n+\n+/*\\\n+ * Test TCGETA/TCGETS and TCSETA/TCSETS ioctl implementations for tty driver.\n+ *\n+ * This test can operate in two modes:\n+ * 1. Single device mode: Use -d option to test a specific TTY device\n+ * 2. Auto-discovery mode: Automatically discovers and tests all valid /dev/tty[0-9]* devices\n+ *\n+ * In this test, the parent and child open the parentty and the childtty\n+ * respectively.  After opening the childtty the child flushes the stream\n+ * and wakes the parent (thereby asking it to continue its testing). The\n+ * parent, then starts the testing. It issues a TCGETA/TCGETS ioctl to\n+ * get all the tty parameters. It then changes them to known values by\n+ * issuing a TCSETA/TCSETS ioctl. Then the parent issues a TCSETA/TCGETS\n+ * ioctl again and compares the received values with what it had set\n+ * earlier. The test fails if TCGETA/TCGETS or TCSETA/TCSETS fails, or if\n+ * the received values don't match those that were set. The parent does\n+ * all the testing, the requirement of the child process is to moniter\n+ * the testing done by the parent, and hence the child just waits for the\n+ * parent.\n+ */\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <ctype.h>\n+#include <dirent.h>\n+#include <sys/stat.h>\n+#include <asm/termbits.h>\n+\n+#include \"lapi/ioctl.h\"\n+#include \"tst_test.h\"\n+\n+#define MAX_TTYS 100\n+#define TTY_PATH_MAX 256\n+\n+static struct termio termio, termio_exp;\n+static struct termios termios, termios_exp, termios_bak;\n+\n+static char *parenttty, *childtty;\n+static int parentfd = -1;\n+static int parentpid, childpid;\n+\n+/* TTY device list for auto-discovery mode */\n+static char *tty_list[MAX_TTYS];\n+static int tty_count = 0;\n+\n+static void do_child(void);\n+static void prepare_termio(void);\n+static void run_ptest(void);\n+static void chk_tty_parms_termio(void);\n+static void chk_tty_parms_termios(void);\n+static void setup(void);\n+static void cleanup(void);\n+static void test_single_device(const char *dev);\n+static void find_valid_ttys(void);\n+static void free_tty_list(void);\n+static int is_valid_tty_name(const char *name);\n+static int is_valid_tty_device(const char *path);\n+\n+static char *device;\n+\n+static struct variant {\n+\tconst char *name;\n+\tvoid *termio, *termio_exp, *termio_bak;\n+\tsize_t termio_size;\n+\tvoid (*check)(void);\n+\tint tcget, tcset;\n+} variants[] = {\n+\t{\n+\t\t.name = \"termio\",\n+\t\t.termio = &termio,\n+\t\t.termio_exp = &termio_exp,\n+\t\t.termio_size = sizeof(termio),\n+\t\t.check = &chk_tty_parms_termio,\n+\t\t.tcget = TCGETA,\n+\t\t.tcset = TCSETA,\n+\t},\n+\t{\n+\t\t.name = \"termios\",\n+\t\t.termio = &termios,\n+\t\t.termio_exp = &termios_exp,\n+\t\t.termio_size = sizeof(termios),\n+\t\t.check = &chk_tty_parms_termios,\n+\t\t.tcget = TCGETS,\n+\t\t.tcset = TCSETS,\n+\t},\n+};\n+\n+/*\n+ * is_valid_tty_name() - Check if device name matches tty[0-9] or tty[0-9][0-9]\n+ */\n+static int is_valid_tty_name(const char *name)\n+{\n+\tconst char *device_no;\n+\n+\t/* Must start with \"tty\" */\n+\tif (strncmp(name, \"tty\", 3) != 0)\n+\t\treturn 0;\n+\n+\tdevice_no = name + 3;\n+\n+\t/* Must have at least one digit */\n+\tif (!isdigit(device_no[0]))\n+\t\treturn 0;\n+\n+\t/* If there's a second character, it must be a digit */\n+\tif (device_no[1] != '\\0' && !isdigit(device_no[1]))\n+\t\treturn 0;\n+\n+\t/* Must not have more than 2 digits */\n+\tif (device_no[1] != '\\0' && device_no[2] != '\\0')\n+\t\treturn 0;\n+\n+\treturn 1;\n+}\n+\n+/*\n+ * is_valid_tty_device() - Validate TTY device by attempting ioctl\n+ * This replaces the shell's \"stty -F\" validation\n+ */\n+static int is_valid_tty_device(const char *path)\n+{\n+\tint fd;\n+\tstruct termios t;\n+\tint ret;\n+\n+\t/* Try to open device with non-blocking flag */\n+\tfd = open(path, O_RDWR | O_NONBLOCK);\n+\tif (fd < 0)\n+\t\treturn 0;\n+\n+\t/* Try to get terminal attributes - this validates it's a real TTY */\n+\tret = ioctl(fd, TCGETS, &t);\n+\tclose(fd);\n+\n+\treturn (ret == 0);\n+}\n+\n+/*\n+ * find_valid_ttys() - Discover all valid TTY devices in /dev\n+ * This replaces the shell wrapper's \"for tttype in `ls /dev/tty*`\" logic\n+ */\n+static void find_valid_ttys(void)\n+{\n+\tDIR *dir;\n+\tstruct dirent *entry;\n+\tchar tty_path[TTY_PATH_MAX];\n+\n+\tdir = opendir(\"/dev\");\n+\tif (!dir)\n+\t\ttst_brk(TBROK | TERRNO, \"Cannot open /dev directory\");\n+\n+\ttst_res(TINFO, \"Scanning /dev for valid TTY devices...\");\n+\n+\twhile ((entry = readdir(dir)) != NULL) {\n+\t\t/* Check if name matches tty[0-9] or tty[0-9][0-9] pattern */\n+\t\tif (!is_valid_tty_name(entry->d_name))\n+\t\t\tcontinue;\n+\n+\t\t/* Build full path */\n+\t\tsnprintf(tty_path, sizeof(tty_path), \"/dev/%s\", entry->d_name);\n+\n+\t\t/* Validate it's a working TTY device */\n+\t\tif (!is_valid_tty_device(tty_path)) {\n+\t\t\ttst_res(TINFO, \"Skipping %s (not a valid TTY)\", tty_path);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Add to list if we have space */\n+\t\tif (tty_count >= MAX_TTYS) {\n+\t\t\ttst_res(TWARN, \"Too many TTY devices found, skipping %s\", tty_path);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\ttty_list[tty_count] = strdup(tty_path);\n+\t\tif (!tty_list[tty_count])\n+\t\t\ttst_brk(TBROK | TERRNO, \"Failed to allocate memory for TTY path\");\n+\n+\t\ttst_res(TINFO, \"Found valid TTY device: %s\", tty_path);\n+\t\ttty_count++;\n+\t}\n+\n+\tclosedir(dir);\n+\n+\tif (tty_count == 0)\n+\t\ttst_brk(TBROK, \"No valid TTY devices found in /dev\");\n+\n+\ttst_res(TINFO, \"Total valid TTY devices found: %d\", tty_count);\n+}\n+\n+/*\n+ * free_tty_list() - Free allocated TTY device paths\n+ */\n+static void free_tty_list(void)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < tty_count; i++) {\n+\t\tif (tty_list[i]) {\n+\t\t\tfree(tty_list[i]);\n+\t\t\ttty_list[i] = NULL;\n+\t\t}\n+\t}\n+\ttty_count = 0;\n+}\n+\n+/*\n+ * test_single_device() - Test a single TTY device\n+ * Extracted from verify_ioctl() to support both single and multi-device modes\n+ */\n+static void test_single_device(const char *dev)\n+{\n+\tparenttty = childtty = (char *)dev;\n+\n+\tparentpid = getpid();\n+\tchildpid = SAFE_FORK();\n+\tif (!childpid) {\n+\t\tdo_child();\n+\t\texit(EXIT_SUCCESS);\n+\t}\n+\n+\tTST_CHECKPOINT_WAIT(0);\n+\n+\tparentfd = SAFE_OPEN(parenttty, O_RDWR, 0777);\n+\tSAFE_IOCTL(parentfd, TCFLSH, TCIOFLUSH);\n+\n+\trun_ptest();\n+\n+\tTST_CHECKPOINT_WAKE(0);\n+\tSAFE_CLOSE(parentfd);\n+\tparentfd = -1;\n+}\n+\n+static void verify_ioctl(void)\n+{\n+\tint i;\n+\n+\ttst_res(TINFO, \"Testing %s variant\", variants[tst_variant].name);\n+\n+\tif (device) {\n+\t\t/* Single device mode - test specified device only */\n+\t\ttst_res(TINFO, \"Single device mode: testing %s\", device);\n+\t\ttest_single_device(device);\n+\t} else {\n+\t\t/* Auto-discovery mode - find and test all valid TTYs */\n+\t\ttst_res(TINFO, \"Auto-discovery mode: scanning for TTY devices\");\n+\t\tfind_valid_ttys();\n+\n+\t\tfor (i = 0; i < tty_count; i++) {\n+\t\t\ttst_res(TINFO, \"Testing device %d/%d: %s\",\n+\t\t\t\ti + 1, tty_count, tty_list[i]);\n+\t\t\ttest_single_device(tty_list[i]);\n+\t\t}\n+\n+\t\tfree_tty_list();\n+\t}\n+}\n+\n+static void prepare_termio(void)\n+{\n+\t/* Use \"old\" line discipline */\n+\ttermios_exp.c_line = termio_exp.c_line = 0;\n+\n+\t/* Set control modes */\n+\ttermios_exp.c_cflag = termio_exp.c_cflag = B50 | CS7 | CREAD | PARENB | PARODD | CLOCAL;\n+\n+\t/* Set control chars. */\n+\tfor (int i = 0; i < NCC; i++)\n+\t\ttermio_exp.c_cc[i] = CSTART;\n+\tfor (int i = 0; i < VEOL2; i++)\n+\t\ttermios_exp.c_cc[i] = CSTART;\n+\n+\t/* Set local modes. */\n+\ttermios_exp.c_lflag = termio_exp.c_lflag =\n+\t    ((unsigned short)(ISIG | ICANON | XCASE | ECHO | ECHOE | NOFLSH));\n+\n+\t/* Set input modes. */\n+\ttermios_exp.c_iflag = termio_exp.c_iflag =\n+\t    BRKINT | IGNPAR | INPCK | ISTRIP | ICRNL | IUCLC | IXON | IXANY |\n+\t    IXOFF;\n+\n+\t/* Set output modes. */\n+\ttermios_exp.c_oflag = termio_exp.c_oflag = OPOST | OLCUC | ONLCR | ONOCR;\n+}\n+\n+/*\n+ * run_ptest() - setup the various termio/termios structure values and issue\n+ * the TCSETA/TCSETS ioctl call with the TEST macro.\n+ */\n+static void run_ptest(void)\n+{\n+\tstruct variant *v = &variants[tst_variant];\n+\n+\t/* Init termio/termios structures used to check if all params got set */\n+\tmemset(v->termio, 0, v->termio_size);\n+\n+\tSAFE_IOCTL(parentfd, v->tcset, v->termio_exp);\n+\n+\t/* Get termio and see if all parameters actually got set */\n+\tSAFE_IOCTL(parentfd, v->tcget, v->termio);\n+\tv->check();\n+}\n+\n+static int cmp_attr(unsigned long long exp, unsigned long long act, const char *attr)\n+{\n+\tif (act == exp)\n+\t\treturn 0;\n+\ttst_res(TFAIL, \"%s has incorrect value %llu, expected %llu\",\n+\t\tattr, act, exp);\n+\treturn 1;\n+}\n+\n+static int cmp_c_cc(unsigned char *exp_c_cc, unsigned char *act_c_cc, int ncc)\n+{\n+\tint i, fails = 0;\n+\tchar what[32];\n+\n+\tfor (i = 0; i < ncc; ++i) {\n+\t\tsprintf(what, \"control char %d\", i);\n+\t\tfails += cmp_attr(exp_c_cc[i], act_c_cc[i], what);\n+\t}\n+\treturn fails;\n+}\n+\n+#define CMP_ATTR(term_exp, term, attr, flag)\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n+\tflag += cmp_attr((term_exp).attr, (term).attr, #attr);\t\\\n+\tflag;                                                   \\\n+})\n+\n+#define CMP_C_CC(term_exp, term, flag)\t\t\t\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n+\tflag += cmp_c_cc(term_exp.c_cc, term.c_cc, sizeof(term.c_cc));\t\\\n+\tflag;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n+})\n+\n+static void chk_tty_parms_termio(void)\n+{\n+\tint flag = 0;\n+\n+\tflag = CMP_ATTR(termio_exp, termio, c_line, flag);\n+\tflag = CMP_C_CC(termio_exp, termio, flag);\n+\tflag = CMP_ATTR(termio_exp, termio, c_lflag, flag);\n+\tflag = CMP_ATTR(termio_exp, termio, c_iflag, flag);\n+\tflag = CMP_ATTR(termio_exp, termio, c_oflag, flag);\n+\n+\tif (!flag)\n+\t\ttst_res(TPASS, \"TCGETA/TCSETA tests\");\n+}\n+\n+static void chk_tty_parms_termios(void)\n+{\n+\tint flag = 0;\n+\n+\tflag = CMP_ATTR(termios_exp, termios, c_line, flag);\n+\tflag = CMP_C_CC(termios_exp, termios, flag);\n+\tflag = CMP_ATTR(termios_exp, termios, c_lflag, flag);\n+\tflag = CMP_ATTR(termios_exp, termios, c_iflag, flag);\n+\tflag = CMP_ATTR(termios_exp, termios, c_oflag, flag);\n+\n+\tif (!flag)\n+\t\ttst_res(TPASS, \"TCGETS/TCSETS tests\");\n+}\n+\n+static void do_child(void)\n+{\n+\tint cfd = SAFE_OPEN(childtty, O_RDWR, 0777);\n+\n+\tSAFE_IOCTL(cfd, TCFLSH, TCIOFLUSH);\n+\n+\t/* tell the parent that we're done */\n+\tTST_CHECKPOINT_WAKE(0);\n+\n+\tTST_CHECKPOINT_WAIT(0);\n+\ttst_res(TINFO, \"child: parent has finished testing\");\n+\tSAFE_CLOSE(cfd);\n+}\n+\n+static void setup(void)\n+{\n+\tint fd;\n+\n+\tif (device) {\n+\t\t/* Single device mode - validate the specified device */\n+\t\ttst_res(TINFO, \"Using specified device: %s\", device);\n+\n+\t\tfd = SAFE_OPEN(device, O_RDWR, 0777);\n+\t\tSAFE_IOCTL(fd, TCGETS, &termios_bak);\n+\t\tSAFE_CLOSE(fd);\n+\t} else {\n+\t\t/* Auto-discovery mode - will find devices during test */\n+\t\ttst_res(TINFO, \"Auto-discovery mode enabled\");\n+\t}\n+\n+\tprepare_termio();\n+}\n+\n+static void cleanup(void)\n+{\n+\tif (parentfd >= 0) {\n+\t\tSAFE_IOCTL(parentfd, TCSETS, &termios_bak);\n+\t\tSAFE_CLOSE(parentfd);\n+\t}\n+\n+\t/* Free any allocated TTY list */\n+\tfree_tty_list();\n+}\n+\n+static struct tst_test test = {\n+\t.timeout = 20,\n+\t.needs_root = 1,\n+\t.needs_checkpoints = 1,\n+\t.forks_child = 1,\n+\t.setup = setup,\n+\t.cleanup = cleanup,\n+\t.test_all = verify_ioctl,\n+\t.test_variants = 2,\n+\t.options = (struct tst_option[]) {\n+\t\t{\"d:\", &device, \"TTY device to test (optional). If not specified, auto-discovers all /dev/tty[0-9]* devices. Example: /dev/tty1\"},\n+\t\t{}\n+\t}\n+};\n+\n","prefixes":[]}