summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/gdbm-lockwait-test.patch
blob: 95c0ffb225f79aebebc7498f5e640777eb96ac51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
Taken from
https://git.savannah.gnu.org/cgit/gdbm.git/commit/?id=5be83b4c5da7c6a68817908b19f8925af09e9b2c
https://git.savannah.gnu.org/cgit/gdbm.git/commit/?id=6f165a8e1745dbd9b88f6fb6882dff7997cfdf74
https://git.savannah.gnu.org/cgit/gdbm.git/commit/?id=aa9baca52ad155ae501ba586ff7b08f4b08e5434
Can be removed with 1.26.

From 5be83b4c5da7c6a68817908b19f8925af09e9b2c Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Thu, 10 Apr 2025 17:31:56 +0300
Subject: Fix timeout calculation in lockwait signal test.

* tests/t_lockwait.c (runtest_signal): mark start time right
after setting alarm, not before it.
---
 tests/t_lockwait.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tests/t_lockwait.c b/tests/t_lockwait.c
index a5e74c8..3547af7 100644
--- a/tests/t_lockwait.c
+++ b/tests/t_lockwait.c
@@ -323,9 +323,6 @@ runtest_signal (struct timespec *ts)
       struct sigaction act;
       struct timeval now;
 
-      gettimeofday (&now, NULL);
-      start = tv_to_ms (&now);
-
       if (pipe (sig_fd))
 	{
 	  perror ("pipe");
@@ -341,6 +338,8 @@ runtest_signal (struct timespec *ts)
 	  return -1;
 	}
       alarm (ts_to_ms (&ts[1]) / MILLI);
+      gettimeofday (&now, NULL);
+      start = tv_to_ms (&now);
     }
 
   op.lock_wait = GDBM_LOCKWAIT_SIGNAL;
-- 
cgit v1.1

From 6f165a8e1745dbd9b88f6fb6882dff7997cfdf74 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Thu, 10 Apr 2025 21:07:41 +0300
Subject: More fixes to lockwait test

* tests/t_lockwait.c (sighan): Close fd.
(runtest_signal): compensate for alarm(2) second precision
---
 tests/t_lockwait.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/t_lockwait.c b/tests/t_lockwait.c
index 3547af7..b378819 100644
--- a/tests/t_lockwait.c
+++ b/tests/t_lockwait.c
@@ -170,6 +170,7 @@ static void
 sighan (int sig)
 {
   write (sig_fd[1], &sig, sizeof (sig));
+  close (sig_fd[1]);
 }
 
 static int runtest_retry (struct timespec *ts);
@@ -364,7 +365,8 @@ runtest_signal (struct timespec *ts)
 
       pfd.fd = sig_fd[0];
       pfd.events = POLLIN;
-      switch (poll (&pfd, 1, ts_to_ms (&ts[1]) - tv_to_ms (&now) + start)) {
+      switch (poll (&pfd, 1,
+		    ts_to_ms (&ts[1]) - tv_to_ms (&now) + start + MILLI)) {
       case 1:
 	break;
 
-- 
cgit v1.1

From aa9baca52ad155ae501ba586ff7b08f4b08e5434 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Fri, 11 Apr 2025 07:53:58 +0300
Subject: Adjust timeouts for setitimer interface in lockwait test.

* tests/t_lockwait.c: Setitimer (at least on some systems) restarts
the timer set by alarm(2). To calculate the ETA of SIGALRM, call
alarm after gdbm_open_ext returns.
---
 tests/t_lockwait.c | 66 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 27 deletions(-)

diff --git a/tests/t_lockwait.c b/tests/t_lockwait.c
index b378819..dfae838 100644
--- a/tests/t_lockwait.c
+++ b/tests/t_lockwait.c
@@ -322,7 +322,6 @@ runtest_signal (struct timespec *ts)
   if (!(ts[1].tv_sec == 0 && ts[1].tv_nsec == 0))
     {
       struct sigaction act;
-      struct timeval now;
 
       if (pipe (sig_fd))
 	{
@@ -338,9 +337,6 @@ runtest_signal (struct timespec *ts)
 	  fprintf (stderr, "%s: sigaction: %s", progname, strerror (errno));
 	  return -1;
 	}
-      alarm (ts_to_ms (&ts[1]) / MILLI);
-      gettimeofday (&now, NULL);
-      start = tv_to_ms (&now);
     }
 
   op.lock_wait = GDBM_LOCKWAIT_SIGNAL;
@@ -354,42 +350,58 @@ runtest_signal (struct timespec *ts)
     }
   gdbm_close (dbf);
 
-  if (start > 0)
+  if (!(ts[1].tv_sec == 0 && ts[1].tv_nsec == 0))
     {
       struct pollfd pfd;
       struct timeval now;
-      int sig;
+      int n, t, sig;
 
-    restart:
+      alarm (ts_to_ms (&ts[1]) / MILLI);
       gettimeofday (&now, NULL);
+      start = tv_to_ms (&now);
 
       pfd.fd = sig_fd[0];
       pfd.events = POLLIN;
-      switch (poll (&pfd, 1,
-		    ts_to_ms (&ts[1]) - tv_to_ms (&now) + start + MILLI)) {
-      case 1:
-	break;
 
-      case 0:
-	fprintf (stderr, "%s: failed waiting for alarm\n", progname);
-	return 1;
-
-      default:
-	if (errno == EINTR) goto restart;
-	fprintf (stderr, "%s: poll: %s\n", progname, strerror (errno));
-	return 1;
-      }
-
-      if (read (sig_fd[0], &sig, sizeof (sig)) != sizeof (sig))
+      do
 	{
-	  fprintf (stderr, "%s: read: %s\n", progname, strerror (errno));
-	  return 1;
+	  gettimeofday (&now, NULL);
+	  t = ts_to_ms (&ts[1]) - tv_to_ms (&now) + start + MILLI;
+	  if (t < 0)
+	    {
+	      n = 0;
+	      break;
+	    }
 	}
-      close (sig_fd[0]);
-      if (sig != SIGALRM)
+      while ((n = poll (&pfd, 1, t)) == -1 && errno == EINTR);
+
+      switch (n)
 	{
-	  fprintf (stderr, "%s: unexpected data read\n", progname);
+	case 1:
+	  if (read (sig_fd[0], &sig, sizeof (sig)) != sizeof (sig))
+	    {
+	      fprintf (stderr, "%s: read: %s\n", progname, strerror (errno));
+	      return 1;
+	    }
+	  close (sig_fd[0]);
+	  if (sig != SIGALRM)
+	    {
+	      fprintf (stderr, "%s: unexpected data read\n", progname);
+	      return 1;
+	    }
+	  break;
+
+	case 0:
+	  fprintf (stderr, "%s: failed waiting for alarm\n", progname);
 	  return 1;
+
+	default:
+	  if (errno != EINTR)
+	    {
+	      fprintf (stderr, "%s: poll: %s\n",
+		       progname, strerror (errno));
+	      return 1;
+	    }
 	}
     }
 
-- 
cgit v1.1