[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250611-kunit-kselftests-v3-16-55e3d148cbc6@linutronix.de>
Date: Wed, 11 Jun 2025 09:38:22 +0200
From: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
To: Masahiro Yamada <masahiroy@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>, Willy Tarreau <w@....eu>,
Thomas Weißschuh <linux@...ssschuh.net>,
Brendan Higgins <brendan.higgins@...ux.dev>,
David Gow <davidgow@...gle.com>, Rae Moar <rmoar@...gle.com>,
Shuah Khan <shuah@...nel.org>, Jonathan Corbet <corbet@....net>,
Nicolas Schier <nicolas.schier@...ux.dev>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>, Nicolas Schier <nicolas.schier@...ux.dev>
Cc: Christophe Leroy <christophe.leroy@...roup.eu>,
linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com,
linux-doc@...r.kernel.org, linux-riscv@...ts.infradead.org,
workflows@...r.kernel.org,
Thomas Weißschuh <thomas.weissschuh@...utronix.de>
Subject: [PATCH v3 16/16] kunit: uapi: Validate usability of /proc
Show that the selftests are executed from a fairly "normal"
userspace context.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
---
lib/kunit/kunit-example-uapi.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/lib/kunit/kunit-example-uapi.c b/lib/kunit/kunit-example-uapi.c
index 4ce657050dd4a576632a41ca0309c4cb5134ce14..5e7a0f3b68f182c42b03e667567e66f02d8c2b86 100644
--- a/lib/kunit/kunit-example-uapi.c
+++ b/lib/kunit/kunit-example-uapi.c
@@ -8,13 +8,45 @@
* This is *userspace* code.
*/
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
#include "../../tools/testing/selftests/kselftest.h"
+static void test_procfs(void)
+{
+ char buf[256];
+ ssize_t r;
+ int fd;
+
+ fd = open("/proc/self/comm", O_RDONLY);
+ if (fd == -1) {
+ ksft_test_result_fail("procfs: open() failed: %s\n", strerror(errno));
+ return;
+ }
+
+ r = read(fd, buf, sizeof(buf));
+ close(fd);
+
+ if (r == -1) {
+ ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno));
+ return;
+ }
+
+ if (r != 16 || strncmp("kunit-example-u\n", buf, 16) != 0) {
+ ksft_test_result_fail("procfs: incorrect comm\n");
+ return;
+ }
+
+ ksft_test_result_pass("procfs\n");
+}
+
int main(void)
{
ksft_print_header();
ksft_set_plan(4);
- ksft_test_result_pass("userspace test 1\n");
+ test_procfs();
ksft_test_result_pass("userspace test 2\n");
ksft_test_result_skip("userspace test 3: some reason\n");
ksft_test_result_pass("userspace test 4\n");
--
2.49.0
Powered by blists - more mailing lists