Exemplo n.º 1
0
        public static IEnumerable <object[]> ConstructorDoesntCrashTestData()
        {
            var times = new object[] {
                new DateTime(DateTime.MinValue.Year + 1, 1, 1).ToUniversalTime(),
                new DateTime(2015, 1, 1).ToUniversalTime(),
                new DateTime(DateTime.MaxValue.Year, 1, 1).ToUniversalTime()
            };

            var spans = new object[] { TimeSpan.Zero, TimeSpan.FromSeconds(1), TimeSpan.MaxValue };
            var ints  = new object[] { 0, int.MaxValue };

            // Let's say that the highest possible memory usage is currently 1TB.
            var ulongs     = new object[] { (ulong)0, (ulong)1, (ulong)1024 * 1024 * 1024 * 1024 };
            var uints      = new object[] { (uint)0, (uint)1, uint.MaxValue };
            var ioCounters = new object[] {
                new IOCounters(
                    readCounters: new IOTypeCounters(operationCount: 1, transferCount: ulong.MaxValue),
                    writeCounters: new IOTypeCounters(operationCount: 0, transferCount: 0),
                    otherCounters: new IOTypeCounters(operationCount: 0, transferCount: 0)
                    ),
                new IOCounters(
                    readCounters: new IOTypeCounters(operationCount: 0, transferCount: 0),
                    writeCounters: new IOTypeCounters(operationCount: 0, transferCount: 0),
                    otherCounters: new IOTypeCounters(operationCount: 0, transferCount: 0)
                    )
            };

            return(BuildXLTestBase.CrossProductN(times, times, spans, ints, ioCounters, spans, spans, ulongs, uints, uints));
        }
Exemplo n.º 2
0
            public static PipProcessErrorTestElement Create(BuildXLTestBase testBase)
            {
                var result          = new PipProcessErrorTestElement();
                var pipProcessError = new PipProcessErrorEventFields(
                    (long)24,
                    "my cool pip",
                    @"specs\mypip.dsc",
                    @"specs\workingDir",
                    "coolpip.exe",
                    "Failure message Line1\r\nFailure message Line2\rFailure message Line3\n",
                    "Find output file in following path:",
                    @"specs\workingDir\out.txt",
                    -1,
                    "what does this do?",
                    "my pip");

                var processedOutputToLog = "Failure message Line1%0D%0A##[error]Failure message Line2%0D##[error]Failure message Line3%0A##[error]";

                result.ExpectingConsoleLog = @$ "##vso[task.logIssue type=error;]DX0064 [Pip0000000000000018, {pipProcessError.ShortPipDescription}, {pipProcessError.PipSpecPath}] - failed with exit code {pipProcessError.ExitCode}, {pipProcessError.OptionalMessage}%0D%0A##[error]{processedOutputToLog}%0D%0A##[error]{pipProcessError.MessageAboutPathsToLog}%0D%0A##[error]{pipProcessError.PathsToLog}";
                result.PipProcessError     = pipProcessError;
                result.Console             = new MockConsole();
                result.ViewModel           = new BuildViewModel();
                var buildSummaryFilePath = Path.Combine(testBase.TestOutputDirectory, "test.md");

                result.ViewModel.BuildSummary = new BuildSummary(buildSummaryFilePath);
                result.m_loggingContext       = testBase.LoggingContext;

                return(result);
            }
Exemplo n.º 3
0
        private static async Task <PipResult> Execute(BuildXLContext context, FileContentTable fileContentTable, IConfiguration config, Pip pip)
        {
            Contract.Requires(context != null);
            Contract.Requires(fileContentTable != null);
            Contract.Requires(config != null);
            Contract.Requires(pip != null);

            var loggingContext   = BuildXLTestBase.CreateLoggingContextForTest();
            var operationTracker = new OperationTracker(loggingContext);

            using (var env = new Test.BuildXL.Scheduler.Utils.DummyPipExecutionEnvironment(loggingContext, context, config, fileContentTable))
                using (var operationContext = operationTracker.StartOperation(PipExecutorCounter.PipRunningStateDuration, pip.PipId, pip.PipType, env.LoggingContext))
                {
                    return(await Test.BuildXL.Scheduler.TestPipExecutor.ExecuteAsync(operationContext, env, pip));
                }
        }
        public void NoWarningsToConsole(bool isFromWorker)
        {
            string warningMessage = "I'm a warning you want to ignore; it hurts.";
            string warningName    = "IgnoreWarning";
            var    warningManager = new WarningManager();

            warningManager.SetState((int)TestEvents.EventId.WarningEvent, WarningState.Suppressed);

            // suppress the warning and check that it is not printed
            using (var console = new MockConsole())
                using (var listener = new ConsoleEventListener(Events.Log, console, DateTime.UtcNow, false, CancellationToken.None, warningMapper: warningManager.GetState))
                {
                    logWarning(console, listener);
                    console.ValidateNoCall();
                }

            // allow the warning
            using (var console = new MockConsole())
                using (var listener = new ConsoleEventListener(Events.Log, console, DateTime.UtcNow, false, CancellationToken.None))
                {
                    logWarning(console, listener);
                    console.ValidateCall(MessageLevel.Warning, warningMessage);
                }

            void logWarning(MockConsole console, ConsoleEventListener listener)
            {
                listener.RegisterEventSource(TestEvents.Log);
                listener.RegisterEventSource(global::BuildXL.Engine.ETWLogger.Log);
                if (isFromWorker)
                {
                    global::BuildXL.Engine.Tracing.Logger.Log.DistributionWorkerForwardedWarning(BuildXLTestBase.CreateLoggingContextForTest(), new WorkerForwardedEvent()
                    {
                        EventId       = (int)TestEvents.EventId.WarningEvent,
                        EventName     = warningName,
                        EventKeywords = 0,
                        Text          = warningMessage,
                    });
                }
                else
                {
                    TestEvents.Log.WarningEvent(warningMessage);
                }
            }
        }
Exemplo n.º 5
0
        private static async Task <bool> CreateAndRunPip(
            PipProgram program,
            string tempDirectory,
            string outFile,
            IEnumerable <string> restInstructions,
            bool is64Bit)
        {
            Contract.Requires(restInstructions != null);
            Contract.Requires(tempDirectory != null);
            Contract.Requires(!string.IsNullOrEmpty(outFile));

            BuildXLContext context = BuildXLContext.CreateInstanceForTesting();

            using (var fileAccessListener = new FileAccessListener(Events.Log))
            {
                fileAccessListener.RegisterEventSource(BuildXL.Processes.ETWLogger.Log);

                var loggingContext   = BuildXLTestBase.CreateLoggingContextForTest();
                var fileContentTable = FileContentTable.CreateNew(loggingContext);
                var config           = ConfigurationHelpers.GetDefaultForTesting(context.PathTable, AbsolutePath.Create(context.PathTable, Path.Combine(tempDirectory, "config.dc")));
                config.Sandbox.LogObservedFileAccesses = true;

                Pip pip = null;

                var instructions = restInstructions as string[] ?? restInstructions.ToArray();

                switch (program)
                {
                case PipProgram.Cmd:
                    pip = CreateCmdPip(context, tempDirectory, outFile, is64Bit);
                    break;

                case PipProgram.Self:
                    pip = CreateSelfPip(context, tempDirectory, outFile, instructions, is64Bit);
                    break;
                }

                Contract.Assume(pip != null);

                var isSubstUsed = FileUtilities.TryGetSubstSourceAndTarget(tempDirectory, out var substSource, out var substTarget, out var errorMessage);
                XAssert.IsFalse(!isSubstUsed && errorMessage != null, errorMessage);

                PipResult executeResult = await Execute(
                    context,
                    fileContentTable,
                    config,
                    pip,
                    isSubstUsed
                    ?(substSource, substTarget)
                    : default((string, string)?));

                bool valid = false;

                switch (program)
                {
                case PipProgram.Cmd:
                    valid = ValidateCmd(fileAccessListener.FileAccesses, outFile, is64Bit);
                    break;

                case PipProgram.Self:
                    valid = ValidateSelf(
                        fileAccessListener.FileAccesses,
                        instructions.Length > 0 ? instructions[0] : string.Empty,
                        outFile,
                        is64Bit);
                    break;
                }

                return(executeResult.Status == PipResultStatus.Succeeded && valid);
            }
        }