bug#75440: dejagnu does not like java.io.Console of OpenJDK >= 22

Jacob Bachmeyer <[email protected]> Tue, 14 Jan 2025 22:00:04 -0600
Newsgroups gmane.comp.sysutils.dejagnu.bugs
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============4243688952732098456==
Content-Type: multipart/alternative;
 boundary="------------nEGNbh0quLEX0Ih2vBfcniNt"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------nEGNbh0quLEX0Ih2vBfcniNt
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

[actually you had the new ZIP file on the first message; I can tell 
because the Java program has a loop now]

[also, traditional email discussions use inline responses with a summary 
or further commentary at the end after the response to the last quote; 
please refrain from top-posting if possible]

On 1/14/25 05:12, Chris Nospam wrote:
> Dear Jacob,
> sorry for my late reply and thanks for your rapid and detailed answer. 
> Also I am sorry for the faulty default.exp, it was a quick & dirty 
> version to trigger the bug and only a short snipped of my real project.

That is a new piece of information and I have found other issues that I 
would normally overlook in a small testsuite, but will make problems for 
you in a large testsuite.  More on this below.

> It should only show the problem with the first echo. However, I have 
> enhanced it somehow now, see the attachement.

I see that the new version of your sample program now contains a loop 
instead of exiting unconditionally after the first input. This produces 
a more useful error, complete with a backtrace explaining how you got 
there.  (The framework will call a "${tool}_exit" procedure during 
per-target cleanup if it exists.)

Unfortunately, coordinating the exit of an interactive program is 
tedious because Expect will close the channel upon reading EOF and 
expecting on a closed channel throws an error.  (This should be a hint 
towards one way to solve the problem.)

You should try using runtest's --debug option, which will cause Expect 
to write considerable information about its operation to the "dbg.log" 
file.  That log is particularly useful when seeking to understand why 
patterns do or do not match.

> > Tcl interpolates backslash escapes in double-quoted strings
> I changed now \r\n to \\r\\n in all regular expressions.

It is important to understand what Tcl will do with your code, although 
that particular item "happens to work" either way. (Literal carriage 
return and newline match themselves in Tcl regexps in normal syntax, but 
can make dbg.log harder to read.)

> Please forgive me, I am not an expert in expect script but I try to do 
> my best. I would be happy if you could give me some (direct) advices.

You still need to think about what your test results mean. DejaGnu has 
other status codes because simple PASS/FAIL does not really work in the 
real world.  You should be using "perror" and "unresolved" to report 
inabilities to run the test program.

More concretely, simple_start should clear the prompt_error flag upon 
receiving a prompt and should use "perror" instead of "send_user" to 
report failure to spawn the program.

Similarly, if the prompt_error flag is set, "simple_test" should emit an 
UNRESOLVED result (using the "unresolved" procedure) before returning, 
because the test was not performed due to a run-time condition.

The important rule here is that the total number of test results should 
not change.

Tcl allows optional arguments; you can replace the dispatch logic around 
"simple_test" by using {proc simple_test {expr result {comment ""}} 
...}  (The outer-most brace pair denotes a Tcl code fragment.)

Tcl procedure arguments are also ordinary local variables, so you can do 
{ if {$comment ne ""} {set comment "\[$comment\]"} } in a combined 
"simple_test" if you want.

Think carefully about what you are doing with the "answer" global 
variable.  It should probably be an argument, if not the "result" 
argument that you already have.

Lastly, your "if" conditionals should usually be in braces; this allows 
the Tcl compiler to produce more efficient bytecode.

> I will open a corresponding issue at https://bugreport.java.com and 
> report back a link. Hopefully, they will look into/fix it and not only 
> dismiss that using dejagnu is an edge case.

Hopefully they will at least recognize that a transparent console mode 
is important and ensure that one remains supported.


-- Jacob

--------------nEGNbh0quLEX0Ih2vBfcniNt
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">[actually you had the new ZIP file on
      the first message; I can tell because the Java program has a loop
      now]</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">[also, traditional email discussions
      use inline responses with a summary or further commentary at the
      end after the response to the last quote; please refrain from
      top-posting if possible]<br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">On 1/14/25 05:12, Chris Nospam wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:trinity-e7e965ee-266d-4ed1-8da4-f3f6bfb162c1-1736853121135@trinity-msg-rest-gmx-gmx-live-bbc95d94c-lv4zd">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div style="font-family: 'verdana'; font-size: 12px; color: #000;">
        <div>Dear Jacob,</div>
        <div
style="font-family: verdana; font-size: 12px; color: rgb(0, 0, 0);"> </div>
        <div
style="font-family: verdana; font-size: 12px; color: rgb(0, 0, 0);">sorry
          for my late reply and thanks for your rapid and detailed
          answer. Also I am sorry for the faulty default.exp, it was a
          quick &amp; dirty version to trigger the bug and only a short
          snipped of my real project.</div>
      </div>
    </blockquote>
    <p>That is a new piece of information and I have found other issues
      that I would normally overlook in a small testsuite, but will make
      problems for you in a large testsuite.  More on this below.<br>
    </p>
    <blockquote type="cite"
cite="mid:trinity-e7e965ee-266d-4ed1-8da4-f3f6bfb162c1-1736853121135@trinity-msg-rest-gmx-gmx-live-bbc95d94c-lv4zd">
      <div style="font-family: 'verdana'; font-size: 12px; color: #000;">
        <div
style="font-family: verdana; font-size: 12px; color: rgb(0, 0, 0);"> It
          should only show the problem with the first echo. However, I
          have enhanced it somehow now, see the attachement.</div>
      </div>
    </blockquote>
    <p>I see that the new version of your sample program now contains a
      loop instead of exiting unconditionally after the first input. 
      This produces a more useful error, complete with a backtrace
      explaining how you got there.  (The framework will call a
      "${tool}_exit" procedure during per-target cleanup if it exists.)</p>
    <p>Unfortunately, coordinating the exit of an interactive program is
      tedious because Expect will close the channel upon reading EOF and
      expecting on a closed channel throws an error.  (This should be a
      hint towards one way to solve the problem.)</p>
    <p>You should try using runtest's --debug option, which will cause
      Expect to write considerable information about its operation to
      the "dbg.log" file.  That log is particularly useful when seeking
      to understand why patterns do or do not match.<br>
    </p>
    <blockquote type="cite"
cite="mid:trinity-e7e965ee-266d-4ed1-8da4-f3f6bfb162c1-1736853121135@trinity-msg-rest-gmx-gmx-live-bbc95d94c-lv4zd">
      <div style="font-family: 'verdana'; font-size: 12px; color: #000;">
        <div>&gt; Tcl interpolates backslash escapes in double-quoted
          strings</div>
        <div>I changed now \r\n to \\r\\n in all regular expressions.</div>
      </div>
    </blockquote>
    <p>It is important to understand what Tcl will do with your code,
      although that particular item "happens to work" either way. 
      (Literal carriage return and newline match themselves in Tcl
      regexps in normal syntax, but can make dbg.log harder to read.)</p>
    <blockquote type="cite"
cite="mid:trinity-e7e965ee-266d-4ed1-8da4-f3f6bfb162c1-1736853121135@trinity-msg-rest-gmx-gmx-live-bbc95d94c-lv4zd">
      <div style="font-family: 'verdana'; font-size: 12px; color: #000;">
        <div>Please forgive me, I am not an expert in expect script but
          I try to do my best. I would be happy if you could give me
          some (direct) advices.</div>
      </div>
    </blockquote>
    <p>You still need to think about what your test results mean. 
      DejaGnu has other status codes because simple PASS/FAIL does not
      really work in the real world.  You should be using "perror" and
      "unresolved" to report inabilities to run the test program.</p>
    <p>More concretely, simple_start should clear the prompt_error flag
      upon receiving a prompt and should use "perror" instead of
      "send_user" to report failure to spawn the program.</p>
    <p>Similarly, if the prompt_error flag is set, "simple_test" should
      emit an UNRESOLVED result (using the "unresolved" procedure)
      before returning, because the test was not performed due to a
      run-time condition.</p>
    <p>The important rule here is that the total number of test results
      should not change.<br>
    </p>
    <p>Tcl allows optional arguments; you can replace the dispatch logic
      around "simple_test" by using {proc simple_test {expr result
      {comment ""}} ...}  (The outer-most brace pair denotes a Tcl code
      fragment.)<br>
    </p>
    <p>Tcl procedure arguments are also ordinary local variables, so you
      can do { if {$comment ne ""} {set comment "\[$comment\]"} } in a
      combined "simple_test" if you want.<br>
    </p>
    <p>Think carefully about what you are doing with the "answer" global
      variable.  It should probably be an argument, if not the "result"
      argument that you already have.</p>
    <p>Lastly, your "if" conditionals should usually be in braces; this
      allows the Tcl compiler to produce more efficient bytecode.<br>
    </p>
    <blockquote type="cite"
cite="mid:trinity-e7e965ee-266d-4ed1-8da4-f3f6bfb162c1-1736853121135@trinity-msg-rest-gmx-gmx-live-bbc95d94c-lv4zd">
      <div style="font-family: 'verdana'; font-size: 12px; color: #000;">
        <div>I will open a corresponding issue at
          <a class="moz-txt-link-freetext" href="https://bugreport.java.com">https://bugreport.java.com</a> and report back a link. Hopefully,
          they will look into/fix it and not only dismiss that using
          dejagnu is an edge case.</div>
      </div>
    </blockquote>
    <p>Hopefully they will at least recognize that a transparent console
      mode is important and ensure that one remains supported.</p>
    <p><br>
    </p>
    <p>-- Jacob<br>
    </p>
  </body>
</html>

--------------nEGNbh0quLEX0Ih2vBfcniNt--




--===============4243688952732098456==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KQnVnLWRlamFn
bnUgbWFpbGluZyBsaXN0CkJ1Zy1kZWphZ251QGdudS5vcmcKaHR0cHM6Ly9saXN0cy5nbnUub3Jn
L21haWxtYW4vbGlzdGluZm8vYnVnLWRlamFnbnUK

--===============4243688952732098456==--