From b8d94bb9270d4c3a05dbcac6f0272105edc56fb5 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 19:28:02 +0000 Subject: Apply patch 0003-test-Implement-self-test-functionality.patch patch_name: 0003-test-Implement-self-test-functionality.patch present_in_specfile: true location_in_specfile: 3 --- diff --git a/test/test.c b/test/test.c index 224c1b4..7eaaaed 100644 --- a/test/test.c +++ b/test/test.c @@ -32,14 +32,23 @@ */ #define _GNU_SOURCE +#include #include #include +#include #include #include #include #include #include +#define assert(x) do { \ + if (!(x)) { \ + printf("%s:%d: assertion '" #x "' failed!\n", __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } \ +} while (0) + int main(void); int main() @@ -47,6 +56,11 @@ int main() int s; int optval; socklen_t optlen = sizeof(optval); + const char *env; + bool selftest = false; + + env = getenv("SELFTEST"); + selftest = env && !strcasecmp(env, "on"); if((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("socket()"); @@ -58,7 +72,12 @@ int main() close(s); exit(EXIT_FAILURE); } - printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF")); + if (selftest) { + env = getenv("KEEPALIVE"); + assert((env && !strcasecmp(env, "off")) ^ optval); + } else { + printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF")); + } if(optval) { #ifdef TCP_KEEPCNT @@ -67,7 +86,12 @@ int main() close(s); exit(EXIT_FAILURE); } - printf("TCP_KEEPCNT = %d\n", optval); + if (selftest) { + env = getenv("KEEPCNT"); + assert(!env || atoi(env) == optval); + } else { + printf("TCP_KEEPCNT = %d\n", optval); + } #endif #ifdef TCP_KEEPIDLE @@ -76,7 +100,12 @@ int main() close(s); exit(EXIT_FAILURE); } - printf("TCP_KEEPIDLE = %d\n", optval); + if (selftest) { + env = getenv("KEEPIDLE"); + assert(!env || atoi(env) == optval); + } else { + printf("TCP_KEEPIDLE = %d\n", optval); + } #endif #ifdef TCP_KEEPINTVL @@ -85,7 +114,12 @@ int main() close(s); exit(EXIT_FAILURE); } - printf("TCP_KEEPINTVL = %d\n", optval); + if (selftest) { + env = getenv("KEEPINTVL"); + assert(!env || atoi(env) == optval); + } else { + printf("TCP_KEEPINTVL = %d\n", optval); + } #endif }