[LTP] [PATCH v3] tst_test.sh: Normalize the locale

Akihiko Odaki akihiko.odaki@daynix.com
Thu Oct 20 21:09:16 CEST 2022


On 2022/10/21 2:30, Petr Vorel wrote:
> Hi all,
> 
> 
>> network/tcp_cmds/tracepath/tracepath01.sh fails with LANG=ja_JP.UTF-8
>> because it parses localized output. The below is an example of such
>> output:
>> $ tracepath localhost
>>   1?: [LOCALHOST]                        0.040ミリ秒 pmtu 65536
>>   1:  localhost                                             0.274ミリ秒 到達しました
>>   1:  localhost                                             0.261ミリ秒 到達しました
>>       要約: pmtu 65536 ホップ数 1 戻りホップ数 1
> 
>> It is necessary to normalize the locale to avoid such a problem.
>> There are some tests do the normalization, but that is not
>> comprehensive. Add code to normalize the locale to tst_test.sh so
>> that it can cover more tests.
> 
>> The added code does the normalization by setting LC_ALL, which
>> takes precedence to the other locale-related environment variables
>> and does not require that "locale" command exists.
> 
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>>   testcases/lib/tst_test.sh | 2 ++
>>   1 file changed, 2 insertions(+)
> 
>> diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
>> index 28b7d12ba..5ebbe1d25 100644
>> --- a/testcases/lib/tst_test.sh
>> +++ b/testcases/lib/tst_test.sh
>> @@ -831,3 +831,5 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
>>   		fi
>>   	fi
>>   fi
>> +
>> +export LC_ALL=C
> 
> Thinking about it twice this might have impact on other tests.
> Li, Cyril, any idea about it?
> 
> Other option would be to put this change just to tracepath01.sh.
> And if we want to test just C locale (I'm really not sure, shouldn't
> it be also in C API?
> 
> Kind regards,
> Petr
If the change of scope needs to be narrowed, we can prefix tracepath 
invocation with LC_ALL=C and limit the impact completely to tracepath.

However, I opt to add this to tst_test.sh because, in my experience with 
Japanese locale, this kind of problem has been so common that even some 
Japanese people set their locale to C for their command line. It can 
happen anywhere using sed, awk, etc for command outputs and often remain 
unnoticed because of its locale-specific nature.

Regarding C API, the scope of setlocale(), available in C, is limited to 
the program, and is not applicable when invoking an external command 
like tracepath. It could be an option if tracepath also has C API, but 
it doesn't, unfortunately.

Regards,
Akihiko Odaki


More information about the ltp mailing list