Project

General

Profile

Bug #9489

Support for different terminal encodings

Added by Tomasz Domin over 1 year ago. Updated 5 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

Related issues

Related to User Interface - Bug #7657: 8-bit character entry problem in ChUI Review

History

#1 Updated by Tomasz Domin over 1 year ago

Currently harness only supports hardcoded ISO-8859-1 character encoding for terminal sessions. In order to test different code pages or unicode text procesing it needs to support different character encodings for remote ssh terminal. As an option detecting remote terminal encoding could be done automatically.

#2 Updated by Tomasz Domin over 1 year ago

  • Related to Bug #7657: 8-bit character entry problem in ChUI added

#3 Updated by Tomasz Domin over 1 year ago

  • Status changed from New to WIP
  • % Done changed from 0 to 90

Created task branch harness/9489a
Commited a change (most of work doen yesterday)
Pushed up to revision 35.
Example usage:
-encoding utf-8
-encoding Cp1252

Encoding should be set according to terminal locale as an output of locale charmap command.

Default encoding is still iso-8859-1.

#4 Updated by Tomasz Domin over 1 year ago

  • % Done changed from 90 to 100
  • Status changed from WIP to Review

Seems to be working as expected, please review

#5 Updated by Greg Shah over 1 year ago

  • reviewer Eugenie Lyzenko, Greg Shah added

#6 Updated by Greg Shah over 1 year ago

Code Review Task Branch 9489a Revision 35

I have no objections, it looks reasonable.

I do wonder if (in the future) we will need different encodings for different driver threads or tests. It isn't something to solve now.

#7 Updated by Greg Shah over 1 year ago

Eugenie: Please review.

#8 Updated by Eugenie Lyzenko over 1 year ago

Greg Shah wrote:

Eugenie: Please review.

I have no objections. It works fine with wide char linked native libp2j.so. The good point is we can just use different config options instead of rebuilding harness for particular tasks.

#9 Updated by Greg Shah over 1 year ago

  • Status changed from Review to Internal Test

Eugenie: Please use this with your #7657 testing.

#10 Updated by Eugenie Lyzenko over 1 year ago

Greg Shah wrote:

Eugenie: Please use this with your #7657 testing.

Yes, I have already use this version instead of harness base/trunk.

#11 Updated by Greg Shah over 1 year ago

  • Status changed from Internal Test to Merge Pending

OK, then this can be merged.

#12 Updated by Tomasz Domin over 1 year ago

  • Status changed from Merge Pending to WIP
  • % Done changed from 100 to 50

Based on Eugenie's report in #7657-216 I think there is a problem with conversion of multi-byte charsets coming from underlying terminal in Harness.
The problem is probably caused by non-stream based conversion of a byte stream. Bytes are incoming from underlying session in chunks up to Terminal.BUFFER_SIZE length.
Then conversion to Character stream occurs using a classic new String(byte []byteArray, String charset) call, which gives wrong result in case multi-byte character appears on byteArray end and does not fully fit in byteArray. In such case underlying layer default conversion rules produce non-decodable Unicode character 0xFFFD when CharsetDecoder try to decode incomplete character for multi-byte character encodings (like UTF-16 or UTF-8).
The solution would be to switch from byte array based character decoding to stream based character decoding. The difference is how CharsetDecoder behaves on chunks borders - for byte array decoding it assumes no more bytes would come, for stream based processing it will wait for next byte to come and produce non-decodable Unicode character 0xFFFD only when underlying stream is closed.

As support for different terminal encodings would be incomplete without that change I will continue my work here.

#13 Updated by Eugenie Lyzenko over 1 year ago

Tomasz Domin wrote:

Based on Eugenie's report in #7657-216 I think there is a problem with conversion of multi-byte charsets coming from underlying terminal in Harness.
The problem is probably caused by non-stream based conversion of a byte stream. Bytes are incoming from underlying session in chunks up to Terminal.BUFFER_SIZE length.
Then conversion to Character stream occurs using a classic new String(byte []byteArray, String charset) call, which gives wrong result in case multi-byte character appears on byteArray end and does not fully fit in byteArray. In such case underlying layer default conversion rules produce non-decodable Unicode character 0xFFFD when CharsetDecoder try to decode incomplete character for multi-byte character encodings (like UTF-16 or UTF-8).
The solution would be to switch from byte array based character decoding to stream based character decoding. The difference is how CharsetDecoder behaves on chunks borders - for byte array decoding it assumes no more bytes would come, for stream based processing it will wait for next byte to come and produce non-decodable Unicode character 0xFFFD only when underlying stream is closed.

As support for different terminal encodings would be incomplete without that change I will continue my work here.

How about to increase the reading buffer size(Terminal.BUFFER_SIZE) to 8192 to cover full screen data (80x24x4bytes) with single buffer?

In wide char version the size of full screen in bytes is doubling.

#14 Updated by Tomasz Domin over 1 year ago

Eugenie Lyzenko wrote:

How about to increase the reading buffer size(Terminal.BUFFER_SIZE) to 8192 to cover full screen data (80x24x4bytes) with single buffer?

In wide char version the size of full screen in bytes is doubling.

I don't think that would solve a general case, AFAIR terminal is not producing line based output so buffer is not filled with line and there is no direct relation here, it is producing stream of bytes to be decoded by VT320 emulator - where we get that line based output, but not earlier. IMHO increasing buffer size would only reduce probability the issue would happen.

I've created task branch 9489b based on 9489a. I had a working solution based on PipedInput/OutputStream but that requires additional threads I'd prefer to avoid.

#15 Updated by Tomasz Domin over 1 year ago

Tomasz Domin wrote:

I've created task branch 9489b based on 9489a. I had a working solution based on PipedInput/OutputStream but that requires additional threads I'd prefer to avoid.

I've implemented java.nio based stream decoding in harness in 9489b revision 36.
Its under testing, but Eugenie you may try it for #7657.
ps. I've actually reduced buffer size as I needed two additional buffers and I didn't want memory consumption increase.

#16 Updated by Tomasz Domin over 1 year ago

  • Assignee set to Tomasz Domin

#17 Updated by Tomasz Domin over 1 year ago

  • Assignee deleted (Tomasz Domin)

Tomasz Domin wrote:

Based on Eugenie's report in #7657-216 I think there is a problem with conversion of multi-byte charsets coming from underlying terminal in Harness.

I was able to replicate #7657-216 issue immediately by reducing Terminal.BUFFER_SIZE size in 9489a from 4096 bytes to 64 bytes.
Reducing Terminal.BUFFER_SIZE in 9489b had no such effect, thus I think the issue is fixed in 9489b

#18 Updated by Tomasz Domin over 1 year ago

  • Assignee set to Tomasz Domin

#19 Updated by Tomasz Domin over 1 year ago

  • % Done changed from 50 to 100
  • Status changed from WIP to Review

Its seems its working fine. Made some javadoc updates and Pushed up to revision 37. Updated harness wiki page.

Please review 9489b revisions 36-37

#20 Updated by Tomasz Domin over 1 year ago

Eugenie - did you find the change working for you ? especially regarding #7657

#21 Updated by Eugenie Lyzenko over 1 year ago

Tomasz Domin wrote:

Eugenie - did you find the change working for you ? especially regarding #7657

Yes, your fixes are working for harness with wide char capable FWD, thanks a lot. The option -encoding utf-8 should be use when testing wide char FWD. The issue with 0xFFFD is not happening anymore.

#22 Updated by Greg Shah over 1 year ago

Code Review Task Branch 9489b Revisions 36 and 37

In Terminal, shouldn't we have some code to handle cases where the Charset.forName() fails (bad charset name) or setup of the CharsetDecoder fails?

Otherwise I have no objections.

#23 Updated by Tomasz Domin over 1 year ago

Greg Shah wrote:

Code Review Task Branch 9489b Revisions 36 and 37

In Terminal, shouldn't we have some code to handle cases where the Charset.forName() fails (bad charset name) or setup of the CharsetDecoder fails?

Otherwise I have no objections.

Initially I was thinking about checking charset on parameters parsing, then I left as I thought it would fail anyway in test initialization. But after I tested it now it seems bad charset only terminates Driver thread causing unnecessary delays to be handled by testing script.

Committed revision 9489b/38 with changes to check charset at beginning of test execution to fail fast in case its invalid.
Please review.

#24 Updated by Greg Shah over 1 year ago

  • Status changed from Review to Internal Test

Code Review Task Branch 9489a Revision 38

The changes are good.

#25 Updated by Tomasz Domin over 1 year ago

Tested branch 9489b with regression tests - both with and without #7657 branch 7657a:
  • for 7657a with following Harness options: -encoding utf-8
  • for trunk with following Harness options: with and without -encoding utf-8 option

Results are identical. I guess its safe to merge it back to harness/trunk

#26 Updated by Greg Shah over 1 year ago

  • Status changed from Internal Test to Merge Pending

You can merge it now.

#27 Updated by Tomasz Domin over 1 year ago

  • Status changed from Merge Pending to Test

Task branch 9489b has been merged into harness/trunk and archived.

#28 Updated by Greg Shah 5 months ago

  • Status changed from Test to Closed

Also available in: Atom PDF