private static VolumeMap CreateMapOfAllLocalVolumes() { VolumeMap map = VolumeMap.TryCreateMapOfAllLocalVolumes(new LoggingContext("Dummy", "Dummy")); XAssert.IsNotNull(map); return(map); }
public static ChangeTrackerSupport Initialize(FileContentTableWithTrackerTests test) { var loggingContext = new LoggingContext("Dummy", "Dummy"); var fileContentTable = FileContentTable.CreateNew(); VolumeMap volumeMap = VolumeMap.TryCreateMapOfAllLocalVolumes(loggingContext); XAssert.IsNotNull(volumeMap); var journal = JournalAccessorGetter.TryGetJournalAccessor(loggingContext, volumeMap, AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly())).Value; XAssert.IsNotNull(journal); var fileChangeTracker = FileChangeTracker.StartTrackingChanges(loggingContext, volumeMap, journal, null); return(new ChangeTrackerSupport( loggingContext, test.m_pathTable, fileChangeTracker, fileContentTable, volumeMap, journal, AbsolutePath.Create(test.m_pathTable, test.TemporaryDirectory), null)); }
public void OverlappingJunctionRoots() { List <string> junctionRoots = new List <string>() { @"c:\windows", @"c:\windows" }; VolumeMap map = VolumeMap.TryCreateMapOfAllLocalVolumes(new LoggingContext("Dummy", "Dummy"), junctionRoots); }
/// <summary> /// Creates a map of local volumes. /// </summary> public static VolumeMap TryCreateMapOfAllLocalVolumes(LoggingContext loggingContext, IReadOnlyList <string> junctionRoots = null) { var volumeMap = VolumeMap.TryCreateMapOfAllLocalVolumes(loggingContext, junctionRoots); // We want to skip volumes that are not local to VM. volumeMap.SkipTrackingJournalIncapableVolume = HasRelocatedTempInVm; return(volumeMap); }
/// <summary> /// Creates an instance of <see cref="IFileContentTableAccessor"/> based on the current OS. /// </summary> /// <param name="accessor">Output file content table accessor.</param> /// <param name="error">Error message for failed creation.</param> /// <returns>True if successful; otherwise false.</returns> public static bool TryCreate(out IFileContentTableAccessor accessor, out string error) { accessor = null; error = null; if (OperatingSystemHelper.IsUnixOS) { accessor = new FileContentTableAccessorUnix(); return(true); } VolumeMap volumeMap = VolumeMap.TryCreateMapOfAllLocalVolumes(new LoggingContext(nameof(IFileContentTableAccessor))); if (volumeMap == null) { error = "Failed to create volume map"; return(false); } accessor = new FileContentTableAccessorWin(volumeMap); return(true); }
private void WithVolumeHandle(Action <SafeFileHandle> action) { VolumeMap map = VolumeMap.TryCreateMapOfAllLocalVolumes(new LoggingContext("Dummy", "Dummy")); XAssert.IsNotNull(map, "Failed to create a volume map"); using (VolumeAccessor volumeAccessor = map.CreateVolumeAccessor()) { SafeFileHandle directoryHandle; var directoryOpenResult = FileUtilities.TryOpenDirectory( TemporaryDirectory, FileShare.ReadWrite | FileShare.Delete, out directoryHandle); using (directoryHandle) { XAssert.IsTrue(directoryOpenResult.Succeeded, "Failed to open the temporary directory to query its volume membership"); SafeFileHandle volumeHandle = volumeAccessor.TryGetVolumeHandle(directoryHandle); XAssert.IsNotNull(volumeHandle, "Failed to open a volume handle"); action(volumeHandle); } } }
/// <summary> /// Runs the scheduler allowing various options to be specifically set /// </summary> public ScheduleRunResult RunSchedulerSpecific( PipGraph graph, SchedulerTestHooks testHooks = null, SchedulerState schedulerState = null, RootFilter filter = null, TempCleaner tempCleaner = null) { var config = new CommandLineConfiguration(Configuration); // Populating the configuration may modify the configuration, so it should occur first. BuildXLEngine.PopulateLoggingAndLayoutConfiguration(config, Context.PathTable, bxlExeLocation: null, inTestMode: true); BuildXLEngine.PopulateAndValidateConfiguration(config, config, Context.PathTable, LoggingContext); FileAccessWhitelist whitelist = new FileAccessWhitelist(Context); whitelist.Initialize(config); IReadOnlyList <string> junctionRoots = Configuration.Engine.DirectoriesToTranslate?.Select(a => a.ToPath.ToString(Context.PathTable)).ToList(); var map = VolumeMap.TryCreateMapOfAllLocalVolumes(LoggingContext, junctionRoots); var optionalAccessor = TryGetJournalAccessor(map); // Although scan change journal is enabled, but if we cannot create an enabled journal accessor, then create a disabled one. m_journalState = map == null || !optionalAccessor.IsValid ? JournalState.DisabledJournal : JournalState.CreateEnabledJournal(map, optionalAccessor.Value); if (config.Schedule.IncrementalScheduling) { // Ensure that we can scan the journal when incremental scheduling is enabled. XAssert.IsTrue(m_journalState.IsEnabled, "Incremental scheduling requires that journal is enabled"); } // Seal the translator if not sealed DirectoryTranslator.Seal(); // ..................................................................................... // some dummy setup in order to get a PreserveOutputsSalt.txt file and an actual salt // ..................................................................................... string dummyCacheDir = Path.Combine(TemporaryDirectory, "Out", "Cache"); Directory.CreateDirectory(dummyCacheDir); // EngineSchedule tries to put the PreserveOutputsSalt.txt here ContentHash?previousOutputsSalt = EngineSchedule.PreparePreviousOutputsSalt(LoggingContext, Context.PathTable, config); Contract.Assert(previousOutputsSalt.HasValue); // ..................................................................................... testHooks = testHooks ?? new SchedulerTestHooks(); Contract.Assert(!(config.Engine.CleanTempDirectories && tempCleaner == null)); using (var queue = new PipQueue(config.Schedule)) using (var testQueue = new TestPipQueue(queue, LoggingContext, initiallyPaused: false)) using (var testScheduler = new TestScheduler( graph: graph, pipQueue: testQueue, context: Context, fileContentTable: FileContentTable, loggingContext: LoggingContext, cache: Cache, configuration: config, journalState: m_journalState, fileAccessWhitelist: whitelist, fingerprintSalt: Configuration.Cache.CacheSalt, directoryMembershipFingerprinterRules: new DirectoryMembershipFingerprinterRuleSet(Configuration, Context.StringTable), tempCleaner: tempCleaner, previousInputsSalt: previousOutputsSalt.Value, successfulPips: null, failedPips: null, ipcProvider: null, directoryTranslator: DirectoryTranslator, testHooks: testHooks)) { if (filter == null) { EngineSchedule.TryGetPipFilter(LoggingContext, Context, config, config, Expander.TryGetRootByMountName, out filter); } XAssert.IsTrue(testScheduler.InitForMaster(LoggingContext, filter, schedulerState), "Failed to initialized test scheduler"); testScheduler.Start(LoggingContext); bool success = testScheduler.WhenDone().GetAwaiter().GetResult(); testScheduler.SaveFileChangeTrackerAsync(LoggingContext).Wait(); return(new ScheduleRunResult { Graph = graph, Config = config, Success = success, PipResults = testScheduler.PipResults, PipExecutorCounters = testScheduler.PipExecutionCounters, PathSets = testScheduler.PathSets, ProcessPipCountersByFilter = testScheduler.ProcessPipCountersByFilter, ProcessPipCountersByTelemetryTag = testScheduler.ProcessPipCountersByTelemetryTag, SchedulerState = new SchedulerState(testScheduler) }); } }
/// <nodoc/> public FactIfSupportedAttribute( bool requiresAdmin = false, bool requiresJournalScan = false, bool requiresSymlinkPermission = false, bool requiresWindowsBasedOperatingSystem = false, bool requiresUnixBasedOperatingSystem = false, bool requiresHeliumDriversAvailable = false, bool requiresHeliumDriversNotAvailable = false) { RequiresAdmin = requiresAdmin; RequiresJournalScan = requiresJournalScan; RequiresSymlinkPermission = requiresSymlinkPermission; if (Skip != null) { // If skip is specified, do nothing because the test will be skipped anyway. return; } if (requiresAdmin) { if (!s_isElevated.HasValue) { s_isElevated = CurrentProcess.IsElevated; } if (!s_isElevated.Value) { Skip = "Test must be run elevated!"; return; } } if (requiresSymlinkPermission) { if (!s_canCreateSymlink.HasValue) { string tempFile = Path.GetTempFileName(); string symlinkPath = Path.GetTempFileName(); FileUtilities.DeleteFile(symlinkPath); // For reliable tests, we ensure that the symlink is created. s_canCreateSymlink = FileUtilities.TryCreateSymbolicLink(symlinkPath, tempFile, true).Succeeded&& FileUtilities.FileExistsNoFollow(symlinkPath); FileUtilities.DeleteFile(symlinkPath); FileUtilities.DeleteFile(tempFile); } if (!s_canCreateSymlink.Value) { Skip = "Test must be run with symbolic link creation privileged"; return; } } if (requiresJournalScan) { if (!s_canScanJournal.HasValue) { var loggingContext = new LoggingContext("Dummy", "Dummy"); var map = VolumeMap.TryCreateMapOfAllLocalVolumes(loggingContext); var accessor = JournalAccessorGetter.TryGetJournalAccessor(loggingContext, map, AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly())); s_canScanJournal = accessor.IsValid && accessor.Value != null; } if (!s_canScanJournal.Value) { Skip = "Test requires access to the in process change journal scan. Either run elevated on install RS2."; return; } } if (requiresWindowsBasedOperatingSystem) { if (OperatingSystemHelper.IsUnixOS) { Skip = "Test must be run on the CLR on Windows based operating systems!"; return; } } if (requiresUnixBasedOperatingSystem) { if (!OperatingSystemHelper.IsUnixOS) { Skip = "Test must be run on the CoreCLR on Unix based operating systems!"; return; } } if (requiresHeliumDriversAvailable) { if (!s_isHeliumFiltersAvailable.HasValue) { s_isHeliumFiltersAvailable = ProcessUtilities.IsWciAndBindFiltersAvailable(); } if (!s_isHeliumFiltersAvailable.Value) { Skip = "Test must be run elevated on a machine with WCI and Bind filters available."; return; } } if (requiresHeliumDriversNotAvailable) { if (!s_isHeliumFiltersAvailable.HasValue) { s_isHeliumFiltersAvailable = ProcessUtilities.IsWciAndBindFiltersAvailable(); } if (s_isHeliumFiltersAvailable.Value) { Skip = "Test must be run on a machine where WCI and Bind filters are NOT available."; return; } } }