sapling/eden/fs/testharness/TestUtil.cpp
Chad Austin 6c8c2ed747 clang-tidy advice
Summary:
clang-tidy had some automated suggestions for our code. Apply the ones
that make sense.

Some of them didn't, like removal of all uses of `volatile`. I
manually reverted those changes.

Reviewed By: genevievehelsel

Differential Revision: D41051052

fbshipit-source-id: 3fe22a91e929d3bb8e6346126c2c7bf9f027eb32
2023-07-13 16:30:55 -07:00

59 lines
1.8 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "eden/fs/testharness/TestUtil.h"
#include <cstring>
#include <stdexcept>
#include "eden/fs/model/Hash.h"
#include "eden/fs/model/ObjectId.h"
using namespace std::chrono_literals;
namespace facebook::eden {
constexpr auto materializationTimeoutLimit = 1000ms;
ObjectId makeTestHash(folly::StringPiece value) {
constexpr size_t ASCII_SIZE = 2 * Hash20::RAW_SIZE;
if (value.size() > ASCII_SIZE) {
throw std::invalid_argument(value.toString() + " is too big for Hash");
}
std::array<char, ASCII_SIZE> fullValue;
memset(fullValue.data(), '0', fullValue.size());
memcpy(
fullValue.data() + fullValue.size() - value.size(),
value.data(),
value.size());
return ObjectId::fromHex(fullValue);
}
Hash20 makeTestHash20(folly::StringPiece value) {
constexpr size_t ASCII_SIZE = 2 * Hash20::RAW_SIZE;
if (value.size() > ASCII_SIZE) {
throw std::invalid_argument(value.toString() + " is too big for Hash");
}
std::array<char, ASCII_SIZE> fullValue;
memset(fullValue.data(), '0', fullValue.size());
memcpy(
fullValue.data() + fullValue.size() - value.size(),
value.data(),
value.size());
return Hash20{folly::StringPiece{folly::range(fullValue)}};
}
bool isInodeMaterializedInQueue(
folly::UnboundedQueue<InodeTraceEvent, true, true, false>&
materializationQueue,
InodeEventProgress progress,
InodeNumber ino) {
auto event =
materializationQueue.try_dequeue_for(materializationTimeoutLimit);
return event.has_value() && event->progress == progress &&
event->ino.getRawValue() == ino.getRawValue();
}
} // namespace facebook::eden