Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHD: add Windows Server 2016 adapter & improve WS2016/2019 reliability #646

Merged
merged 8 commits into from
Feb 16, 2024

Conversation

gjcolombo
Copy link
Contributor

@gjcolombo gjcolombo commented Feb 15, 2024

Add a Windows Server 2016 guest adapter to PHD. It's more or less identical to the Windows Server 2019 adapter (but is still worth keeping separate since the guests support different command-line tools and Powershell cmdlets out of the box).

Tighten a few bolts to improve (but not perfect) test performance and reliability for these guests:

  • Rework the way shell commands are issued:
    • GuestOses now specify a serial console CommandSequence that the framework should execute in order to run a shell command.
    • Waiting for a string to appear in the serial console buffer no longer consumes any characters from the buffer. Instead, callers must clear the buffer manually.

With this change, it no longer matters that Windows guests don't re-echo characters that are already on-screen, because the framework no longer invalidates them until it knows they're no longer wanted.

Additionally improve the keystroke debounce logic:

  • Only apply the debounce delay if the next character to be issued is the same as the previous character. This allows the debounce timeout to be lengthened considerably without tanking test performance (which is important to minimize flakiness).

    It might be worth investigating whether we could avoid this delay by doing byte-by-byte "call and response" for characters we expect the guest to echo. This may require a more substantial refactoring of the serial console code, so I've just resorted to having a longer debounce for now.

  • Change TestVm::send_serial_bytes_async to wait for the serial task to acknowledge that it has sent all the requested bytes to the guest before returning so that TestVm can time out waiting for characters to be echoed without including the time spent waiting for them to be sent.

Tested with WS2016, WS2019, and Debian 11 guests.

Fixes #601. Fixes #644. Fixes #643.

@gjcolombo gjcolombo added the testing Related to testing and/or the PHD test framework. label Feb 15, 2024
/// Wait for the supplied string to appear on the guest serial console.
WaitFor(&'static str),
WaitFor(Cow<'a, str>),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it might be the wrong tool for the job, but maybe not?

Previously this was only used for the string literals that appear in guest OSes' boot sequences, but now a command might be an owned string, e.g. if shell_command_sequence had to amend it. It seemed silly to make all the literals into owned Strings just to accommodate this case, but I'm not sure if Cow is the best (or even an appropriate) way for this code to have its &'static str cake and eat Strings too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cow is absolutely an appropriate way to have something that's "either a &'static str or a String" --- honestly, I think I see it used for that purpose far more than for use-cases that actually use copy-on-write...

@gjcolombo gjcolombo marked this pull request as ready for review February 15, 2024 20:54
@gjcolombo gjcolombo requested a review from hawkw February 15, 2024 20:54
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! i left a few suggestions, but none of them seemed like actual problems.

Change the semantics of waiting for characters in the serial buffer so that
waits return the preceding buffer contents but don't actually erase anything
from the buffer. Instead, make callers manually issue a "clear" command to
discard from the buffer anything they know they're not going to want, and update
the guest shell command sequences to clear the buffer between echoing the entire
command and pressing Enter to execute it.

This fixes issues with command echoing for Windows guests that don't redraw
characters that the guest believes are already on the screen--now those
characters don't get consumed from the buffer, so it's OK that the guest doesn't
explicitly reprint them.
@gjcolombo
Copy link
Contributor Author

Thanks @hawkw! I still need to address your feedback here. I pushed bb39823 to change the serial console wait discipline in a way that should fix #643 for good:

  • Waiting for characters on the serial console no longer consumes anything from the buffer
  • Instead, there's an explicit "clear the buffer" command that callers have to issue
  • The shell command issuance sequences clear the buffer just before they actually issue the last '\n' that executes the command

With this change Windows Server 2019 passes all the running_process tests that it previously failed (and existing passing tests appear to continue passing, but I'm doing one more full Debian 11 run to make sure).

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely!

@gjcolombo
Copy link
Contributor Author

The phd-run job failed due to a known flake in VMM teardown that I've filed as #648. All the tests otherwise passed.

@gjcolombo gjcolombo merged commit d4beb64 into master Feb 16, 2024
9 of 10 checks passed
@gjcolombo gjcolombo deleted the gjcolombo/phd/ws2016-plus branch February 16, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to testing and/or the PHD test framework.
Projects
None yet
2 participants