From: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk into ve/ and reuse ve_selftest.h
Date: Thu, 19 Nov 2026 12:16:28 +0400 [thread overview]
Message-ID: <20261119081654.484107-4-mirian.shilakadze@virtuozzo.com> (raw)
In-Reply-To: <20261119081654.484107-1-mirian.shilakadze@virtuozzo.com>
ve_printk lives in its own selftests directory and drives the cgroup
side of its fixture by hand: it looks the cgroup2 mount up in
/proc/mounts, writes the control files through system("echo ..."),
searches the free ctid itself and has a path based enter_cgroup. The
openat based form of all of that is in ve_selftest.h, used by the other
ve tests.
Move the test and its two helper programs into
tools/testing/selftests/ve/, include ve_selftest.h and drop the local
copies. The fixture holds the fd of the host cgroup2 mount from
open_cg2_fd() instead of a path, creates its VE cgroup with make_ve and
removes it with destroy_ve, and the container child writes ve.state
through write_file_at on that fd. The vz.slice removal in the teardown
stays, since the kernel creates that cgroup when the container is
started. The includes that lose their last user with the local helpers
go too, together with the unused __STACK_SIZE define and time.h include
next to them.
The -I../../../../usr/include flag is dropped: the ve Makefile already
passes the same headers through KHDR_INCLUDES. Like the other ve tests,
the fixture now needs the host cgroup2 mount at /sys/fs/cgroup instead
of looking one up in /proc/mounts. The test cases are unchanged.
Feature: fix selftests
https://virtuozzo.atlassian.net/browse/VSTOR-139515
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
tools/testing/selftests/Makefile | 1 -
tools/testing/selftests/ve/.gitignore | 3 +
tools/testing/selftests/ve/Makefile | 2 +
.../selftests/{ve_printk => ve}/test_segf.c | 0
.../selftests/{ve_printk => ve}/test_trap.c | 0
.../{ve_printk => ve}/ve_printk_test.c | 176 ++++--------------
tools/testing/selftests/ve_printk/.gitignore | 3 -
tools/testing/selftests/ve_printk/Makefile | 8 -
8 files changed, 43 insertions(+), 150 deletions(-)
rename tools/testing/selftests/{ve_printk => ve}/test_segf.c (100%)
rename tools/testing/selftests/{ve_printk => ve}/test_trap.c (100%)
rename tools/testing/selftests/{ve_printk => ve}/ve_printk_test.c (77%)
delete mode 100644 tools/testing/selftests/ve_printk/.gitignore
delete mode 100644 tools/testing/selftests/ve_printk/Makefile
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 9f820344c16c..7f458f1bcb5c 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -118,7 +118,6 @@ TARGETS += uevent
TARGETS += user_events
TARGETS += vDSO
TARGETS += ve
-TARGETS += ve_printk
TARGETS += mm
TARGETS += vfio
TARGETS += x86
diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore
index 9b1a8911b4cf..9f0f4832326e 100644
--- a/tools/testing/selftests/ve/.gitignore
+++ b/tools/testing/selftests/ve/.gitignore
@@ -8,3 +8,6 @@ ve_aio_ring_test
ve_numa_syscalls_prohibited_test
ve_tmpfs_mpol_test
ve_devcg_bpf_test
+ve_printk_test
+test_segf
+test_trap
diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
index 38d92eecc3c8..36c068b4bb66 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -11,6 +11,8 @@ TEST_GEN_PROGS += ve_aio_ring_test
TEST_GEN_PROGS += ve_numa_syscalls_prohibited_test
TEST_GEN_PROGS += ve_tmpfs_mpol_test
TEST_GEN_PROGS += ve_devcg_bpf_test
+TEST_GEN_PROGS += ve_printk_test
+TEST_GEN_FILES += test_segf test_trap
# CPUID faulting is x86-64 only. ARCH says "x86" for 32-bit too and lib.mk
# picks the clang target by its emptiness, so decide by the compiler.
diff --git a/tools/testing/selftests/ve_printk/test_segf.c b/tools/testing/selftests/ve/test_segf.c
similarity index 100%
rename from tools/testing/selftests/ve_printk/test_segf.c
rename to tools/testing/selftests/ve/test_segf.c
diff --git a/tools/testing/selftests/ve_printk/test_trap.c b/tools/testing/selftests/ve/test_trap.c
similarity index 100%
rename from tools/testing/selftests/ve_printk/test_trap.c
rename to tools/testing/selftests/ve/test_trap.c
diff --git a/tools/testing/selftests/ve_printk/ve_printk_test.c b/tools/testing/selftests/ve/ve_printk_test.c
similarity index 77%
rename from tools/testing/selftests/ve_printk/ve_printk_test.c
rename to tools/testing/selftests/ve/ve_printk_test.c
index 020df691e5d5..fa8403da089f 100644
--- a/tools/testing/selftests/ve_printk/ve_printk_test.c
+++ b/tools/testing/selftests/ve/ve_printk_test.c
@@ -22,7 +22,6 @@
*/
#define _GNU_SOURCE
#include <linux/sched.h>
-#include <time.h>
#include <sched.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -31,119 +30,56 @@
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
-#include <sys/stat.h>
#include <sys/mount.h>
-#include <linux/limits.h>
-#include <errno.h>
#include "../kselftest_harness.h"
+#include "ve_selftest.h"
-#define __STACK_SIZE (8 * 1024 * 1024)
-#define CTID_MIN 108
-#define CTID_MAX 200
#define SEGFAULT_PROG "test_segf"
#define TRAP_PROG "test_trap"
#define TEST_RATELIMIT_BURST 10
#define TEST_RATELIMIT 5
-static int has_substr(char *buf, const char *str)
-{
- char *token;
- char *str_ptr = buf;
-
- while ((token = strsep(&str_ptr, ",")) != NULL) {
- if (!strcmp(token, str))
- return 1;
- }
- return 0;
-}
-
-static int get_mount_path(const char *fstype, const char *subsys, char *out, int size)
-{
- FILE *fp;
- int n;
- char buf[PATH_MAX];
- char target[4096];
- char ops[4096];
- char format[4096];
- int ret = 1;
-
- snprintf(format, sizeof(format), "%%*s %%4095s %s %%4095s", fstype);
-
- fp = fopen("/proc/mounts", "r");
- if (fp == NULL)
- return -1;
-
- while (fgets(buf, sizeof(buf), fp)) {
- n = sscanf(buf, format, target, ops);
- if (n != 2)
- continue;
- if (subsys == NULL || has_substr(ops, subsys)) {
- strncpy(out, target, size);
- out[size-1] = '\0';
- ret = 0;
- break;
- }
- }
- fclose(fp);
-
- return ret;
-}
-
FIXTURE(ve_printk)
{
- char cgv2_path[PATH_MAX];
+ int cgv2_fd;
int ctid;
};
FIXTURE_SETUP(ve_printk)
{
- char path[PATH_MAX * 2];
-
- ASSERT_EQ(get_mount_path("cgroup2", NULL, self->cgv2_path, sizeof(self->cgv2_path)), 0);
+ char ctid_str[16];
+ char path[64];
- snprintf(path, sizeof(path), "echo \"+cpuset +cpu +cpuacct +io +memory +hugetlb +pids +rdma +misc +ve\""
- " > %s/cgroup.subtree_control 2>/dev/null", self->cgv2_path);
- ASSERT_EQ(system(path), 0);
+ self->cgv2_fd = open_cg2_fd();
+ ASSERT_GE(self->cgv2_fd, 0);
- snprintf(path, sizeof(path), "echo \"/ rx\" > %s/ve.default_sysfs_permissions 2>/dev/null", self->cgv2_path);
- ASSERT_EQ(system(path), 0);
-
- snprintf(path, sizeof(path), "echo \"fs rx\" > %s/ve.default_sysfs_permissions 2>/dev/null", self->cgv2_path);
- ASSERT_EQ(system(path), 0);
-
- snprintf(path, sizeof(path), "echo \"fs/cgroup rw\" > %s/ve.default_sysfs_permissions 2>/dev/null", self->cgv2_path);
- ASSERT_EQ(system(path), 0);
-
- self->ctid = CTID_MIN;
- while (self->ctid < CTID_MAX) {
- snprintf(path, sizeof(path), "%s/%d", self->cgv2_path, self->ctid);
- if (access(path, F_OK) != 0 && errno == ENOENT) {
- break;
- }
- self->ctid++;
- }
- ASSERT_LT(self->ctid, CTID_MAX);
+ ASSERT_EQ(write_file_at(self->cgv2_fd, "cgroup.subtree_control",
+ VE_CONTROLLERS), 0);
- ASSERT_EQ(mkdir(path, 0755), 0);
+ ASSERT_EQ(write_file_at(self->cgv2_fd,
+ "ve.default_sysfs_permissions", "/ rx"), 0);
+ ASSERT_EQ(write_file_at(self->cgv2_fd,
+ "ve.default_sysfs_permissions", "fs rx"), 0);
+ ASSERT_EQ(write_file_at(self->cgv2_fd,
+ "ve.default_sysfs_permissions", "fs/cgroup rw"), 0);
- snprintf(path, sizeof(path), "echo -ve > %s/%d/cgroup.controllers_hidden",
- self->cgv2_path, self->ctid);
- ASSERT_EQ(system(path), 0);
+ self->ctid = make_ve(self->cgv2_fd, CTID_MIN);
+ ASSERT_GE(self->ctid, 0);
- snprintf(path, sizeof(path), "echo %d > %s/%d/ve.veid",
- self->ctid, self->cgv2_path, self->ctid);
- ASSERT_EQ(system(path), 0);
+ snprintf(ctid_str, sizeof(ctid_str), "%d", self->ctid);
+ snprintf(path, sizeof(path), "%d/ve.veid", self->ctid);
+ ASSERT_EQ(write_file_at(self->cgv2_fd, path, ctid_str), 0);
};
FIXTURE_TEARDOWN(ve_printk)
{
- char path[PATH_MAX * 2];
+ char path[64];
- snprintf(path, sizeof(path), "%s/%d/vz.slice", self->cgv2_path, self->ctid);
- rmdir(path);
- snprintf(path, sizeof(path), "%s/%d", self->cgv2_path, self->ctid);
- rmdir(path);
+ snprintf(path, sizeof(path), "%d/vz.slice", self->ctid);
+ unlinkat(self->cgv2_fd, path, AT_REMOVEDIR);
+ destroy_ve(self->cgv2_fd, self->ctid);
+ close(self->cgv2_fd);
}
int setup_timens(void)
@@ -169,7 +105,7 @@ int setup_timens(void)
}
struct fargs {
- char *cgve;
+ int cgv2_fd;
int ctid;
int test;
};
@@ -371,14 +307,12 @@ int child_func(void *arg)
int ret;
int fd;
struct fargs *args = (struct fargs *)arg;
- char cg_state[PATH_MAX];
+ char path[64];
ret = setup_timens();
if (ret)
return ret;
- snprintf(cg_state, sizeof(cg_state), "%s/%d/ve.state", args->cgve, args->ctid);
-
(void)umount2("/proc", MNT_DETACH);
ret = mount("proc", "/proc", "proc", 0, NULL);
if (ret < 0)
@@ -394,18 +328,10 @@ int child_func(void *arg)
}
close(fd);
- fd = open(cg_state, O_WRONLY);
- if (fd < 0) {
- return 1;
- }
-
- ret = write(fd, "START", strlen("START"));
- if (ret < 0 || ret != strlen("START")) {
- close(fd);
+ snprintf(path, sizeof(path), "%d/ve.state", args->ctid);
+ ret = write_file_at(args->cgv2_fd, path, "START");
+ if (ret < 0)
return 1;
- }
-
- close(fd);
switch (args->test) {
case TEST_LOG:
@@ -429,37 +355,11 @@ int child_func(void *arg)
return ret;
}
-int enter_cgroup(const char *cgroup, int ctid)
-{
- char cg_path[PATH_MAX];
- char pid_str[64];
- int fd;
- int ret = 0;
-
- if (ctid)
- snprintf(cg_path, sizeof(cg_path), "%s/%d/cgroup.procs", cgroup, ctid);
- else
- snprintf(cg_path, sizeof(cg_path), "%s/cgroup.procs", cgroup);
- snprintf(pid_str, sizeof(pid_str), "%d", getpid());
- fd = open(cg_path, O_WRONLY);
- if (fd < 0) {
- return -1;
- }
-
- ret = write(fd, pid_str, strlen(pid_str));
- if (ret < 0 || ret != strlen(pid_str)) {
- ret = -1;
- }
-
- close(fd);
- return ret;
-}
-
-int run_vzct(char *cgv2, int ctid, int testid)
+int run_vzct(int cgv2_fd, int ctid, int testid)
{
pid_t pid;
struct fargs args = {
- .cgve = cgv2,
+ .cgv2_fd = cgv2_fd,
.ctid = ctid,
.test = testid,
};
@@ -472,7 +372,7 @@ int run_vzct(char *cgv2, int ctid, int testid)
int status;
int ret;
- ret = enter_cgroup(cgv2, ctid);
+ ret = enter_cgroup(cgv2_fd, ctid);
if (ret < 0)
return -1;
@@ -489,7 +389,7 @@ int run_vzct(char *cgv2, int ctid, int testid)
if (WIFEXITED(status)) {
ret = WEXITSTATUS(status);
}
- enter_cgroup(cgv2, 0);
+ enter_cgroup(cgv2_fd, 0);
return ret;
}
@@ -566,7 +466,7 @@ TEST_F(ve_printk, ve_log)
fdmesg = open_dmesg();
ASSERT_NE(fdmesg, NULL);
- ret = run_vzct(self->cgv2_path, self->ctid, TEST_LOG);
+ ret = run_vzct(self->cgv2_fd, self->ctid, TEST_LOG);
ASSERT_EQ(ret, 0);
while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -595,7 +495,7 @@ TEST_F(ve_printk, ve0_log)
fdmesg = open_dmesg();
ASSERT_NE(fdmesg, NULL);
- ret = run_vzct(self->cgv2_path, self->ctid, TEST_LOGV0);
+ ret = run_vzct(self->cgv2_fd, self->ctid, TEST_LOGV0);
ASSERT_EQ(ret, 0);
while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -631,7 +531,7 @@ TEST_F(ve_printk, ve_log_both)
fdmesg = open_dmesg();
ASSERT_NE(fdmesg, NULL);
- ret = run_vzct(self->cgv2_path, self->ctid, TEST_LOGBOTH);
+ ret = run_vzct(self->cgv2_fd, self->ctid, TEST_LOGBOTH);
ASSERT_EQ(ret, 0);
while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -667,7 +567,7 @@ TEST_F(ve_printk, ve_printk_ratelimited)
fdmesg = open_dmesg();
ASSERT_NE(fdmesg, NULL);
- ret = run_vzct(self->cgv2_path, self->ctid, TEST_PR_RATELIMIT);
+ ret = run_vzct(self->cgv2_fd, self->ctid, TEST_PR_RATELIMIT);
ASSERT_EQ(ret, 0);
while (fgets(buf, sizeof(buf), fdmesg)) {
@@ -693,7 +593,7 @@ TEST_F(ve_printk, ve_printk_overflow)
ASSERT_EQ(set_param("/proc/sys/debug/exception-trace", 1, &ex_trace), 0);
- ret = run_vzct(self->cgv2_path, self->ctid, TEST_OVERFLOW);
+ ret = run_vzct(self->cgv2_fd, self->ctid, TEST_OVERFLOW);
ASSERT_EQ(ret, 0);
restore_param("/proc/sys/debug/exception-trace", ex_trace);
diff --git a/tools/testing/selftests/ve_printk/.gitignore b/tools/testing/selftests/ve_printk/.gitignore
deleted file mode 100644
index a4ad6620b803..000000000000
--- a/tools/testing/selftests/ve_printk/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-ve_printk_test
-test_segf
-test_trap
diff --git a/tools/testing/selftests/ve_printk/Makefile b/tools/testing/selftests/ve_printk/Makefile
deleted file mode 100644
index e3edcbacda1e..000000000000
--- a/tools/testing/selftests/ve_printk/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# Makefile for ve_printk selftests.
-CFLAGS = -g -I../../../../usr/include/ -Wall -O2
-
-TEST_GEN_PROGS += ve_printk_test
-TEST_GEN_FILES += test_segf test_trap
-
-include ../lib.mk
--
2.47.3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-19 8:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:16 [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Mirian Shilakadze
2026-11-19 8:16 ` [Devel] [PATCH hci-8.2 v2 1/3] selftests/ve: open the host cgroup2 mount instead of creating one Mirian Shilakadze
2026-11-19 8:21 ` no-reply
2026-11-19 17:00 ` Konstantin Khorenko
2026-11-19 8:16 ` [Devel] [PATCH hci-8.2 v2 2/3] selftests/ve: move ve_devcg_bpf into ve/ and reuse ve_selftest.h Mirian Shilakadze
2026-11-19 8:20 ` no-reply
2026-11-19 17:00 ` Konstantin Khorenko
2026-11-19 8:16 ` Mirian Shilakadze [this message]
2026-11-19 8:22 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: move ve_printk " no-reply
2026-11-19 17:00 ` Konstantin Khorenko
2026-11-19 17:00 ` [Devel] [PATCH hci-8.2 v2 0/3] selftests/ve: move ve_devcg_bpf and ve_printk into ve/ Konstantin Khorenko
2026-11-19 17:01 ` Konstantin Khorenko
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=20261119081654.484107-4-mirian.shilakadze@virtuozzo.com \
--to=mirian.shilakadze@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
--cc=vladimir.riabchun@virtuozzo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.