-
Notifications
You must be signed in to change notification settings - Fork 317
utests - call tzset after setenv TZ #2367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
unit-tests can fail if run in an env where TZ is already set.
This is because utest.h setup calls setenv("TZ"), but does not call
tzset() immediately after that.
This causes tzname, timezone, and daylight global variables to by out of
sync from the newly set environment value of "TZ".
To fix this, explicitly call tzset().
It's unlikely that a program would call setenv("TZ") during it's
lifetime, and this should ideally only happen in a test env.
2a9c44d to
3fea1af
Compare
|
I think the idea here was that anything that depends on TZ will call |
|
Without this change, the following failure can be seen: export TZ="NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0"
make -j all >/dev/null 2>&1 && ctest -R 'yang_types$' -V
25: Test timeout computed to be: 10000000
25: [==========] Running 5 test(s).
25: [ RUN ] test_data_xml
25: [ OK ] test_data_xml
25: [ RUN ] test_print
25: [ OK ] test_print
25: [ RUN ] test_duplicate
25: [ ERROR ] --- "<l1 xmlns="urn:tests:a">2005-05-26T06:45:15.88888+12:00</l1><l2 xmlns="urn:tests:a" xmlns:pref="urn:tests:a">/pref:l2[.='/pref:l2']</l2>" != "<l1 xmlns="urn:tests:a">2005-05-25T16:45:15.88888-02:00</l1><l2 xmlns="urn:tests:a" xmlns:pref="urn:tests:a">/pref:l2[.='/pref:l2']</l2>"
25: [ LINE ] --- /home/irfan/opensource/libyang/tests/utests/types/yang_types.c:204: error: Failure!
25: [ FAILED ] test_duplicate
The reason is as per the static void
tzset_internal (int always)
{
static int is_initialized;
const char *tz;
if (is_initialized && !always)
return;
is_initialized = 1;
...
}Only calling |
|
Right, so with my logic the I would follow the first logic since TZ may not be changed only in code. |
I was going for this. because if the code changes the |
|
So then you think the call is not needed at all in |
No, it is still needed to be called at least once, as per our previous discussion in #2363 (comment).
A user setting TZ before starting the program will use the set TZ. IMHO, If the user code changes the TZ value during the program execution, then it must call Although, the previous solution of always calling |
Okay, but based on what you said, it does not have to be called in |
|
Going with this solution, why not completely remove |
a335eb6 to
c8ea19f
Compare
It does not seem necessary to call `ly_tzset_once()` from `ly_time_time2str()` or `ly_time_tz_offset_at()`. If the user changes TZ env variable, they must explicitly call `tzset()` to update the global variables `tzname`, `timezone` and `daylight`
c8ea19f to
fa1d3d4
Compare
unit-tests can fail if run in an env where TZ is already set. This is because utest.h setup calls setenv("TZ"), but does not call tzset() immediately after that.
This causes tzname, timezone, and daylight global variables to by out of sync from the newly set environment value of "TZ".
To fix this, explicitly call tzset().
It's unlikely that a program would call setenv("TZ") during it's lifetime, and this should ideally only happen in a test env.