Files
linux-cryptodev-2.6/tools/testing/selftests/user_events/user_events_selftests.h
Bala-Vignesh-Reddy e6fbd1759c selftests: complete kselftest include centralization
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>
2025-11-27 14:24:31 -08:00

115 lines
2.1 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _USER_EVENTS_SELFTESTS_H
#define _USER_EVENTS_SELFTESTS_H
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <unistd.h>
#include <errno.h>
#include "kselftest.h"
static inline void tracefs_unmount(void)
{
umount("/sys/kernel/tracing");
}
static inline bool tracefs_enabled(char **message, bool *fail, bool *umount)
{
struct stat buf;
int ret;
*message = "";
*fail = false;
*umount = false;
/* Ensure tracefs is installed */
ret = stat("/sys/kernel/tracing", &buf);
if (ret == -1) {
*message = "Tracefs is not installed";
return false;
}
/* Ensure mounted tracefs */
ret = stat("/sys/kernel/tracing/README", &buf);
if (ret == -1 && errno == ENOENT) {
if (mount(NULL, "/sys/kernel/tracing", "tracefs", 0, NULL) != 0) {
*message = "Cannot mount tracefs";
*fail = true;
return false;
}
*umount = true;
ret = stat("/sys/kernel/tracing/README", &buf);
}
if (ret == -1) {
*message = "Cannot access tracefs";
*fail = true;
return false;
}
return true;
}
static inline bool user_events_enabled(char **message, bool *fail, bool *umount)
{
struct stat buf;
int ret;
*message = "";
*fail = false;
*umount = false;
if (getuid() != 0) {
*message = "Must be run as root";
*fail = true;
return false;
}
if (!tracefs_enabled(message, fail, umount))
return false;
/* Ensure user_events is installed */
ret = stat("/sys/kernel/tracing/user_events_data", &buf);
if (ret == -1) {
switch (errno) {
case ENOENT:
*message = "user_events is not installed";
return false;
default:
*message = "Cannot access user_events_data";
*fail = true;
return false;
}
}
return true;
}
#define USER_EVENT_FIXTURE_SETUP(statement, umount) do { \
char *message; \
bool fail; \
if (!user_events_enabled(&message, &fail, &(umount))) { \
if (fail) { \
TH_LOG("Setup failed due to: %s", message); \
ASSERT_FALSE(fail); \
} \
SKIP(statement, "Skipping due to: %s", message); \
} \
} while (0)
#define USER_EVENT_FIXTURE_TEARDOWN(umount) do { \
if ((umount)) \
tracefs_unmount(); \
} while (0)
#endif /* _USER_EVENTS_SELFTESTS_H */