linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Abhinav Saxena <xandfury@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Jiri Slaby <jirislaby@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	 Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	 Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	 Kees Cook <kees@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	 llvm@lists.linux.dev, linux-hardening@vger.kernel.org,
	 Abhinav Saxena <xandfury@gmail.com>
Subject: [RFC PATCH 1/5] tty: Add KUnit test infrastructure configuration
Date: Tue, 26 Aug 2025 16:51:31 -0600	[thread overview]
Message-ID: <20250826-tty-tests-v1-1-e904a817df92@gmail.com> (raw)
In-Reply-To: <20250826-tty-tests-v1-0-e904a817df92@gmail.com>

Add Kconfig and Makefile support for TTY KUnit testing framework.
Introduces CONFIG_TTY_GCOV_PROFILE for targeted coverage analysis
and CONFIG_TTY_KUNIT_TESTS for test infrastructure enabling.

The infrastructure allows selective testing of TTY components without
instrumenting the entire kernel, improving development efficiency for
TTY subsystem changes.

Signed-off-by: Abhinav Saxena <xandfury@gmail.com>
---
 drivers/tty/Kconfig            |  9 +++++++++
 drivers/tty/Makefile           |  7 +++++++
 drivers/tty/tests/.kunitconfig | 44 ++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/tests/Kconfig      | 44 ++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/tests/Makefile     |  2 ++
 5 files changed, 106 insertions(+)

diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 149f3d53b76086cd4ac5acf116ebe36d816664ac..92d27761e1543ceb138a670194480ed1e711124b 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -424,6 +424,15 @@ config RPMSG_TTY
 	  To compile this driver as a module, choose M here: the module will be
 	  called rpmsg_tty.
 
+config TTY_GCOV_PROFILE
+	bool "Enable gcov profiling for TTY subsystem"
+	depends on GCOV_KERNEL && TTY
+	help
+	  Instrument drivers/tty/* with gcov when GCOV is enabled.
+	  Useful for targeted coverage runs without profiling the whole kernel.
+
+source "drivers/tty/tests/Kconfig"
+
 endif # TTY
 
 source "drivers/tty/serdev/Kconfig"
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 07aca5184a55dd38036587c3485ba9f12d2e7ec7..c0cb47c32e94abe072f4cd7e2023480bbb5da9f2 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -29,3 +29,10 @@ obj-$(CONFIG_VCC)		+= vcc.o
 obj-$(CONFIG_RPMSG_TTY)		+= rpmsg_tty.o
 
 obj-y += ipwireless/
+
+obj-$(CONFIG_TTY_KUNIT_TESTS) += tests/
+
+# tty profiling & coverage
+ifdef CONFIG_TTY_GCOV_PROFILE
+GCOV_PROFILE := y
+endif
diff --git a/drivers/tty/tests/.kunitconfig b/drivers/tty/tests/.kunitconfig
new file mode 100644
index 0000000000000000000000000000000000000000..a29112fa03ae78e096d9e22546b3cfd3007d710c
--- /dev/null
+++ b/drivers/tty/tests/.kunitconfig
@@ -0,0 +1,44 @@
+# TTY KUnit Test Configuration
+# =============================
+#
+# Running test with something like this:
+# -------------------------------------
+# ./tools/testing/kunit/kunit.py run tty_io_core \
+#     --kunitconfig=.kunit/ \
+#     --kunitconfig=drivers/tty/tests/.kunitconfig \
+#     --jobs "$(nproc)" \
+#     --arch=x86_64 \
+#     --make_options="LLVM=-18"
+
+# Core KUnit Infrastructure
+# -------------------------
+CONFIG_KUNIT=y
+CONFIG_KUNIT_DEBUGFS=y
+CONFIG_KUNIT_TEST=y
+CONFIG_PROC_FS=y
+CONFIG_SYSFS=y
+CONFIG_DEBUG_FS=y
+
+# TTY Subsystem Core
+# ------------------
+CONFIG_TTY=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_SERIAL_CORE=y
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+
+# TTY Drivers for Testing
+# -----------------------
+# Enable ttynull driver (required for ttynull tests)
+CONFIG_NULL_TTY=y
+
+# TTY KUnit Tests
+# ---------------
+CONFIG_TTY_KUNIT_TESTS=y
+CONFIG_TTY_KUNIT_CORE_TESTS=y
+CONFIG_TTY_KUNIT_NULL_TTY_TESTS=y
+
+# Code Coverage
+# -------------------------------------------
+CONFIG_GCOV_KERNEL=y
+CONFIG_TTY_GCOV_PROFILE=y
diff --git a/drivers/tty/tests/Kconfig b/drivers/tty/tests/Kconfig
new file mode 100644
index 0000000000000000000000000000000000000000..6012f4ab7f1bc90d434d69ee82e87e89c1291763
--- /dev/null
+++ b/drivers/tty/tests/Kconfig
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0
+menu "TTY KUnit tests"
+	depends on KUNIT && TTY
+
+config TTY_KUNIT_TESTS
+	bool "TTY KUnit test infrastructure"
+	depends on KUNIT && TTY
+	default KUNIT_ALL_TESTS
+	help
+	  Enable KUnit test infrastructure for TTY drivers.
+
+	  This enables test helper functions that are included directly
+	  into tty_io.c to provide access to internal TTY functions for
+	  testing. The helpers are only available when KUNIT is enabled.
+
+	  This option provides the foundation for TTY testing but does not
+	  run any tests by itself. Enable specific test suites below.
+
+config TTY_KUNIT_CORE_TESTS
+	bool "TTY core functionality tests"
+	depends on TTY_KUNIT_TESTS
+	default KUNIT_ALL_TESTS
+	help
+	  Enable KUnit tests for TTY core functionality.
+
+	  Tests cover basic TTY operations including open/close lifecycle,
+	  write operations, buffer management, line discipline integration,
+	  and error handling through real kernel code paths.
+
+	  If unsure, say N.
+
+config TTY_KUNIT_NULL_TTY_TESTS
+	tristate "TTY null driver tests" if !KUNIT_ALL_TESTS
+	depends on TTY_KUNIT_TESTS && NULL_TTY
+	default KUNIT_ALL_TESTS
+	help
+	  Enable KUnit tests for the TTY null driver.
+
+	  Tests validate ttynull behavior as a data sink, including write
+	  operations, data discarding, and error handling. The ttynull
+	  driver discards all written data while providing minimal overhead.
+
+	  If unsure, say N.
+endmenu
diff --git a/drivers/tty/tests/Makefile b/drivers/tty/tests/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..854911a0f87d6a6fdc826cc40f99afb1202afd46
--- /dev/null
+++ b/drivers/tty/tests/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_TTY_KUNIT_CORE_TESTS) += tty_mock.o test_tty_io_core.o

-- 
2.43.0


  reply	other threads:[~2025-08-26 22:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-26 22:51 [RFC PATCH 0/5] tty: Add KUnit test framework for TTY drivers Abhinav Saxena
2025-08-26 22:51 ` Abhinav Saxena [this message]
2025-08-26 22:51 ` [RFC PATCH 2/5] tty: Add KUnit test helper functions Abhinav Saxena
2025-08-26 22:51 ` [RFC PATCH 3/5] tty: Add mock TTY driver for KUnit testing Abhinav Saxena
2025-08-26 22:51 ` [RFC PATCH 4/5] tty: Add KUnit tests for core TTY functionality Abhinav Saxena
2025-08-26 22:51 ` [RFC PATCH 5/5] tty: Add KUnit tests for ttynull driver Abhinav Saxena
2025-08-31  6:07 ` [RFC PATCH 0/5] tty: Add KUnit test framework for TTY drivers Jiri Slaby
2025-09-03  0:56   ` Abhinav Saxena

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250826-tty-tests-v1-1-e904a817df92@gmail.com \
    --to=xandfury@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).