mirror of
https://github.com/torvalds/linux.git
synced 2026-01-25 07:47:50 +00: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>
96 lines
1.9 KiB
C
96 lines
1.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
|
|
#include "kselftest.h"
|
|
|
|
struct socket_testcase {
|
|
int domain;
|
|
int type;
|
|
int protocol;
|
|
|
|
/* 0 = valid file descriptor
|
|
* -foo = error foo
|
|
*/
|
|
int expect;
|
|
|
|
/* If non-zero, accept EAFNOSUPPORT to handle the case
|
|
* of the protocol not being configured into the kernel.
|
|
*/
|
|
int nosupport_ok;
|
|
};
|
|
|
|
static struct socket_testcase tests[] = {
|
|
{ AF_MAX, 0, 0, -EAFNOSUPPORT, 0 },
|
|
{ AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 1 },
|
|
{ AF_INET, SOCK_DGRAM, IPPROTO_TCP, -EPROTONOSUPPORT, 1 },
|
|
{ AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 1 },
|
|
{ AF_INET, SOCK_STREAM, IPPROTO_UDP, -EPROTONOSUPPORT, 1 },
|
|
};
|
|
|
|
#define ERR_STRING_SZ 64
|
|
|
|
static int run_tests(void)
|
|
{
|
|
char err_string1[ERR_STRING_SZ];
|
|
char err_string2[ERR_STRING_SZ];
|
|
const char *msg1, *msg2;
|
|
int i, err;
|
|
|
|
err = 0;
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++) {
|
|
struct socket_testcase *s = &tests[i];
|
|
int fd;
|
|
|
|
fd = socket(s->domain, s->type, s->protocol);
|
|
if (fd < 0) {
|
|
if (s->nosupport_ok &&
|
|
errno == EAFNOSUPPORT)
|
|
continue;
|
|
|
|
if (s->expect < 0 &&
|
|
errno == -s->expect)
|
|
continue;
|
|
|
|
msg1 = strerror_r(-s->expect, err_string1, ERR_STRING_SZ);
|
|
msg2 = strerror_r(errno, err_string2, ERR_STRING_SZ);
|
|
|
|
fprintf(stderr, "socket(%d, %d, %d) expected "
|
|
"err (%s) got (%s)\n",
|
|
s->domain, s->type, s->protocol,
|
|
msg1, msg2);
|
|
|
|
err = -1;
|
|
break;
|
|
} else {
|
|
close(fd);
|
|
|
|
if (s->expect < 0) {
|
|
msg1 = strerror_r(errno, err_string1, ERR_STRING_SZ);
|
|
|
|
fprintf(stderr, "socket(%d, %d, %d) expected "
|
|
"success got err (%s)\n",
|
|
s->domain, s->type, s->protocol,
|
|
msg1);
|
|
|
|
err = -1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int err = run_tests();
|
|
|
|
return err;
|
|
}
|