Tcl Source Code

View Ticket
Login
Ticket UUID: 5137b4387019d0e118d958fb2b51139219ba9978
Title: clock.test failures with -singleproc 1 on Windows
Type: Bug Created on: 2025-07-31 06:40:17
Submitter: apnadkarni Assigned to: nobody
Subsystem: - New Builtin Commands Severity: Minor
Priority: 5 Medium Last modified: 2025-08-05 15:58:44
Status: Closed Closed by: dgp
Resolution: Fixed Closed on: 2025-08-05 15:58:44
Version: 8.7+
Description:

Failures disappear with -Od or -singleproc 0. Unix does not exhibit failures but MinGW build also show failures. Note only clock.test is run so not a result of other test files.

nmake /f makefile.vc TESTFLAGS="-f clock.test -singleproc 1" test

Running tests that match:  *
Skipping test files that match:  l.*.test
Only running test files that match:  clock.test
Tests began at Thu Jul 31 12:04:51 +0530 2025
clock.test
  Validity default mode: on


==== clock-31.1.vm:1 system locale FAILED
==== Contents of test case:

        clock format 0 -timezone :UTC -locale system -format %x

---- Result was:
01/01/1970
---- Result should have been (exact matching):
01-Jan-1970
==== clock-31.1.vm:1 FAILED



==== clock-31.2.vm:1 system locale FAILED
==== Contents of test case:

        clock format 0 -timezone :UTC -locale system -format %Ex

---- Result was:
01/01/1970
---- Result should have been (exact matching):
the 01' day of January 1970
==== clock-31.2.vm:1 FAILED



==== clock-31.3.vm:1 system locale FAILED
==== Contents of test case:

        clock format 0 -timezone :UTC -locale system -format %X

---- Result was:
00:00:00
---- Result should have been (exact matching):
12:00:00 AM
==== clock-31.3.vm:1 FAILED



==== clock-31.4.vm:1 system locale FAILED
==== Contents of test case:

        clock format 0 -locale system -format %x

---- Result was:
01/01/1970
---- Result should have been (exact matching):
31-Dec-1969
==== clock-31.4.vm:1 FAILED



==== clock-31.5.vm:1 system locale FAILED
==== Contents of test case:

        clock format 0 -locale system -format %Ex

---- Result was:
01/01/1970
---- Result should have been (exact matching):
the 31' day of December 1969
==== clock-31.5.vm:1 FAILED



==== clock-31.6.vm:1 system locale FAILED
==== Contents of test case:

        clock format 0 -locale system -format "%X %Z"

---- Result was:
05:30:00 +0530
---- Result should have been (exact matching):
 7:00:00 PM EST
==== clock-31.6.vm:1 FAILED



==== clock-38.2.vm:1 make sure TZ is not cached after unset FAILED
==== Contents of test case:

        set t1 [clock format 0]
        # a time zone that is unlikely to anywhere
        set env(TZ) "+04:20"
        set t2 [clock format 0]
        unset env(TZ)
        set t3 [clock format 0]
        expr {$t1 eq $t3 && $t1 ne $t2}

---- Result was:
0
---- Result should have been (exact matching):
1
==== clock-38.2.vm:1 FAILED



==== clock-49.2.vm:1 regression test - missing time zone file (Bug 1237907) FAILED
==== Contents of test case:

        list [::tcl::clock::GuessWindowsTimeZone]  [clock format 0 -locale system -format "%H:%M:%S %Z"]  [clock format -86400 -format "%Y"]

---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: localtime failed (clock value may be too large/small to represent)
    while executing
"clock format -86400 -format "%Y""
    ("uplevel" body line 2)
    invoked from within
"uplevel 1 $script"
---- errorCode: CLOCK localtimeFailed
==== clock-49.2.vm:1 FAILED


Tests ended at Thu Jul 31 12:04:55 +0530 2025
all.tcl:        Total   8724    Passed  8716    Skipped 0       Failed  8
Sourced 1 Test Files.
Files with failing tests: clock.test
User Comments:
sebres added on 2025-07-31 10:36:06:

No idea, why I'm abrupt responsible for that errors (since this tests exist almost since begin of clock, and they are older than 20 years and I saw such errors already with 8.5), but OK...

The tests have only conditionally the issue with -singleproc 1, and it goes to the "timing" problem - the tests using "system" locale, for this TCL would need registry module under windows, but this cannot be used unless really installed. The root of the issue - tcltest also uses the clock ensemble (to output "Tests began at" on start), and the registry would not be found there, so a later usage in the same interpreter (if registry package gets provided by -load parameters) may be too late, so may cause that the registry would not be tried to load anymore, so after all the retrieved locale may be different.

I made at some point (see [0c05a83862b9967c]) the registry package loadable in development environment, even uninstalled (pkgIndex tried to load it relative build folder). But it was ultimately reverted.

The next fix I made in this direction was the loading of -load in tcltest to correct time (cannot find the commit now).

Anyway I cannot reproduce it in MinGW (have no VS to hand right now), with both ways:

$ make -j8 test TESTFLAGS="-file 'clock*.test' -singleproc 1"
TCL_LIBRARY="/d/prj/tcl9.0/library"; export TCL_LIBRARY; \
 ./tclsh90.exe "../../tests/all.tcl" -file 'clock*.test' -singleproc 1 \
-load "package ifneeded tcl::test 9.0.3 [list load tcltest90.dll Tcltest]; lappend ::auto_path {d:/prj/tcl9.0/tests}; package ifneeded dde 1.4.5 [list load tcl9dde14.dll]; package ifneeded registry 1.3.7 [list load tcl9registry13.dll]"
Tests running in interp:  d:/prj/tcl9.0/win/Release_MGW64/tclsh90.exe
Tests located in:  D:/prj/tcl9.0/tests
Tests running in:  D:/prj/tcl9.0/win/Release_MGW64
Temporary files stored in D:/prj/tcl9.0/win/Release_MGW64
Test files sourced into current interpreter
Running tests that match:  *
Skipping test files that match:  l.*.test
Only running test files that match:  clock*.test
Tests began at Thu Jul 31 12:23:52 CEST 2025
clock-ivm.test
  Validity default mode: off
clock.test
  Validity default mode: off

Tests ended at Thu Jul 31 12:23:58 CEST 2025 all.tcl: Total 17472 Passed 17472 Skipped 0 Failed 0 Sourced 2 Test Files.

$ make -j8 tcltest && ./tcltest.sh -file 'clock*.test' -singleproc 1 make: Nothing to be done for `tcltest'. Tests running in interp: d:/prj/tcl9.0/win/Release_MGW64/tcltest.exe Tests located in: D:/prj/tcl9.0/tests Tests running in: T:/Temp Temporary files stored in T:/Temp Test files sourced into current interpreter Running tests that match: * Skipping test files that match: l.*.test Only running test files that match: clock*.test Tests began at Thu Jul 31 12:24:34 CEST 2025 clock-ivm.test Validity default mode: off clock.test Validity default mode: off

Tests ended at Thu Jul 31 12:24:40 CEST 2025 all.tcl: Total 17472 Passed 17472 Skipped 0 Failed 0 Sourced 2 Test Files.

The same is valid for clock.test only (single file).

But I'd try to find the roots if I'd get VS to hand.


apnadkarni added on 2025-07-31 11:06:07:
No, I didn't assign to you because I thought you are responsible :-) Rather I felt you are most knowledgeable about the clock implementation.

I can reproduce it with MinGW as well so may be it is some configuration specific to my system.

I don't think it has any urgency so no need for you to waste time on it. I'll come back to it at some point.

sebres added on 2025-07-31 13:46:23:

No problem... I tried to improve tests setups/cleans and rewrite them more system/locale/TZ independent, can you please test [557de3c0e552e76b].


apnadkarni added on 2025-07-31 14:06:01:

Progress! Now down to a single bug each in clock.test and clock-ivm.test. Both VC++ and MINGW show same failure.

Tests began at 2025-07-31 19:32:22 +0530
clock-ivm.test
  Validity default mode: off


==== clock-38.2.vm:0 make sure TZ is not cached after unset FAILED
==== Contents of test case:

        set t1 [clock format 0]
        # a time zone that is unlikely to anywhere
        set env(TZ) "+04:20"
        set t2 [clock format 0]
        unset -nocomplain env(TZ)
        set t3 [clock format 0]
        expr {$t1 eq $t3 && $t1 ne $t2}

---- Result was:
0
---- Result should have been (exact matching):
1
==== clock-38.2.vm:0 FAILED

clock.test
  Validity default mode: off


==== clock-38.2.vm:0 make sure TZ is not cached after unset FAILED
==== Contents of test case:

        set t1 [clock format 0]
        # a time zone that is unlikely to anywhere
        set env(TZ) "+04:20"
        set t2 [clock format 0]
        unset -nocomplain env(TZ)
        set t3 [clock format 0]
        expr {$t1 eq $t3 && $t1 ne $t2}

---- Result was:
0
---- Result should have been (exact matching):
1
==== clock-38.2.vm:0 FAILED


Tests ended at 2025-07-31 19:32:29 +0530
all.tcl:        Total   17472   Passed  17470   Skipped 0       Failed  2
Sourced 2 Test Files.
Files with failing tests: clock.test


sebres added on 2025-07-31 17:11:07:

I have no idea what happens there (and cannot reproduce it)... The test is extended now with more informative result in error case. Can you try it again, please?


apnadkarni added on 2025-08-01 05:34:48:

The puts outputs:

With -singleproc 0 (passing):

1 {"Thu Jan 01 05:30:00 IST 1970" eq "Thu Jan 01 05:30:00 IST 1970" && "Thu Jan 01 05:30:00 IST 1970" ne "Thu Jan 01 04:20:00 +04:20 1970"}

With -singleproc 1 (fail):

0 {"Thu Jan 01 01:00:00 +0530 1970" eq "Thu Jan 01 05:30:00 +0530 1970" && "Thu Jan 01 01:00:00 +0530 1970" ne "Thu Jan 01 04:20:00 +04:20 1970"}

You were on the right track when you mentioned registry. Bisect shows:

  9 BAD     2024-11-06 20:33:01 b11c0b7e61e1f3c9 CURRENT
  5 GOOD    2024-11-04 20:39:42 1310d7228e6ffaeb

Note the GOOD commit does not show any of the other failures I reported in the ticket either.

The failing commit removes the registry dlls from the build, presumably to keep them out of the zipfs.

A build without embedding zipfs (nmake OPTS="noembed") shows no failures.

So it has something to do with absence of the registry dll. I'm still puzzled as to

  • why -singleproc 0 does not show the failure
  • why the failure does not show up on your system (may be my timezone makes a difference?
  • whether the absence of registry matters to clock.test since it seems to emulate the registry command with a dummy registry to prevent modification of the real registry

sebres added on 2025-08-01 10:33:48:

Oops... No, it looks worse than I thought:

Because "$t1" eq "$t3" shows that t1 is:

- "Thu Jan 01 05:30:00 +0530 1970"
+ "Thu Jan 01 01:00:00 +0530 1970"
So before the TZ (and epoch) change t1 looks completely wrong if the test fails (red is OK, green is wrong) and obviously not equal 0 unix time in that TZ (+0530), looks more like CET (+0100).

And this may point to something like wrong cache invalidation (e. g. of the current loaded TZ data) or something similar. And potentially, this is completely different bug, happening only on certain circumstances (e. g. the only difference I see at the moment is the "IST" vs. "+0530" as your current timezone).

Anyway, thx for testing, I will try to figure it out.


sebres added on 2025-08-01 12:25:44:

Well, it shall now be fixed in [ba25401d6eaac4b2] - it was basically simple and as assumed the cache. The circumstances are indeed "noregistry" and fallback to :localtime TZ, what by change of TZ env (so often as in test suite) may miss the change of epoch (since obtained twice and second time dataPtr->lastTZEpoch == TzsetIfNecessary() is true), so despite the cache of last base is invalid, it'd mistakenly considered as valid, because everything in check condition is the same. This was definitely a bug and has now been fixed.

Can you please give it a try again?

I'll also provide new test later that covers this (no matter, with -singleproc 1 or 0).


apnadkarni added on 2025-08-01 13:05:15:
Looks good! I'm actually happy to know it was a real bug so your time spent was not a loss.

Are the changes you made to the other tests (other than 38.2) still necessary?

```
c:\src\tcltk\bisect\win>nmake /f makefile.vc /s /nologo test TESTFLAGS="-f clock*.test -singleproc 1"
Tests running in interp:  c:/src/tcltk/bisect/win/Release_AMD64_VC1939/tcltest90.exe
Tests located in:  C:/src/tcltk/bisect/tests
Tests running in:  C:/src/tcltk/bisect/win
Temporary files stored in C:/src/tcltk/bisect/win
Test files sourced into current interpreter
Running tests that match:  *
Skipping test files that match:  l.*.test
Only running test files that match:  clock*.test
Tests began at 2025-08-01 18:29:09 +0530
clock-ivm.test
  Validity default mode: off
clock.test
  Validity default mode: off

Tests ended at 2025-08-01 18:29:15 +0530
all.tcl:        Total   17472   Passed  17472   Skipped 0       Failed  0
Sourced 2 Test Files.
```

sebres added on 2025-08-01 13:55:10:

> Are the changes you made to the other tests (other than 38.2) still necessary?

I think yes (at least it is not wrong), because [557de3c0e5] fixes the setup of test registry, and previously ::tcl::clock::NoRegistry did nothing, since unused anymore in new clock engine (and the tests would be wrong if no registry is there, they imply a wrapper ::testClock::registry would work only if _hasRegistry returns 1).
Another part with setupTZ is just a simplification and code deduplication (but also resetting TCL_TZ everywhere, what could bother too).

Thus I'd add more tests and merge it hereafter to all affected branches.
Thx again!


sebres added on 2025-08-04 16:06:40:

In [aded3f3f0220b422] added test coverage for the switch of epoch and TZ-environment variable for the case if there is no registry.
Merged now. Closed.


dgp added on 2025-08-04 18:00:03:
The changes made to address this ticket included a change to
the tcltest package.  When the tcltest package changes, it needs
a version number bump, and to be kept in sync on all branches.
I made a start at this, but then I see another concern...

The change to tcltest gives me doubts.

-    set timeCmd {clock format [clock seconds]}
+    set timeCmd {clock format now -format "%Y-%m-%d %H:%M:%S %Z" -locale en}

This is forcing the "timeCmd" used by the tcltest package to
construct timestamps to always use the "en" locale.

This seems like a very consequential thing to force on every
user of the tcltest package in (presumably) a patch release.
This will change output reporting by tcltest when run in non-en
locales, right?  Many tcltest users who process tcltest output
are likely to see their expectations overturned, right?

Can't the testing of the clock command use other mechanisms to
induce tcltest to act (as if it is) in the en locale?

What am I missing?

sebres added on 2025-08-04 18:57:58:

> This will change output reporting by tcltest when run in non-en locales, right?

Well, it is not well correct, how [1b7d5ee5b46a96e8] says - it would now always output an ISO timestamp (which is obviously never locale dependent, since has only numeric values), but...

This change basically serves multiple purposes and it'd:

  • make the output of test case locale independent;
  • avoid dependency to registry on windows (windows may need registry package to get system locale);
  • help to avoid side effects, like a bit "unexpected" state of interpreter, but also different outputs on different test operation (installed/uninstalled, started from make or manually etc, but sometimes also the start and end timestamp (where end occurred after the registry is loaded);
  • stop to load another locale (which is not needed now).

In particular, for German user the difference in timestamp may look:

# either like this (e. g. on uninstalled Tcl the locale may remain "en"):
- Mon Aug 04 20:49:33 +0200 2025
+ 2025-08-04 20:49:42 +0200
# or like this (e. g. on installed Tcl, the locale may be obtained from system):
- Mo Aug 04 20:52:40 +0200 2025
+ 2025-08-04 20:49:42 +0200

If you mean ISO timestamp is not good for the output of start/end time in the test-suite, we can revert [1b7d5ee5b46a96e8] - with the possible consequences I mentioned above. But they would happen only on certain circumstances.


dgp added on 2025-08-05 15:58:44:
Thanks for the reply.  To summarize my understanding.

  * Yes, the change results in user-visible changes to tcltest output
  * The revised output is more robust, predictable, and standards
    compliant than the prior output.

I plan to take the following steps.

  * Bump the tcltest version on the changed branches to 2.6.0
  * When version tcltest 2.6.0 is included in a Tcl release, include
    release notes information about the change.
  * I will not make tcltest 2.6 a part of Tcl 8.6.* releases (following
    the existing state where the change was not backported there).