All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: Ghanshyam Thakkar <shyamthakkar001@gmail.com>,
	Achu Luma <ach.lumap@gmail.com>,
	git@vger.kernel.org, christian.couder@gmail.com,
	Christian Couder <chriscool@tuxfamily.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [Outreachy][PATCH 2/2] Port helper/test-date.c to unit-tests/t-date.c
Date: Tue, 28 May 2024 15:20:13 +0200	[thread overview]
Message-ID: <ZlXaDWy0lQA1FM7d@tanuki> (raw)
In-Reply-To: <xmqqttkquxes.fsf@gitster.g>

[-- Attachment #1: Type: text/plain, Size: 2539 bytes --]

On Thu, Mar 28, 2024 at 09:35:39AM -0700, Junio C Hamano wrote:
> Ghanshyam Thakkar <shyamthakkar001@gmail.com> writes:
> 
> > I believe the issue might not be related to the setenv function, but rather
> > with tzset(). As you can see here[1], when we set TZ before we call the
> > unit-testing binaries, the tests which were failing (EST5 ones that I
> > separated with t-datetest) pass on 'win test (0)', and the ones which
> > were passing (UTC ones, t-date) fail. (Although some tests on linux are also
> > failing, but that can be explained by the fact that t-date runs first
> > and sets the TZ to UTC, afterwhich t-datetest runs and fails, although
> > this is not conclusive). Therefore, I am almost certain that the issue
> > is with changing the timezone during runtime on windows and not with setting
> > TZ variable with setenv(). CC'ing Johannes to see if he has any insights
> > on this.
> 
> Interesting.  Sometime before I started working on Git, I learned
> that no program did tzset() after it started running to switch
> multiple timezones and worked correctly on many different variants
> of UNIXes (there were many of them back then), and because I never
> got interested in writing a world-clock program, I didn't know, and
> kind of surprised to learn that it works on some platforms (like
> Linux and macOS) to switch zones with tzset() these days ;-).
> 
> So, if Windows runtime is unhappy with the program calling tzset()
> more than once, I wouldn't be too surprised.
> 
> Thanks.

As I was debugging other Windows-specific issues in a VM already, Chris
asked me to also have a look at this issue. And indeed, most of the
tests fail deterministically. I also found a fix:

    diff --git a/t/unit-tests/t-date.c b/t/unit-tests/t-date.c
    index dd5dbbb2e0..2d7b1f085a 100644
    --- a/t/unit-tests/t-date.c
    +++ b/t/unit-tests/t-date.c
    @@ -31,7 +31,7 @@ static int check_prereqs(unsigned int prereqs) {
     }
     
     static void set_TZ_env(const char *zone) {
    -	setenv("TZ", zone, 1);
    +	_putenv_s("TZ", zone);
        tzset();
     }

I have no idea why that works though, and the fix is of course not
portable. But with this change, the timezones do get picked up by
`tzset()` and related date functions as expected.

I'm quite dumb when it comes to the Windows API, so I don't have much of
a clue why this works. The documentation also didn't point out anything
obvious. Dscho, do you happen to have an explanation for this?

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-05-28 13:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 16:25 [Outreachy][PATCH 1/2] date: refactor 64 bit prereq code into reusable functions Achu Luma
2024-02-05 16:25 ` [Outreachy][PATCH 2/2] Port helper/test-date.c to unit-tests/t-date.c Achu Luma
2024-03-28 12:35   ` Ghanshyam Thakkar
2024-03-28 16:35     ` Junio C Hamano
2024-05-28 13:20       ` Patrick Steinhardt [this message]
2024-05-28 16:41         ` Junio C Hamano
2024-05-29  5:49           ` Patrick Steinhardt
2024-06-27  6:49             ` Johannes Schindelin
2024-02-05 17:34 ` [Outreachy][PATCH 1/2] date: refactor 64 bit prereq code into reusable functions rsbecker
2024-02-06  8:39   ` Christian Couder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZlXaDWy0lQA1FM7d@tanuki \
    --to=ps@pks.im \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=ach.lumap@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=shyamthakkar001@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.