Example #1
0
        public void ValidateSharedCompilation(string sourceFilename, [CanBeNull] string targetType, [CanBeNull] string outputAssembly)
        {
            var managedProject = GetCscProject(sourceFilename, targetType, outputAssembly);
            var program        = GetHelloWorldProgram();

            var config = (CommandLineConfiguration)Build(useSharedCompilation: true)
                         .AddSpec(R("ManagedProject.csproj"), managedProject)
                         .AddFile(R("Program.cs"), program)
                         .PersistSpecsAndGetConfiguration();

            config.Sandbox.FileSystemMode          = FileSystemMode.RealAndMinimalPipGraph;
            config.Sandbox.LogObservedFileAccesses = true;

            var listener = new FileAccessDetoursListenerCollector(PathTable);

            var result = RunEngineWithConfig(config, detoursListener: listener);

            Assert.True(result.IsSuccess);

            // Let's verify now that accesses were properly compensated. We should see the (single) source
            // file and the output + pdb as outputs
            var allAccesses = listener.GetAllFileAccessPaths().Select(path => path.ToUpperInvariant());

            Assert.True(allAccesses.Any(input => input.Contains(sourceFilename.ToUpperInvariant())));

            // If the output assembly is not specified, there should be an output reported anyway, with a
            // filename (modulo extension) equal to the source
            if (outputAssembly == null)
            {
                outputAssembly = Path.ChangeExtension(sourceFilename, null);
            }

            Assert.True(allAccesses.Any(output => output.Contains(outputAssembly.ToUpperInvariant())));
            Assert.True(allAccesses.Any(output => output.Contains(Path.ChangeExtension(outputAssembly, ".pdb").ToUpperInvariant())));
        }
Example #2
0
        public void AugmentedAccessPathsAreCanonicalized()
        {
            var fam = new FileAccessManifest(
                Context.PathTable,
                childProcessesToBreakawayFromSandbox: new[] { TestProcessToolName })
            {
                FailUnexpectedFileAccesses   = false,
                ReportUnexpectedFileAccesses = true,
                ReportFileAccesses           = true
            };

            var basePath = TestBinRootPath.Combine(Context.PathTable, "foo").Combine(Context.PathTable, "bar");

            // Let's create a path that is equivalent to base path but it is constructed with '..'
            string nonCanonicalBasePath = Path.Combine(basePath.ToString(Context.PathTable), "..", "bar");

            var source = CreateSourceFile(basePath);
            var output = CreateOutputFileArtifact(basePath);

            // Now create non-canonical paths for source and output
            string nonCanonicalSource = Path.Combine(nonCanonicalBasePath, source.Path.GetName(Context.PathTable).ToString(Context.StringTable));
            string nonCanonicalOutput = Path.Combine(nonCanonicalBasePath, output.Path.GetName(Context.PathTable).ToString(Context.StringTable));

            var collector = new FileAccessDetoursListenerCollector(Context.PathTable);

            var info = ToProcessInfo(
                ToProcess(
                    Operation.AugmentedRead(nonCanonicalSource),
                    Operation.AugmentedWrite(nonCanonicalOutput)),
                fileAccessManifest: fam,
                detoursListener: collector);

            var result = RunProcess(info).GetAwaiter().GetResult();

            XAssert.AreEqual(0, result.ExitCode);

            // Let's check the raw paths reported by detours to make sure they are canonicalized
            var allRawPaths = collector.GetAllFileAccessPaths().Select(path => path.ToUpperInvariant());

            XAssert.Contains(allRawPaths, source.Path.ToString(Context.PathTable).ToUpperInvariant(), output.Path.ToString(Context.PathTable).ToUpperInvariant());
        }