1 /* Multithread-safety test for nl_langinfo().
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2019. */
21 #if USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS
32 #include "glthread/thread.h"
35 /* Some common locale names. */
37 #if defined _WIN32 && !defined __CYGWIN__
38 # define ENGLISH "English_United States"
39 # define FRENCH "French_France"
40 # define GERMAN "German_Germany"
41 # define ENCODING ".1252"
43 # define ENGLISH "en_US"
44 # define FRENCH "fr_FR"
45 # define GERMAN "de_DE"
47 # define ENCODING ".ISO8859-15"
49 # define ENCODING ".utf8"
51 # define ENCODING ".UTF-8"
55 static const char LOCALE1
[] = ENGLISH ENCODING
;
56 static const char LOCALE2
[] = FRENCH ENCODING
;
57 static const char LOCALE3
[] = GERMAN ENCODING
;
59 static char *expected1
;
62 thread1_func (void *arg
)
66 const char *value
= nl_langinfo (CODESET
);
67 if (strcmp (expected1
, value
) != 0)
69 fprintf (stderr
, "thread1 disturbed by threadN!\n"); fflush (stderr
);
78 static char *expected2
;
81 thread2_func (void *arg
)
85 const char *value
= nl_langinfo (PM_STR
);
86 if (strcmp (expected2
, value
) != 0)
88 fprintf (stderr
, "thread2 disturbed by threadN!\n"); fflush (stderr
);
97 static char *expected3
;
100 thread3_func (void *arg
)
104 const char *value
= nl_langinfo (DAY_2
);
105 if (strcmp (expected3
, value
) != 0)
107 fprintf (stderr
, "thread3 disturbed by threadN!\n"); fflush (stderr
);
116 static char *expected4
;
119 thread4_func (void *arg
)
123 const char *value
= nl_langinfo (ALTMON_2
);
124 if (strcmp (expected4
, value
) != 0)
126 fprintf (stderr
, "thread4 disturbed by threadN!\n"); fflush (stderr
);
135 static char *expected5
;
138 thread5_func (void *arg
)
142 const char *value
= nl_langinfo (CRNCYSTR
);
143 if (strcmp (expected5
, value
) != 0)
145 fprintf (stderr
, "thread5 disturbed by threadN!\n"); fflush (stderr
);
154 static char *expected6
;
157 thread6_func (void *arg
)
161 const char *value
= nl_langinfo (RADIXCHAR
);
162 if (strcmp (expected6
, value
) != 0)
164 fprintf (stderr
, "thread6 disturbed by threadN!\n"); fflush (stderr
);
174 threadN_func (void *arg
)
178 nl_langinfo (CODESET
); /* LC_CTYPE */ /* locale charmap */
179 nl_langinfo (AM_STR
); /* LC_TIME */ /* locale -k am_pm */
180 nl_langinfo (PM_STR
); /* LC_TIME */ /* locale -k am_pm */
181 nl_langinfo (DAY_2
); /* LC_TIME */ /* locale -k day */
182 nl_langinfo (DAY_5
); /* LC_TIME */ /* locale -k day */
183 nl_langinfo (ALTMON_2
); /* LC_TIME */ /* locale -k alt_mon */
184 nl_langinfo (ALTMON_9
); /* LC_TIME */ /* locale -k alt_mon */
185 nl_langinfo (CRNCYSTR
); /* LC_MONETARY */ /* locale -k currency_symbol */
186 nl_langinfo (RADIXCHAR
); /* LC_NUMERIC */ /* locale -k decimal_point */
187 nl_langinfo (THOUSEP
); /* LC_NUMERIC */ /* locale -k thousands_sep */
195 main (int argc
, char *argv
[])
197 if (setlocale (LC_ALL
, LOCALE1
) == NULL
)
199 fprintf (stderr
, "Skipping test: LOCALE1 not recognized\n");
202 if (setlocale (LC_MONETARY
, LOCALE2
) == NULL
)
204 fprintf (stderr
, "Skipping test: LOCALE2 not recognized\n");
207 if (setlocale (LC_NUMERIC
, LOCALE3
) == NULL
)
209 fprintf (stderr
, "Skipping test: LOCALE3 not recognized\n");
213 expected1
= strdup (nl_langinfo (CODESET
));
214 expected2
= strdup (nl_langinfo (PM_STR
));
215 expected3
= strdup (nl_langinfo (DAY_2
));
216 expected4
= strdup (nl_langinfo (ALTMON_2
));
217 expected5
= strdup (nl_langinfo (CRNCYSTR
));
218 expected6
= strdup (nl_langinfo (RADIXCHAR
));
220 /* Create the checker threads. */
221 gl_thread_create (thread1_func
, NULL
);
222 gl_thread_create (thread2_func
, NULL
);
223 gl_thread_create (thread3_func
, NULL
);
224 gl_thread_create (thread4_func
, NULL
);
225 gl_thread_create (thread5_func
, NULL
);
226 gl_thread_create (thread6_func
, NULL
);
227 /* Create the disturber thread. */
228 gl_thread_create (threadN_func
, NULL
);
230 /* Let them run for 2 seconds. */
232 struct timespec duration
;
233 duration
.tv_sec
= (argc
> 1 ? atoi (argv
[1]) : 2);
234 duration
.tv_nsec
= 0;
236 nanosleep (&duration
, NULL
);
244 /* No multithreading available. */
251 fputs ("Skipping test: multithreading not enabled\n", stderr
);