Error message when measure functions mismatch
Summary: To sanity check that a capture is working as expected when running benchmark We could maybe even throw here as a bad measure function will throw off the rest of the benchmark. Reviewed By: NickGerleman Differential Revision: D53681506 fbshipit-source-id: f5ab7e00e76df0ac899d62c3f6b4535b3780d45d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e679327904
commit
b35456b93c
@@ -25,6 +25,27 @@ constexpr uint32_t kNumRepititions = 100;
|
|||||||
using SteadyClockDurations =
|
using SteadyClockDurations =
|
||||||
std::array<steady_clock::duration, kNumRepititions>;
|
std::array<steady_clock::duration, kNumRepititions>;
|
||||||
|
|
||||||
|
static bool inputsMatch(
|
||||||
|
float actualWidth,
|
||||||
|
float expectedWidth,
|
||||||
|
float actualHeight,
|
||||||
|
float expectedHeight,
|
||||||
|
YGMeasureMode actualWidthMode,
|
||||||
|
YGMeasureMode expectedWidthMode,
|
||||||
|
YGMeasureMode actualHeightMode,
|
||||||
|
YGMeasureMode expectedHeightMode) {
|
||||||
|
bool widthsAreUndefined =
|
||||||
|
YGFloatIsUndefined(actualWidth) && YGFloatIsUndefined(expectedWidth);
|
||||||
|
bool widthsAreEqual = widthsAreUndefined || actualWidth == expectedWidth;
|
||||||
|
bool heightsAreUndefined =
|
||||||
|
YGFloatIsUndefined(actualHeight) && YGFloatIsUndefined(expectedHeight);
|
||||||
|
bool heightsAreEqual = heightsAreUndefined || actualHeight == expectedHeight;
|
||||||
|
|
||||||
|
return widthsAreEqual && heightsAreEqual &&
|
||||||
|
actualWidthMode == expectedWidthMode &&
|
||||||
|
actualHeightMode == expectedHeightMode;
|
||||||
|
}
|
||||||
|
|
||||||
YGSize mockMeasureFunc(
|
YGSize mockMeasureFunc(
|
||||||
YGNodeConstRef node,
|
YGNodeConstRef node,
|
||||||
float availableWidth,
|
float availableWidth,
|
||||||
@@ -32,17 +53,37 @@ YGSize mockMeasureFunc(
|
|||||||
float availableHeight,
|
float availableHeight,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
(void)node;
|
(void)node;
|
||||||
(void)availableHeight;
|
|
||||||
(void)availableWidth;
|
|
||||||
(void)widthMode;
|
|
||||||
(void)heightMode;
|
|
||||||
MeasureFuncVecWithIndex* fns =
|
MeasureFuncVecWithIndex* fns =
|
||||||
static_cast<MeasureFuncVecWithIndex*>(YGNodeGetContext(node));
|
static_cast<MeasureFuncVecWithIndex*>(YGNodeGetContext(node));
|
||||||
|
|
||||||
if (fns->index >= fns->vec.size()) {
|
if (fns->index >= fns->vec.size()) {
|
||||||
|
std::cout << "Extra measure function call made" << std::endl;
|
||||||
return {10.0, 10.0};
|
return {10.0, 10.0};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto values = fns->vec.at(fns->index);
|
auto values = fns->vec.at(fns->index);
|
||||||
|
|
||||||
|
if (!inputsMatch(
|
||||||
|
availableWidth,
|
||||||
|
values.inputWidth,
|
||||||
|
availableHeight,
|
||||||
|
values.inputHeight,
|
||||||
|
widthMode,
|
||||||
|
values.widthMode,
|
||||||
|
heightMode,
|
||||||
|
values.heightMode)) {
|
||||||
|
std::cout << "Measure function input mismatch." << std::endl
|
||||||
|
<< "Expected width: " << values.inputWidth
|
||||||
|
<< ", actual width: " << availableWidth << std::endl
|
||||||
|
<< "Expected height: " << values.inputHeight
|
||||||
|
<< ", actual height: " << availableHeight << std::endl
|
||||||
|
<< "Expected width mode: " << values.widthMode
|
||||||
|
<< ", actual width mode: " << widthMode << std::endl
|
||||||
|
<< "Expected height mode: " << values.heightMode
|
||||||
|
<< ", actual height mode: " << heightMode << std::endl;
|
||||||
|
return {10.0, 10.0};
|
||||||
|
}
|
||||||
|
|
||||||
fns->index++;
|
fns->index++;
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::nanoseconds(values.durationNs));
|
std::this_thread::sleep_for(std::chrono::nanoseconds(values.durationNs));
|
||||||
|
Reference in New Issue
Block a user