hwdb: fix screen rotation for EXO Wings 2in1 w1125 (#36283)
[systemd.io.git] / test / units / TEST-73-LOCALE.sh
blob0617bd0d51a1db8f851c7b279b5262e716220deb
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
4 set -eux
5 set -o pipefail
7 # shellcheck source=test/units/test-control.sh
8 . "$(dirname "$0")"/test-control.sh
9 # shellcheck source=test/units/util.sh
10 . "$(dirname "$0")"/util.sh
12 enable_debug() {
13 mkdir -p /run/systemd/system/systemd-localed.service.d
14 cat >>/run/systemd/system/systemd-localed.service.d/override.conf <<EOF
15 [Service]
16 Environment=SYSTEMD_LOG_LEVEL=debug
17 EOF
19 mkdir -p /run/systemd/system/systemd-vconsole-setup.service.d
20 cat >>/run/systemd/system/systemd-vconsole-setup.service.d/override.conf <<EOF
21 [Unit]
22 StartLimitIntervalSec=0
24 [Service]
25 Environment=SYSTEMD_LOG_LEVEL=debug
26 EOF
28 systemctl daemon-reload
31 testcase_locale() {
32 local i output
34 if [[ -f /etc/locale.conf ]]; then
35 cp /etc/locale.conf /tmp/locale.conf.bak
38 # Debian/Ubuntu specific file
39 if [[ -f /etc/default/locale ]]; then
40 cp /etc/default/locale /tmp/default-locale.bak
43 if [[ -f /etc/locale.gen ]]; then
44 cp /etc/locale.gen /tmp/locale.gen.bak
47 # remove locale.conf to make /etc/default/locale used by Debian/Ubuntu
48 rm -f /etc/locale.conf
49 # also remove /etc/default/locale
50 rm -f /etc/default/locale
51 # and create /etc/default to make /etc/default/locale created by localed
52 mkdir -p /etc/default
54 trap restore_locale RETURN
55 # Ensure at least one UTF-8 locale exists.
56 generate_locale en_US.UTF-8
58 # create invalid locale
59 mkdir -p /usr/lib/locale/xx_XX.UTF-8
60 assert_not_in "xx_XX.UTF-8" "$(localectl list-locales)"
62 if [[ -z "$(localectl list-locales)" ]]; then
63 echo "No locale installed, skipping test."
64 return
67 # start with a known default environment and make sure to also give a
68 # default value to LC_CTYPE= since we're about to also set/unset it. We
69 # also reload PID1 configuration to make sure that PID1 environment itself
70 # is updated as it's not always been the case.
71 assert_rc 0 localectl set-locale "LANG=en_US.UTF-8" "LC_CTYPE=C"
72 systemctl daemon-reload
73 output=$(localectl)
74 assert_in "System Locale: LANG=en_US.UTF-8" "$output"
75 assert_in "LC_CTYPE=C" "$output"
76 output=$(systemctl show-environment)
77 assert_in "LANG=en_US.UTF-8" "$output"
78 assert_in "LC_CTYPE=C" "$output"
80 # warn when kernel command line has locale settings
81 output=$(SYSTEMD_PROC_CMDLINE="locale.LANG=C.UTF-8 locale.LC_CTYPE=ja_JP.UTF-8" localectl 2>&1)
82 assert_in "Warning:" "$output"
83 assert_in "Command Line: LANG=C.UTF-8" "$output"
84 assert_in "LC_CTYPE=ja_JP.UTF-8" "$output"
85 assert_in "System Locale:" "$output"
87 # change locale
88 for i in $(localectl list-locales); do
89 assert_rc 0 localectl set-locale "LANG=C" "LC_CTYPE=$i"
90 if [[ -f /etc/default/locale ]]; then
91 assert_eq "$(cat /etc/default/locale)" "LANG=C
92 LC_CTYPE=$i"
93 else
94 assert_eq "$(cat /etc/locale.conf)" "LANG=C
95 LC_CTYPE=$i"
97 output=$(localectl)
98 assert_in "System Locale: LANG=C" "$output"
99 assert_in "LC_CTYPE=$i" "$output"
100 output=$(systemctl show-environment)
101 assert_in "LANG=C" "$output"
102 assert_in "LC_CTYPE=$i" "$output"
104 assert_rc 0 localectl set-locale "$i"
105 if [[ -f /etc/default/locale ]]; then
106 assert_eq "$(cat /etc/default/locale)" "LANG=$i"
107 else
108 assert_eq "$(cat /etc/locale.conf)" "LANG=$i"
110 output=$(localectl)
111 assert_in "System Locale: LANG=$i" "$output"
112 assert_not_in "LC_CTYPE=" "$output"
113 output=$(systemctl show-environment)
114 assert_in "LANG=$i" "$output"
115 assert_not_in "LC_CTYPE=" "$output"
116 done
118 # test if localed auto-runs locale-gen
119 if command -v locale-gen >/dev/null 2>&1 &&
120 ! localectl list-locales | grep -F "de_DE.UTF-8"; then
122 # clear previous locale
123 systemctl stop systemd-localed.service
124 rm -f /etc/locale.conf /etc/default/locale
126 # change locale
127 assert_rc 0 localectl set-locale de_DE.UTF-8
128 if [[ -f /etc/default/locale ]]; then
129 assert_eq "$(cat /etc/default/locale)" "LANG=de_DE.UTF-8"
130 else
131 assert_eq "$(cat /etc/locale.conf)" "LANG=de_DE.UTF-8"
133 assert_in "System Locale: LANG=de_DE.UTF-8" "$(localectl)"
134 assert_in "LANG=de_DE.UTF-8" "$(systemctl show-environment)"
136 # ensure tested locale exists and works now
137 assert_in "de_DE.UTF-8" "$(localectl list-locales)"
141 backup_keymap() {
142 if [[ -f /etc/vconsole.conf ]]; then
143 cp /etc/vconsole.conf /tmp/vconsole.conf.bak
146 if [[ -f /etc/X11/xorg.conf.d/00-keyboard.conf ]]; then
147 cp /etc/X11/xorg.conf.d/00-keyboard.conf /tmp/00-keyboard.conf.bak
150 # Debian/Ubuntu specific file
151 if [[ -f /etc/default/keyboard ]]; then
152 cp /etc/default/keyboard /tmp/default-keyboard.bak
155 mkdir -p /etc/default
158 restore_keymap() {
159 if [[ -f /tmp/vconsole.conf.bak ]]; then
160 mv /tmp/vconsole.conf.bak /etc/vconsole.conf
161 else
162 rm -f /etc/vconsole.conf
165 if [[ -f /tmp/00-keyboard.conf.bak ]]; then
166 mv /tmp/00-keyboard.conf.bak /etc/X11/xorg.conf.d/00-keyboard.conf
167 else
168 rm -f /etc/X11/xorg.conf.d/00-keyboard.conf
171 if [[ -f /tmp/default-keyboard.bak ]]; then
172 mv /tmp/default-keyboard.bak /etc/default/keyboard
173 else
174 rm -f /etc/default/keyboard
175 rmdir --ignore-fail-on-non-empty /etc/default
179 wait_vconsole_setup() {
180 local i ss
181 for i in {1..20}; do
182 (( i > 1 )) && sleep 0.5
183 ss="$(systemctl --property SubState --value show systemd-vconsole-setup.service)"
184 if [[ "$ss" == "exited" || "$ss" == "dead" || "$ss" == "condition" ]]; then
185 return 0
186 elif [[ "$ss" == "failed" ]]; then
187 echo "WARNING: systemd-vconsole-setup.service failed, ignoring." >&2
188 systemctl reset-failed systemd-vconsole-setup.service
189 return 0
191 done
193 systemctl status systemd-vconsole-setup.service
194 return 1
197 testcase_vc_keymap() {
198 local i output vc
200 if [[ -z "$(localectl list-keymaps)" ]]; then
201 echo "No vconsole keymap installed, skipping test."
202 return
205 backup_keymap
206 trap restore_keymap RETURN
208 # should activate daemon and work
209 assert_in "VC Keymap:" "$(localectl)"
211 for i in $(localectl list-keymaps); do
212 # clear previous conversion from VC -> X11 keymap
213 systemctl stop systemd-localed.service
214 wait_vconsole_setup
215 rm -f /etc/vconsole.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
217 # set VC keymap
218 assert_rc 0 localectl set-keymap "$i"
219 output=$(localectl)
221 # check VC keymap
222 vc=$(cat /etc/vconsole.conf)
223 assert_in "KEYMAP=$i" "$vc"
224 assert_in "VC Keymap: $i" "$output"
226 # check VC -> X11 keymap conversion
227 if [[ "$i" == "us" ]]; then
228 assert_in "X11 Layout: us" "$output"
229 assert_in "X11 Model: pc105\+inet" "$output"
230 assert_not_in "X11 Variant:" "$output"
231 assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
233 assert_in "XKBLAYOUT=us" "$vc"
234 assert_in "XKBMODEL=pc105\+inet" "$vc"
235 assert_not_in "XKBVARIANT" "$vc"
236 assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
237 elif [[ "$i" == "us-acentos" ]]; then
238 assert_in "X11 Layout: us" "$output"
239 assert_in "X11 Model: pc105" "$output"
240 assert_in "X11 Variant: intl" "$output"
241 assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
243 assert_in "XKBLAYOUT=us" "$vc"
244 assert_in "XKBMODEL=pc105" "$vc"
245 assert_in "XKBVARIANT=intl" "$vc"
246 assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
247 elif [[ "$i" =~ ^us-.* ]]; then
248 assert_in "X11 Layout: us" "$output"
249 assert_in "X11 Model: microsoftpro" "$output"
250 assert_in "X11 Variant:" "$output"
251 assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
253 assert_in "XKBLAYOUT=us" "$vc"
254 assert_in "XKBMODEL=microsoftpro" "$vc"
255 assert_in "XKBVARIANT=" "$vc"
256 assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
258 done
260 # gets along without config file
261 systemctl stop systemd-localed.service
262 wait_vconsole_setup
263 rm -f /etc/vconsole.conf
264 assert_in "VC Keymap: .unset." "$(localectl)"
267 testcase_x11_keymap() {
268 local output
270 if [[ -z "$(localectl list-x11-keymap-layouts)" ]]; then
271 echo "No x11 keymap installed, skipping test."
272 return
275 backup_keymap
276 trap restore_keymap RETURN
278 # should activate daemon and work
279 assert_in "X11 Layout:" "$(localectl)"
281 # set x11 keymap (layout, model, variant, options)
282 assert_rc 0 localectl set-x11-keymap us pc105+inet intl terminate:ctrl_alt_bksp
284 if [[ -f /etc/default/keyboard ]]; then
285 assert_eq "$(cat /etc/default/keyboard)" "XKBLAYOUT=us
286 XKBMODEL=pc105+inet
287 XKBVARIANT=intl
288 XKBOPTIONS=terminate:ctrl_alt_bksp"
289 else
290 output=$(cat /etc/X11/xorg.conf.d/00-keyboard.conf)
291 assert_in 'Option "XkbLayout" "us"' "$output"
292 assert_in 'Option "XkbModel" "pc105\+inet"' "$output"
293 assert_in 'Option "XkbVariant" "intl"' "$output"
294 assert_in 'Option "XkbOptions" "terminate:ctrl_alt_bksp"' "$output"
296 output=$(cat /etc/vconsole.conf)
297 assert_in 'XKBLAYOUT=us' "$output"
298 assert_in 'XKBMODEL=pc105\+inet' "$output"
299 assert_in 'XKBVARIANT=intl' "$output"
300 assert_in 'XKBOPTIONS=terminate:ctrl_alt_bksp' "$output"
303 output=$(localectl)
304 assert_in "X11 Layout: us" "$output"
305 assert_in "X11 Model: pc105\+inet" "$output"
306 assert_in "X11 Variant: intl" "$output"
307 assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
309 # Debian/Ubuntu patch is buggy, unspecified settings are not cleared
310 rm -f /etc/default/keyboard
312 # set x11 keymap (layout, model, variant)
313 assert_rc 0 localectl set-x11-keymap us pc105+inet intl
315 if [[ -f /etc/default/keyboard ]]; then
316 assert_eq "$(cat /etc/default/keyboard)" "XKBLAYOUT=us
317 XKBMODEL=pc105+inet
318 XKBVARIANT=intl"
319 else
320 output=$(cat /etc/X11/xorg.conf.d/00-keyboard.conf)
321 assert_in 'Option "XkbLayout" "us"' "$output"
322 assert_in 'Option "XkbModel" "pc105\+inet"' "$output"
323 assert_in 'Option "XkbVariant" "intl"' "$output"
324 assert_not_in 'Option "XkbOptions"' "$output"
326 output=$(cat /etc/vconsole.conf)
327 assert_in 'XKBLAYOUT=us' "$output"
328 assert_in 'XKBMODEL=pc105\+inet' "$output"
329 assert_in 'XKBVARIANT=intl' "$output"
330 assert_not_in 'XKBOPTIONS' "$output"
333 output=$(localectl)
334 assert_in "X11 Layout: us" "$output"
335 assert_in "X11 Model: pc105\+inet" "$output"
336 assert_in "X11 Variant: intl" "$output"
337 assert_not_in "X11 Options:" "$output"
339 # Debian/Ubuntu patch is buggy, unspecified settings are not cleared
340 rm -f /etc/default/keyboard
342 # set x11 keymap (layout, model)
343 assert_rc 0 localectl set-x11-keymap us pc105+inet
345 if [[ -f /etc/default/keyboard ]]; then
346 assert_eq "$(cat /etc/default/keyboard)" "XKBLAYOUT=us
347 XKBMODEL=pc105+inet"
348 else
349 output=$(cat /etc/X11/xorg.conf.d/00-keyboard.conf)
350 assert_in 'Option "XkbLayout" "us"' "$output"
351 assert_in 'Option "XkbModel" "pc105\+inet"' "$output"
352 assert_not_in 'Option "XkbVariant"' "$output"
353 assert_not_in 'Option "XkbOptions"' "$output"
355 output=$(cat /etc/vconsole.conf)
356 assert_in 'XKBLAYOUT=us' "$output"
357 assert_in 'XKBMODEL=pc105\+inet' "$output"
358 assert_not_in 'XKBVARIANT' "$output"
359 assert_not_in 'XKBOPTIONS' "$output"
362 output=$(localectl)
363 assert_in "X11 Layout: us" "$output"
364 assert_in "X11 Model: pc105\+inet" "$output"
365 assert_not_in "X11 Variant:" "$output"
366 assert_not_in "X11 Options:" "$output"
368 # Debian/Ubuntu patch is buggy, unspecified settings are not cleared
369 rm -f /etc/default/keyboard
371 # set x11 keymap (layout)
372 assert_rc 0 localectl set-x11-keymap us
374 if [[ -f /etc/default/keyboard ]]; then
375 assert_eq "$(cat /etc/default/keyboard)" "XKBLAYOUT=us"
376 else
377 output=$(cat /etc/X11/xorg.conf.d/00-keyboard.conf)
378 assert_in 'Option "XkbLayout" "us"' "$output"
379 assert_not_in 'Option "XkbModel"' "$output"
380 assert_not_in 'Option "XkbVariant"' "$output"
381 assert_not_in 'Option "XkbOptions"' "$output"
383 output=$(cat /etc/vconsole.conf)
384 assert_in 'XKBLAYOUT=us' "$output"
385 assert_not_in 'XKBMODEL' "$output"
386 assert_not_in 'XKBVARIANT' "$output"
387 assert_not_in 'XKBOPTIONS' "$output"
390 output=$(localectl)
391 assert_in "X11 Layout: us" "$output"
392 assert_not_in "X11 Model:" "$output"
393 assert_not_in "X11 Variant:" "$output"
394 assert_not_in "X11 Options:" "$output"
396 # gets along without config file
397 systemctl stop systemd-localed.service
398 rm -f /etc/vconsole.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
399 output=$(localectl)
400 assert_in "X11 Layout: .unset." "$output"
401 assert_not_in "X11 Model:" "$output"
402 assert_not_in "X11 Variant:" "$output"
403 assert_not_in "X11 Options:" "$output"
406 testcase_convert() {
407 if [[ -z "$(localectl list-keymaps)" ]]; then
408 echo "No vconsole keymap installed, skipping test."
409 return
412 if [[ -z "$(localectl list-x11-keymap-layouts)" ]]; then
413 echo "No x11 keymap installed, skipping test."
414 return
417 backup_keymap
418 trap restore_keymap RETURN
420 # clear previous settings
421 systemctl stop systemd-localed.service
422 wait_vconsole_setup
423 rm -f /etc/vconsole.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
425 # set VC keymap without conversion
426 assert_rc 0 localectl --no-convert set-keymap us
427 output=$(localectl)
429 # check VC keymap
430 vc=$(cat /etc/vconsole.conf)
431 assert_in "KEYMAP=us" "$vc"
432 assert_in "VC Keymap: us" "$output"
434 # check VC -> X11 keymap conversion (nothing set)
435 assert_in "X11 Layout: .unset." "$output"
436 assert_not_in "X11 Model:" "$output"
437 assert_not_in "X11 Variant:" "$output"
438 assert_not_in "X11 Options:" "$output"
440 assert_not_in "XKBLAYOUT=" "$vc"
441 assert_not_in "XKBMODEL=" "$vc"
442 assert_not_in "XKBVARIANT=" "$vc"
443 assert_not_in "XKBOPTIONS=" "$vc"
445 # set VC keymap with conversion
446 assert_rc 0 localectl set-keymap us
447 output=$(localectl)
449 # check VC keymap
450 vc=$(cat /etc/vconsole.conf)
451 assert_in "KEYMAP=us" "$vc"
452 assert_in "VC Keymap: us" "$output"
454 # check VC -> X11 keymap conversion
455 assert_in "X11 Layout: us" "$output"
456 assert_in "X11 Model: pc105\+inet" "$output"
457 assert_not_in "X11 Variant:" "$output"
458 assert_in "X11 Options: terminate:ctrl_alt_bksp" "$output"
460 assert_in "XKBLAYOUT=us" "$vc"
461 assert_in "XKBMODEL=pc105\+inet" "$vc"
462 assert_not_in "XKBVARIANT" "$vc"
463 assert_in "XKBOPTIONS=terminate:ctrl_alt_bksp" "$vc"
465 # clear previous settings
466 systemctl stop systemd-localed.service
467 wait_vconsole_setup
468 rm -f /etc/vconsole.conf /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
470 # set x11 keymap (layout) without conversion
471 assert_rc 0 localectl --no-convert set-x11-keymap us
473 assert_not_in "KEYMAP=" "$(cat /etc/vconsole.conf)"
474 assert_in "VC Keymap: .unset." "$(localectl)"
476 if [[ -f /etc/default/keyboard ]]; then
477 assert_eq "$(cat /etc/default/keyboard)" "XKBLAYOUT=us"
478 else
479 output=$(cat /etc/X11/xorg.conf.d/00-keyboard.conf)
480 assert_in 'Option "XkbLayout" "us"' "$output"
481 assert_not_in 'Option "XkbModel"' "$output"
482 assert_not_in 'Option "XkbVariant"' "$output"
483 assert_not_in 'Option "XkbOptions"' "$output"
485 output=$(cat /etc/vconsole.conf)
486 assert_in 'XKBLAYOUT=us' "$output"
487 assert_not_in 'XKBMODEL=' "$output"
488 assert_not_in 'XKBVARIANT=' "$output"
489 assert_not_in 'XKBOPTIONS=' "$output"
492 output=$(localectl)
493 assert_in "X11 Layout: us" "$output"
494 assert_not_in "X11 Model:" "$output"
495 assert_not_in "X11 Variant:" "$output"
496 assert_not_in "X11 Options:" "$output"
498 # set x11 keymap (layout, model) with conversion
499 assert_rc 0 localectl set-x11-keymap us
501 assert_in "KEYMAP=us" "$(cat /etc/vconsole.conf)"
502 assert_in "VC Keymap: us" "$(localectl)"
504 if [[ -f /etc/default/keyboard ]]; then
505 assert_eq "$(cat /etc/default/keyboard)" "XKBLAYOUT=us"
506 else
507 output=$(cat /etc/X11/xorg.conf.d/00-keyboard.conf)
508 assert_in 'Option "XkbLayout" "us"' "$output"
509 assert_not_in 'Option "XkbModel"' "$output"
510 assert_not_in 'Option "XkbVariant"' "$output"
511 assert_not_in 'Option "XkbOptions"' "$output"
513 output=$(cat /etc/vconsole.conf)
514 assert_in 'XKBLAYOUT=us' "$output"
515 assert_not_in 'XKBMODEL=' "$output"
516 assert_not_in 'XKBVARIANT=' "$output"
517 assert_not_in 'XKBOPTIONS=' "$output"
520 output=$(localectl)
521 assert_in "X11 Layout: us" "$output"
522 assert_not_in "X11 Model:" "$output"
523 assert_not_in "X11 Variant:" "$output"
524 assert_not_in "X11 Options:" "$output"
527 testcase_validate() {
528 if [[ -z "$(localectl list-keymaps)" ]]; then
529 echo "No vconsole keymap installed, skipping test."
530 return
533 if [[ -z "$(localectl list-x11-keymap-layouts)" ]]; then
534 echo "No x11 keymap installed, skipping test."
535 return
538 backup_keymap
539 trap restore_keymap RETURN
541 # clear previous settings
542 systemctl stop systemd-localed.service
543 wait_vconsole_setup
544 rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
546 # create invalid configs
547 cat >/etc/vconsole.conf <<EOF
548 KEYMAP=foobar
549 XKBLAYOUT=hogehoge
552 # confirm that the invalid settings are not shown
553 output=$(localectl)
554 assert_in "VC Keymap: .unset." "$output"
555 if [[ "$output" =~ "X11 Layout: hogehoge" ]]; then
556 # Debian/Ubuntu build systemd without xkbcommon.
557 echo "systemd built without xkbcommon, skipping test."
558 return
560 assert_in "X11 Layout: .unset." "$output"
562 # only update the virtual console keymap
563 assert_rc 0 localectl --no-convert set-keymap us
565 output=$(localectl)
566 assert_in "VC Keymap: us" "$output"
567 assert_in "X11 Layout: .unset." "$output"
569 output=$(cat /etc/vconsole.conf)
570 assert_in "KEYMAP=us" "$output"
571 assert_not_in "XKBLAYOUT=" "$output"
573 # clear previous settings
574 systemctl stop systemd-localed.service
575 wait_vconsole_setup
576 rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
578 # create invalid configs
579 cat >/etc/vconsole.conf <<EOF
580 KEYMAP=foobar
581 XKBLAYOUT=hogehoge
584 # confirm that the invalid settings are not shown
585 output=$(localectl)
586 assert_in "VC Keymap: .unset." "$output"
587 assert_in "X11 Layout: .unset." "$output"
589 # only update the X11 keyboard layout
590 assert_rc 0 localectl --no-convert set-x11-keymap us
592 output=$(localectl)
593 assert_in "VC Keymap: .unset." "$output"
594 assert_in "X11 Layout: us" "$output"
596 output=$(cat /etc/vconsole.conf)
597 assert_not_in "KEYMAP=" "$output"
598 assert_in "XKBLAYOUT=us" "$output"
600 # clear previous settings
601 systemctl stop systemd-localed.service
602 wait_vconsole_setup
603 rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
605 # create invalid configs
606 cat >/etc/vconsole.conf <<EOF
607 KEYMAP=foobar
608 XKBLAYOUT=hogehoge
611 # update the virtual console keymap with conversion
612 assert_rc 0 localectl set-keymap us
614 output=$(localectl)
615 assert_in "VC Keymap: us" "$output"
616 assert_in "X11 Layout: us" "$output"
618 output=$(cat /etc/vconsole.conf)
619 assert_in "KEYMAP=us" "$output"
620 assert_in "XKBLAYOUT=us" "$output"
623 locale_gen_cleanup() {
624 # Some running apps might keep the mount point busy, hence the lazy unmount
625 mountpoint -q /usr/lib/locale && umount --lazy /usr/lib/locale
626 [[ -e /tmp/locale.gen.bak ]] && mv -f /tmp/locale.gen.bak /etc/locale.gen
628 return 0
631 # Issue: https://github.com/systemd/systemd/pull/27179
632 testcase_locale_gen_leading_space() {
633 if ! command -v locale-gen >/dev/null; then
634 echo "No locale-gen support, skipping test."
635 return 0
638 [[ -e /etc/locale.gen ]] && cp -f /etc/locale.gen /tmp/locale.gen.bak
639 trap locale_gen_cleanup RETURN
640 # Overmount the existing locale-gen database with an empty directory
641 # to force it to regenerate locales
642 mount -t tmpfs tmpfs /usr/lib/locale
645 echo -e "en_US.UTF-8 UTF-8"
646 echo -e " en_US.UTF-8 UTF-8"
647 echo -e "\ten_US.UTF-8 UTF-8"
648 echo -e " \t en_US.UTF-8 UTF-8 \t"
649 } >/etc/locale.gen
651 localectl set-locale de_DE.UTF-8
652 localectl set-locale en_US.UTF-8
655 # Make sure the content of kbd-model-map is the one that the tests expect
656 # regardless of the version installed on the distro where the testsuite is
657 # running on.
658 export SYSTEMD_KBD_MODEL_MAP=/usr/lib/systemd/tests/testdata/test-keymap-util/kbd-model-map
660 # On Debian and derivatives writing calls to localed are blocked as other tools are used to change settings,
661 # override that policy
662 mkdir -p /etc/dbus-1/system.d/
663 cat >/etc/dbus-1/system.d/systemd-localed-read-only.conf <<EOF
664 <?xml version="1.0"?>
665 <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
666 "https://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
667 <busconfig>
668 <policy user="root">
669 <allow send_destination="org.freedesktop.locale1" send_interface="org.freedesktop.locale1" send_member="SetLocale"/>
670 <allow send_destination="org.freedesktop.locale1" send_interface="org.freedesktop.locale1" send_member="SetVConsoleKeyboard"/>
671 <allow send_destination="org.freedesktop.locale1" send_interface="org.freedesktop.locale1" send_member="SetX11Keyboard"/>
672 </policy>
673 </busconfig>
675 trap 'rm -f /etc/dbus-1/system.d/systemd-localed-read-only.conf' EXIT
676 systemctl reload dbus.service
678 enable_debug
679 run_testcases
681 touch /testok