linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org
Cc: Slava.Dubeyko@ibm.com, slava@dubeyko.com, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v1 4/4] ml-lib: Implement simple user-space testing application
Date: Fri,  6 Feb 2026 11:11:36 -0800	[thread overview]
Message-ID: <20260206191136.2609767-5-slava@dubeyko.com> (raw)
In-Reply-To: <20260206191136.2609767-1-slava@dubeyko.com>

Implement simple user-space testing application

Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
---
 .../test_application/ml_lib_char_dev_ioctl.h  |  21 ++
 .../test_application/test_ml_lib_char_dev.c   | 206 ++++++++++++++++++
 2 files changed, 227 insertions(+)
 create mode 100644 lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h
 create mode 100644 lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c

diff --git a/lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h b/lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h
new file mode 100644
index 000000000000..7ea74e840fda
--- /dev/null
+++ b/lib/ml-lib/test_driver/test_application/ml_lib_char_dev_ioctl.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Machine Learning (ML) library
+ *
+ * Userspace API for ml_lib_dev testing driver
+ *
+ * Copyright (C) 2025-2026 Viacheslav Dubeyko <slava@dubeyko.com>
+ */
+
+#ifndef _ML_LIB_TEST_DEV_IOCTL_H
+#define _ML_LIB_TEST_DEV_IOCTL_H
+
+#include <linux/ioctl.h>
+
+/* IOCTL commands */
+#define ML_LIB_TEST_DEV_IOC_MAGIC   'M'
+#define ML_LIB_TEST_DEV_IOCRESET    _IO(ML_LIB_TEST_DEV_IOC_MAGIC, 0)
+#define ML_LIB_TEST_DEV_IOCGETSIZE  _IOR(ML_LIB_TEST_DEV_IOC_MAGIC, 1, int)
+#define ML_LIB_TEST_DEV_IOCSETSIZE  _IOW(ML_LIB_TEST_DEV_IOC_MAGIC, 2, int)
+
+#endif /* _ML_LIB_TEST_DEV_IOCTL_H */
diff --git a/lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c b/lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c
new file mode 100644
index 000000000000..432b8a0ad068
--- /dev/null
+++ b/lib/ml-lib/test_driver/test_application/test_ml_lib_char_dev.c
@@ -0,0 +1,206 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Machine Learning (ML) library
+ *
+ * Test program for ml_lib_dev testing driver
+ *
+ * Copyright (C) 2025-2026 Viacheslav Dubeyko <slava@dubeyko.com>
+ *
+ * Compile with: gcc -o test_ml_lib_char_dev test_ml_lib_char_dev.c
+ * Run with:     sudo ./test_ml_lib_char_dev
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include "ml_lib_char_dev_ioctl.h"
+
+#define DEVICE_PATH "/dev/mllibdev"
+#define SYSFS_BASE "/sys/class/ml_lib_test/mllibdev"
+#define PROC_PATH "/proc/mllibdev"
+
+static void print_separator(const char *title)
+{
+	printf("\n========== %s ==========\n", title);
+}
+
+static void read_sysfs_attr(const char *attr_name)
+{
+	char path[256];
+	char buffer[256];
+	FILE *fp;
+
+	snprintf(path, sizeof(path), "%s/%s", SYSFS_BASE, attr_name);
+	fp = fopen(path, "r");
+	if (!fp) {
+		perror("Failed to open sysfs attribute");
+		return;
+	}
+
+	if (fgets(buffer, sizeof(buffer), fp)) {
+		printf("  %s: %s", attr_name, buffer);
+	}
+
+	fclose(fp);
+}
+
+static void show_sysfs_info(void)
+{
+	print_separator("Sysfs Attributes");
+	read_sysfs_attr("buffer_size");
+	read_sysfs_attr("data_size");
+	read_sysfs_attr("access_count");
+	printf("\n");
+	read_sysfs_attr("stats");
+}
+
+static void show_proc_info(void)
+{
+	char buffer[1024];
+	FILE *fp;
+
+	print_separator("Procfs Information");
+
+	fp = fopen(PROC_PATH, "r");
+	if (!fp) {
+		perror("Failed to open procfs entry");
+		return;
+	}
+
+	while (fgets(buffer, sizeof(buffer), fp)) {
+		printf("%s", buffer);
+	}
+
+	fclose(fp);
+}
+
+static void test_write(int fd)
+{
+	const char *test_data = "Hello from userspace! This is a test of the mllibdev driver.";
+	ssize_t ret;
+
+	print_separator("Write Test");
+
+	ret = write(fd, test_data, strlen(test_data));
+	if (ret < 0) {
+		perror("Write failed");
+		return;
+	}
+
+	printf("Successfully wrote %zd bytes\n", ret);
+	printf("Data: \"%s\"\n", test_data);
+}
+
+static void test_read(int fd)
+{
+	char buffer[256];
+	ssize_t ret;
+
+	print_separator("Read Test");
+
+	/* Seek to beginning */
+	lseek(fd, 0, SEEK_SET);
+
+	ret = read(fd, buffer, sizeof(buffer) - 1);
+	if (ret < 0) {
+		perror("Read failed");
+		return;
+	}
+
+	buffer[ret] = '\0';
+	printf("Successfully read %zd bytes\n", ret);
+	printf("Data: \"%s\"\n", buffer);
+}
+
+static void test_ioctl(int fd)
+{
+	int size;
+	int ret;
+
+	print_separator("IOCTL Tests");
+
+	/* Get current size */
+	ret = ioctl(fd, ML_LIB_TEST_DEV_IOCGETSIZE, &size);
+	if (ret < 0) {
+		perror("IOCTL GETSIZE failed");
+		return;
+	}
+	printf("Current data size: %d bytes\n", size);
+
+	/* Set new size */
+	size = 50;
+	ret = ioctl(fd, ML_LIB_TEST_DEV_IOCSETSIZE, &size);
+	if (ret < 0) {
+		perror("IOCTL SETSIZE failed");
+		return;
+	}
+	printf("Set data size to: %d bytes\n", size);
+
+	/* Verify new size */
+	ret = ioctl(fd, ML_LIB_TEST_DEV_IOCGETSIZE, &size);
+	if (ret < 0) {
+		perror("IOCTL GETSIZE failed");
+		return;
+	}
+	printf("Verified new size: %d bytes\n", size);
+
+	/* Reset buffer */
+	ret = ioctl(fd, ML_LIB_TEST_DEV_IOCRESET);
+	if (ret < 0) {
+		perror("IOCTL RESET failed");
+		return;
+	}
+	printf("Buffer reset successfully\n");
+
+	/* Verify size after reset */
+	ret = ioctl(fd, ML_LIB_TEST_DEV_IOCGETSIZE, &size);
+	if (ret < 0) {
+		perror("IOCTL GETSIZE failed");
+		return;
+	}
+	printf("Size after reset: %d bytes\n", size);
+}
+
+int main(void)
+{
+	int fd;
+
+	printf("ML Library Testing Device Driver Test Program\n");
+	printf("==================================\n");
+
+	/* Open the device */
+	fd = open(DEVICE_PATH, O_RDWR);
+	if (fd < 0) {
+		perror("Failed to open device");
+		printf("\nMake sure:\n");
+		printf("1. The driver module is loaded (lsmod | grep mllibdev)\n");
+		printf("2. You have proper permissions (run with sudo)\n");
+		printf("3. The device node exists (ls -l /dev/mllibdev)\n");
+		return 1;
+	}
+
+	printf("Device opened successfully: %s\n", DEVICE_PATH);
+
+	/* Run tests */
+	test_write(fd);
+	test_read(fd);
+	test_ioctl(fd);
+
+	/* Show sysfs and proc information */
+	show_sysfs_info();
+	show_proc_info();
+
+	/* Final stats */
+	print_separator("Final Test");
+	printf("All tests completed successfully!\n\n");
+
+	/* Close the device */
+	close(fd);
+
+	return 0;
+}
-- 
2.34.1



  parent reply	other threads:[~2026-02-06 19:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-06 19:11 [RFC PATCH v1 0/4] Machine Learning (ML) library in Linux kernel Viacheslav Dubeyko
2026-02-06 19:11 ` [RFC PATCH v1 1/4] ml-lib: Introduce Machine Learning (ML) library declarations Viacheslav Dubeyko
2026-02-07 15:52   ` Greg KH
2026-02-09 20:48     ` Viacheslav Dubeyko
2026-02-10  5:20       ` gregkh
2026-02-10 22:44         ` Viacheslav Dubeyko
2026-02-06 19:11 ` [RFC PATCH v1 2/4] ml-lib: Implement PoC of Machine Learning (ML) library functionality Viacheslav Dubeyko
2026-02-06 19:11 ` [RFC PATCH v1 3/4] ml-lib: Implement simple testing character device driver Viacheslav Dubeyko
2026-02-07 15:55   ` Greg KH
2026-02-09 20:56     ` Viacheslav Dubeyko
2026-02-10  5:21       ` greg
2026-02-06 19:11 ` Viacheslav Dubeyko [this message]
2026-02-06 22:59 ` [RFC PATCH v1 0/4] Machine Learning (ML) library in Linux kernel Jonathan Corbet
2026-02-09 20:33   ` Viacheslav Dubeyko

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=20260206191136.2609767-5-slava@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=Slava.Dubeyko@ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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