|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +import {Transformer} from "Sdk.Transformers"; |
| 5 | +import * as Deployment from "Sdk.Deployment"; |
| 6 | +import * as BuildXLSdk from "Sdk.BuildXL"; |
| 7 | + |
| 8 | +namespace Tests.MacOS { |
| 9 | + export declare const qualifier : { configuration: "debug" | "release", targetFramework: BuildXLSdk.TargetFrameworks.CoreClrTargetFrameworks, targetRuntime: "osx-x64" }; |
| 10 | + |
| 11 | + const sharedBinFolderName = a`sharedbin`; |
| 12 | + const tests = createAllDefs(); |
| 13 | + |
| 14 | + function createAllDefs() : TestDeploymentDefinition[] { |
| 15 | + return [ |
| 16 | + // Utilities |
| 17 | + createDef(importFrom("BuildXL.Utilities.Instrumentation.UnitTests").Core.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 18 | + createDef(importFrom("BuildXL.Utilities.UnitTests").Collections.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 19 | + createDef(importFrom("BuildXL.Utilities.UnitTests").Configuration.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 20 | + createDef(importFrom("BuildXL.Utilities.UnitTests").Ipc.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 21 | + createDef(importFrom("BuildXL.Utilities.UnitTests").KeyValueStoreTests.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 22 | + createDef(importFrom("BuildXL.Utilities.UnitTests").Storage.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 23 | + createDef(importFrom("BuildXL.Utilities.UnitTests").Storage.Untracked.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 24 | + createDef(importFrom("BuildXL.Utilities.UnitTests").ToolSupport.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 25 | + createDef(importFrom("BuildXL.Utilities.UnitTests").Core.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 26 | + |
| 27 | + // Cache |
| 28 | + createDef(importFrom("BuildXL.Cache.ContentStore").Test.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 29 | + createDef(importFrom("BuildXL.Cache.ContentStore").GrpcTest.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 30 | + createDef(importFrom("BuildXL.Cache.ContentStore").InterfacesTest.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 31 | + createDef(importFrom("BuildXL.Cache.ContentStore").DistributedTest.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 32 | + createDef(importFrom("BuildXL.Cache.MemoizationStore").Test.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 33 | + createDef(importFrom("BuildXL.Cache.MemoizationStore").InterfacesTest.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 34 | + createDef(importFrom("BuildXL.Cache.DistributedCache.Host").Test.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 35 | + createDef(importFrom("BuildXL.Cache.Core.UnitTests").Analyzer.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 36 | + createDef(importFrom("BuildXL.Cache.Core.UnitTests").BasicFilesystem.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 37 | + createDef(importFrom("BuildXL.Cache.Core.UnitTests").InputListFilter.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 38 | + createDef(importFrom("BuildXL.Cache.Core.UnitTests").Interfaces.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 39 | + createDef(importFrom("BuildXL.Cache.Core.UnitTests").MemoizationStoreAdapter.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 40 | + createDef(importFrom("BuildXL.Cache.Core.UnitTests").VerticalAggregator.withQualifier({ targetFramework: "net6.0" }).dll, true), |
| 41 | + ...addIfLazy(BuildXLSdk.Flags.isMicrosoftInternal, () => [ |
| 42 | + createDef(importFrom("BuildXL.Cache.Logging").Test.withQualifier({ targetFramework: "net6.0" }).dll, true) |
| 43 | + ]), |
| 44 | + createDef(importFrom("BuildXL.Cache.MemoizationStore").Test.withQualifier({ targetFramework: "net6.0" }).dll, true) |
| 45 | + ]; |
| 46 | + } |
| 47 | + |
| 48 | + interface TestDeploymentDefinition extends Deployment.NestedDefinition { |
| 49 | + assembly: File; |
| 50 | + enabled: boolean; |
| 51 | + testClasses: string[]; |
| 52 | + categoriesToRunInParallel: string[]; |
| 53 | + categoriesToNeverRun: string[]; |
| 54 | + runSuppliedCategoriesOnly: boolean; |
| 55 | + } |
| 56 | + |
| 57 | + function createDef(testResult: BuildXLSdk.TestResult, enabled: boolean) : TestDeploymentDefinition { |
| 58 | + let assembly = testResult.testDeployment.primaryFile; |
| 59 | + return <TestDeploymentDefinition>{ |
| 60 | + subfolder: sharedBinFolderName, |
| 61 | + contents: [ |
| 62 | + testResult.testDeployment.deployedDefinition |
| 63 | + ], |
| 64 | + |
| 65 | + assembly: assembly, |
| 66 | + testAssemblies: [], |
| 67 | + enabled: enabled, |
| 68 | + testClasses: undefined, |
| 69 | + categoriesToRunInParallel: undefined, |
| 70 | + categoriesToNeverRun: undefined, |
| 71 | + runSuppliedCategoriesOnly: false |
| 72 | + }; |
| 73 | + } |
| 74 | + |
| 75 | + function genXUnitExtraArgs(definition: TestDeploymentDefinition): string { |
| 76 | + return [ |
| 77 | + ...(definition.testClasses || []).map(testClass => `-class ${testClass}`), |
| 78 | + ...(definition.categoriesToNeverRun || []).map(cat => `-notrait "Category=${cat}"`) |
| 79 | + ].join(" "); |
| 80 | + } |
| 81 | + |
| 82 | + function getRunXunitCommands(def: TestDeploymentDefinition): string[] { |
| 83 | + const base: string = `run_xunit "\${MY_DIR}/tests/${def.subfolder}"${' '}${def.assembly.name}${' '}${genXUnitExtraArgs(def)}`; |
| 84 | + const traits: string[] = (def.categoriesToRunInParallel || []) |
| 85 | + .map(cat => `${base} -trait "Category=${cat}"`); |
| 86 | + const rest: string = [ |
| 87 | + base, |
| 88 | + ...(def.categoriesToRunInParallel || []).map(cat => `-notrait "Category=${cat}"`) |
| 89 | + ].join(" "); |
| 90 | + return def.runSuppliedCategoriesOnly |
| 91 | + ? traits |
| 92 | + : [...traits, rest]; |
| 93 | + } |
| 94 | + |
| 95 | + function createUnixTestRunnerScript(definitions: TestDeploymentDefinition[]): string { |
| 96 | + const runTestCommands = tests |
| 97 | + .filter(def => def.enabled) |
| 98 | + .mapMany(getRunXunitCommands); |
| 99 | + |
| 100 | + return [ |
| 101 | + "#!/bin/bash", |
| 102 | + "", |
| 103 | + "MY_DIR=$(cd `dirname ${BASH_SOURCE[0]}` && pwd)", |
| 104 | + "source $MY_DIR/xunitrunner.sh", |
| 105 | + "", |
| 106 | + "find . \\( -name SandboxedProcessExecutor -o -name Test.BuildXL.Executables.InfiniteWaiter -o -name Test.BuildXL.Executables.TestProcess \\) -print0 | xargs -0 chmod +x", |
| 107 | + "", |
| 108 | + "numTestFailures=0", |
| 109 | + "trap \"((numTestFailures++))\" ERR", |
| 110 | + "", |
| 111 | + ...runTestCommands, |
| 112 | + "", |
| 113 | + "exit $numTestFailures" |
| 114 | + ].join("\n"); |
| 115 | + } |
| 116 | + |
| 117 | + function writeFile(fileName: PathAtom, content: string): DerivedFile { |
| 118 | + return Transformer.writeAllText({ |
| 119 | + outputPath: p`${Context.getNewOutputDirectory("standalone-tests")}/${fileName}`, |
| 120 | + text: content |
| 121 | + }); |
| 122 | + } |
| 123 | + |
| 124 | + /* |
| 125 | + Folder layout: |
| 126 | + |
| 127 | + ├── [tests] |
| 128 | + │ └── [sharedbin] |
| 129 | + | └── ... (BuildXL core drop + test deployments) |
| 130 | + ├── bashrunner.sh |
| 131 | + ├── env.sh |
| 132 | + └── xunitrunner.sh |
| 133 | + */ |
| 134 | + @@public |
| 135 | + export const deployment : Deployment.Definition = { |
| 136 | + contents: [ |
| 137 | + f`xunitrunner.sh`, |
| 138 | + writeFile(a`bashrunner.sh`, createUnixTestRunnerScript(tests)), |
| 139 | + f`${Context.getMount("Sandbox").path}/MacOs/scripts/env.sh`, |
| 140 | + { |
| 141 | + subfolder: r`tests`, |
| 142 | + contents: [ |
| 143 | + // BuildXL core drop (Contains test dependencies) |
| 144 | + { |
| 145 | + subfolder: sharedBinFolderName, |
| 146 | + contents: [ BuildXL.deployment ] |
| 147 | + }, |
| 148 | + // Test dlls |
| 149 | + ...tests, |
| 150 | + ] |
| 151 | + |
| 152 | + } |
| 153 | + ] |
| 154 | + }; |
| 155 | + |
| 156 | + @@public |
| 157 | + export const deployed = BuildXLSdk.DeploymentHelpers.deploy({ |
| 158 | + definition: deployment, |
| 159 | + targetLocation: r`${qualifier.configuration}/tests/${qualifier.targetRuntime}`, |
| 160 | + }); |
| 161 | +} |
0 commit comments