Package: glib2.0 / 2.58.3-2

gwakeuptest-Be-less-parallel-unless-invoked-with-m-slow.patch Patch series | download
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
From: Simon McVittie <smcv@debian.org>
Date: Mon, 18 Dec 2017 18:06:05 +0000
Subject: gwakeuptest: Be less parallel unless invoked with -m slow

This is a workaround for test failures on the reproducible-builds
infrastructure, where a multi-threaded stress-test sometimes takes longer
to finish on x86_64 than it would have done on slow architectures like
arm and mips on the official Debian autobuilders. It is not clear why.

This change will make this test more likely to pass, but less likely to
detect bugs.

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug-Debian: https://bugs.debian.org/884659
Forwarded: no
---
 glib/tests/gwakeuptest.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/glib/tests/gwakeuptest.c b/glib/tests/gwakeuptest.c
index 2ec29bd..2111483 100644
--- a/glib/tests/gwakeuptest.c
+++ b/glib/tests/gwakeuptest.c
@@ -89,6 +89,9 @@ struct context
 #define NUM_TOKENS       5
 #define TOKEN_TTL   100000
 
+static gint num_threads = NUM_THREADS;
+static gint token_ttl = TOKEN_TTL;
+
 static struct context contexts[NUM_THREADS];
 static GThread *threads[NUM_THREADS];
 static GWakeup *last_token_wakeup;
@@ -155,7 +158,7 @@ dispatch_token (struct token *token)
       struct context *ctx;
       gint next_ctx;
 
-      next_ctx = g_test_rand_int_range (0, NUM_THREADS);
+      next_ctx = g_test_rand_int_range (0, num_threads);
       ctx = &contexts[next_ctx];
       token->owner = ctx;
       token->ttl--;
@@ -212,6 +215,12 @@ test_threaded (void)
 {
   gint i;
 
+  if (!g_test_slow ())
+    {
+      num_threads = NUM_THREADS / 10;
+      token_ttl = TOKEN_TTL / 10;
+    }
+
   /* make sure we don't block forever */
   alarm (60);
 
@@ -229,7 +238,7 @@ test_threaded (void)
   last_token_wakeup = g_wakeup_new ();
 
   /* create contexts, assign to threads */
-  for (i = 0; i < NUM_THREADS; i++)
+  for (i = 0; i < num_threads; i++)
     {
       context_init (&contexts[i]);
       threads[i] = g_thread_new ("test", thread_func, &contexts[i]);
@@ -237,13 +246,13 @@ test_threaded (void)
 
   /* dispatch tokens */
   for (i = 0; i < NUM_TOKENS; i++)
-    dispatch_token (token_new (TOKEN_TTL));
+    dispatch_token (token_new (token_ttl));
 
   /* wait until all tokens are gone */
   wait_for_signaled (last_token_wakeup);
 
   /* ask threads to quit, join them, cleanup */
-  for (i = 0; i < NUM_THREADS; i++)
+  for (i = 0; i < num_threads; i++)
     {
       context_quit (&contexts[i]);
       g_thread_join (threads[i]);