terminal/src/host/ft_uia/ExperimentalTabTests.cs
Michael Niksa 5d082ffe67
Helix Testing (#6992)
Use the Helix testing orchestration framework to run our Terminal LocalTests and Console Host UIA tests.

## References
#### Creates the following new issues:
- #7281 - re-enable local tests that were disabled to turn on Helix
- #7282 - re-enable UIA tests that were disabled to turn on Helix
- #7286 - investigate and implement appropriate compromise solution to how Skipped is handled by MUX Helix scripts

#### Consumes from:
- #7164 - The update to TAEF includes wttlog.dll. The WTT logs are what MUX's Helix scripts use to track the run state, convert to XUnit format, and notify both Helix and AzDO of what's going on.

#### Produces for:
- #671 - Making Terminal UIA tests is now possible
- #6963 - MUX's Helix scripts are already ready to capture PGO data on the Helix machines as certain tests run. Presuming we can author some reasonable scenarios, turning on the Helix environment gets us a good way toward automated PGO.

#### Related:
- #4490 - We lost the AzDO integration of our test data when I moved from the TAEF/VSTest adapter directly back to TE. Thanks to the WTTLog + Helix conversion scripts to XUnit + new upload phase, we have it back!

## PR Checklist
* [x] Closes #3838
* [x] I work here.
* [x] Literally adds tests.
* [ ] Should I update a testing doc in this repo?
* [x] Am core contributor. Hear me roar.
* [ ] Correct spell-checking the right way before merge.

## Detailed Description of the Pull Request / Additional comments
We have had two classes of tests that don't work in our usual build-machine testing environment:
1. Tests that require interactive UI automation or input injection (a.k.a. require a logged in user)
2. Tests that require the entire Windows Terminal to stand up (because our Xaml Islands dependency requires 1903 or later and the Windows Server instance for the build is based on 1809.)

The Helix testing environment solves both of these and is brought to us by our friends over in https://github.com/microsoft/microsoft-ui-xaml.

This PR takes a large portion of scripts and pipeline configuration steps from the Microsoft-UI-XAML repository and adjusts them for Terminal needs.
You can see the source of most of the files in either https://github.com/microsoft/microsoft-ui-xaml/tree/master/build/Helix or https://github.com/microsoft/microsoft-ui-xaml/tree/master/build/AzurePipelinesTemplates

Some of the modifications in the files include (but are not limited to) reasons like:
- Our test binaries are named differently than MUX's test binaries
- We don't need certain types of testing that MUX does.
- We use C++ and C# tests while MUX was using only C# tests (so the naming pattern and some of the parsing of those names is different e.g. :: separators in C++ and . separators in C#)
- Our pipeline phases work a bit differently than MUX and/or we need significantly fewer pieces to the testing matrix (like we don't test a wide variety of OS versions).

The build now runs in a few stages:
1. The usual build and run of unit tests/feature tests, packaging verification, and whatnot. This phase now also picks up and packs anything required for running tests in Helix into an artifact. (It also unifies the artifact name between the things Helix needs and the existing build outputs into the single `drop` artifact to make life a little easier.)
2. The Helix preparation build runs that picks up those artifacts, generates all the scripts required for Helix to understand the test modules/functions from our existing TAEF tests, packs it all up, and queues it on the Helix pool.
3. Helix generates a VM for our testing environment and runs all the TAEF tests that require it. The orchestrator at helix.dot.net watches over this and tracks the success/fail and progress of each module and function. The scripts from our MUX friends handle installing dependencies, making the system quiet for better reliability, detecting flaky tests and rerunning them, and coordinating all the log uploads (including for the subruns of tests that are re-run.)
4. A final build phase is run to look through the results with the Helix API and clean up the marking of tests that are flaky, link all the screenshots and console output logs into the AzDO tests panel, and other such niceities.

We are set to run Helix tests on the Feature test policy of only x64 for now. 

Additionally, because the set up of the Helix VMs takes so long, we are *NOT* running these in PR trigger right now as I believe we all very much value our 15ish minute PR turnaround (and the VM takes another 15 minutes to just get going for whatever reason.) For now, they will only run as a rolling build on master after PRs are merged. We should still know when there's an issue within about an hour of something merging and multiple PRs merging fast will be done on the rolling build as a batch run (not one per).

In addition to setting up the entire Helix testing pipeline for the tests that require it, I've preserved our classic way of running unit and feature tests (that don't require an elaborate environment) directly on the build machines. But with one bonus feature... They now use some of the scripts from MUX to transform their log data and report it to AzDO so it shows up beautifully in the build report. (We used to have this before I removed the MStest/VStest wrapper for performance reasons, but now we can have reporting AND performance!) See https://dev.azure.com/ms/terminal/_build/results?buildId=101654&view=ms.vss-test-web.build-test-results-tab for an example. 

I explored running all of the tests on Helix but.... the Helix setup time is long and the resources are more expensive. I felt it was better to preserve the "quick signal" by continuing to run these directly on the build machine (and skipping the more expensive/slow Helix setup if they fail.) It also works well with the split between PR builds not running Helix and the rolling build running Helix. PR builds will get a good chunk of tests for a quick turn around and the rolling build will finish the more thorough job a bit more slowly.

## Validation Steps Performed
- [x] Ran the updated pipelines with Pull Request configuration ensuring that Helix tests don't run in the usual CI
- [x] Ran with simulation of the rolling build to ensure that the tests now running in Helix will pass. All failures marked for follow on in reference issues.
2020-08-18 18:23:24 +00:00

505 lines
22 KiB
C#

//----------------------------------------------------------------------------------------------------------------------
// <copyright file="ExperimentalTabTests.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// </copyright>
// <summary>UI Automation tests for the Experimental Tab control in the Console Properties dialog window.</summary>
//----------------------------------------------------------------------------------------------------------------------
namespace Conhost.UIA.Tests
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32;
using WEX.Common.Managed;
using WEX.Logging.Interop;
using WEX.TestExecution;
using WEX.TestExecution.Markup;
using Conhost.UIA.Tests.Common;
using Conhost.UIA.Tests.Common.NativeMethods;
using Conhost.UIA.Tests.Elements;
using OpenQA.Selenium.Appium;
[TestClass]
public class ExperimentalTabTests
{
public TestContext TestContext { get; set; }
public const int timeout = Globals.Timeout;
[TestMethod]
[TestProperty("Ignore", "True")] // GH#7282 - investigate and reenable
public void CheckExperimentalDisableState()
{
using (RegistryHelper reg = new RegistryHelper())
{
reg.BackupRegistry(); // manipulating the global v1/v2 state can affect the registry so back it up.
using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext))
{
using (PropertiesDialog properties = new PropertiesDialog(app))
{
properties.Open(OpenTarget.Defaults);
using (Tabs tabs = new Tabs(properties))
{
// check everything stays enabled when global is on.
AutoHelpers.LogInvariant("Check that items are all enabled when global is enabled.");
tabs.SetGlobalState(Tabs.GlobalState.ConsoleV2);
// iterate through each tab
AutoHelpers.LogInvariant("Checking elements on all tabs.");
foreach (TabBase tab in tabs.AllTabs)
{
tab.NavigateToTab();
IEnumerable<AppiumWebElement> itemsUnaffected = tab.GetObjectsUnaffectedByV1V2Switch();
IEnumerable<AppiumWebElement> itemsThatDisable = tab.GetObjectsDisabledForV1Console();
foreach (AppiumWebElement obj in itemsThatDisable.Concat(itemsUnaffected))
{
Verify.IsTrue(obj.Enabled, AutoHelpers.FormatInvariant("Option: {0}", obj.Text));
}
}
// check that relevant boxes are disabled when global is off.
AutoHelpers.LogInvariant("Check that necessary items are disabled when global is disabled.");
tabs.SetGlobalState(Tabs.GlobalState.ConsoleV1);
foreach (TabBase tab in tabs.AllTabs)
{
tab.NavigateToTab();
IEnumerable<AppiumWebElement> itemsUnaffected = tab.GetObjectsUnaffectedByV1V2Switch();
IEnumerable<AppiumWebElement> itemsThatDisable = tab.GetObjectsDisabledForV1Console();
foreach (AppiumWebElement obj in itemsThatDisable)
{
Verify.IsFalse(obj.Enabled, AutoHelpers.FormatInvariant("Option: {0}", obj.Text));
}
foreach (AppiumWebElement obj in itemsUnaffected)
{
Verify.IsTrue(obj.Enabled, AutoHelpers.FormatInvariant("Option: {0}", obj.Text));
}
}
}
}
}
}
}
[TestMethod]
[TestProperty("Ignore", "True")] // GH#7282 - investigate and reenable
public void CheckRegistryWritebacks()
{
using (RegistryHelper reg = new RegistryHelper())
{
reg.BackupRegistry();
using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext))
{
this.CheckRegistryWritebacks(reg, app, OpenTarget.Defaults);
this.CheckRegistryWritebacks(reg, app, OpenTarget.Specifics);
}
}
}
[TestMethod]
[TestProperty("Ignore", "True")] // GH#7282 - investigate and reenable
public void CheckShortcutWritebacks()
{
using (RegistryHelper reg = new RegistryHelper())
{
// The global state changes can still impact the registry, so back up the registry anyway despite this being the shortcut test.
reg.BackupRegistry();
using (ShortcutHelper shortcut = new ShortcutHelper())
{
shortcut.CreateTempCmdShortcut();
using (CmdApp app = new CmdApp(CreateType.ShortcutFile, TestContext, shortcut.ShortcutPath))
{
this.CheckShortcutWritebacks(shortcut, app, OpenTarget.Specifics);
}
}
}
}
private void CheckRegistryWritebacks(RegistryHelper reg, CmdApp app, OpenTarget target)
{
this.CheckWritebacks(reg, null, app, target);
}
private void CheckShortcutWritebacks(ShortcutHelper shortcut, CmdApp app, OpenTarget target)
{
this.CheckWritebacks(null, shortcut, app, target);
}
private void CheckWritebacks(RegistryHelper reg, ShortcutHelper shortcut, CmdApp app, OpenTarget target)
{
// either registry or shortcut are null
if ((reg == null && shortcut == null) || (reg != null && shortcut != null))
{
throw new NotSupportedException("Must leave either registry or shortcut null. And must supply one of the two.");
}
bool isRegMode = reg != null; // true is reg mode, false is shortcut mode
string modeName = isRegMode ? "registry" : "shortcut";
AutoHelpers.LogInvariant("Beginning {0} writeback tests for {1}", modeName, target.ToString());
using (PropertiesDialog props = new PropertiesDialog(app))
{
// STEP 1: VERIFY EVERYTHING SAVES IN AN ON/MAX STATE
AutoHelpers.LogInvariant("Open dialog and check boxes.");
props.Open(target);
using (Tabs tabs = new Tabs(props))
{
// Set V2 on.
tabs.SetGlobalState(Tabs.GlobalState.ConsoleV2);
AutoHelpers.LogInvariant("Toggling elements on all tabs.");
foreach (TabBase tab in tabs.AllTabs)
{
tab.NavigateToTab();
foreach (CheckBoxMeta obj in tab.GetCheckboxesForVerification())
{
obj.Check();
}
foreach (SliderMeta obj in tab.GetSlidersForVerification())
{
// adjust slider to the maximum
obj.SetToMaximum();
}
}
AutoHelpers.LogInvariant("Hit OK to save.");
props.Close(PropertiesDialog.CloseAction.OK);
AutoHelpers.LogInvariant("Verify values changed as appropriate.");
CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tabs, SliderMeta.ExpectedPosition.Maximum, false, Tabs.GlobalState.ConsoleV2);
}
// STEP 2: VERIFY EVERYTHING SAVES IN AN OFF/MIN STATE
AutoHelpers.LogInvariant("Open dialog and uncheck boxes.");
props.Open(target);
using (Tabs tabs = new Tabs(props))
{
AutoHelpers.LogInvariant("Toggling elements on all tabs.");
foreach (TabBase tab in tabs.AllTabs)
{
tab.NavigateToTab();
foreach (SliderMeta slider in tab.GetSlidersForVerification())
{
// adjust slider to the minimum
slider.SetToMinimum();
}
foreach (CheckBoxMeta obj in tab.GetCheckboxesForVerification())
{
obj.Uncheck();
}
}
tabs.SetGlobalState(Tabs.GlobalState.ConsoleV1);
AutoHelpers.LogInvariant("Hit OK to save.");
props.Close(PropertiesDialog.CloseAction.OK);
AutoHelpers.LogInvariant("Verify values changed as appropriate.");
CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tabs, SliderMeta.ExpectedPosition.Minimum, true, Tabs.GlobalState.ConsoleV1);
}
// STEP 3: VERIFY CANCEL DOES NOT SAVE
AutoHelpers.LogInvariant("Open dialog and check boxes.");
props.Open(target);
using (Tabs tabs = new Tabs(props))
{
tabs.SetGlobalState(Tabs.GlobalState.ConsoleV2);
AutoHelpers.LogInvariant("Toggling elements on all tabs.");
foreach (TabBase tab in tabs.AllTabs)
{
tab.NavigateToTab();
foreach (CheckBoxMeta obj in tab.GetCheckboxesForVerification())
{
obj.Check();
}
foreach (SliderMeta obj in tab.GetSlidersForVerification())
{
// adjust slider to the maximum
obj.SetToMaximum();
}
}
AutoHelpers.LogInvariant("Hit cancel to not save.");
props.Close(PropertiesDialog.CloseAction.Cancel);
AutoHelpers.LogInvariant("Verify values did not change.");
CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tabs, SliderMeta.ExpectedPosition.Minimum, true, Tabs.GlobalState.ConsoleV1);
}
}
}
private void CheckWritebacksVerifyValues(bool isRegMode, RegistryHelper reg, ShortcutHelper shortcut, OpenTarget target, Tabs tabs, SliderMeta.ExpectedPosition sliderExpected, bool checkboxValue, Tabs.GlobalState consoleVersion)
{
foreach (TabBase tab in tabs.AllTabs)
{
CheckWritebacksVerifyValues(isRegMode, reg, shortcut, target, tab, sliderExpected, checkboxValue, consoleVersion);
}
}
private void CheckWritebacksVerifyValues(bool isRegMode, RegistryHelper reg, ShortcutHelper shortcut, OpenTarget target, TabBase tab, SliderMeta.ExpectedPosition sliderExpected, bool checkboxValue, Tabs.GlobalState consoleVersion)
{
if (isRegMode)
{
VerifyBoxes(tab, reg, checkboxValue, target, consoleVersion);
VerifySliders(tab, reg, sliderExpected, target, consoleVersion);
}
else
{
// Have to wait for shortcut to get written.
// There isn't really an event to know when this occurs, so just wait.
Globals.WaitForTimeout();
VerifyBoxes(tab, shortcut, checkboxValue, consoleVersion);
VerifySliders(tab, shortcut, sliderExpected, consoleVersion);
}
}
private void VerifyBoxes(TabBase tab, RegistryHelper reg, bool inverse, OpenTarget target, Tabs.GlobalState consoleVersion)
{
// get the key for the current target
RegistryKey consoleKey = reg.GetMatchingKey(target);
// hold the parent console key in case we need to look things up for specifics.
RegistryKey parentConsoleKey = reg.GetMatchingKey(OpenTarget.Defaults);
// include the global checkbox in the set for verification purposes
IEnumerable<CheckBoxMeta> boxes = tab.GetCheckboxesForVerification();
AutoHelpers.LogInvariant("Testing target: {0} in inverse {1} mode", target.ToString(), inverse.ToString());
// If we're opened as specifics, remove all global only boxes from the test set
if (target == OpenTarget.Specifics)
{
AutoHelpers.LogInvariant("Reducing");
boxes = boxes.Where(box => !box.IsGlobalOnly);
}
foreach (CheckBoxMeta meta in boxes)
{
int? storedValue = consoleKey.GetValue(meta.ValueName) as int?;
string boxName = AutoHelpers.FormatInvariant("Box: {0}", meta.ValueName);
// if we're in specifics mode, we might have a null and if so, we check the parent value
if (target == OpenTarget.Specifics)
{
if (storedValue == null)
{
AutoHelpers.LogInvariant("Specific setting missing. Checking defaults.");
storedValue = parentConsoleKey.GetValue(meta.ValueName) as int?;
}
}
else
{
Verify.IsNotNull(storedValue, boxName);
}
if (consoleVersion == Tabs.GlobalState.ConsoleV1 && meta.IsV2Property)
{
AutoHelpers.LogInvariant("Skipping validation of v2 property {0} after switching to v1 console.", meta.ValueName);
}
else
{
// A box can be inverse if checking it means false in the registry.
// This method can be inverse if we're turning off the boxes and expecting it to be on.
// Therefore, a box will be false if it's checked and supposed to be off. Or if it's unchecked and supposed to be on.
if ((meta.IsInverse && !inverse) || (!meta.IsInverse && inverse))
{
Verify.IsFalse(storedValue.Value.DwordToBool(), boxName);
}
else
{
Verify.IsTrue(storedValue.Value.DwordToBool(), boxName);
}
}
}
}
private void VerifyBoxes(TabBase tab, ShortcutHelper shortcut, bool inverse, Tabs.GlobalState consoleVersion)
{
IEnumerable<CheckBoxMeta> boxes = tab.GetCheckboxesForVerification();
// collect up properties that we need to retrieve keys for
IEnumerable<CheckBoxMeta> propBoxes = boxes.Where(box => box.PropKey != null);
IEnumerable<Wtypes.PROPERTYKEY> keys = propBoxes.Select(box => box.PropKey).Cast<Wtypes.PROPERTYKEY>();
// fetch data for keys
IDictionary<Wtypes.PROPERTYKEY, object> propertyData = shortcut.GetFromPropertyStore(keys);
// enumerate each box and validate the data
foreach (CheckBoxMeta meta in propBoxes)
{
string boxName = AutoHelpers.FormatInvariant("Box: {0}", meta.ValueName);
Wtypes.PROPERTYKEY key = (Wtypes.PROPERTYKEY)meta.PropKey;
bool? value = (bool?)propertyData[key];
Verify.IsNotNull(value, boxName);
if (consoleVersion == Tabs.GlobalState.ConsoleV1 && meta.IsV2Property)
{
AutoHelpers.LogInvariant("Skipping validation of v2 property {0} after switching to v1 console.", meta.ValueName);
}
else
{
// A box can be inverse if checking it means false in the registry.
// This method can be inverse if we're turning off the boxes and expecting it to be on.
// Therefore, a box will be false if it's checked and supposed to be off. Or if it's unchecked and supposed to be on.
if ((meta.IsInverse && !inverse) || (!meta.IsInverse && inverse))
{
Verify.IsFalse(value.Value, boxName);
}
else
{
Verify.IsTrue(value.Value, boxName);
}
}
}
}
private void VerifySliders(TabBase tab, RegistryHelper reg, SliderMeta.ExpectedPosition expected, OpenTarget target, Tabs.GlobalState consoleVersion)
{
// get the key for the current target
RegistryKey consoleKey = reg.GetMatchingKey(target);
// hold the parent console key in case we need to look things up for specifics.
RegistryKey parentConsoleKey = reg.GetMatchingKey(OpenTarget.Defaults);
IEnumerable<SliderMeta> sliders = tab.GetSlidersForVerification();
foreach (SliderMeta meta in sliders)
{
int? storedValue = consoleKey.GetValue(meta.ValueName) as int?;
string sliderName = AutoHelpers.FormatInvariant("Slider: {0}", meta.ValueName);
if (target == OpenTarget.Specifics)
{
if (storedValue == null)
{
AutoHelpers.LogInvariant("Specific setting missing. Checking defaults.");
storedValue = parentConsoleKey.GetValue(meta.ValueName) as int?;
}
}
else
{
Verify.IsNotNull(storedValue, sliderName);
}
int transparency = 0;
switch (expected)
{
case SliderMeta.ExpectedPosition.Maximum:
transparency = meta.GetMaximum();
break;
case SliderMeta.ExpectedPosition.Minimum:
transparency = meta.GetMinimum();
break;
default:
throw new NotImplementedException();
}
if (consoleVersion == Tabs.GlobalState.ConsoleV1 && meta.IsV2Property)
{
AutoHelpers.LogInvariant("Skipping validation of v2 property {0} after switching to v1 console.", meta.ValueName);
}
else
{
Verify.AreEqual(storedValue.Value, RescaleSlider(transparency), sliderName);
}
}
}
private void VerifySliders(TabBase tab, ShortcutHelper shortcut, SliderMeta.ExpectedPosition expected, Tabs.GlobalState consoleVersion)
{
IEnumerable<SliderMeta> sliders = tab.GetSlidersForVerification();
// collect up properties that we need to retrieve keys for
IEnumerable<SliderMeta> propSliders = sliders.Where(slider => slider.PropKey != null);
IEnumerable<Wtypes.PROPERTYKEY> keys = propSliders.Select(slider => slider.PropKey).Cast<Wtypes.PROPERTYKEY>();
// fetch data for keys
IDictionary<Wtypes.PROPERTYKEY, object> propertyData = shortcut.GetFromPropertyStore(keys);
// enumerate each slider and validate data
foreach (SliderMeta meta in sliders)
{
string sliderName = AutoHelpers.FormatInvariant("Slider: {0}", meta.ValueName);
Wtypes.PROPERTYKEY key = (Wtypes.PROPERTYKEY)meta.PropKey;
short value = (short)propertyData[key];
int transparency = 0;
switch (expected)
{
case SliderMeta.ExpectedPosition.Maximum:
transparency = meta.GetMaximum();
break;
case SliderMeta.ExpectedPosition.Minimum:
transparency = meta.GetMinimum();
break;
default:
throw new NotImplementedException();
}
if (consoleVersion == Tabs.GlobalState.ConsoleV1 && meta.IsV2Property)
{
AutoHelpers.LogInvariant("Skipping validation of v2 property {0} after switching to v1 console.", meta.ValueName);
}
else
{
Verify.AreEqual(value, RescaleSlider(transparency), sliderName);
}
}
}
private short RescaleSlider(int inputValue)
{
// we go on a scale from 0x4D to 0xFF.
int minValue = 0x4D;
int maxValue = 0xFF;
int valueRange = maxValue - minValue;
double scaleFactor = (double)inputValue / 100.0;
short finalValue = (short)((valueRange * scaleFactor) + minValue);
return finalValue;
}
}
}