linux_dsm_epyc7002/tools/testing/selftests/proc/proc.h
Alexey Dobriyan 61d47c4e71 proc: test /proc/self symlink
There are plans to change how /proc/self result is calculated,
for that a test is necessary.

Use direct system call because of this whole getpid caching story.

Link: http://lkml.kernel.org/r/20180627195103.GB18113@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:45 -07:00

47 lines
775 B
C

#pragma once
#undef NDEBUG
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
static inline pid_t sys_getpid(void)
{
return syscall(SYS_getpid);
}
static inline bool streq(const char *s1, const char *s2)
{
return strcmp(s1, s2) == 0;
}
static unsigned long long xstrtoull(const char *p, char **end)
{
if (*p == '0') {
*end = (char *)p + 1;
return 0;
} else if ('1' <= *p && *p <= '9') {
unsigned long long val;
errno = 0;
val = strtoull(p, end, 10);
assert(errno == 0);
return val;
} else
assert(0);
}
static struct dirent *xreaddir(DIR *d)
{
struct dirent *de;
errno = 0;
de = readdir(d);
assert(de || errno == 0);
return de;
}