brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 20a95dd Raw
92 lines · c
1//===- CASTestConfig.h ----------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_UNITTESTS_CASTESTCONFIG_H10#define LLVM_UNITTESTS_CASTESTCONFIG_H11 12#include "llvm/CAS/ActionCache.h"13#include "llvm/CAS/ObjectStore.h"14#include "llvm/Testing/Support/SupportHelpers.h"15#include "gtest/gtest.h"16#include <memory>17 18#ifdef _WIN3219#include "llvm/Support/VersionTuple.h"20#include "llvm/Support/Windows/WindowsSupport.h"21#endif22 23namespace llvm::unittest::cas {24class MockEnv {25  void anchor();26 27public:28  virtual ~MockEnv();29};30} // namespace llvm::unittest::cas31 32struct CASTestingEnv {33  std::unique_ptr<llvm::cas::ObjectStore> CAS;34  std::unique_ptr<llvm::cas::ActionCache> Cache;35  std::optional<llvm::unittest::TempDir> Temp;36};37 38void setMaxOnDiskCASMappingSize();39 40// Test fixture for on-disk data base tests.41class OnDiskCASTest : public ::testing::Test {42protected:43  void SetUp() override {44#if !LLVM_ENABLE_ONDISK_CAS45    GTEST_SKIP() << "OnDiskCAS is not enabled";46#endif47    // Use a smaller database size for testing to conserve disk space.48    setMaxOnDiskCASMappingSize();49  }50};51 52// Parametered test fixture for ObjectStore and ActionCache tests.53class CASTest54    : public testing::TestWithParam<std::function<CASTestingEnv(int)>> {55protected:56  std::optional<int> NextCASIndex;57 58  llvm::SmallVector<llvm::unittest::TempDir> Dirs;59 60  llvm::SmallVector<std::unique_ptr<llvm::unittest::cas::MockEnv>> Envs;61 62  std::unique_ptr<llvm::cas::ObjectStore> createObjectStore() {63    auto TD = GetParam()(++(*NextCASIndex));64    if (TD.Temp)65      Dirs.push_back(std::move(*TD.Temp));66    return std::move(TD.CAS);67  }68  std::unique_ptr<llvm::cas::ActionCache> createActionCache() {69    auto TD = GetParam()(++(*NextCASIndex));70    if (TD.Temp)71      Dirs.push_back(std::move(*TD.Temp));72    return std::move(TD.Cache);73  }74 75  void SetUp() override {76#ifdef _WIN3277    if (llvm::GetWindowsOSVersion() < llvm::VersionTuple(10, 0, 0, 17763))78      GTEST_SKIP() << "CAS tests skipped on older windows version";79#endif80    NextCASIndex = 0;81    setMaxOnDiskCASMappingSize();82  }83 84  void TearDown() override {85    NextCASIndex = std::nullopt;86    Dirs.clear();87    Envs.clear();88  }89};90 91#endif92