From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 3A5483858D1E for ; Sat, 24 Dec 2022 05:33:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A5483858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-x22f.google.com with SMTP id d127so4874791oif.12 for ; Fri, 23 Dec 2022 21:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:subject:cc:to :mime-version:user-agent:reply-to:from:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=fDHkv/7q3/jswZF0m9f19bpJUkbuSeqhfFevb129iYg=; b=hWwOlHBV9nBqxNm5ATD8U89j8K8hlCazENmlKjgSXY/vzSnV5HnD9pE6coOuG+kUAN Upi8Rswy9O8KCcDaF5vEcF+RakKdnkzESRmpvut6Abjx3Hgsxzv6O5cOh7zDNGwBGkXk jJBJx3DDnEPtz4G4dfaAauZ4FSVCBxk9nOSPCxRkQfkBJN/tx3MreU9qZAYqN25E14Zh VjkZhd5JHXs0tW99MJWrJdVixvVWSFeLBdKRUvOG2pVvFdEusVWG3E6DTaul/bFBg9N+ LYUPqEFSJJCK5I6ZB1ggEQ4xqsXAm8ckqKH3QtMmz3s1bRKEMnrWstqHj+S8R1HvPBjm BAiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:subject:cc:to :mime-version:user-agent:reply-to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fDHkv/7q3/jswZF0m9f19bpJUkbuSeqhfFevb129iYg=; b=RWKYulxDxZrMY7fiW8tUYOxbXG7Qepvrhvs7TUsW0w0V4SH+Lh7hABsnyGf7VvM180 y1NhkIc5thkGuRsbk+nup1ale/ITOX6V+cKhhBwdasK4oJINHfHeCm3T72Kwbg/4CFnc US7yrQ4RkBD3KjtzGQ2dntOeKpE/elp8h1UWuPztZY9wuV9Jch+J0k/pajLuDW7vpwiK C7QwEerVPFsLtL2Gaq9tiechUPbIDI3shjqOL/Lgkc6ZcGQFg0sXxBEIood8RrdI3gBh 9lAxzcezZ8T33tMeRSMUa6VKaD2aPOn/WcZQKMeuVcOkF718uUYwtsvxUgRlk1CugS9f C6Rg== X-Gm-Message-State: AFqh2kr9MtYWyY55tocG4KmVuTGMGqMJRlcckEzM/603oqGyQJ3MjajL /kxhogKO8+jaDW8CYNs0NsQ= X-Google-Smtp-Source: AMrXdXtQm4d4Gq/29A2Cvp/rG6XKK1pOMTHH0iSaOiTl5cavWtAsFQUPWO+vI7PD+nI1Hqr+cMuF2g== X-Received: by 2002:a05:6808:2384:b0:355:1de8:de31 with SMTP id bp4-20020a056808238400b003551de8de31mr7431863oib.10.1671860017430; Fri, 23 Dec 2022 21:33:37 -0800 (PST) Received: from [127.0.0.1] ([70.133.144.146]) by smtp.gmail.com with ESMTPSA id j12-20020a9d7f0c000000b00660fe564e12sm2584055otq.58.2022.12.23.21.33.36 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Dec 2022 21:33:37 -0800 (PST) Message-ID: <63A68F2E.6080904@gmail.com> Date: Fri, 23 Dec 2022 23:33:34 -0600 From: Jacob Bachmeyer Reply-To: jcb62281@gmail.com User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090807 SeaMonkey/1.1.17 Mnenhy/0.7.6.0 MIME-Version: 1.0 To: Jacek Caban CC: Eric Pouech , fortran@gcc.gnu.org, NightStrike , DejaGnu mailing list Subject: Re: testsuite under wine References: <639FE88D.7090408@gmail.com> <7cb45ab2-cc6e-c502-5592-51ffabcbc6f8@codeweavers.com> <63A3DA04.4060804@gmail.com> <0bfd557c-aa07-dac5-86f4-104e71593212@orange.fr> <63A525CE.4070408@gmail.com> <446e92cc-4942-5095-b92e-bed4db13f615@codeweavers.com> In-Reply-To: <446e92cc-4942-5095-b92e-bed4db13f615@codeweavers.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FREEMAIL_REPLYTO_END_DIGIT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Jacek Caban wrote: > On 12/23/22 04:51, Jacob Bachmeyer wrote: >> Eric Pouech wrote: >>> Le 22/12/2022 à 05:16, Jacob Bachmeyer a écrit : >>>>> I think that it would not be enough. The way Windows consoles work >>>>> is that we manage complete internal screen buffer and emit output >>>>> that synchronizes the buffer with Unix terminal inside conhost.exe >>>>> process. It means that its output heavily processed and may be >>>>> very different from what application writes to its console handle. >>>>> While escape codes discussed in this thread are the most prominent >>>>> difference (and that part could, in theory, be improved on our >>>>> side), there are more differences. For example, if application >>>>> writes "\rA\rB\rC", conhost will process it, update its internal >>>>> buffer which changes just one character and cursor position, and >>>>> emit sequence to update it in Unix terminal, which could be just >>>>> "\rC" (or even "C" if cursor was already at the beginning of the >>>>> line). Another example would be long lines: conhost will emit >>>>> additional EOLs instead of depending on embedder to wrap the line. >>>> >>>> So conhost is essentially a Wine-specific screen(1) in that sense, >>>> except that it translates Windows screen buffer manipulations >>>> instead of VT100 escape codes? As I understand ncurses also >>>> implements most of this; perhaps simply delegating output to >>>> ncurses would solve the problem? If output were simply delegated >>>> to ncurses, (as I understand) setting TERM=dumb should be effective >>>> to eliminate escape codes from the output, since the "dumb" >>>> terminal does not support them. >>> >>> unfortunately, things are not as simple as that: on one hand we need >>> to mimic Windows behavior, and on the other hand let apps running in >>> wine behave like regular posix applications >>> >>> (Note: conhost(.exe) is not wine specific, it's part of the way >>> windows handle the console input/output) >> >> Right. So that is the name of the program that manages consoles in >> Windows. I knew it was not cmd.exe itself. I was testing an >> understanding that conhost.exe in Wine is essentially similar to GNU >> screen, in that both emulate a console/terminal using a *nix >> terminal. If so, then it should be possible to delegate the actual >> output (including reductions like the example "\rA\rB\rC" to "\rC") >> to the ncurses library and get proper sensitivity to TERM "for free" >> as well. >> >> To do that, conhost.exe would need to translate the Windows console >> buffer manipulations into curses operations, or possibly lower-level >> terminfo operations, if you still want to roll your own optimization >> code. If this were done, you could check if the current terminal has >> sufficient support to properly emulate a Windows console and switch >> to "raw" mode if the needed terminfo capabilities are not found. >> Setting TERM=dumb in the environment would then force the use of >> "raw" mode. > > > Yes, an analogy to screen is right in many aspects, but there are also > architectural difference that require implementation to be very > different. ncurses operates on tty file descriptors backed by OS > kernel. conhost needs to be able to operate on Windows names pipes, > which are not associated with any file descriptor in Wine. Please explain this. Programs using curses make calls into the curses library, which ultimately produces I/O on a tty file descriptor. It seems to me that conhost is in the same position as the curses library: programs use Windows API calls for the console which [...across an IPC bridge of some type?...] result in dispatches in conhost that ultimately produce I/O on a tty file descriptor. Does conhost not actually hold the file descriptor, instead performing translations and sending the result back to the client process, which writes it out? If full curses is not usable for architectural reasons, terminfo would still be an improvement. Its setupterm() call may send any known init strings, but it could be given either the write end of a pipe or a file descriptor open on /dev/null if that is a problem. The terminfo database access functions tparm(), tigetflag(), tigetnum(), and tigetstr() all return values to their callers for further processing and the information needed to perform curses-style terminal initialization is stored as string capabilities in the terminfo database. > Also my point was that if you capture the output sent by the > application to the terminal and match that to a pattern, then any > processing made by conhost could cause problems. Please correct me if > I'm wrong, but my understanding is that, in the above hypothetical > example, a test case doing printf(stdout, "\rA\rB\rC") and matching > output to "\rA\rB\rC" would be considered valid (and fail on Wine). This type of thing is a general problem with testing curses programs, so the only difference would be effectively adding curses to programs that are not expected to use it. Yes, this could break testsuites that should work, so some kind of full bypass would be very helpful; you already have this if wine is run inside a pipeline. > That's why we're trying to figure out a solution that bypasses conhost > and makes the application write directly to stdout, like usual native > application would do. Such mode would be less compatible with Windows, > but if tests only does simple I/O and no other console interactions, > it should work fine. Interpreting TERM=dumb would be a possible > solution to enter that mode. I see two aspects to this, and I think both of them have value as improvements to Wine: 1. Programs that only use the standard handles (a la ISO C) probably do not /want/ full compatibility with Windows, so their I/O should be direct to the underlying POSIX fds. Note that line endings are still an issue here, but are /not/ Wine's problem---the program's I/O library module is generating Windows-style line endings because it was written for Windows. 2. Programs using Windows CUI probably should be mapped to curses; as I see it, conhost currently is implementing a subset of curses, poorly since it does not use terminfo. Wine should use curses if $TERM supports curses and either pop up an X11 Wine console window or bail out if a CUI call is made and $TERM does not support curses. (Actually, an option to explicitly select an X11 Wine console window might be helpful for people that want to invoke a Windows CUI program from a graphical menu; otherwise, you might end up with the CUI silently appearing on the console from which the X session was started... I know adding xterm to the mix solves this, but it is a use case.) I think the best goal here is that, for the standard handles, Wine I/O should be equivalent to a network connection (telnet?) to a Windows box. For CUI, Wine should actually use curses or at least terminfo, to allow the escape codes produced to match the user's terminal. The user's terminal might not always be a VT100-alike and custom simulated terminals could be very reasonable for testing curses TUI programs. (To my knowledge, there are as yet no testsuites that actually /do/ that, but the composition seems reasonable to me.) Finding that NightStrike's MinGW test cases are transparently using CUI would be a MinGW issue, not a Wine issue. It has been a long time since I have looked at Windows API, but I am guessing that there is both some equivalent to "fwrite(stdout, ...)" (ok, so likely something like "WriteToHandle(GetStandardHandle(STANDARD_HANDLE_OUTPUT),...)" if I remember the Windows API "style" and its affinity for RSI-supporting names correctly) and a more complex API for CUI that is more closely akin to curses. Could you delay initializing conhost until the program actually attempts to use CUI features? For this option, CUIInit() ends up calling newterm() and using curses if that succeeds, (possibly, after considerable future implementation effort) popping up a Wine console window using X11 if $DISPLAY is usable, or bailing out if neither way to get a full Windows console works. Until CUIInit() is called, the standard handles are just that and simply mapped through to the underlying POSIX handles. Is this architecturally feasible for Wine to do? -- Jacob