Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 192 lines 5.1 kB view raw
1From 5be83b4c5da7c6a68817908b19f8925af09e9b2c Mon Sep 17 00:00:00 2001 2From: Sergey Poznyakoff <gray@gnu.org> 3Date: Thu, 10 Apr 2025 17:31:56 +0300 4Subject: Fix timeout calculation in lockwait signal test. 5 6* tests/t_lockwait.c (runtest_signal): mark start time right 7after setting alarm, not before it. 8--- 9 tests/t_lockwait.c | 5 ++--- 10 1 file changed, 2 insertions(+), 3 deletions(-) 11 12diff --git a/tests/t_lockwait.c b/tests/t_lockwait.c 13index a5e74c8..3547af7 100644 14--- a/tests/t_lockwait.c 15+++ b/tests/t_lockwait.c 16@@ -323,9 +323,6 @@ runtest_signal (struct timespec *ts) 17 struct sigaction act; 18 struct timeval now; 19 20- gettimeofday (&now, NULL); 21- start = tv_to_ms (&now); 22- 23 if (pipe (sig_fd)) 24 { 25 perror ("pipe"); 26@@ -341,6 +338,8 @@ runtest_signal (struct timespec *ts) 27 return -1; 28 } 29 alarm (ts_to_ms (&ts[1]) / MILLI); 30+ gettimeofday (&now, NULL); 31+ start = tv_to_ms (&now); 32 } 33 34 op.lock_wait = GDBM_LOCKWAIT_SIGNAL; 35-- 36cgit v1.2.3 37 38From 6f165a8e1745dbd9b88f6fb6882dff7997cfdf74 Mon Sep 17 00:00:00 2001 39From: Sergey Poznyakoff <gray@gnu.org> 40Date: Thu, 10 Apr 2025 21:07:41 +0300 41Subject: More fixes to lockwait test 42 43* tests/t_lockwait.c (sighan): Close fd. 44(runtest_signal): compensate for alarm(2) second precision 45--- 46 tests/t_lockwait.c | 4 +++- 47 1 file changed, 3 insertions(+), 1 deletion(-) 48 49diff --git a/tests/t_lockwait.c b/tests/t_lockwait.c 50index 3547af7..b378819 100644 51--- a/tests/t_lockwait.c 52+++ b/tests/t_lockwait.c 53@@ -170,6 +170,7 @@ static void 54 sighan (int sig) 55 { 56 write (sig_fd[1], &sig, sizeof (sig)); 57+ close (sig_fd[1]); 58 } 59 60 static int runtest_retry (struct timespec *ts); 61@@ -364,7 +365,8 @@ runtest_signal (struct timespec *ts) 62 63 pfd.fd = sig_fd[0]; 64 pfd.events = POLLIN; 65- switch (poll (&pfd, 1, ts_to_ms (&ts[1]) - tv_to_ms (&now) + start)) { 66+ switch (poll (&pfd, 1, 67+ ts_to_ms (&ts[1]) - tv_to_ms (&now) + start + MILLI)) { 68 case 1: 69 break; 70 71-- 72cgit v1.2.3 73 74From aa9baca52ad155ae501ba586ff7b08f4b08e5434 Mon Sep 17 00:00:00 2001 75From: Sergey Poznyakoff <gray@gnu.org> 76Date: Fri, 11 Apr 2025 07:53:58 +0300 77Subject: Adjust timeouts for setitimer interface in lockwait test. 78 79* tests/t_lockwait.c: Setitimer (at least on some systems) restarts 80the timer set by alarm(2). To calculate the ETA of SIGALRM, call 81alarm after gdbm_open_ext returns. 82--- 83 tests/t_lockwait.c | 66 ++++++++++++++++++++++++++++++++---------------------- 84 1 file changed, 39 insertions(+), 27 deletions(-) 85 86diff --git a/tests/t_lockwait.c b/tests/t_lockwait.c 87index b378819..dfae838 100644 88--- a/tests/t_lockwait.c 89+++ b/tests/t_lockwait.c 90@@ -322,7 +322,6 @@ runtest_signal (struct timespec *ts) 91 if (!(ts[1].tv_sec == 0 && ts[1].tv_nsec == 0)) 92 { 93 struct sigaction act; 94- struct timeval now; 95 96 if (pipe (sig_fd)) 97 { 98@@ -338,9 +337,6 @@ runtest_signal (struct timespec *ts) 99 fprintf (stderr, "%s: sigaction: %s", progname, strerror (errno)); 100 return -1; 101 } 102- alarm (ts_to_ms (&ts[1]) / MILLI); 103- gettimeofday (&now, NULL); 104- start = tv_to_ms (&now); 105 } 106 107 op.lock_wait = GDBM_LOCKWAIT_SIGNAL; 108@@ -354,42 +350,58 @@ runtest_signal (struct timespec *ts) 109 } 110 gdbm_close (dbf); 111 112- if (start > 0) 113+ if (!(ts[1].tv_sec == 0 && ts[1].tv_nsec == 0)) 114 { 115 struct pollfd pfd; 116 struct timeval now; 117- int sig; 118+ int n, t, sig; 119 120- restart: 121+ alarm (ts_to_ms (&ts[1]) / MILLI); 122 gettimeofday (&now, NULL); 123+ start = tv_to_ms (&now); 124 125 pfd.fd = sig_fd[0]; 126 pfd.events = POLLIN; 127- switch (poll (&pfd, 1, 128- ts_to_ms (&ts[1]) - tv_to_ms (&now) + start + MILLI)) { 129- case 1: 130- break; 131 132- case 0: 133- fprintf (stderr, "%s: failed waiting for alarm\n", progname); 134- return 1; 135- 136- default: 137- if (errno == EINTR) goto restart; 138- fprintf (stderr, "%s: poll: %s\n", progname, strerror (errno)); 139- return 1; 140- } 141- 142- if (read (sig_fd[0], &sig, sizeof (sig)) != sizeof (sig)) 143+ do 144 { 145- fprintf (stderr, "%s: read: %s\n", progname, strerror (errno)); 146- return 1; 147+ gettimeofday (&now, NULL); 148+ t = ts_to_ms (&ts[1]) - tv_to_ms (&now) + start + MILLI; 149+ if (t < 0) 150+ { 151+ n = 0; 152+ break; 153+ } 154 } 155- close (sig_fd[0]); 156- if (sig != SIGALRM) 157+ while ((n = poll (&pfd, 1, t)) == -1 && errno == EINTR); 158+ 159+ switch (n) 160 { 161- fprintf (stderr, "%s: unexpected data read\n", progname); 162+ case 1: 163+ if (read (sig_fd[0], &sig, sizeof (sig)) != sizeof (sig)) 164+ { 165+ fprintf (stderr, "%s: read: %s\n", progname, strerror (errno)); 166+ return 1; 167+ } 168+ close (sig_fd[0]); 169+ if (sig != SIGALRM) 170+ { 171+ fprintf (stderr, "%s: unexpected data read\n", progname); 172+ return 1; 173+ } 174+ break; 175+ 176+ case 0: 177+ fprintf (stderr, "%s: failed waiting for alarm\n", progname); 178 return 1; 179+ 180+ default: 181+ if (errno != EINTR) 182+ { 183+ fprintf (stderr, "%s: poll: %s\n", 184+ progname, strerror (errno)); 185+ return 1; 186+ } 187 } 188 } 189 190-- 191cgit v1.2.3 192