#include #include #include #include #include #include #include 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 ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define ERR_STRING_SZ 64 static int run_tests(void) { char err_string1[ERR_STRING_SZ]; char err_string2[ERR_STRING_SZ]; 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; strerror_r(-s->expect, err_string1, ERR_STRING_SZ); 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, err_string1, err_string2); err = -1; break; } else { close(fd); if (s->expect < 0) { 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, err_string1); err = -1; break; } } } return err; } int main(void) { int err = run_tests(); return err; } git/commit/tools?id=c14024dbb156c8392908aaa822097d27c6af8ec8'>commitdiff
path: root/tools
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2017-01-27 11:56:06 -0700
committerJens Axboe <axboe@fb.com>2017-01-27 11:56:06 -0700
commitc14024dbb156c8392908aaa822097d27c6af8ec8 (patch)
tree02f6ffa664b16bd76750c05f62708a518de2acdc /tools
parent08965c2eba135bdfb6e86cf25308e01421c7e0ce (diff)
parent3b4f18843e511193e7eb616710e838f5852e661d (diff)
Merge branch 'stable/for-jens-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen into for-linus
Konrad writes: Please pull in your 'for-linus' branch two little fixes for Xen block front: One fix is for handling the XEN_PAGE_SIZE != PAGE_SIZE (4KB vs 64KB on ARM for example) mishandling while the other is fixing the accounting for the configuration changes.
Diffstat (limited to 'tools')