CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
117 lines
3.8 KiB
C++
117 lines
3.8 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
/// \file Helper functions to test OnDiskCASDatabases.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/CAS/BuiltinObjectHasher.h"
|
|
#include "llvm/CAS/OnDiskGraphDB.h"
|
|
#include "llvm/CAS/OnDiskKeyValueDB.h"
|
|
#include "llvm/CAS/UnifiedOnDiskCache.h"
|
|
#include "llvm/Support/BLAKE3.h"
|
|
#include "llvm/Testing/Support/Error.h"
|
|
|
|
namespace llvm::unittest::cas {
|
|
|
|
using namespace llvm::cas;
|
|
using namespace llvm::cas::ondisk;
|
|
|
|
using HasherT = BLAKE3;
|
|
using HashType = decltype(HasherT::hash(std::declval<ArrayRef<uint8_t> &>()));
|
|
using ValueType = std::array<char, 20>;
|
|
|
|
inline HashType digest(StringRef Data, ArrayRef<ArrayRef<uint8_t>> RefHashes) {
|
|
return BuiltinObjectHasher<HasherT>::hashObject(
|
|
RefHashes, arrayRefFromStringRef<char>(Data));
|
|
}
|
|
|
|
inline ObjectID digest(OnDiskGraphDB &DB, StringRef Data,
|
|
ArrayRef<ObjectID> Refs) {
|
|
SmallVector<ArrayRef<uint8_t>, 8> RefHashes;
|
|
for (ObjectID Ref : Refs)
|
|
RefHashes.push_back(DB.getDigest(Ref));
|
|
HashType Digest = digest(Data, RefHashes);
|
|
std::optional<ObjectID> ID;
|
|
EXPECT_THAT_ERROR(DB.getReference(Digest).moveInto(ID), Succeeded());
|
|
return *ID;
|
|
}
|
|
|
|
inline HashType digest(StringRef Data) {
|
|
return HasherT::hash(arrayRefFromStringRef(Data));
|
|
}
|
|
|
|
inline HashType digestFile(StringRef FilePath) {
|
|
std::optional<HashType> Digest;
|
|
EXPECT_THAT_ERROR(
|
|
BuiltinObjectHasher<HasherT>::hashFile(FilePath).moveInto(Digest),
|
|
Succeeded());
|
|
return *Digest;
|
|
}
|
|
|
|
inline ObjectID digestFile(OnDiskGraphDB &DB, StringRef FilePath) {
|
|
HashType Digest = digestFile(FilePath);
|
|
std::optional<ObjectID> ID;
|
|
EXPECT_THAT_ERROR(DB.getReference(Digest).moveInto(ID), Succeeded());
|
|
return *ID;
|
|
}
|
|
|
|
inline ValueType valueFromString(StringRef S) {
|
|
ValueType Val = {};
|
|
llvm::copy(S.substr(0, sizeof(Val)), Val.data());
|
|
return Val;
|
|
}
|
|
|
|
inline Expected<ObjectID> store(OnDiskGraphDB &DB, StringRef Data,
|
|
ArrayRef<ObjectID> Refs) {
|
|
ObjectID ID = digest(DB, Data, Refs);
|
|
if (Error E = DB.store(ID, Refs, arrayRefFromStringRef<char>(Data)))
|
|
return std::move(E);
|
|
return ID;
|
|
}
|
|
|
|
inline Expected<ObjectID> cachePut(OnDiskKeyValueDB &DB, ArrayRef<uint8_t> Key,
|
|
ObjectID ID) {
|
|
auto Value = UnifiedOnDiskCache::getValueFromObjectID(ID);
|
|
auto Result = DB.put(Key, Value);
|
|
if (!Result)
|
|
return Result.takeError();
|
|
return UnifiedOnDiskCache::getObjectIDFromValue(*Result);
|
|
}
|
|
|
|
inline Expected<std::optional<ObjectID>> cacheGet(OnDiskKeyValueDB &DB,
|
|
ArrayRef<uint8_t> Key) {
|
|
auto Result = DB.get(Key);
|
|
if (!Result)
|
|
return Result.takeError();
|
|
if (!*Result)
|
|
return std::nullopt;
|
|
return UnifiedOnDiskCache::getObjectIDFromValue(**Result);
|
|
}
|
|
|
|
inline Error printTree(OnDiskGraphDB &DB, ObjectID ID, raw_ostream &OS,
|
|
unsigned Indent = 0) {
|
|
std::optional<ondisk::ObjectHandle> Obj;
|
|
if (Error E = DB.load(ID).moveInto(Obj))
|
|
return E;
|
|
if (!Obj)
|
|
return Error::success();
|
|
OS.indent(Indent) << toStringRef(DB.getObjectData(*Obj)) << '\n';
|
|
for (ObjectID Ref : DB.getObjectRefs(*Obj)) {
|
|
if (Error E = printTree(DB, Ref, OS, Indent + 2))
|
|
return E;
|
|
}
|
|
return Error::success();
|
|
}
|
|
|
|
std::unique_ptr<unittest::TempFile> createSmallFile(char initChar);
|
|
std::unique_ptr<unittest::TempFile> createLargeFile(char initChar);
|
|
std::unique_ptr<unittest::TempFile> createLargePageAlignedFile(char initChar);
|
|
|
|
} // namespace llvm::unittest::cas
|