Exemplo n.º 1
0
            public Harness(string testOutputDirectory)
            {
                Context = BuildXLContext.CreateInstanceForTesting();
                var config = ConfigurationHelpers.GetDefaultForTesting(Context.PathTable, AbsolutePath.Create(Context.PathTable, System.IO.Path.Combine(testOutputDirectory, "config.dc")));

                m_env = new DummyPipExecutionEnvironment(
                    CreateLoggingContextForTest(),
                    Context,
                    config,
                    subst: FileUtilities.TryGetSubstSourceAndTarget(testOutputDirectory, out var substSource, out var substTarget)
                        ? (substSource, substTarget)
                        : default((string, string)?),
                    sandboxConnection: GetSandboxConnection());
                var sealContentsCache = new ConcurrentBigMap <DirectoryArtifact, int[]>();

                Table = Context.PathTable;

                // Create the paths in the PathTable before creating the CachedFileSystemView
                Path(a);
                Path(b);
                Path(c);
                Path(d);
                Path(e);
                Path(f);
                Path(g);
                Path(h);
                Path(i);
                Path(j);
                Path(k);
                Path(l);

                m_fileSystem = new PipFileSystemView();
                m_fileSystem.Initialize(Table);
            }
Exemplo n.º 2
0
        private CompositeGraphFingerprint GenerateRandomTopLevelHash(string configPath, string index, bool flag)
        {
            var context1 = BuildXLContext.CreateInstanceForTesting();

            var configuration1 = ConfigurationHelpers.GetDefaultForTesting(context1.PathTable, AbsolutePath.Create(context1.PathTable, configPath));

            var evaluationFilter1 = new EvaluationFilter(
                context1.SymbolTable,
                context1.PathTable,
                new FullSymbol[0],
                new[]
            {
                AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"testFile{index}.txt")),
            },
                CollectionUtilities.EmptyArray <StringId>());

            configuration1.Layout.ObjectDirectory                = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"ObjectDirectory{index}"));
            configuration1.Layout.TempDirectory                  = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"TempDirectory{index}"));
            configuration1.Layout.SourceDirectory                = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"SourceDirectory{index}"));
            configuration1.Logging.SubstTarget                   = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"SubstTarget{index}"));
            configuration1.Engine.CompressGraphFiles             = flag;
            configuration1.Schedule.SkipHashSourceFile           = flag;
            configuration1.Schedule.ComputePipStaticFingerprints = flag;

            var loggingContext1 = CreateLoggingContextForTest();

            var fileContentTable1 = FileContentTable.CreateNew(loggingContext1);

            return(GraphFingerprinter.TryComputeFingerprint(loggingContext1, configuration1.Startup, configuration1, context1.PathTable, evaluationFilter1, fileContentTable1, "111aaa", null).ExactFingerprint);
        }
Exemplo n.º 3
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 fileContentTable = FileContentTable.CreateNew();
                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);
                PipResult executeResult = await Execute(context, fileContentTable, config, pip);

                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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a default configuration
        /// </summary>
        public static CommandLineConfiguration CreateDefaultForScript(PathTable pathTable, AbsolutePath rootPath)
        {
            var paths = new Paths(pathTable);

            var configFile = paths.CreateAbsolutePath(rootPath, Names.ConfigDsc);

            return(ConfigurationHelpers.GetDefaultForTesting(pathTable, configFile));
        }
        public PerProcessPipPerformanceInformationStoreTests(ITestOutputHelper output)
            : base(output)
        {
            m_context       = BuildXLContext.CreateInstanceForTesting();
            m_configuration = ConfigurationHelpers.GetDefaultForTesting(m_context.PathTable, AbsolutePath.Create(m_context.PathTable, Path.Combine(TemporaryDirectory, "config.ds")));

            m_perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(m_configuration.Logging.MaxNumPipTelemetryBatches, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a default configuration
        /// </summary>
        public static CommandLineConfiguration CreateDefault(PathTable pathTable, string configFilePath, TempFileStorage tempStorage)
        {
            var paths = new Paths(pathTable);

            var configFile = paths.CreateAbsolutePath(configFilePath);

            var result = ConfigurationHelpers.GetDefaultForTesting(pathTable, configFile);

            result.Layout.ObjectDirectory = paths.CreateAbsolutePath(tempStorage.GetUniqueDirectory());
            result.Layout.CacheDirectory  = paths.CreateAbsolutePath(tempStorage.GetUniqueDirectory());

            return(result);
        }
Exemplo n.º 7
0
        public void GenerateHashWithDifferentEvaluationFilters()
        {
            WriteFile("config.ds", "SampleConfig");

            var context1 = BuildXLContext.CreateInstanceForTesting();

            var configuration1 = ConfigurationHelpers.GetDefaultForTesting(context1.PathTable, AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, "config.ds")));

            var evaluationFilter1 = new EvaluationFilter(
                context1.SymbolTable,
                context1.PathTable,
                new FullSymbol[0],
                new[]
            {
                AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"testFile1.txt")),
            },
                CollectionUtilities.EmptyArray <StringId>());

            var evaluationFilter2 = new EvaluationFilter(
                context1.SymbolTable,
                context1.PathTable,
                new FullSymbol[0],
                new[]
            {
                AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"testFile2.txt")),
            },
                CollectionUtilities.EmptyArray <StringId>());

            configuration1.Layout.ObjectDirectory                = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"ObjectDirectory1"));
            configuration1.Layout.TempDirectory                  = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"TempDirectory1"));
            configuration1.Layout.SourceDirectory                = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"SourceDirectory1"));
            configuration1.Logging.SubstTarget                   = AbsolutePath.Create(context1.PathTable, Path.Combine(TemporaryDirectory, $"SubstTarget1"));
            configuration1.Engine.CompressGraphFiles             = false;
            configuration1.Schedule.SkipHashSourceFile           = false;
            configuration1.Schedule.ComputePipStaticFingerprints = false;

            var loggingContext1 = CreateLoggingContextForTest();

            var fileContentTable1 = FileContentTable.CreateNew(loggingContext1);

            var oldFingerprint  = GraphFingerprinter.TryComputeFingerprint(loggingContext1, configuration1.Startup, configuration1, context1.PathTable, evaluationFilter1, fileContentTable1, "111aaa", null).ExactFingerprint;
            var newFingerprint1 = GraphFingerprinter.TryComputeFingerprint(loggingContext1, configuration1.Startup, configuration1, context1.PathTable, evaluationFilter2, fileContentTable1, "111aaa", null).ExactFingerprint;

            var comparison = oldFingerprint.CompareFingerprint(newFingerprint1);

            Assert.Equal(GraphCacheMissReason.EvaluationFilterChanged, comparison);
        }
        public PerProcessPipPerformanceInformationStoreTests(ITestOutputHelper output)
            : base(output)
        {
            m_context        = BuildXLContext.CreateInstanceForTesting();
            m_loggingContext = CreateLoggingContextForTest();
            m_configuration  = ConfigurationHelpers.GetDefaultForTesting(m_context.PathTable, AbsolutePath.Create(m_context.PathTable, Path.Combine(TemporaryDirectory, "config.ds")));
            m_perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(MaxNumPipTelemetryBatches, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);
            m_runnablePips = new Hashtable();

            var pipTable = new PipTable(
                m_context.PathTable,
                m_context.SymbolTable,
                initialBufferSize: 1024,
                maxDegreeOfParallelism: (Environment.ProcessorCount + 2) / 3,
                debug: false);

            m_executionEnvironment = new DummyPipExecutionEnvironment(m_loggingContext, m_context, m_configuration, pipTable: pipTable);

            m_individualPipInfoStringLength = PerProcessPipPerformanceInformationStore.SerializePipPerfInfo(CreateSamplePip(0)).Length;
        }
Exemplo n.º 9
0
        private async Task TestDownloadResolver(DownloadData data, Func <DownloadResolver, Task> performTest, bool useHttpServer = true)
        {
            var dummyConfigFile = Path.Combine(TemporaryDirectory, m_uniqueTestFolder, "config.dsc");

            var statistics       = new Statistics();
            var moduleRegistry   = new ModuleRegistry(FrontEndContext.SymbolTable);
            var workspaceFactory = CreateWorkspaceFactoryForTesting(FrontEndContext, ParseAndEvaluateLogger);
            var configuration    = ConfigurationHelpers.GetDefaultForTesting(FrontEndContext.PathTable, AbsolutePath.Create(FrontEndContext.PathTable, dummyConfigFile));
            var resolverSettings = new ResolverSettings();

            var frontEndFactory = new FrontEndFactory();

            frontEndFactory.AddFrontEnd(new DownloadFrontEnd());
            frontEndFactory.TrySeal(new LoggingContext("UnitTest"));

            using (var host = new FrontEndHostController(
                       frontEndFactory,
                       workspaceFactory,
                       new EvaluationScheduler(degreeOfParallelism: 1),
                       moduleRegistry,
                       new FrontEndStatistics(),
                       global::BuildXL.FrontEnd.Core.Tracing.Logger.CreateLogger(),
                       collector: null,
                       collectMemoryAsSoonAsPossible: false))
            {
                var frontEndEngineAbstraction = new BasicFrontEndEngineAbstraction(
                    FrontEndContext.PathTable,
                    FrontEndContext.FileSystem,
                    configuration);

                ((IFrontEndController)host).InitializeHost(FrontEndContext, configuration);
                host.SetState(frontEndEngineAbstraction, new TestEnv.TestPipGraph(), configuration);

                var resolver = new DownloadResolver(
                    statistics,
                    host,
                    FrontEndContext,
                    Logger.Log,
                    "TestFrontEnd"
                    );

                var workspaceResolver = new DownloadWorkspaceResolver();
                workspaceResolver.UpdateDataForDownloadData(data, FrontEndContext);
                await resolver.InitResolverAsync(resolverSettings, workspaceResolver);

                if (useHttpServer)
                {
                    using (var listener = new HttpListener())
                    {
                        // This test relies on the mutex in the build engine to only run one unittest at a time and this assembly to be single thread
                        // if any of those assumptions will be broken we will have to either dynamically (remind you globally) get unique ports.
                        // HttpListner doesn't have this built-in so there will always be a race. Just spam the ports utnill one doesn't fail
                        // use a global mutex (This is not honored by qtest since it can run in a different session on cloudbuild).
                        listener.Prefixes.Add(TestServer);
                        listener.Start();

                        StartRequestHandler(listener);

                        await performTest(resolver);

                        listener.Stop();
                        listener.Close();
                    }
                }
                else
                {
                    await performTest(resolver);
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public TestHarness(BuildXLContext context, AbsolutePath configFile)
 {
     m_context     = context;
     Configuration = ConfigurationHelpers.GetDefaultForTesting(context.PathTable, configFile);
 }