mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-06 07:55:28 -04:00
This follow-up patch completes centralization of kselftest.h and ksefltest_harness.h includes in remaining seltests files, replacing all relative paths with a non-relative paths using shared -I include path in lib.mk Tested with gcc-13.3 and clang-18.1, and cross-compiled successfully on riscv, arm64, x86_64 and powerpc arch. [reddybalavignesh9979@gmail.com: add selftests include path for kselftest.h] Link: https://lkml.kernel.org/r/20251017090201.317521-1-reddybalavignesh9979@gmail.com Link: https://lkml.kernel.org/r/20251016104409.68985-1-reddybalavignesh9979@gmail.com Signed-off-by: Bala-Vignesh-Reddy <reddybalavignesh9979@gmail.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Link: https://lore.kernel.org/lkml/20250820143954.33d95635e504e94df01930d0@linux-foundation.org/ Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Cc: David Hildenbrand <david@redhat.com> Cc: David S. Miller <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Günther Noack <gnoack@google.com> Cc: Jakub Kacinski <kuba@kernel.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Mickael Salaun <mic@digikod.net> Cc: Ming Lei <ming.lei@redhat.com> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Simon Horman <horms@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (c) 2025 Christian Brauner <brauner@kernel.org>
|
|
|
|
#define _GNU_SOURCE
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <linux/nsfs.h>
|
|
|
|
#include "kselftest_harness.h"
|
|
|
|
struct ns_info {
|
|
const char *name;
|
|
const char *proc_path;
|
|
unsigned int expected_ino;
|
|
};
|
|
|
|
static struct ns_info namespaces[] = {
|
|
{ "ipc", "/proc/1/ns/ipc", IPC_NS_INIT_INO },
|
|
{ "uts", "/proc/1/ns/uts", UTS_NS_INIT_INO },
|
|
{ "user", "/proc/1/ns/user", USER_NS_INIT_INO },
|
|
{ "pid", "/proc/1/ns/pid", PID_NS_INIT_INO },
|
|
{ "cgroup", "/proc/1/ns/cgroup", CGROUP_NS_INIT_INO },
|
|
{ "time", "/proc/1/ns/time", TIME_NS_INIT_INO },
|
|
{ "net", "/proc/1/ns/net", NET_NS_INIT_INO },
|
|
{ "mnt", "/proc/1/ns/mnt", MNT_NS_INIT_INO },
|
|
};
|
|
|
|
TEST(init_namespace_inodes)
|
|
{
|
|
struct stat st;
|
|
|
|
for (int i = 0; i < sizeof(namespaces) / sizeof(namespaces[0]); i++) {
|
|
int ret = stat(namespaces[i].proc_path, &st);
|
|
|
|
/* Some namespaces might not be available (e.g., time namespace on older kernels) */
|
|
if (ret < 0) {
|
|
if (errno == ENOENT) {
|
|
ksft_test_result_skip("%s namespace not available\n",
|
|
namespaces[i].name);
|
|
continue;
|
|
}
|
|
ASSERT_GE(ret, 0)
|
|
TH_LOG("Failed to stat %s: %s",
|
|
namespaces[i].proc_path, strerror(errno));
|
|
}
|
|
|
|
ASSERT_EQ(st.st_ino, namespaces[i].expected_ino)
|
|
TH_LOG("Namespace %s has inode 0x%lx, expected 0x%x",
|
|
namespaces[i].name, st.st_ino, namespaces[i].expected_ino);
|
|
|
|
ksft_print_msg("Namespace %s: inode 0x%lx matches expected 0x%x\n",
|
|
namespaces[i].name, st.st_ino, namespaces[i].expected_ino);
|
|
}
|
|
}
|
|
|
|
TEST_HARNESS_MAIN
|