예제 #1
0
        public async Task FailToCreateL2CacheWorks()
        {
            const string TestName    = "FailToCreateL2CacheWorks";
            string       testCacheId = MakeCacheId(TestName);

            string localConfig  = new TestInMemory().NewCache(testCacheId + VerticalAggregatorBaseTests.LocalMarker, false);
            string remoteConfig = new TestInMemory().NewCacheFailure(testCacheId + VerticalAggregatorBaseTests.RemoteMarker, true, authoritative: true);

            string cacheConfigData = VerticalAggregatorBaseTests.NewCacheString(testCacheId, localConfig, remoteConfig, false, false, false, false);

            ICache cache = await InitializeCacheAsync(cacheConfigData).SuccessAsync();

            bool   warningSent     = false;
            string warningMessage  = string.Empty;
            string expectedWarning = string.Format(System.Globalization.CultureInfo.InvariantCulture, VerticalCacheAggregatorFactory.RemoteConstructionFailureWarning, testCacheId + VerticalAggregatorBaseTests.LocalMarker);

            cache.SuscribeForCacheStateDegredationFailures((failure) => { warningSent    = true;
                                                                          warningMessage = failure.Describe(); });

            XAssert.IsTrue(warningSent);

            XAssert.IsNull(cache as VerticalCacheAggregator, "We should have eliminated the VerticalCacheAggregator as there is only 1 operating cache");

            XAssert.AreEqual(expectedWarning, warningMessage);

            await cache.ShutdownAsync().SuccessAsync();
        }
예제 #2
0
        public async Task TestMinJsonString()
        {
            string jsonString = GetJsonStringFromDictionary(new Dictionary <string, object>()
            {
                { "StringWithNoDefaultValue", "Value_of_StringWithNoDefaultValue" },
            });

            // set up the result validation lambda
            resultValidationLambda = (obj1) =>
            {
                XAssert.AreEqual("Value_of_StringWithDefaultValue", obj1.StringWithDefaultValue);
                XAssert.AreEqual("Value_of_StringWithNoDefaultValue", obj1.StringWithNoDefaultValue);
                XAssert.AreEqual(1, obj1.IntValue);
                XAssert.AreEqual(true, obj1.BoolValue);
                XAssert.AreEqual(3.1415F, obj1.FloatValue);

                XAssert.IsNull(obj1.CacheConfigValue);

                // the lambda assigned to resultValidationLambda is static and each test should set it. We will set it to null to make sure that no other tests use this lambda accidentally.
                resultValidationLambda = null;
            };

            // call InitializeCache, there should be no exception
            Possible <ICache, Failure> cache = await InitializeCacheAsync(jsonString);

            // make sure that we get an actual cache
            XAssert.IsTrue(cache.Succeeded);
        }
        public void TryExpandNameRelativeToAnother()
        {
            var hnt = new HierarchicalNameTable(new StringTable(), true, Path.DirectorySeparatorChar);
            HierarchicalNameId root = hnt.AddName(A("c", "dir", "root"));
            HierarchicalNameId immediateDescendant = hnt.AddName(A("c", "dir", "root", "file"));
            HierarchicalNameId furtherDescendant   = hnt.AddName(A("c", "dir", "root", "moredir", "file2"));
            HierarchicalNameId sibling             = hnt.AddName(A("c", "dir", "sibling"));

            string immediateDescendantPath;

            XAssert.IsTrue(hnt.TryExpandNameRelativeToAnother(root, immediateDescendant, out immediateDescendantPath));
            XAssert.AreEqual("file", immediateDescendantPath);

            string furtherDescendantPath;

            XAssert.IsTrue(hnt.TryExpandNameRelativeToAnother(root, furtherDescendant, out furtherDescendantPath));
            XAssert.AreEqual(R("moredir", "file2"), furtherDescendantPath);

            string siblingPath;

            XAssert.IsFalse(hnt.TryExpandNameRelativeToAnother(root, sibling, out siblingPath));
            XAssert.IsNull(siblingPath);

            string emptyPath;

            XAssert.IsTrue(hnt.TryExpandNameRelativeToAnother(root, root, out emptyPath));
            XAssert.AreEqual(string.Empty, emptyPath);
        }
        public void ChangesToGvfsProjectionsInvalidatePossiblyChangedPaths(bool changeGvfsProjection)
        {
            var gvfsProjections = new[]
            {
                X("/c/.gvfs/GVFS_projection"),
                X("/d/.gvfs/GVFS_projection")
            };
            var otherFile = X("/c/whatever");

            var graphChanges = new GraphInputArtifactChanges(LoggingContext, gvfsProjections);

            graphChanges.OnInit();
            if (changeGvfsProjection)
            {
                graphChanges.OnNext(new ChangedPathInfo(gvfsProjections[0], PathChanges.Removed));
            }
            graphChanges.OnNext(new ChangedPathInfo(otherFile, PathChanges.DataOrMetadataChanged));
            graphChanges.OnCompleted(ScanningJournalResult.Success(EmptyStats));

            if (changeGvfsProjection)
            {
                XAssert.IsNull(graphChanges.ChangedDirs);
                XAssert.IsNull(graphChanges.PossiblyChangedPaths);
            }
            else
            {
                XAssert.SetEqual(new string[0], graphChanges.ChangedDirs);
                XAssert.SetEqual(new[] { otherFile }, graphChanges.PossiblyChangedPaths);
            }
        }
예제 #5
0
        public void TestStatFs(string path, bool pathExists)
        {
            var pathExistsAsFile = FileUtilities.FileExistsNoFollow(path);
            var pathExistsAsDir  = FileUtilities.DirectoryExistsNoFollow(path);

            XAssert.AreEqual(
                pathExists, pathExistsAsFile || pathExistsAsDir,
                $"Expected exists: {pathExists}, Actual exists as file: {pathExistsAsFile}, Actual exists as dir: {pathExistsAsDir}");

            var   buf   = new StatFsBuffer();
            int   error = IO.StatFs(path, ref buf);
            ulong?maybeFreeSpaceBytes = IO.FreeSpaceLeftOnDeviceInBytes(path);

            if (pathExists)
            {
                XAssert.IsNotNull(maybeFreeSpaceBytes);
                ulong freeSpaceBytes = maybeFreeSpaceBytes.Value;
                var   dbg            = $"{path} (free {freeSpaceBytes >> 30}GB) :: {buf.f_fstypename}: {buf.f_mntfromname} -> {buf.f_mntonname}";

                XAssert.AreEqual(0, error, $"Expected statfs to return 0 on {path} which exists. {dbg}");
                XAssert.IsTrue(freeSpaceBytes > 0, $"Expected free space to be greater than 0B, instead it is {freeSpaceBytes}B. {dbg}");
                if (path == "/")
                {
                    XAssert.AreEqual("/", buf.f_mntonname, $"Path '/' must be mounted to '/'. {dbg}");
                }
            }
            else
            {
                XAssert.AreEqual(-1, error, $"Expected statfs to return -1 on '{path}' which does not exist.");
                XAssert.IsNull(maybeFreeSpaceBytes, $"Expected free space to be -1 for path '{path}' that does not exist.");
            }
        }
예제 #6
0
        public async Task TestNonDefaultForStreamCas()
        {
            var jsonConfig = NewCache(nameof(TestNonDefaultForStreamCas), true);
            ICacheConfigData cacheData;
            Exception        exception;
            var success = CacheFactory.TryCreateCacheConfigData(jsonConfig, out cacheData, out exception);

            XAssert.IsTrue(success);
            XAssert.IsNull(exception);

            var maybeCacheConfig = cacheData.Create <MemoizationStoreCacheFactory.Config>();

            XAssert.IsTrue(maybeCacheConfig.Succeeded);

            var cacheConfig = maybeCacheConfig.Result;

            XAssert.IsTrue(cacheConfig.UseStreamCAS);

            var rootForStream = Path.Combine(cacheConfig.CacheRootPath, "streams");

            Possible <ICache, Failure> cachePossible = await InitializeCacheAsync(jsonConfig);

            ICache cache = cachePossible.Success();

            XAssert.IsTrue(Directory.Exists(rootForStream));

            await ShutdownCacheAsync(cache, nameof(TestNonDefaultForStreamCas));
        }
예제 #7
0
        public void CannotAccessDeletedFile()
        {
            ulong  volumeSerial;
            FileId fileId;
            string path = GetFullPath("F");

            using (FileStream fs = File.Create(path))
            {
                volumeSerial = FileUtilities.GetVolumeSerialNumberByHandle(fs.SafeFileHandle);
                fileId       = FileUtilities.ReadFileUsnByHandle(fs.SafeFileHandle).Value.FileId;
            }

            File.Delete(path);

            VolumeMap map = CreateMapOfAllLocalVolumes();

            using (FileAccessor accessor = map.CreateFileAccessor())
            {
                SafeFileHandle handle;
                FileAccessor.OpenFileByIdResult openResult = accessor.TryOpenFileById(
                    volumeSerial,
                    fileId,
                    FileDesiredAccess.GenericRead,
                    FileShare.ReadWrite,
                    FileFlagsAndAttributes.None,
                    out handle);
                using (handle)
                {
                    XAssert.AreEqual(FileAccessor.OpenFileByIdResult.FailedToFindFile, openResult);
                    XAssert.IsNull(handle);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Builds the <see cref="TestEnv.PipGraph"/> and asserts failure
        /// </summary>
        internal static void AssertFailedGraphBuilding(TestEnv env)
        {
            var builder = env.PipGraph as PipGraph.Builder;

            XAssert.IsNotNull(builder);
            XAssert.IsNull(builder.Build());
        }
예제 #9
0
        public void FileGetsUpdated()
        {
            FakeFile initial = CreateFakeFile(R("foo", "bar1.txt"), "BeginningContent");

            // Create a combiner and add some files
            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path, 1))
            {
                AddFile(combiner, initial);
            }

            FakeFile updated = CreateFakeFile(R("foo", "bar1.txt"), "UpdatedContent");

            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path, 1))
            {
                AddFile(combiner, updated);
            }

            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path, 1))
            {
                using (MemoryStream ms = combiner.RequestFile(initial.Path, initial.Hash))
                {
                    XAssert.IsNull(ms);
                }

                using (MemoryStream ms = combiner.RequestFile(updated.Path, updated.Hash))
                {
                    XAssert.IsNotNull(ms);
                    AssertContentMatches(ms, updated);
                }
            }
        }
예제 #10
0
        public void CorruptFile()
        {
            // Write out some garbage to create a corrupt file
            File.WriteAllText(m_path, "1Cleanasldkjf09234,kns90j23lk4n2309u4");

            FakeFile f1 = CreateFakeFile(R("foo", "bar1.txt"), "bar1.txt");

            // Try to use it
            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path))
            {
                XAssert.IsNull(combiner.RequestFile(f1.Path, f1.Hash));
                AddFile(combiner, f1);
            }

            // Reload and consume the added file
            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path))
            {
                using (MemoryStream ms = combiner.RequestFile(f1.Path, f1.Hash))
                {
                    XAssert.IsNotNull(ms);
                }
            }

            AssertWarningEventLogged(EventId.FileCombinerVersionIncremented);
        }
        private async Task TestForOutOfSpace(string cacheId, Func <ICacheSession, Task> testSessionAsyncFunc)
        {
            var jsonConfig = NewCache(cacheId, true);
            ICacheConfigData cacheData;
            Exception        exception;
            var success = CacheFactory.TryCreateCacheConfigData(jsonConfig, out cacheData, out exception);

            XAssert.IsTrue(success);
            XAssert.IsNull(exception);

            var maybeCacheConfig = cacheData.Create <MemoizationStoreCacheFactory.Config>();

            XAssert.IsTrue(maybeCacheConfig.Succeeded);

            Possible <ICache, Failure> cachePossible = await InitializeCacheAsync(jsonConfig);

            ICache cache = cachePossible.Success();

            string testSessionId = "Session1-" + cacheId;

            ICacheSession session = await CreateSessionAsync(cache, testSessionId);

            await testSessionAsyncFunc(session);

            await CloseSessionAsync(session, testSessionId);
            await ShutdownCacheAsync(cache, cacheId);
        }
예제 #12
0
        public async Task DeterminismUpgraded(int fromDeterminism, int toDeterminism, bool differentCasEntries)
        {
            string testName    = I($"DeterminismUpgraded{fromDeterminism}x{toDeterminism}{(differentCasEntries ? "Diff" : "Same")}");
            string testCacheId = MakeCacheId(testName);
            ICache cache       = await CreateCacheAsync(testCacheId);

            string        testSessionId = "Session1-" + testCacheId;
            ICacheSession session       = await CreateSessionAsync(cache, testSessionId);

            // We need at least 2 to make "differentCasEntries" work
            PipDefinition[] pips =
            {
                new PipDefinition("PipA", determinism: s_determinism[fromDeterminism]),
                new PipDefinition("PipB", determinism: s_determinism[fromDeterminism])
            };

            var records = (await pips.BuildAsync(session)).ToArray();

            await CloseSessionAsync(session, testSessionId);

            testSessionId = "Session2-" + testCacheId;
            session       = await CreateSessionAsync(cache, testSessionId);

            // What we will do here is AddOrGet() a record with the determinism bit changed.
            for (int i = 0; i < records.Length; i++)
            {
                var record = records[i];

                // This gets the CasEntries we want
                CasEntries newEntries = records[(i + (differentCasEntries ? 1 : 0)) % records.Length].CasEntries;

                // Validate that the entry for the record is what we expect
                var entries = (await session.GetCacheEntryAsync(record.StrongFingerprint)).Success();
                XAssert.AreEqual(s_determinism[fromDeterminism].EffectiveGuid, entries.Determinism.EffectiveGuid);

                // Now pin the CasElement and all of the CasEntries
                (await session.PinToCasAsync(record.StrongFingerprint.CasElement, CancellationToken.None)).Success();
                (await session.PinToCasAsync(newEntries, CancellationToken.None)).Success();

                // Now make a new record
                var newRecord = (await session.AddOrGetAsync(
                                     record.StrongFingerprint.WeakFingerprint,
                                     record.StrongFingerprint.CasElement,
                                     record.StrongFingerprint.HashElement,
                                     new CasEntries(newEntries, s_determinism[toDeterminism]))).Success();

                // The new record should be null since the determinism was upgraded
                XAssert.IsNull(newRecord.Record);

                // Now, we will try to get the same record from the cache to validate
                // the setting of the bit
                entries = (await session.GetCacheEntryAsync(record.StrongFingerprint)).Success();
                XAssert.AreEqual(newEntries, entries);
                XAssert.AreEqual(s_determinism[toDeterminism].EffectiveGuid, entries.Determinism.EffectiveGuid);
            }

            await CloseSessionAsync(session, testSessionId);
            await ShutdownCacheAsync(cache, testCacheId);
        }
예제 #13
0
 private void RunAndAssertGraphCacheHit(ICommandLineConfiguration config, AppDeployment appDeployment, bool rememberAllChangedTrackedInputs = false)
 {
     using (var hostController = RunEngineAndGetFrontEndHostController(config, appDeployment, null, rememberAllChangedTrackedInputs))
     {
         AssertNotLogged(LogEventId.EndSerializingPipGraph);
         XAssert.IsNull(hostController.Workspace);
     }
 }
        public void StubFileContentTableDoesNotThrowOnQuery()
        {
            var table = FileContentTable.CreateStub();

            WriteTestFiles();

            XAssert.IsNull(table.TryGetKnownContentHash(m_testFileA.ToString(m_pathTable)));
        }
예제 #15
0
        public void DoNotSchedulePhonyProcess()
        {
            var trueNode  = CreateNinjaNode(outputs: Paths("foo.out"));
            var phonyNode = CreateNinjaNode(rule: "phony", command: "", inputs: Paths("foo.out"));

            var process = Start().AddAll(trueNode, phonyNode).ScheduleAll().RetrieveSuccessfulProcess(phonyNode);

            XAssert.IsNull(process);
        }
        public void TestBadCredentialHelperPath(bool emptyPath)
        {
            var outStream  = new StringBuilder();
            var credHelper = AzureArtifactsCredentialHelper.CreateInstanceForTesting(m => outStream.AppendLine(m), emptyPath ? "" : "badPath", "");

            var result = credHelper.AcquirePat(new Uri("https://foo"), PatType.CacheReadWrite).Result;

            XAssert.IsTrue(result.Result == AzureArtifactsCredentialHelperResultType.NoCredentialProviderSpecified);
            XAssert.IsNull(result.Pat);
        }
예제 #17
0
 private void AssertPathCongruent(PathTable pathTable, string s, AbsolutePath p)
 {
     if (!p.IsValid)
     {
         XAssert.IsNull(s);
     }
     else
     {
         XAssert.AreEqual(s, p.ToString(pathTable));
     }
 }
예제 #18
0
        public void CreateAndReloadCombinedFile()
        {
            int maxBackingBufferBytes = 3; // let's make sure we are going to span multiple chunks...

            FakeFile f1 = CreateFakeFile(R("foo", "bar1.txt"), "bar1.txt");
            FakeFile f2 = CreateFakeFile(R("foo", "bar2.txt"), "bar2.txt");
            FakeFile f3 = CreateFakeFile(R("foo", "bar3.txt"), "bar3.txt");

            XAssert.IsTrue(f1.Content.Length > maxBackingBufferBytes * 3);
            XAssert.IsTrue(f2.Content.Length > maxBackingBufferBytes * 3);
            XAssert.IsTrue(f3.Content.Length > maxBackingBufferBytes * 3);

            Logger.FileCombinerStats stats = new Logger.FileCombinerStats();

            // Create a combiner and add some files
            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path, 1))
            {
                combiner.GetStatsRefForTest(ref stats);
                AddFile(combiner, f3);
                AddFile(combiner, f2);
                AddFile(combiner, f1);
            }

            XAssert.AreEqual(3, stats.EndCount);
            XAssert.AreEqual(0, stats.CompactingTimeMs, "FileCombiner should not have been compacted");

            // Make sure the file is longer than the max backing buffer so we can test data being split across buffers
            FileInfo info = new FileInfo(m_path);

            XAssert.IsTrue(info.Length > maxBackingBufferBytes);

            // reload the combiner
            using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path, 1, maxBackingBufferBytes))
            {
                // fetch a file that exists and verify the correct data is returned
                using (MemoryStream ms = combiner.RequestFile(f1.Path, f1.Hash))
                {
                    XAssert.IsNotNull(ms);
                    AssertContentMatches(ms, f1);
                }

                // Fetch a file with the wrong hash. Make sure no content is returned
                using (MemoryStream ms = combiner.RequestFile(f1.Path, f2.Hash))
                {
                    XAssert.IsNull(ms);
                }

                // Fetch a file that doesn't exist. Make sure no content is returned
                using (MemoryStream ms = combiner.RequestFile(R("foo", "bar4"), f2.Hash))
                {
                    XAssert.IsNull(ms);
                }
            }
        }
        public void TestBadExitCode()
        {
            var outStream  = new StringBuilder();
            var credHelper = AzureArtifactsCredentialHelper.CreateInstanceForTesting(m => outStream.AppendLine(m), CmdHelper.OsShellExe, "/d /c exit 1");

            var result = credHelper.AcquirePat(new Uri("https://foo"), PatType.CacheReadWrite).Result;

            XAssert.IsTrue(result.Result == AzureArtifactsCredentialHelperResultType.BadStatusCodeReturned);
            XAssert.IsTrue(outStream.ToString().Contains("Credential provider execution failed with exit code 1"));
            XAssert.IsNull(result.Pat);
        }
예제 #20
0
        public async Task DeserializationReturnsNullIfUnavailable()
        {
            var cache = new InMemoryArtifactContentCache();

            ContentHash imaginaryContent = ContentHashingUtilities.HashBytes(Encoding.UTF8.GetBytes("Imagination"));

            var maybeDeserialized =
                await cache.TryLoadAndDeserializeContent <PipCacheDescriptorV2Metadata>(imaginaryContent);

            XAssert.IsTrue(maybeDeserialized.Succeeded);
            XAssert.IsNull(maybeDeserialized.Result, "Should be a miss (cache empty)");
        }
예제 #21
0
        public void TestAllDirectoriesSourceSealDirectoryContainingOutputFile()
        {
            using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler(nameof(TestAllDirectoriesSourceSealDirectoryContainingOutputFile)))
            {
                AbsolutePath directoryPath = env.Paths.CreateAbsolutePath(env.ObjectRoot, "ssd");
                ScheduleWriteOutputFileUnderDirectory(env, directoryPath, @"a\b\f.txt");

                ScheduleSourceSealDirectory(env, directoryPath, allDirectories: true);

                XAssert.IsNull(env.PipGraph.Build());
                AssertErrorEventLogged(LogEventId.InvalidGraphSinceSourceSealedDirectoryContainsOutputFile);
            }
        }
예제 #22
0
        public async Task NoItemFingerprint()
        {
            const string TestName    = nameof(NoItemFingerprint);
            string       testCacheId = MakeCacheId(TestName);
            ICache       cache       = await CreateCacheAsync(testCacheId);

            // Now for the session (which we base on the cache ID)
            string testSessionId = "Session1-" + testCacheId;

            ICacheSession session = await CreateSessionAsync(cache, testSessionId);

            // Note that we will be making a new fingerprint with a CasHash of NoItem
            // without pre-sending it as NoItem is a special case - it is nothing
            FullCacheRecord record = await FakeBuild.DoPipAsync(session, TestName);

            // We place this in and did not pin the NoItem yet or even send it around
            // Note that this also is doing a zero-length CasEntries
            var strong = new StrongFingerprint(record.StrongFingerprint.WeakFingerprint, CasHash.NoItem, new Hash(FingerprintUtilities.ZeroFingerprint), TestName);
            FullCacheRecordWithDeterminism oldRecord = (await session.AddOrGetAsync(
                                                            strong.WeakFingerprint,
                                                            strong.CasElement,
                                                            strong.HashElement,
                                                            CasEntries.FromCasHashes())).Success("Should work even though I did not pin CasHash.NoItem, instead it failed with {0}");

            XAssert.IsNull(oldRecord.Record, "Should have been the first one like this");

            var result = await session.GetCacheEntryAsync(strong).SuccessAsync();

            XAssert.AreEqual(0, result.Count, "We should have gotten a zero-length CasEntries");

            // We place this in and did not pin the NoItem yet or even send it around
            // Note that this does an array of NoItem CasEntries and use the
            // record.CasElement as the weak fingerprint
            CasHash[] empties = { CasHash.NoItem, CasHash.NoItem, CasHash.NoItem };
            strong    = new StrongFingerprint(new WeakFingerprintHash(strong.CasElement.ToFingerprint()), CasHash.NoItem, new Hash(FingerprintUtilities.ZeroFingerprint), TestName);
            oldRecord = (await session.AddOrGetAsync(
                             strong.WeakFingerprint,
                             CasHash.NoItem,
                             new Hash(FingerprintUtilities.ZeroFingerprint),
                             empties)).Success("Should work even though I did not pin CasHash.NoItem, instead it failed with {0}");

            XAssert.IsNull(oldRecord.Record, "Should have been the first one like this");

            result = await session.GetCacheEntryAsync(strong).SuccessAsync();

            XAssert.AreEqual(empties, result, "We should have gotten the set of empties");

            await CloseSessionAsync(session, testSessionId);

            await ShutdownCacheAsync(cache, testCacheId);
        }
예제 #23
0
        public void TestSealDirectoryWithUnderspecifiedRewriteContentsOutputContents()
        {
            using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler(nameof(TestSealDirectoryWithUnderspecifiedRewriteContentsOutputContents)))
            {
                AbsolutePath directoryPath = env.Paths.CreateAbsolutePath(env.ObjectRoot, "seal");
                FileArtifact a1            = ScheduleWriteOutputFileUnderDirectory(env, directoryPath, "a");
                FileArtifact b             = ScheduleWriteOutputFileUnderDirectory(env, directoryPath, "b");
                FileArtifact a2            = ScheduleRewrite(env, b, a1);

                ScheduleSealDirectory(env, directoryPath, a2);

                XAssert.IsNull(env.PipGraph.Build());
                AssertErrorEventLogged(LogEventId.InvalidGraphSinceFullySealedDirectoryIncomplete);
            }
        }
예제 #24
0
        public void DoNotFailWhenFieldsAreMissing()
        {
            var path = Path.GetTempFileName();

            File.WriteAllText(path, "{ }");
            var metadata = BsiMetadataExtractor.ProduceSbomMetadata(path, BuildEnvironmentName.BuildXL, "packageName", "1.0");

            XAssert.AreEqual(BuildEnvironmentName.BuildXL, metadata.BuildEnvironmentName);
            XAssert.AreEqual("packageName", metadata.PackageName);
            XAssert.IsNull(metadata.Branch);
            XAssert.IsNull(metadata.BuildName);
            XAssert.IsNull(metadata.BuildId);
            XAssert.IsNull(metadata.CommitId);
            XAssert.IsNull(metadata.RepositoryUri);
        }
예제 #25
0
        [Trait("Category", "WindowsOSOnly")] // need to investigate if equivalent behavior on Unix
        public void FileInUse()
        {
            // Open the backing file so the FileCombiner can't open it
            using (var file = File.Open(m_path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None))
            {
                FakeFile f1 = CreateFakeFile(R("foo", "bar1.txt"), "bar1.txt");

                // Try to use it
                using (FileCombiner combiner = CreateFileCombiner(m_loggingContext, m_path))
                {
                    XAssert.IsNull(combiner.RequestFile(f1.Path, f1.Hash));
                    AddFile(combiner, f1);
                }

                AssertWarningEventLogged(EventId.FileCombinerFailedToInitialize);
                AssertWarningEventLogged(EventId.FileCombinerFailedToCreate);
            }
        }
예제 #26
0
        public async Task AddWithoutPinWeak()
        {
            const string TestName    = nameof(AddWithoutPinWeak);
            string       testCacheId = MakeCacheId(TestName);
            ICache       cache       = await CreateCacheAsync(testCacheId, strictMetadataCasCoupling : false);

            // Only caches that are not strict metadata to CAS coupling need this test
            if (cache.StrictMetadataCasCoupling)
            {
                (await cache.ShutdownAsync()).Success();
                return;
            }

            string        testSessionId = "Session1-" + testCacheId;
            ICacheSession session       = await CreateSessionAsync(cache, testSessionId);

            FakeBuild fake = new FakeBuild(TestName, 2);

            // We fake up a CasHash - never actually add to the cache - weak cas
            CasHash inputList = fake.OutputListHash;

            CasHash[] items = new CasHash[fake.Outputs.Length];
            for (int i = 0; i < fake.Outputs.Length; i++)
            {
                items[i] = new CasHash(fake.OutputHashes[i]);
            }

            // We use the hash of our output list as the weak fingerprint and extra hash
            var outputListFingerprintHash = fake.OutputListHash.ToFingerprint();
            WeakFingerprintHash weak      = new WeakFingerprintHash(outputListFingerprintHash);

            // This should work since the session is weak.
            FullCacheRecordWithDeterminism record = (await session.AddOrGetAsync(weak, inputList, outputListFingerprintHash, items)).Success();

            XAssert.IsNull(record.Record, "There should not have been anything in the cache");

            // Doing it twice does not change things...
            record = (await session.AddOrGetAsync(weak, inputList, outputListFingerprintHash, items)).Success();
            XAssert.IsNull(record.Record, "It matches exactly, so no bother");

            await CloseSessionAsync(session, testSessionId);

            await ShutdownCacheAsync(cache, testCacheId);
        }
예제 #27
0
        public void ReOpenFileSharingViolation()
        {
            string path = Path.Combine(TemporaryDirectory, "file");

            using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                SafeFileHandle   writableHandle;
                ReOpenFileStatus status = FileUtilities.TryReOpenFile(
                    stream.SafeFileHandle,
                    FileDesiredAccess.GenericWrite,
                    FileShare.ReadWrite,
                    FileFlagsAndAttributes.None,
                    out writableHandle);

                using (writableHandle)
                {
                    XAssert.AreEqual(ReOpenFileStatus.SharingViolation, status);
                    XAssert.IsNull(writableHandle);
                }
            }
        }
예제 #28
0
        public void TestSourceSealDirectoryCannotCoincideOutputFile1()
        {
            using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler(nameof(TestSourceSealDirectoryCannotCoincideOutputFile1)))
            {
                AbsolutePath path = env.Paths.CreateAbsolutePath(env.ObjectRoot, "ssd");

                var pip1 = CreatePipBuilderWithTag(env, "test");
                pip1.AddOutputFile(path);
                env.PipConstructionHelper.AddProcess(pip1);

                var ssd = env.PipConstructionHelper.SealDirectorySource(path);

                var pip2 = CreatePipBuilderWithTag(env, "test");
                pip2.AddInputDirectory(ssd);
                pip2.AddOutputFile(env.Paths.CreateAbsolutePath(env.ObjectRoot, "out2"));
                env.PipConstructionHelper.AddProcess(pip2);

                XAssert.IsNull(env.PipGraph.Build());
                AssertErrorEventLogged(LogEventId.InvalidGraphSinceSourceSealedDirectoryCoincidesOutputFile);
            }
        }
예제 #29
0
        public async Task CopyPredicate()
        {
            const string Src    = "src";
            const string Target = "target";

            File.WriteAllText(GetFullPath(Src), "Source");
            XAssert.IsFalse(File.Exists(GetFullPath(Target)));

            bool copied = await FileUtilities.CopyFileAsync(
                GetFullPath(Src),
                GetFullPath(Target),
                (source, dest) =>
            {
                XAssert.IsNull(dest, "Destination handle should be null if the file does not exist");
                return(true);
            });

            XAssert.IsTrue(File.Exists(GetFullPath(Target)));
            XAssert.IsTrue(copied);
            XAssert.AreEqual("Source", File.ReadAllText(GetFullPath(Target)));
            File.WriteAllText(GetFullPath(Target), "Leave this here");

            copied = await FileUtilities.CopyFileAsync(
                GetFullPath(Src),
                GetFullPath(Target),
                (source, dest) => false);

            XAssert.IsTrue(File.Exists(GetFullPath(Target)));
            XAssert.IsFalse(copied);
            XAssert.AreEqual("Leave this here", File.ReadAllText(GetFullPath(Target)));

            copied = await FileUtilities.CopyFileAsync(
                GetFullPath(Src),
                GetFullPath(Target),
                (source, dest) => true);

            XAssert.IsTrue(File.Exists(GetFullPath(Target)));
            XAssert.IsTrue(copied);
            XAssert.AreEqual("Source", File.ReadAllText(GetFullPath(Target)));
        }
예제 #30
0
        public void MoveTempDeletionCanReplaceRunningExecutable()
        {
            // Make a copy of DummyWaiter.exe to use as the test subject for deleting a running executable.
            // Keep the copy in the same directory as the original since it will need runtime dlls
            string dummyWaiterLocation = DummyWaiter.GetDummyWaiterExeLocation();
            string exeCopy             = dummyWaiterLocation + ".copy.exe";

            File.Copy(dummyWaiterLocation, exeCopy);

            using (var waiter = DummyWaiter.RunAndWait(exeCopy))
            {
                BuildXLException caughtException = null;
                try
                {
                    FileUtilities.DeleteFile(exeCopy);
                }
                catch (BuildXLException ex)
                {
                    caughtException = ex;
                }

                XAssert.IsNotNull(caughtException, "Expected deletion without a tempCleaner to fail");
                XAssert.IsTrue(File.Exists(exeCopy));

                caughtException = null;


                try
                {
                    FileUtilities.DeleteFile(exeCopy, tempDirectoryCleaner: MoveDeleteCleaner);
                }
                catch (BuildXLException ex)
                {
                    caughtException = ex;
                }

                XAssert.IsNull(caughtException, "Expected deletion with a MoveDeleteCleaner to succeed");
                XAssert.IsFalse(File.Exists(exeCopy));
            }
        }