Skip to content

Commit ca8f618

Browse files
committedMar 19, 2025
fish: fix aarch64-linux test failures
Parallel locale changes cause flaky tests on fast harder.
1 parent f88a223 commit ca8f618

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
From 1d78c8bd4295262a3118f478e6b3a7c7536fa282 Mon Sep 17 00:00:00 2001
2+
From: Johannes Altmanninger <aclopte@gmail.com>
3+
Date: Wed, 19 Mar 2025 09:39:04 +0100
4+
Subject: [PATCH] Fix concurrent setlocale() in string escape tests
5+
6+
In our C++ implementation, these tests were run serially. As pointed out in
7+
https://github.com/fish-shell/fish-shell/issues/11254#issuecomment-2735623229
8+
we run them in parallel now, which means that one test could be changing
9+
the global locale used by another.
10+
11+
In theory this could be fine because all tests are setting setting the
12+
global locale to the same thing but the existence of a lock suggests that
13+
setlocale() is not guaranteed to be atomic, so it's possible that another
14+
thread uses a temporarily-invalid locale.
15+
16+
Fixes #11254
17+
---
18+
src/tests/string_escape.rs | 14 ++++++++------
19+
1 file changed, 8 insertions(+), 6 deletions(-)
20+
21+
diff --git a/src/tests/string_escape.rs b/src/tests/string_escape.rs
22+
index ba8ee7534ebf..4428d679cd35 100644
23+
--- a/src/tests/string_escape.rs
24+
+++ b/src/tests/string_escape.rs
25+
@@ -1,3 +1,5 @@
26+
+use std::sync::MutexGuard;
27+
+
28+
use crate::common::{
29+
escape_string, str2wcstring, unescape_string, wcs2string, EscapeFlags, EscapeStringStyle,
30+
UnescapeStringStyle, ENCODE_DIRECT_BASE, ENCODE_DIRECT_END,
31+
@@ -10,21 +12,21 @@ use rand::{Rng, RngCore};
32+
33+
/// wcs2string is locale-dependent, so ensure we have a multibyte locale
34+
/// before using it in a test.
35+
-fn setlocale() {
36+
- let _guard = LOCALE_LOCK.lock().unwrap();
37+
+fn setlocale() -> MutexGuard<'static, ()> {
38+
+ let guard = LOCALE_LOCK.lock().unwrap();
39+
40+
#[rustfmt::skip]
41+
const UTF8_LOCALES: &[&str] = &[
42+
"C.UTF-8", "en_US.UTF-8", "en_GB.UTF-8", "de_DE.UTF-8", "C.utf8", "UTF-8",
43+
];
44+
if crate::libc::MB_CUR_MAX() > 1 {
45+
- return;
46+
+ return guard;
47+
}
48+
for locale in UTF8_LOCALES {
49+
let locale = std::ffi::CString::new(locale.to_owned()).unwrap();
50+
unsafe { libc::setlocale(libc::LC_CTYPE, locale.as_ptr()) };
51+
if crate::libc::MB_CUR_MAX() > 1 {
52+
- return;
53+
+ return guard;
54+
}
55+
}
56+
panic!("No UTF-8 locale found");
57+
@@ -100,7 +102,7 @@ fn test_escape_var() {
58+
}
59+
60+
fn escape_test(escape_style: EscapeStringStyle, unescape_style: UnescapeStringStyle) {
61+
- setlocale();
62+
+ let _locale_guard = setlocale();
63+
let seed: u128 = 92348567983274852905629743984572;
64+
let mut rng = get_seeded_rng(seed);
65+
66+
@@ -174,7 +176,7 @@ fn str2hex(input: &[u8]) -> String {
67+
/// string comes back through double conversion.
68+
#[test]
69+
fn test_convert() {
70+
- setlocale();
71+
+ let _locale_guard = setlocale();
72+
let seed = get_rng_seed();
73+
let mut rng = get_seeded_rng(seed);
74+
let mut origin = Vec::new();

‎pkgs/by-name/fi/fish/package.nix

+6-6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ stdenv.mkDerivation (finalAttrs: {
188188
# * <https://github.com/LnL7/nix-darwin/issues/122>
189189
# * <https://github.com/fish-shell/fish-shell/issues/7142>
190190
./nix-darwin-path.patch
191+
192+
# remove 4.0.2
193+
# https://github.com/fish-shell/fish-shell/issues/11254
194+
./1d78c8bd4295262a3118f478e6b3a7c7536fa282.patch
191195
];
192196

193197
# Fix FHS paths in tests
@@ -317,16 +321,12 @@ stdenv.mkDerivation (finalAttrs: {
317321
darwin.system_cmds
318322
];
319323

324+
# we target the top-level make target which runs all the cmake/ctest
325+
# tests, including test_cargo-test
320326
checkTarget = "fish_run_tests";
321327
preCheck = ''
322328
export TERMINFO="${ncurses}/share/terminfo"
323329
'';
324-
checkFlags = lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
325-
# thread 'tests::string_escape::test_escape_random_url' panicked at src/tests/string_escape.rs:122:9:
326-
# assertion `left == right` failed: Escaped and then unescaped string ... but got back a different string ...
327-
# https://github.com/fish-shell/fish-shell/issues/11254
328-
"--skip=tests::string_escape::test_escape_random_url"
329-
];
330330

331331
nativeInstallCheckInputs = [
332332
versionCheckHook

0 commit comments

Comments
 (0)
Failed to load comments.