@@ -6,13 +6,51 @@
* Author: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
*/
+#ifndef NOLIBC
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#endif
+
#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));
+ if (r == -1) {
+ close(fd);
+ ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno));
+ return;
+ }
+
+ close(fd);
+
+ if (r > 0 && buf[r - 1] == '\n')
+ buf[r - 1] = '\0';
+
+ if (strncmp("kunit-uapi-exam", buf, sizeof(buf)) != 0) {
+ ksft_test_result_fail("procfs: incorrect comm: %s\n", buf);
+ 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");
Show that the selftests are executed from a fairly "normal" userspace context. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> --- lib/kunit/kunit-uapi-example.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)