Tk Source Code

View Ticket
Login
Ticket UUID: 4f9946f4f3fcdd9d30ced2f816e963dc18e124c9
Title: Simplify testfile initialization for the case of "-singleproc 1"
Type: RFE Version: trunk
Submitter: erikleunissen Created on: 2025-08-10 17:25:01
Subsystem: 99. Other Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2025-08-13 13:02:31
Resolution: None Closed By: nobody
    Closed on:
Description:
The Tk test currently uses the combination of the tcltest option "-loadfile"
and the command "tcltest::loadTestedCommands" for loading common code into all
test files.

It invokes the option -loadfile in "all.tcl", registering the file "main.tcl",
which holds code shared amongst test files. The command tcltest::loadTestedCommands
is called from each test file at testfile initialization, and loads the code
that "main.tcl" contains.

Although not explicitly documented as such, the combination -loadfile/loadTestedCommands
is tailored towards test suites that invoke each test file in a separate process
(configurable through "-singleproc 0"). The mechanism serves to pass the registered script
to each sub-process as a command line parameter, which "loadTestedCommands" queries in turn.

The -loadfile/loadTestedCommands mechanism is unadapted to the situation where all
test files are evaluated in the same interpreter (tcltest option "-singleproc 1").
It is very inefficient because:
- it stores/retrieves the file name of the script main.tcl
- it accesses the file system to read what's in that file
- it does so repeatedly for each testfile
- of the script file "main.tcl" only the first 4 lines are executed by each test file.
  (The remainder, some 25 lines of code, comment lines excluded, is protected from
  repeated execution and is therefore run by the first test file only.)

Therefore, what this mechanism accomplishes in the case of "-singleproc 1" can
easily be obtained with a very much more simple, and straight-forward alternative
that is based on:
- factoring out the four code lines from main.tcl that are executed by each test file and
  turn them into a proc (named "resetWindows")
- placing this proc in the testutils utility domain "generic", which makes the proc
  automatically available to each test file.
- invoking this utility proc in each test file in the section TESTFILE INITIALIZATION,
  instead of the call to loadTestedCommands.

Notes aside:
* The main test script all.tcl currently disables support for "-singleproc 0".
  Given the questions about the commit that disabled that support, I intend to
  restore support for "-singleproc 0", but keep "-singleproc 1" as the default.
* The Tk test files already supported both mode "-singleproc 0" and "-singleproc 1".
  We only need to diversify the section TESTFILE INITIALIZATION for these two modes.
* Some cleanup and improvements regarding command line handling are done along the way.

Development takes place in branch "simplify_test_file_init_for_singleproc_1", see:

    [https://core.tcl-lang.org/tk/timeline?r=simplify_test_file_init_for_singleproc_1]
User Comments: erikleunissen added on 2025-08-13 13:02:31:
WORKING AROUND PROBLEM WITH "tk appname" (AND "winfo interps")
--------------------------------------------------------------

The issue in the previous post, has more to it than meets the eye. My reason to
remove the conditional in commit [e8cd6dc4a2] was correct after all. But the
removal lead to test failures in send.test and winfo.test. (That's why I reverted
the commit.)

As it appears now, the test failures are caused by an issue with "tk appname".
Please see ticket [280189e35d]. These failures arise when childTkProcess creates
a new interpreter, while relying on the automatic detection of duplicate interp
names.

The subsequent update statement (the one that follows "wm geometry . +0+0")
confounds the issue because:
- by its position, it suggests to update the event loop w.r.t. things that are
  induced by "wm geometry . +0+0". However, this isn't needed at all.
- it does have an entirely different function though: it works as a prevention
  of the issue with "tk appname" (under Linux *). It probably wasn't intended as
  such, otherwise it would have been called immediately after the command
  "tk appname".

        * Not under Windows; but no test failures occur on that platform because:
          - tests in send.test are not executed because the send command doesn't
            exist
          - tests in winfo.test that would otherwise fail (5.4 and 5.5), have been
            constrained to unix, and I don't see a good reason why that is so.

Because an immediately successive "update", cannot reliably prevent the issue
with "tk appname" on all platforms, I decide to resolve the issue by not
relying on the automatic detection of duplicate interp names, and let the test
suite itself exert control over the interp names passed to child interpreters.

This is now done in commits [3aed0c3049] and [b04482afa7].

erikleunissen added on 2025-08-12 10:37:55:
Correction to the previous post: the test failures regarding test file send.test
under Linux were caused by a mistaken commit of mine. This is now corrected with
commit [9e85dfd977].

erikleunissen added on 2025-08-11 16:03:05:
Interestingly, "-singleproc 0" leads to some problems:

* Segfault under Windows, test file menu.test (even with -match NONE).
  Ticket for the segfault is here: [d8f9640fcd]

* Test failures under Linux, test file send.test, for:
send-4.1
send-4.2
send-5.4
send-7.1
send-7.2
send-7.3
send-7.4
send-9.1
send-9.2

* Test failure under Linux + Windows, test file config.test, for config-2.1.

erikleunissen added on 2025-08-11 11:41:16:
The implementation is now in commit [aedbf424a6].