Exemple #1
0
        public void ReadingFromAbsentSidebandFileReturnsEmptyIterator()
        {
            var absentFile = "absent-file";

            XAssert.IsFalse(File.Exists(absentFile));
            XAssert.ArrayEqual(new string[0], ReadRecordedPathsFromSidebandFile(absentFile).ToArray());
        }
        public async Task TestGetSealedDirectoryContentAsync(uint partialSealId, bool isSharedOpaque, int numSealedDirectoryFiles)
        {
            // skip the invalid configuration
            if (partialSealId == 0 && isSharedOpaque)
            {
                return;
            }

            var dirPath     = X("/a/b/");
            var dirArtifact = new DirectoryArtifact(AbsPath(dirPath), partialSealId, isSharedOpaque);
            var cmdResult   = Enumerable
                              .Range(0, numSealedDirectoryFiles)
                              .Select(i => new SealedDirectoryFile($"f{i}", SourceFile(X($"{dirPath}/f{i}")), RandomFileContentInfo()))
                              .ToList();

            using var apiClient = CreateApiClient(ipcOperation =>
            {
                var cmd = (GetSealedDirectoryContentCommand)Command.Deserialize(ipcOperation.Payload);
                XAssert.AreEqual(dirArtifact, cmd.Directory);
                XAssert.AreEqual(dirPath, cmd.FullDirectoryPath);
                return(IpcResult.Success(cmd.RenderResult(cmdResult)));
            });

            var maybeResult = await apiClient.GetSealedDirectoryContent(dirArtifact, dirPath);

            XAssert.PossiblySucceeded(maybeResult);
            XAssert.ArrayEqual(cmdResult.ToArray(), maybeResult.Result.ToArray());
        }
Exemple #3
0
        public void TestRootDirectoryFiltering(string rootDirsStr, string pathToTest, bool expectedToBeRecorded)
        {
            var myDir = Path.Combine(TemporaryDirectory, nameof(TestRootDirectoryFiltering));

            Directory.CreateDirectory(myDir);
            XAssert.IsTrue(Directory.Exists(myDir));

            var rootDirs = rootDirsStr == null ? null : rootDirsStr
                           .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                           .Select(p => X(p))
                           .ToList();

            pathToTest = X(pathToTest);

            var logPath = Path.Combine(myDir, "Pip0");

            using (var writer = CreateWriter(logPath, rootDirs))
            {
                bool recorded = RecordFileWrite(writer, pathToTest);
                XAssert.AreEqual(expectedToBeRecorded, recorded);
            }

            XAssert.ArrayEqual(
                expectedToBeRecorded ? new[] { pathToTest } : new string[0],
                ReadRecordedPathsFromSidebandFile(logPath).ToArray());
        }
Exemple #4
0
        public void ConcurrentWritesToSidebandFilesInTheSameFolder(int numLogs, int numPathsPerLog)
        {
            var myDir = Path.Combine(TemporaryDirectory, nameof(ConcurrentWritesToSidebandFilesInTheSameFolder));

            string[][] pathsPerLog = Enumerable
                                     .Range(0, numLogs)
                                     .Select(logIdx => Enumerable
                                             .Range(0, numPathsPerLog)
                                             .Select(pathIdx => Path.Combine(TemporaryDirectory, $"path-{logIdx}-{pathIdx}"))
                                             .ToArray())
                                     .ToArray();

            string[] logFiles = Enumerable
                                .Range(0, numLogs)
                                .Select(logIdx => Path.Combine(myDir, $"Pip{logIdx}"))
                                .ToArray();

            Enumerable
            .Range(0, numLogs)
            .ToArray()
            .AsParallel()
            .ForAll(logIdx => CreateSidebandWriterAndRecordPaths(logFiles[logIdx], pathsPerLog[logIdx]));

            for (int i = 0; i < numLogs; i++)
            {
                XAssert.ArrayEqual(pathsPerLog[i], ReadRecordedPathsFromSidebandFile(logFiles[i]).ToArray());
            }
        }
Exemple #5
0
        public void GenerateNuSpecForStub()
        {
            var pkg  = m_packageGenerator.AnalyzePackageStub(s_packagesOnConfig);
            var spec = new NugetSpecGenerator(m_context.PathTable, pkg).CreateScriptSourceFile(pkg);
            var text = spec.ToDisplayStringV2();

            m_output.WriteLine(text);

            string expectedSpec = @"import {Transformer} from ""Sdk.Transformers"";

export declare const qualifier: {
    targetFramework: ""net10"" | ""net11"" | ""net20"" | ""net35"" | ""net40"" | ""net45"" | ""net451"" | ""net452"" | ""net46"" | ""net461"" | ""net462"" | ""net472"" | ""netstandard1.0"" | ""netstandard1.1"" | ""netstandard1.2"" | ""netstandard1.3"" | ""netstandard1.4"" | ""netstandard1.5"" | ""netstandard1.6"" | ""netstandard2.0"" | ""netcoreapp2.0"" | ""netcoreapp2.1"" | ""netcoreapp2.2"" | ""netcoreapp3.0"" | ""netcoreapp3.1"" | ""netstandard2.1"",
    targetRuntime: ""win-x64"" | ""osx-x64"" | ""linux-x64"",
};

const packageRoot = Contents.packageRoot;

namespace Contents {
    export declare const qualifier: {
    };
    export const packageRoot = d`../../../pkgs/TestPkgStub.1.999`;
    @@public
    export const all: StaticDirectory = Transformer.sealDirectory(packageRoot, []);
}

@@public
export const pkg: NugetPackage = {contents: Contents.all, dependencies: []};";

            XAssert.ArrayEqual(SplitToLines(expectedSpec), SplitToLines(text));
        }
Exemple #6
0
        public void Test1(bool useStdErr, string text, string errRegex, bool enableMultiLineScanning, string expectedPrintedError)
        {
            EventListener.NestedLoggerHandler += eventData =>
            {
                if (eventData.EventId == (int)LogEventId.PipProcessError)
                {
                    var loggedMessage = eventData.Payload.ToArray()[5].ToString();
                    m_loggedPipFailures.Add(loggedMessage);
                }
            };

            var ops = SplitLines(text)
                      .Select(l => Operation.Echo(l, useStdErr))
                      .Concat(new[]
            {
                Operation.WriteFile(CreateOutputFileArtifact()),
                Operation.Fail()
            });
            var pipBuilder = CreatePipBuilder(ops);

            pipBuilder.ErrorRegex = new RegexDescriptor(StringId.Create(Context.StringTable, errRegex), RegexOptions.None);
            pipBuilder.EnableMultiLineErrorScanning = enableMultiLineScanning;

            SchedulePipBuilder(pipBuilder);
            RunScheduler().AssertFailure();

            AssertErrorEventLogged(LogEventId.PipProcessError);
            XAssert.ArrayEqual(
                SplitLines(expectedPrintedError),
                m_loggedPipFailures.SelectMany(SplitLines).ToArray());
        }
Exemple #7
0
 public void DeserializeIsInverseOfSerialize(string logFile, string[] rootDirs)
 {
     using (var original = new SidebandWriter(DefaultSidebandMetadata, logFile, rootDirs))
         using (var clone = CloneViaSerialization(original))
         {
             XAssert.AreEqual(original.SidebandLogFile, clone.SidebandLogFile);
             XAssert.ArrayEqual(original.RootDirectories?.ToArray(), clone.RootDirectories?.ToArray());
         }
 }
Exemple #8
0
        public void TestParseArgsWithDoubleDashInProcArgs()
        {
            var procArgs = new string[] { "/bin/cat", "--" };
            var args     = new[] { "--" }.Concat(procArgs).ToArray();
            var result   = SandboxExecRunner.ParseArgs(args);

            XAssert.AreEqual(Defaults, result.toolOptions);
            XAssert.ArrayEqual(procArgs, result.procArgs);
        }
 public void DeserializeIsInverseOfSerialize(string logFile, string[] rootDirs)
 {
     using (var original = new SharedOpaqueOutputLogger(logFile, rootDirs))
         using (var clone = CloneViaSerialization(original))
         {
             XAssert.AreEqual(original.SidebandLogFile, clone.SidebandLogFile);
             XAssert.ArrayEqual(original.RootDirectories?.ToArray(), clone.RootDirectories?.ToArray());
         }
 }
Exemple #10
0
        public void FindAllSidebandFilesHandlesAbsentFolder()
        {
            var dir = Path.Combine(TemporaryDirectory, "absent-qwre");

            XAssert.IsFalse(Directory.Exists(dir));
            var result = FindAllProcessPipSidebandFiles(dir);

            XAssert.ArrayEqual(new string[0], result.ToArray());
        }
Exemple #11
0
        public void BoundedExhaustiveTest(int[] arr, int capacity)
        {
            // expected: top 'capacity' elements in the sorted version of 'arr'
            var expectedResult = arr.OrderBy(i => i).Reverse().Take(capacity).Reverse().ToArray();

            var sl = new ConcurrentBoundedSortedCollection<int, int>(capacity);
            Parallel.ForEach(arr, e => sl.TryAdd(e, e));
            var slArray = sl.Select(kvp => kvp.Key).ToArray();
            XAssert.ArrayEqual(expectedResult, slArray);
        }
Exemple #12
0
        public void TestParseArgsWithTwoToolArgs(string arg1, string arg2, bool?expectedVerboseValue, int?expectedQueueSizeValue)
        {
            var procArgs = new string[] { "/bin/cat", "--" };
            var args     = new[] { arg1, arg2, "--" }.Concat(procArgs).ToArray();
            var result   = SandboxExecRunner.ParseArgs(args);

            XAssert.AreEqual(expectedVerboseValue ?? Defaults.Verbose, result.toolOptions.Verbose);
            XAssert.AreEqual(expectedQueueSizeValue ?? (int)Defaults.ReportQueueSizeMB, (int)result.toolOptions.ReportQueueSizeMB);
            XAssert.ArrayEqual(procArgs, result.procArgs);
        }
Exemple #13
0
        public void TestParseArgsNoToolArgs(bool withSeparator)
        {
            var procArgs = new string[] { "/bin/ls", "-l" };
            var args     = withSeparator
                ? new[] { "--" }.Concat(procArgs).ToArray()
                : procArgs;
            var result = SandboxExecRunner.ParseArgs(args);

            XAssert.AreEqual(Defaults, result.toolOptions);
            XAssert.ArrayEqual(procArgs, result.procArgs);
        }
Exemple #14
0
        public void RecordingDeduplicatesPaths()
        {
            var myDir = Path.Combine(TemporaryDirectory, nameof(RecordingDeduplicatesPaths));

            var path    = Path.Combine(TemporaryDirectory, "path1");
            var logFile = Path.Combine(myDir, "Pip0");

            CreateSidebandWriterAndRecordPaths(logFile, new[] { path, path, path });

            XAssert.ArrayEqual(
                new[] { path },
                ReadRecordedPathsFromSidebandFile(logFile).ToArray());
        }
Exemple #15
0
        public void TestFilteredEvaluationWithDefaultSourceResolverDisabled(string configTemplate)
        {
            var builder = CreateBuilder(configTemplate, disableDefaultSourceResolver: true).RootSpec(@"lib/package.dsc");

            builder.EvaluateWithNoErrors();

            var pips = GetPipsWithoutModuleAndSpec();

            XAssert.AreEqual(4, pips.Length);
            AssertPipTypeCount(pips, PipType.WriteFile, 2);
            AssertPipTypeCount(pips, PipType.Value, 2);
            XAssert.ArrayEqual(new[] { "file1", "file2" }, GetOrderedValuePipValues(pips));
        }
Exemple #16
0
        public void TestFilteredEvaluationOfExternalModuleShouldIncludeAllPipsFromThatModule(string configTemplate)
        {
            var builder = CreateBuilder(configTemplate).RootSpec(@"lib/package.dsc");

            builder.EvaluateWithNoErrors();

            var pips = GetPipsWithoutModuleAndSpec();

            XAssert.AreEqual(4, pips.Length);
            AssertPipTypeCount(pips, PipType.WriteFile, 2);
            AssertPipTypeCount(pips, PipType.Value, 2);
            XAssert.ArrayEqual(new[] { "file1", "file2" }, GetOrderedValuePipValues(pips));
        }
Exemple #17
0
        public void ReadingFromCorruptedSidebandFiles(
            int numValidRecordsToWriteFirst,
            bool closeSidebandWriterCleanly,
            bool appendBogusBytes)
        {
            var myDir = Path.Combine(TemporaryDirectory, nameof(ReadingFromCorruptedSidebandFiles));

            Directory.CreateDirectory(myDir);
            XAssert.IsTrue(Directory.Exists(myDir));

            // write some valid records first
            var validRecords = Enumerable
                               .Range(0, numValidRecordsToWriteFirst)
                               .Select(i => Path.Combine(TemporaryDirectory, $"path-{i}"))
                               .ToArray();

            var sidebandFile   = Path.Combine(myDir, $"bogus-log-close_{closeSidebandWriterCleanly}-append_{appendBogusBytes}");
            var sidebandWriter = CreateWriter(sidebandFile);

            sidebandWriter.EnsureHeaderWritten();
            foreach (var path in validRecords)
            {
                XAssert.IsTrue(RecordFileWrite(sidebandWriter, path));
            }

            if (closeSidebandWriterCleanly)
            {
                sidebandWriter.Dispose();
            }
            else
            {
                sidebandWriter.CloseWriterWithoutFixingUpHeaderForTestingOnly();
            }

            if (appendBogusBytes)
            {
                // append some bogus stuff at the end
                using (var s = new FileStream(sidebandFile, FileMode.OpenOrCreate))
                    using (var bw = new BinaryWriter(s))
                    {
                        bw.Seek(0, SeekOrigin.End);
                        bw.Write(1231);
                        bw.Flush();
                    }
            }

            // reading should produce valid records and just finish when it encounters the bogus stuff
            var read = SidebandWriter.ReadRecordedPathsFromSidebandFile(sidebandFile).ToArray();

            XAssert.ArrayEqual(validRecords, read);
        }
Exemple #18
0
        public void TestNonFilteredEvaluation(string configTemplate)
        {
            var builder = CreateBuilder(configTemplate).RootSpec("config.dsc");

            builder.EvaluateWithNoErrors();

            var pips = GetPipsWithoutModuleAndSpec();

            XAssert.AreEqual(6, pips.Count());
            AssertPipTypeCount(pips, PipType.WriteFile, 2);
            AssertPipTypeCount(pips, PipType.CopyFile, 1);
            AssertPipTypeCount(pips, PipType.Value, 3);
            XAssert.ArrayEqual(new[] { "copy1", "file1", "file2" }, GetOrderedValuePipValues(pips));
        }
        public void ValueCacheGetOrAddInvokesFactoryOnlyOnce(int count)
        {
            var evalScheduler = new EvaluationScheduler(degreeOfParallelism: 1);
            var counter       = 0;
            var result        = Enumerable
                                .Range(1, count)
                                .ToArray()
                                .AsParallel()
                                .Select(i => evalScheduler.ValueCacheGetOrAdd("some-key", () => Interlocked.Increment(ref counter)))
                                .ToArray();

            XAssert.AreEqual(1, counter);
            var expectedResult = Enumerable.Range(1, count).Select(i => counter).ToArray();

            XAssert.ArrayEqual(expectedResult, result);
        }
Exemple #20
0
        public void ReadIsInverseOfWrite(int numFiles)
        {
            var myDir = Path.Combine(TemporaryDirectory, nameof(ReadIsInverseOfWrite));

            var paths = Enumerable
                        .Range(0, numFiles)
                        .Select(i => Path.Combine(TemporaryDirectory, $"path-{i}"))
                        .ToArray();

            var logFile = Path.Combine(myDir, "Pip0");

            CreateSidebandWriterAndRecordPaths(logFile, paths);

            var readPaths = ReadRecordedPathsFromSidebandFile(logFile).ToArray();

            XAssert.ArrayEqual(paths, readPaths);
        }
Exemple #21
0
        public void AddParallelManyElements(int capacity)
        {
            Random r = new Random();
            ConcurrentBoundedSortedCollection<int, int> cbsl = new ConcurrentBoundedSortedCollection<int, int>(capacity);

            // Build array of random ints
            int arraySize = 400;
            int[] valArray = new int[arraySize];
            for (int i = 0; i < arraySize; i++)
            {
                valArray[i] = r.Next();
            }

            Parallel.ForEach(valArray, i => cbsl.TryAdd(i, i));

            XAssert.ArrayEqual(valArray.OrderByDescending(i => i).Take(capacity).Reverse().ToArray(), cbsl.Select(kvp => kvp.Key).ToArray());
        }
Exemple #22
0
        public void TestFilteredEvaluationOfOwnModuleShouldNotIncludeUnusedValuesFromExternalModules(string configTemplate)
        {
            var builder = CreateBuilder(configTemplate).RootSpec(@"src/package.dsc");

            builder.EvaluateWithNoErrors();

            var pips = GetPipsWithoutModuleAndSpec();

            XAssert.AreEqual(4, pips.Length);
            AssertPipTypeCount(pips, PipType.CopyFile, 1);
            AssertPipTypeCount(pips, PipType.WriteFile, 1);
            AssertPipTypeCount(pips, PipType.Value, 2);

            var valuePipValues = GetOrderedValuePipValues(pips);

            XAssert.ArrayEqual(valuePipValues, new[] { "copy1", "file1" });
        }
        public void Basic()
        {
            var hnt = new HierarchicalNameTable(new StringTable(), true, Path.DirectorySeparatorChar);
            int c1  = hnt.Count;

            XAssert.IsTrue(c1 > 0);

            HierarchicalNameId id  = hnt.AddName(A("c", "a", "b", "c"));
            string             str = hnt.ExpandName(id);

            XAssert.AreEqual(A("c", "a", "b", "c"), str);

            int c2 = hnt.Count;

            XAssert.IsTrue(c2 > c1);

            hnt.AddName(A("c", "a", "b", "c", "d"));
            hnt.AddName(A("c", "a", "b", "c"));

            int c3 = hnt.Count;

            XAssert.IsTrue(c3 > c2);

            long size = hnt.SizeInBytes;

            XAssert.IsTrue(size > 0);

            if (OperatingSystemHelper.IsUnixOS)
            {
                var id2 = hnt.AddName("/");
                c3 = hnt.Count;
                XAssert.AreEqual("/", hnt.ExpandName(id2));
                XAssert.ArrayEqual(new[] { id2 }, hnt.EnumerateHierarchyBottomUp(id2).ToArray());
            }

            hnt.Freeze();

            size = hnt.SizeInBytes;
            XAssert.IsTrue(size > 0);

            int c4 = hnt.Count;

            XAssert.AreEqual(c3, c4);
        }
        public async Task TestRegisterFilesForBuildManifestFailureAsync()
        {
            string dropName = "DropName";

            List <BuildManifestEntry> buildManifestEntries = new List <BuildManifestEntry>();

            buildManifestEntries.Add(new BuildManifestEntry("/a/b", ContentHash.Random(), X("/x/y/z")));

            using var apiClient = CreateApiClient(ipcOperation =>
            {
                var cmd = (RegisterFilesForBuildManifestCommand)Command.Deserialize(ipcOperation.Payload);
                XAssert.AreEqual(dropName, cmd.DropName);
                XAssert.ArrayEqual(buildManifestEntries.ToArray(), cmd.BuildManifestEntries);
                return(IpcResult.Success(cmd.RenderResult(buildManifestEntries.ToArray())));
            });

            var maybeResult = await apiClient.RegisterFilesForBuildManifest(dropName, buildManifestEntries.ToArray());

            XAssert.PossiblySucceeded(maybeResult);
            XAssert.ArrayEqual(buildManifestEntries.ToArray(), maybeResult.Result);
        }
        public void BoundedExhaustiveTest(int n)
        {
            var arr   = Enumerable.Range(0, n).ToArray();
            var perms = GenAllPermutations(arr).ToArray();

            Assert.All(
                Enumerable.Range(1, n + 1), // test for all possible capacities from 1 to n+1
                capacity =>
            {
                var top = arr.OrderBy(i => i).Reverse().Take(capacity).Reverse().ToArray();
                Assert.All(
                    perms,     // test for all possible permutations
                    perm =>
                {
                    var sl = new ConcurrentBoundedSortedCollection <int, int>(capacity);
                    Parallel.ForEach(perm, e => sl.TryAdd(e, e));
                    var slArray = sl.Select(kvp => kvp.Key).ToArray();
                    XAssert.ArrayEqual(top, slArray);
                });
            });
        }
Exemple #26
0
        public void TestArrayEqualSimple()
        {
            var len0Arr = new string[0];
            var len1Arr = new[] { "str1" };
            var len2Arr = new[] { "str1", "str2" };

            XAssert.ArrayEqual <object>(null, null);

            XAssert.ArrayNotEqual(len1Arr, null);
            XAssert.ArrayNotEqual(null, len1Arr);

            XAssert.ArrayEqual(len0Arr, len0Arr);
            XAssert.ArrayEqual(len1Arr, len1Arr);

            XAssert.ArrayNotEqual(len0Arr, len1Arr);
            XAssert.ArrayNotEqual(len1Arr, len0Arr);
            XAssert.ArrayNotEqual(new[] { "another string" }, len1Arr);
            XAssert.ArrayNotEqual(len2Arr, len1Arr);

            XAssert.ArrayNotEqual(new[] { new ObjectWithBogusToString(1) }, null);
            XAssert.ArrayNotEqual(new[] { new ObjectWithBogusToString(1) }, new[] { new ObjectWithBogusToString(2) });
            XAssert.ArrayEqual(new[] { new ObjectWithBogusToString(1) }, new[] { new ObjectWithBogusToString(1) });
        }
Exemple #27
0
 private static void AssertEqual(HistoricTableSizes expected, HistoricTableSizes actual)
 {
     XAssert.IsNotNull(expected);
     XAssert.IsNotNull(actual);
     XAssert.ArrayEqual(expected.ToArray(), actual.ToArray());
 }
        public void SerializeSandboxedProcessInfo(bool useNullFileStorage)
        {
            var pt  = new PathTable();
            var fam =
                new FileAccessManifest(pt, CreateDirectoryTranslator())
            {
                FailUnexpectedFileAccesses   = false,
                IgnoreCodeCoverage           = false,
                ReportFileAccesses           = false,
                ReportUnexpectedFileAccesses = false,
                MonitorChildProcesses        = false
            };

            var vac = new ValidationDataCreator(fam, pt);

            vac.AddScope(A("C", "Users", "AppData"), FileAccessPolicy.AllowAll);
            vac.AddPath(A("C", "Source", "source.txt"), FileAccessPolicy.AllowReadAlways);
            vac.AddPath(A("C", "Out", "out.txt"), FileAccessPolicy.AllowAll);

            SandboxedProcessStandardFiles standardFiles = null;
            ISandboxedProcessFileStorage  fileStorage;

            if (useNullFileStorage)
            {
                fileStorage = null;
            }
            else
            {
                standardFiles = new SandboxedProcessStandardFiles(A("C", "pip", "pip.out"), A("C", "pip", "pip.err"));
                fileStorage   = new StandardFileStorage(standardFiles);
            }

            var envVars = new Dictionary <string, string>()
            {
                ["Var1"] = "Val1",
                ["Var2"] = "Val2",
            };
            IBuildParameters buildParameters = BuildParameters.GetFactory().PopulateFromDictionary(envVars);

            var sidebandLogFile = A("C", "engine-cache", "sideband-logs", "log-1");
            var loggerRootDirs  = new[] { A("C", "out", "dir1"), A("C", "out", "dir2") };

            var sharedOpaqueOutputLogger = new SidebandWriter(DefaultSidebandMetadata, sidebandLogFile, loggerRootDirs);

            SandboxedProcessInfo info = new SandboxedProcessInfo(
                pt,
                fileStorage,
                A("C", "tool", "tool.exe"),
                fam,
                true,
                null,
                sidebandWriter: sharedOpaqueOutputLogger)
            {
                Arguments            = @"/arg1:val1 /arg2:val2",
                WorkingDirectory     = A("C", "Source"),
                EnvironmentVariables = buildParameters,
                Timeout              = TimeSpan.FromMinutes(15),
                PipSemiStableHash    = 0x12345678,
                PipDescription       = nameof(SerializeSandboxedProcessInfo),
                TimeoutDumpDirectory = A("C", "Timeout"),
                SandboxKind          = global::BuildXL.Utilities.Configuration.SandboxKind.Default,
                AllowedSurvivingChildProcessNames = new[] { "conhost.exe", "mspdbsrv.exe" },
                NestedProcessTerminationTimeout   = SandboxedProcessInfo.DefaultNestedProcessTerminationTimeout,
                StandardInputSourceInfo           = StandardInputInfo.CreateForData("Data"),
                StandardObserverDescriptor        = new SandboxObserverDescriptor()
                {
                    WarningRegex = new ExpandedRegexDescriptor("*warn", System.Text.RegularExpressions.RegexOptions.Compiled)
                },
            };

            // Serialize and deserialize.
            SandboxedProcessInfo readInfo = null;

            using (var stream = new MemoryStream())
            {
                info.Serialize(stream);
                stream.Position = 0;
                readInfo        = SandboxedProcessInfo.Deserialize(
                    stream,
                    new global::BuildXL.Utilities.Instrumentation.Common.LoggingContext("Test"),
                    null);
            }

            using (readInfo.SidebandWriter)
            {
                // Verify.
                XAssert.AreEqual(info.FileName, readInfo.FileName);
                XAssert.AreEqual(info.Arguments, readInfo.Arguments);
                XAssert.AreEqual(info.WorkingDirectory, readInfo.WorkingDirectory);
                var readEnvVars = readInfo.EnvironmentVariables.ToDictionary();
                XAssert.AreEqual(envVars.Count, readEnvVars.Count);
                foreach (var kvp in envVars)
                {
                    XAssert.AreEqual(kvp.Value, readEnvVars[kvp.Key]);
                }

                XAssert.AreEqual(info.Timeout, readInfo.Timeout);
                XAssert.AreEqual(info.PipSemiStableHash, readInfo.PipSemiStableHash);
                XAssert.AreEqual(info.PipDescription, readInfo.PipDescription);
                XAssert.AreEqual(info.TimeoutDumpDirectory, readInfo.TimeoutDumpDirectory);
                XAssert.AreEqual(info.SandboxKind, readInfo.SandboxKind);

                XAssert.AreEqual(info.AllowedSurvivingChildProcessNames.Length, readInfo.AllowedSurvivingChildProcessNames.Length);
                for (int i = 0; i < info.AllowedSurvivingChildProcessNames.Length; ++i)
                {
                    XAssert.AreEqual(info.AllowedSurvivingChildProcessNames[i], readInfo.AllowedSurvivingChildProcessNames[i]);
                }

                XAssert.AreEqual(info.NestedProcessTerminationTimeout, readInfo.NestedProcessTerminationTimeout);
                XAssert.AreEqual(info.StandardInputSourceInfo, readInfo.StandardInputSourceInfo);

                if (useNullFileStorage)
                {
                    XAssert.IsNull(readInfo.SandboxedProcessStandardFiles);
                    XAssert.IsNull(readInfo.FileStorage);
                }
                else
                {
                    XAssert.IsNotNull(readInfo.SandboxedProcessStandardFiles);
                    XAssert.AreEqual(standardFiles.StandardOutput, readInfo.SandboxedProcessStandardFiles.StandardOutput);
                    XAssert.AreEqual(standardFiles.StandardError, readInfo.SandboxedProcessStandardFiles.StandardError);
                    XAssert.AreEqual(standardFiles.StandardOutput, readInfo.FileStorage.GetFileName(SandboxedProcessFile.StandardOutput));
                    XAssert.AreEqual(standardFiles.StandardError, readInfo.FileStorage.GetFileName(SandboxedProcessFile.StandardError));
                }

                XAssert.IsFalse(readInfo.ContainerConfiguration.IsIsolationEnabled);

                XAssert.AreEqual(sidebandLogFile, readInfo.SidebandWriter.SidebandLogFile);
                XAssert.ArrayEqual(loggerRootDirs, readInfo.SidebandWriter.RootDirectories.ToArray());

                if (!OperatingSystemHelper.IsUnixOS)
                {
                    // this validator examines serialized FAM bytes using the same Windows-only native parser used by Detours
                    ValidationDataCreator.TestManifestRetrieval(vac.DataItems, readInfo.FileAccessManifest, false);
                }
            }
        }
Exemple #29
0
        public void StdFileCopyTest(global::BuildXL.Utilities.Configuration.OutputReportingMode outputReportingMode)
        {
            EventListener.NestedLoggerHandler += eventData =>
            {
                if (eventData.EventId == (int)LogEventId.PipProcessError)
                {
                    var loggedMessage      = eventData.Payload.ToArray()[5].ToString();
                    var extraLoggedMessage = eventData.Payload.ToArray()[6].ToString();
                    m_loggedPipFailures.Add(loggedMessage);
                    m_loggedPipFailures.Add(extraLoggedMessage);
                }
            };

            Configuration.Sandbox.OutputReportingMode = outputReportingMode;
            var text = @"
* BEFORE *
* <error> *
* err1 *
* </error> *
* AFTER *
* <error>err2</error> * <error>err3</error> *
";

            var errRegex = "error";

            var ops = SplitLines(text)
                      .Select(l => Operation.Echo(l, true))
                      .Concat(new[]
            {
                Operation.WriteFile(CreateOutputFileArtifact()),
                Operation.Fail()
            });
            var pipBuilder = CreatePipBuilder(ops);

            pipBuilder.ErrorRegex = new RegexDescriptor(StringId.Create(Context.StringTable, errRegex), RegexOptions.None);
            pipBuilder.EnableMultiLineErrorScanning = false;

            Process pip       = SchedulePipBuilder(pipBuilder).Process;
            var     runResult = RunScheduler();

            runResult.AssertFailure();

            AssertErrorEventLogged(LogEventId.PipProcessError);
            string expectedPrintedError;
            var    stdFilePathInLogDir = Path.Combine(runResult.Config.Logging.LogsDirectory.ToString(Context.PathTable), SandboxedProcessPipExecutor.StdOutputsDirNameInLog, pip.FormattedSemiStableHash, SandboxedProcessFile.StandardError.DefaultFileName());

            if (outputReportingMode == global::BuildXL.Utilities.Configuration.OutputReportingMode.TruncatedOutputOnError)
            {
                expectedPrintedError = @"
* <error> *
* </error> *
* <error>err2</error> * <error>err3</error> *
This message has been filtered by a regex. Please find the complete stdout/stderr in the following file(s) in the log directory.";

                XAssert.FileExists(stdFilePathInLogDir, $"StandardError file {stdFilePathInLogDir} should had been copied to log directory");
            }
            else
            {
                expectedPrintedError = @"
* <error> *
* </error> *
* <error>err2</error> * <error>err3</error> *
This message has been filtered by a regex. Please find the complete stdout/stderr in the following file(s) or in the DX0066 event in the log file.";

                XAssert.FileDoesNotExist(stdFilePathInLogDir, $"StandardError file {stdFilePathInLogDir} should had been copied to log directory");
            }

            XAssert.ArrayEqual(
                SplitLines(expectedPrintedError),
                m_loggedPipFailures.SelectMany(SplitLines).ToArray());

            // Rerun the pip and the std file will be copied to the log directory too
            runResult = RunScheduler();
            runResult.AssertFailure();

            string extension = Path.GetExtension(stdFilePathInLogDir);
            var    basename  = stdFilePathInLogDir.Substring(0, stdFilePathInLogDir.Length - extension.Length);

            stdFilePathInLogDir = $"{basename}.1{extension}";

            if (outputReportingMode == global::BuildXL.Utilities.Configuration.OutputReportingMode.TruncatedOutputOnError)
            {
                XAssert.FileExists(stdFilePathInLogDir, $"StandardError file {stdFilePathInLogDir} should had been copied to log directory");
            }
            else
            {
                XAssert.FileDoesNotExist(stdFilePathInLogDir, $"StandardError file {stdFilePathInLogDir} should had been copied to log directory");
            }

            AssertErrorEventLogged(LogEventId.PipProcessError);
        }
Exemple #30
0
        private static void AssertArraysEqual(string[] expected, object actual)
        {
            var actualArray = (actual as ArrayLiteral).Values.Select(v => v.Value).ToArray();

            XAssert.ArrayEqual(expected, actualArray);
        }