Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions .vsts-ci/mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
variables:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
POWERSHELL_TELEMETRY_OPTOUT: 1
# Avoid expensive initialization of dotnet cli, see: http://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
# Enable VSTS debug mode until stabilitized
system.debug: 'true'

resources:
- repo: self
clean: true
phases:
- phase: macOS_CI

queue:
name: Hosted macOS Preview
steps:
- powershell: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhss"))"
displayName: Set Build Name for Non-PR
condition: ne(variables['Build.Reason'], 'PullRequest')

# Several scripts require TMPDIR to exist
# Set it to AGENT_TEMPDIRECTORY so that we know it exists
- powershell: |
Write-Host "##vso[task.setvariable variable=TMPDIR]$env:AGENT_TEMPDIRECTORY"
displayName: Set TMPDIR to AGENT_TEMPDIRECTORY
condition: succeededOrFailed()

- powershell: |
git submodule update --init
displayName: SubModule Init
condition: succeededOrFailed()

- powershell: |
rvm install ruby-2.3.3;
rvm --default use 2.3.3;
displayName: Install Ruby
condition: succeededOrFailed()
enabled: false

- powershell: |
tools/travis.ps1 -Stage Bootstrap
displayName: Bootstrap
condition: succeeded()

- powershell: |
$ErrorActionPreference = 'continue'
tools/travis.ps1
displayName: Build and test
condition: succeeded()

- powershell: |
tools/travis.ps1 -Stage Failure
displayName: After Failure
condition: failed()

- powershell: |
tools/travis.ps1 -Stage Success
displayName: After Success
condition: succeeded()

# Uploads any packages as an artifact
- powershell: |
Get-ChildItem -Path *.pkg, *.tar.gz -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object {
Write-Host "##vso[artifact.upload containerfolder=artifacts;artifactname=artifacts]$_"
}
displayName: Publish Artifacts
condition: succeededOrFailed()

# Uploads any Test results as an artifact
- powershell: |
Get-ChildItem -Path Test*.xml, *XUnitTestResults.xml -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object {
Write-Host "##vso[artifact.upload containerfolder=testResults;artifactname=testResults]$_"
}
displayName: Publish Test Results
condition: succeededOrFailed()

# Publish the various Test results as Test results to VSTS
# Separate tasks are used because a failure will stop the task
- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: Publish Test Results TestResultsSudo.xml
inputs:
testRunner: NUnit
testResultsFiles: '**\TestResultsSudo.xml'
testRunTitle: Sudo
mergeTestResults: true

- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: Publish Test Results TestResultsNoSudo.xml
inputs:
testRunner: NUnit
testResultsFiles: '**\TestResultsNoSudo.xml'
testRunTitle: NoSudo
mergeTestResults: true

- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: Publish Test Results TestResultsSudo.ExpTest.*.xml
inputs:
testRunner: NUnit
testResultsFiles: '**\TestResultsSudo.ExpTest.*.xml'
testRunTitle: Sudo Experimental Features
mergeTestResults: true

- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: Publish Test Results TestResultsNoSudo.ExpTest.*.xml
inputs:
testRunner: NUnit
testResultsFiles: '**\TestResultsNoSudo.ExpTest.*.xml'
testRunTitle: Sudo Experimental Features
mergeTestResults: true

- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: Publish Test Results ParallelXUnitTestResults.xml
inputs:
testRunner: XUnit
testResultsFiles: '**\ParallelXUnitTestResults.xml'
testRunTitle: Parallel XUnit
mergeTestResults: true

- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: Publish Test Results SequentialXUnitTestResults.xml
inputs:
testRunner: XUnit
testResultsFiles: '**\SequentialXUnitTestResults.xml'
testRunTitle: Sequential XUnit
mergeTestResults: true
71 changes: 44 additions & 27 deletions test/powershell/Host/Logging.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using namespace System.Text
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

Import-Module HelpersCommon
Import-Module PSSysLog

<#
Expand Down Expand Up @@ -202,35 +203,51 @@ Describe 'Basic os_log tests on MacOS' -Tag @('Feature','RequireSudoOnUnix') {
}

It 'Verifies basic logging with no customizations' -Skip:(!$IsSupportedEnvironment) {
$configFile = WriteLogSettings -LogId $logId
$testPid = & $powershell -NoProfile -SettingsFile $configFile -Command '$PID'

# Made tests more reliable
Start-Sleep -Milliseconds 500

Export-PSOsLog -After $after -LogPid $testPid -Verbose | Set-Content -Path $contentFile
$items = @(Get-PSOsLog -Path $contentFile -Id $logId -After $after -TotalCount 3 -Verbose)

$items | Should -Not -Be $null
$items.Count | Should -BeGreaterThan 1
$items[0].EventId | Should -BeExactly 'Perftrack_ConsoleStartupStart:PowershellConsoleStartup.WinStart.Informational'
$items[1].EventId | Should -BeExactly 'Perftrack_ConsoleStartupStop:PowershellConsoleStartup.WinStop.Informational'
# if there are more items than expected...
if ($items.Count -gt 2)
{
# Force reporting of the first unexpected item to help diagnosis
$items[2] | Should -Be $null
try {
$configFile = WriteLogSettings -LogId $logId
$testPid = & $powershell -NoProfile -SettingsFile $configFile -Command '$PID'

Export-PSOsLog -After $after -LogPid $testPid -TimeoutInMilliseconds 30000 -IntervalInMilliseconds 3000 -MinimumCount 2 |
Set-Content -Path $contentFile
$items = @(Get-PSOsLog -Path $contentFile -Id $logId -After $after -TotalCount 3 -Verbose)

$items | Should -Not -Be $null
$items.Count | Should -BeGreaterThan 1
$items[0].EventId | Should -BeExactly 'Perftrack_ConsoleStartupStart:PowershellConsoleStartup.WinStart.Informational'
$items[1].EventId | Should -BeExactly 'Perftrack_ConsoleStartupStop:PowershellConsoleStartup.WinStop.Informational'
# if there are more items than expected...
if ($items.Count -gt 2)
{
# Force reporting of the first unexpected item to help diagnosis
$items[2] | Should -Be $null
}
}
catch {
if (Test-Path $contentFile) {
Send-VstsLogFile -Path $contentFile
}
throw
}
}

It 'Verifies logging level filtering works' -Skip:(!$IsSupportedEnvironment) {
$configFile = WriteLogSettings -LogId $logId -LogLevel Warning
$testPid = & $powershell -NoLogo -NoProfile -SettingsFile $configFile -Command '$PID'

Export-PSOsLog -After $after -LogPid $testPid -Verbose | Set-Content -Path $contentFile
# by default, powershell startup should only logs informational events.
# With Level = Warning, nothing should be logged.
$items = Get-PSOsLog -Path $contentFile -Id $logId -After $after -TotalCount 3
$items | Should -Be $null
# This is pending because it results in false postitives (-Skip:(!$IsSupportedEnvironment) )
It 'Verifies logging level filtering works' -Pending {
try {
$configFile = WriteLogSettings -LogId $logId -LogLevel Warning
$testPid = & $powershell -NoLogo -NoProfile -SettingsFile $configFile -Command '$PID'

Export-PSOsLog -After $after -LogPid $testPid |
Set-Content -Path $contentFile
# by default, powershell startup should only logs informational events.
# With Level = Warning, nothing should be logged.
$items = Get-PSOsLog -Path $contentFile -Id $logId -After $after -TotalCount 3
$items | Should -Be $null
}
catch {
if (Test-Path $contentFile) {
Send-VstsLogFile -Path $contentFile
}
throw
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@
Describe "Start-Sleep DRT Unit Tests" -Tags "CI" {

# WaitHandle.WaitOne(milliseconds, exitContext) is not accurate.
# The wait time varies from 980ms to 1020ms from observation, so
# The wait time varies from 980ms to 1150ms from observation, so
# the tests here are changed to be greater than 950ms.

$minTime = 950
$maxTime = 1200

It "Should work properly when sleeping with Second" {
$watch = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -Seconds 1
$watch.Stop()
$watch.ElapsedMilliseconds | Should -BeGreaterThan 950
$watch.ElapsedMilliseconds | Should -BeLessThan 1100
$watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime
$watch.ElapsedMilliseconds | Should -BeLessThan $maxTime
}

It "Should work properly when sleeping with Milliseconds" {
$watch = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -Milliseconds 1000
$watch.Stop()
$watch.ElapsedMilliseconds | Should -BeGreaterThan 950
$watch.ElapsedMilliseconds | Should -BeLessThan 1100
$watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime
$watch.ElapsedMilliseconds | Should -BeLessThan $maxTime
}

It "Should work properly when sleeping with ms alias" {
$watch = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -ms 1000
$watch.Stop()
$watch.ElapsedMilliseconds | Should -BeGreaterThan 950
$watch.ElapsedMilliseconds | Should -BeLessThan 1100
$watch.ElapsedMilliseconds | Should -BeGreaterThan $minTime
$watch.ElapsedMilliseconds | Should -BeLessThan $maxTime
}
}

Expand Down
13 changes: 12 additions & 1 deletion test/tools/Modules/HelpersCommon/HelpersCommon.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ Copyright = 'Copyright (c) Microsoft Corporation. All rights reserved.'

Description = 'Temporary module contains functions for using in tests'

FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'Wait-FileToBePresent', 'Get-RandomFileName', 'Enable-Testhook', 'Disable-Testhook', 'Set-TesthookResult', 'Test-TesthookIsSet', 'Add-TestDynamicType'
FunctionsToExport = @(
'Add-TestDynamicType'
'Disable-Testhook'
'Enable-Testhook'
'Get-RandomFileName'
'Send-VstsLogFile'
'Set-TesthookResult'
'Test-IsElevated'
'Test-TesthookIsSet'
'Wait-FileToBePresent'
'Wait-UntilTrue'
)
}
44 changes: 44 additions & 0 deletions test/tools/Modules/HelpersCommon/HelpersCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,47 @@ public class TestDynamic : DynamicObject
}
'@
}

# Upload an artifact in VSTS
# On other systems will just log where the file was placed
function Send-VstsLogFile {
param (
[parameter(Mandatory,ParameterSetName='contents')]
[string[]]
$Contents,
[parameter(Mandatory,ParameterSetName='contents')]
[string]
$LogName,
[parameter(Mandatory,ParameterSetName='path')]
[ValidateScript({Test-Path -Path $_})]
[string]
$Path
)

$logFolder = Join-Path -path $pwd -ChildPath 'logfile'
if(!(Test-Path -Path $logFolder))
{
$null = New-Item -Path $logFolder -ItemType Directory
if($IsMacOS -or $IsLinux)
{
$null = chmod a+rw $logFolder
}
}

if($Contents)
{
$logFile = Join-Path -Path $logFolder -ChildPath ([System.Io.Path]::GetRandomFileName() + "-$LogName.txt")
$name = Split-Path -leaf -Path $logFile

$Contents | out-file -path $logFile -Encoding ascii
}
else
{
$name = Split-Path -leaf -Path $path
$logFile = Join-Path -Path $logFolder -ChildPath ([System.Io.Path]::GetRandomFileName() + '-' + $name)
Copy-Item -Path $Path -Destination $logFile
}

Write-Host "##vso[artifact.upload containerfolder=$name;artifactname=$name]$logFile"
Write-Verbose "Log file captured as $name" -Verbose
}
Loading