From jai.forums2013 at gmail.com Fri Sep 3 14:25:04 2021 From: jai.forums2013 at gmail.com (Jaikiran Pai) Date: Fri, 3 Sep 2021 19:55:04 +0530 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <30a84ffd-7f37-3440-c820-34f2d02cf8f5@gmail.com> References: <30a84ffd-7f37-3440-c820-34f2d02cf8f5@gmail.com> Message-ID: <0af0cecb-6ef4-b8d5-684b-5d1bb0cec1ad@gmail.com> Any inputs? Is this a bug or an intentional implementation detail? -Jaikiran On 29/08/21 6:54 pm, Jaikiran Pai wrote: > Please consider this trivial Java code which prints to System.out: > > public class FooTest { > ??? public static void main(final String[] args) throws Exception { > ??????? final String m = "hello \\ world"; > ??????? System.out.println("Message is " + m); > ??? } > } > > When you run this as Java code using the "java" command, the output > that gets printed is (as expected): > > Message is hello \ world > > Now, if I convert this Java code a jtreg test as follows (without any > code change, just adding jtreg tags): > > /** > ?* @test > ?* @run main FooTest > ?*/ > public class FooTest { > ??? public static void main(final String[] args) throws Exception { > ??????? final String m = "hello \\ world"; > ??????? System.out.println("Message is " + m); > ??? } > } > > Running it as a jtreg test, generates a report which has the > System.out section that is: > > ----------System.out:(1/26)*---------- > Message is hello \\ world > > Notice the unexpected additional backslash in that output. Is this > intentional? > > In a non-trivial test case, that I was working on, it took me a (long) > while to figure out that it was jtreg which was adding the additional > backslash in the output and it wasn't my test case that had something > wrong. > > For reference, jtreg -version gives: > > jtreg -version > jtreg 6-dev+0 > Installed in /jtreg/build/images/jtreg/lib/jtreg.jar > Running on platform version 1.8.0_265 from > /adoptopenjdk-8.jdk/Contents/Home/jre. > Built with Java(TM) 2 SDK, Version 1.8.0_265-b01 on June 27, 2021. > Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights > reserved. > Use is subject to license terms. > JT Harness, version 6.0 ea b14 (June 27, 2021) > JCov 3.0-2 > Java Assembler Tools, version 7.0 ea b09 (June 27, 2021) > TestNG (testng.jar): version 7.3.0 > TestNG (jcommander.jar): version unknown > TestNG (guice.jar): version 4.2.3 > JUnit (junit.jar): version 4.13.2 > JUnit (hamcrest.jar): version 2.2 > > -Jaikiran > > > > From pavel.rappo at oracle.com Wed Sep 15 13:15:14 2021 From: pavel.rappo at oracle.com (Pavel Rappo) Date: Wed, 15 Sep 2021 13:15:14 +0000 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? Message-ID: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> David Holmes pointed me to this thread after I started a discussion elsewhere. Coincidentally, I stumbled upon the described jtreg behavior myself yesterday. It took me a while to figure out what was happening. When I described my finding to a colleague, Jonathan Gibbons, he suggested that if required I could read `.jtr` files using a (lesser-known?) option called `show`. This option's description is buried in help output and is not particularly clear: (Care to file a bug to improve that? File a JBS issue against Project=CODETOOLS and Subcomponent=jtreg.) $ jtreg --help General Options | grep -A 3 'show: Show information from a section in the results file for a test. For example, -show:rerun -showGroups Show the expansion (to files and directories) of the groups As far as I understand, when run with this option, jtreg does not run your test. Instead, it reads the specified section from the existing `.jtr` file and outputs the same way it would otherwise appear on the console: no escapes. You can specify System.out or System.err as such a section. Now, here are some details. JTHarness, which is used by jtreg, encodes special symbols it encounters in standard streams. While CR, LR and TAB are output as they are, \ is output as \\ and the rest of the escape sequences are output using the \uxxxx notation. The code I saw suggests that it is not a bug and is done on purpose. Anyhow, this is how output is stored in `.jtr` files. My understanding is that jtreg knows about that and recovers original output from `.jtr` files on demand. -Pavel From jonathan.gibbons at oracle.com Wed Sep 15 14:30:39 2021 From: jonathan.gibbons at oracle.com (Jonathan Gibbons) Date: Wed, 15 Sep 2021 07:30:39 -0700 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <0af0cecb-6ef4-b8d5-684b-5d1bb0cec1ad@gmail.com> References: <30a84ffd-7f37-3440-c820-34f2d02cf8f5@gmail.com> <0af0cecb-6ef4-b8d5-684b-5d1bb0cec1ad@gmail.com> Message-ID: <58984f20-bea1-528e-9040-18909605d733@oracle.com> Jaikiran, The encoding is intentional ... and has been there since the beginning of jtreg! While .jtr files are intended to only contain ASCII characters, they are not intended for direct human consumption.? The stream output from tests is encoded so that it can be subsequently read back in by jtreg and related software. To view the output of a test without the encoding used in the .jtr file, use one of: * run the test under jtreg with the -va option * run the test directly, using its main(String...) method ... you can get a script to run the test from the "rerun" section in the .jtr file * use jtreg to report the content of the stream using the `-show:` option, such as `jtreg -w:/path/to/work -show:System.out /path/to/test -- Jon On 9/3/21 7:25 AM, Jaikiran Pai wrote: > Any inputs? Is this a bug or an intentional implementation detail? > > -Jaikiran > > On 29/08/21 6:54 pm, Jaikiran Pai wrote: >> Please consider this trivial Java code which prints to System.out: >> >> public class FooTest { >> ??? public static void main(final String[] args) throws Exception { >> ??????? final String m = "hello \\ world"; >> ??????? System.out.println("Message is " + m); >> ??? } >> } >> >> When you run this as Java code using the "java" command, the output >> that gets printed is (as expected): >> >> Message is hello \ world >> >> Now, if I convert this Java code a jtreg test as follows (without any >> code change, just adding jtreg tags): >> >> /** >> ?* @test >> ?* @run main FooTest >> ?*/ >> public class FooTest { >> ??? public static void main(final String[] args) throws Exception { >> ??????? final String m = "hello \\ world"; >> ??????? System.out.println("Message is " + m); >> ??? } >> } >> >> Running it as a jtreg test, generates a report which has the >> System.out section that is: >> >> ----------System.out:(1/26)*---------- >> Message is hello \\ world >> >> Notice the unexpected additional backslash in that output. Is this >> intentional? >> >> In a non-trivial test case, that I was working on, it took me a >> (long) while to figure out that it was jtreg which was adding the >> additional backslash in the output and it wasn't my test case that >> had something wrong. >> >> For reference, jtreg -version gives: >> >> jtreg -version >> jtreg 6-dev+0 >> Installed in /jtreg/build/images/jtreg/lib/jtreg.jar >> Running on platform version 1.8.0_265 from >> /adoptopenjdk-8.jdk/Contents/Home/jre. >> Built with Java(TM) 2 SDK, Version 1.8.0_265-b01 on June 27, 2021. >> Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights >> reserved. >> Use is subject to license terms. >> JT Harness, version 6.0 ea b14 (June 27, 2021) >> JCov 3.0-2 >> Java Assembler Tools, version 7.0 ea b09 (June 27, 2021) >> TestNG (testng.jar): version 7.3.0 >> TestNG (jcommander.jar): version unknown >> TestNG (guice.jar): version 4.2.3 >> JUnit (junit.jar): version 4.13.2 >> JUnit (hamcrest.jar): version 2.2 >> >> -Jaikiran >> >> >> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonathan.gibbons at oracle.com Wed Sep 15 14:32:24 2021 From: jonathan.gibbons at oracle.com (Jonathan Gibbons) Date: Wed, 15 Sep 2021 07:32:24 -0700 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> References: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> Message-ID: <84a35709-7ca0-7ca6-883b-d5e8173bf0db@oracle.com> On 9/15/21 6:15 AM, Pavel Rappo wrote: > (Care to file a bug to improve that? File a JBS issue against Project=CODETOOLS and Subcomponent=jtreg.) Yesterday, I filed and fixed CODETOOLS-7903024. -- Jon From jonathan.gibbons at oracle.com Wed Sep 15 14:35:44 2021 From: jonathan.gibbons at oracle.com (Jonathan Gibbons) Date: Wed, 15 Sep 2021 07:35:44 -0700 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> References: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> Message-ID: <4e6df09e-38ca-b7e1-8a7f-b8ad633467da@oracle.com> Separate from fixing/improving jtreg -show: option and its command-line help (CODETOOLS-7903024), given the recent interest in this issue, I'll add info to the FAQ. -- Jon On 9/15/21 6:15 AM, Pavel Rappo wrote: > David Holmes pointed me to this thread after I started a discussion elsewhere. Coincidentally, I stumbled upon the described jtreg behavior myself yesterday. It took me a while to figure out what was happening. When I described my finding to a colleague, Jonathan Gibbons, he suggested that if required I could read `.jtr` files using a (lesser-known?) option called `show`. This option's description is buried in help output and is not particularly clear: (Care to file a bug to improve that? File a JBS issue against Project=CODETOOLS and Subcomponent=jtreg.) > > $ jtreg --help General Options | grep -A 3 'show: -show: > Show information from a section in the results file for a > test. For example, -show:rerun > -showGroups Show the expansion (to files and directories) of the groups > > As far as I understand, when run with this option, jtreg does not run your test. Instead, it reads the specified section from the existing `.jtr` file and outputs the same way it would otherwise appear on the console: no escapes. You can specify System.out or System.err as such a section. > > Now, here are some details. JTHarness, which is used by jtreg, encodes special symbols it encounters in standard streams. While CR, LR and TAB are output as they are, \ is output as \\ and the rest of the escape sequences are output using the \uxxxx notation. The code I saw suggests that it is not a bug and is done on purpose. Anyhow, this is how output is stored in `.jtr` files. My understanding is that jtreg knows about that and recovers original output from `.jtr` files on demand. > > -Pavel > From jonathan.gibbons at oracle.com Wed Sep 15 14:52:58 2021 From: jonathan.gibbons at oracle.com (Jonathan Gibbons) Date: Wed, 15 Sep 2021 07:52:58 -0700 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <4e6df09e-38ca-b7e1-8a7f-b8ad633467da@oracle.com> References: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> <4e6df09e-38ca-b7e1-8a7f-b8ad633467da@oracle.com> Message-ID: <69f62f9e-7dee-6c5f-1d9b-7871ac2ad615@oracle.com> The FAQ already covers this to some extent: https://openjdk.java.net/jtreg/faq.html#how-do-i-view-what-a-test-sends-to-system.out-or-system.err I'll still consider adding more info. -- Jon On 9/15/21 7:35 AM, Jonathan Gibbons wrote: > Separate from fixing/improving jtreg -show: option and its > command-line help (CODETOOLS-7903024), given the recent interest in > this issue, I'll add info to the FAQ. > > -- Jon > > > On 9/15/21 6:15 AM, Pavel Rappo wrote: >> David Holmes pointed me to this thread after I started a discussion >> elsewhere. Coincidentally, I stumbled upon the described jtreg >> behavior myself yesterday. It took me a while to figure out what was >> happening. When I described my finding to a colleague, Jonathan >> Gibbons, he suggested that if required I could read `.jtr` files >> using a (lesser-known?) option called `show`. This option's >> description is buried in help output and is not particularly clear: >> (Care to file a bug to improve that? File a JBS issue against >> Project=CODETOOLS and Subcomponent=jtreg.) >> >> ???? $ jtreg --help General Options | grep -A 3 'show:> ???????? -show: >> ???????????????????????? Show information from a section in the >> results file for a >> ???????????????????????? test. For example, -show:rerun >> ???????? -showGroups???? Show the expansion (to files and >> directories) of the groups >> ???????? As far as I understand, when run with this option, jtreg >> does not run your test. Instead, it reads the specified section from >> the existing `.jtr` file and outputs the same way it would otherwise >> appear on the console: no escapes. You can specify System.out or >> System.err as such a section. >> >> Now, here are some details. JTHarness, which is used by jtreg, >> encodes special symbols it encounters in standard streams. While CR, >> LR and TAB are output as they are, \ is output as \\ and the rest of >> the escape sequences are output using the \uxxxx notation. The code I >> saw suggests that it is not a bug and is done on purpose. Anyhow, >> this is how output is stored in `.jtr` files. My understanding is >> that jtreg knows about that and recovers original output from `.jtr` >> files on demand. >> >> -Pavel >> From jonathan.gibbons at oracle.com Wed Sep 15 14:54:30 2021 From: jonathan.gibbons at oracle.com (Jonathan Gibbons) Date: Wed, 15 Sep 2021 07:54:30 -0700 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <949524ED-CA5E-4AEF-AD43-2ED087577447@oracle.com> References: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> <84a35709-7ca0-7ca6-883b-d5e8173bf0db@oracle.com> <949524ED-CA5E-4AEF-AD43-2ED087577447@oracle.com> Message-ID: <61f54594-815f-32d4-26eb-c674f98bd891@oracle.com> My fault, it's fixed on my laptop but I didn't get around to the final "Commit" after running all the self-tests. -- Jon On 9/15/21 7:41 AM, Pavel Rappo wrote: > Thanks for filing it, Jon. That said, I can see that https://bugs.openjdk.java.net/browse/CODETOOLS-7903024 is still Open (Unresolved) and there are no recent relevant commits to https://github.com/openjdk/jtreg/. > > Where did you fix it? > >> On 15 Sep 2021, at 15:32, Jonathan Gibbons wrote: >> >> >> On 9/15/21 6:15 AM, Pavel Rappo wrote: >>> (Care to file a bug to improve that? File a JBS issue against Project=CODETOOLS and Subcomponent=jtreg.) >> Yesterday, I filed and fixed CODETOOLS-7903024. >> >> -- Jon >> From pavel.rappo at oracle.com Wed Sep 15 14:41:27 2021 From: pavel.rappo at oracle.com (Pavel Rappo) Date: Wed, 15 Sep 2021 14:41:27 +0000 Subject: jtreg adds additional backslashes in Strings that are written to System.out/err? In-Reply-To: <84a35709-7ca0-7ca6-883b-d5e8173bf0db@oracle.com> References: <54F0F64B-E9DE-4B3F-86EE-AD774090DC8B@oracle.com> <84a35709-7ca0-7ca6-883b-d5e8173bf0db@oracle.com> Message-ID: <949524ED-CA5E-4AEF-AD43-2ED087577447@oracle.com> Thanks for filing it, Jon. That said, I can see that https://bugs.openjdk.java.net/browse/CODETOOLS-7903024 is still Open (Unresolved) and there are no recent relevant commits to https://github.com/openjdk/jtreg/. Where did you fix it? > On 15 Sep 2021, at 15:32, Jonathan Gibbons wrote: > > > On 9/15/21 6:15 AM, Pavel Rappo wrote: >> (Care to file a bug to improve that? File a JBS issue against Project=CODETOOLS and Subcomponent=jtreg.) > > Yesterday, I filed and fixed CODETOOLS-7903024. > > -- Jon >