Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Migration of some additional legacy port tests (#15867)
Browse files Browse the repository at this point in the history
* Migrated Open tests

* Increase flexibility of serial port / null modem detection

* Improve cleanup after test failure

* Migrate Open_Stress from legacy format

* Avoid Console.WriteLine calls

* Further progress on migrating legacy SerialPort tests

There are lots of files touched which are not yet in the build, but have had relatively simple replacement operations run across them in preparation for the manual conversion.

* Prevent parallel execution of tests

* Migration of more SerialPort tests

* Complete first pass through migrating Legacy/SerialPort

This is everything which fits pattern of standard tests - not some special manual / regression tests.

This runs with failures but without serious problems on a machine with a single real serial port, with or without a data-loopback connected.

* Removed SlashSlash tests

* Add timeouts to various potential hang points

* Some tidying in PortHelper, etc

* Make DiscardOutBuffer tests work correctly

* More assiduous disposal of SerialPort objects, fix some bogus test failures

* Added ActiveIssue attributes on tests which fail on the CI

* Correct / add ActiveIssue numbers

* Tidying
  • Loading branch information
willdean authored and JeremyKuhne committed Feb 8, 2017
1 parent 4556962 commit c96871e
Show file tree
Hide file tree
Showing 82 changed files with 11,433 additions and 24,630 deletions.
8 changes: 8 additions & 0 deletions src/System.IO.Ports/tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

// We don't want to run the tests in parallel because they need exclusive access to serial ports
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true)]
195 changes: 48 additions & 147 deletions src/System.IO.Ports/tests/Legacy/SerialPort/BaseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,185 +3,86 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.IO.PortsTests;
using Legacy.Support;
using Xunit;

public class BaseStream_Property
public class BaseStream_Property : PortsTest
{
public static readonly String s_strDtTmVer = "MsftEmpl, 2003/02/21 15:37 MsftEmpl";
public static readonly String s_strClassMethod = "SerialPort.BaseStream";
public static readonly String s_strTFName = "BaseStream.cs";
public static readonly String s_strTFAbbrev = s_strTFName.Substring(0, 6);
public static readonly String s_strTFPath = Environment.CurrentDirectory;

private int _numErrors = 0;
private int _numTestcases = 0;
private int _exitValue = TCSupport.PassExitCode;
#region Test Cases

public static void Main(string[] args)
[ConditionalFact(nameof(HasOneSerialPort))]
public void BaseStream_Default()
{
BaseStream_Property objTest = new BaseStream_Property();
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(objTest.AppDomainUnhandledException_EventHandler);

Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);

try
using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
{
objTest.RunTest();
}
catch (Exception e)
{
Console.WriteLine(s_strTFAbbrev + " : FAIL The following exception was thorwn in RunTest(): \n" + e.ToString());
objTest._numErrors++;
objTest._exitValue = TCSupport.FailExitCode;
}
SerialPortProperties serPortProp = new SerialPortProperties();

//// Finish Diagnostics
if (objTest._numErrors == 0)
{
Console.WriteLine("PASS. " + s_strTFPath + " " + s_strTFName + " ,numTestcases==" + objTest._numTestcases);
}
else
{
Console.WriteLine("FAIL! " + s_strTFPath + " " + s_strTFName + " ,numErrors==" + objTest._numErrors);

if (TCSupport.PassExitCode == objTest._exitValue)
objTest._exitValue = TCSupport.FailExitCode;
Debug.WriteLine("Verifying default BaseStream");
serPortProp.SetAllPropertiesToDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
serPortProp.VerifyPropertiesAndPrint(com1);
}

Environment.ExitCode = objTest._exitValue;
}

private void AppDomainUnhandledException_EventHandler(Object sender, UnhandledExceptionEventArgs e)
{
_numErrors++;
Console.WriteLine("\nAn unhandled exception was thrown and not caught in the app domain: \n{0}", e.ExceptionObject);
Console.WriteLine("Test FAILED!!!\n");

Environment.ExitCode = 101;
}

public bool RunTest()
[ConditionalFact(nameof(HasOneSerialPort))]
public void BaseStream_Open()
{
bool retValue = true;
TCSupport tcSupport = new TCSupport();

retValue &= tcSupport.BeginTestcase(new TestDelegate(BaseStream_Default), TCSupport.SerialPortRequirements.OneSerialPort);
retValue &= tcSupport.BeginTestcase(new TestDelegate(BaseStream_Open), TCSupport.SerialPortRequirements.OneSerialPort);
retValue &= tcSupport.BeginTestcase(new TestDelegate(BaseStream_Open_Close), TCSupport.SerialPortRequirements.OneSerialPort);
retValue &= tcSupport.BeginTestcase(new TestDelegate(BaseStream_Open_BaseStreamClose), TCSupport.SerialPortRequirements.OneSerialPort);

_numErrors += tcSupport.NumErrors;
_numTestcases = tcSupport.NumTestcases;
_exitValue = tcSupport.ExitValue;

return retValue;
}

#region Test Cases
public bool BaseStream_Default()
{
SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
SerialPortProperties serPortProp = new SerialPortProperties();
bool retValue = true;

Console.WriteLine("Verifying default BaseStream");
serPortProp.SetAllPropertiesToDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
retValue &= serPortProp.VerifyPropertiesAndPrint(com1);

if (!retValue)
using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
{
Console.WriteLine("Err_001!!! Verifying default BaseStream FAILED");
}
SerialPortProperties serPortProp = new SerialPortProperties();

Debug.WriteLine("Verifying BaseStream after Open() has been called");
serPortProp.SetAllPropertiesToOpenDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
com1.Open();

if (com1.IsOpen)
com1.Close();
Assert.NotNull(com1.BaseStream);
Assert.True(com1.BaseStream.GetType().BaseType == typeof(Stream));

return retValue;
serPortProp.VerifyPropertiesAndPrint(com1);
}
}

public bool BaseStream_Open()
[ConditionalFact(nameof(HasOneSerialPort))]
public void BaseStream_Open_Close()
{
SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
SerialPortProperties serPortProp = new SerialPortProperties();
bool retValue = true;

Console.WriteLine("Verifying BaseStream after Open() has been called");
serPortProp.SetAllPropertiesToOpenDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
com1.Open();

if (null == com1.BaseStream || !com1.BaseStream.GetType().BaseType.Equals(typeof(System.IO.Stream)))
using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
{
Console.WriteLine("ERROR!!! BaseStream is either null or is not of the Type System.IO.Stream");
retValue = false;
}
SerialPortProperties serPortProp = new SerialPortProperties();

retValue &= serPortProp.VerifyPropertiesAndPrint(com1);
Debug.WriteLine("Verifying BaseStream after Open() and Close have been called");

if (!retValue)
{
Console.WriteLine("Err_002!!! Verifying BaseStream after Open() has been called FAILED");
}
serPortProp.SetAllPropertiesToDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);

if (com1.IsOpen)
com1.Open();
com1.Close();

return retValue;
}

public bool BaseStream_Open_Close()
{
SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
SerialPortProperties serPortProp = new SerialPortProperties();
bool retValue = true;

Console.WriteLine("Verifying BaseStream after Open() and Close have been called");

serPortProp.SetAllPropertiesToDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);

com1.Open();
com1.Close();

retValue &= serPortProp.VerifyPropertiesAndPrint(com1);

if (!retValue)
{
Console.WriteLine("Err_003!!! Verifying BaseStream after Open() and Close have been called FAILED");
serPortProp.VerifyPropertiesAndPrint(com1);
}

if (com1.IsOpen)
com1.Close();

return retValue;
}

public bool BaseStream_Open_BaseStreamClose()
[ConditionalFact(nameof(HasOneSerialPort))]
public void BaseStream_Open_BaseStreamClose()
{
SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
SerialPortProperties serPortProp = new SerialPortProperties();
bool retValue = true;

Console.WriteLine("Verifying BaseStream after Open() and BaseStream.Close() have been called");
using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
{
SerialPortProperties serPortProp = new SerialPortProperties();

serPortProp.SetAllPropertiesToDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
Debug.WriteLine("Verifying BaseStream after Open() and BaseStream.Close() have been called");

com1.Open();
com1.BaseStream.Close();
serPortProp.SetAllPropertiesToDefaults();
serPortProp.SetProperty("PortName", TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);

retValue &= serPortProp.VerifyPropertiesAndPrint(com1);
com1.Open();
com1.BaseStream.Close();

if (!retValue)
{
Console.WriteLine("Err_004!!! Verifying BaseStream after Open() and BaseStream.Close have been called FAILED");
serPortProp.VerifyPropertiesAndPrint(com1);
}

if (com1.IsOpen)
com1.Close();

return retValue;
}
#endregion

Expand Down
Loading

0 comments on commit c96871e

Please sign in to comment.