mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add unit tests for Layout Animations
Summary: Add unit tests for Layout Animations. This first batch generates a random mutation, then animates it to completion. I found one issue with UPDATE+REMOVE+INSERT animation consistency. That shouldn't cause any crashes in production, but is a chance to improve consistency of mutations overall - and could in theory point to memory corruption, though it's somewhat unlikely. I ran with randomized seeds, found issues, fixed them, re-ran to ensure issues were fixed, rinsed and repeated. At the end I was able to run dozens of times (with random seeds) and found nothing. The next step is to repeatedly generate mutations that conflict with ongoing animations. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D28343750 fbshipit-source-id: c1c60d89a31be3ac05d57482f0af3c482b866abe
This commit is contained in:
committed by
Facebook GitHub Bot
parent
10b9308eb9
commit
967eeff86e
@@ -91,6 +91,7 @@ fb_xplat_cxx_test(
|
||||
react_native_xplat_target("react/renderer/components/root:root"),
|
||||
react_native_xplat_target("react/renderer/components/scrollview:scrollview"),
|
||||
react_native_xplat_target("react/renderer/components/view:view"),
|
||||
react_native_xplat_target("react/test_utils:test_utils"),
|
||||
"//xplat/js/react-native-github:generated_components-rncore",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -307,14 +307,14 @@ void LayoutAnimationKeyFrameManager::uiManagerDidConfigureNextLayoutAnimation(
|
||||
if (layoutAnimationConfig) {
|
||||
std::lock_guard<std::mutex> lock(currentAnimationMutex_);
|
||||
|
||||
currentAnimation_ = better::optional<LayoutAnimation>{LayoutAnimation{
|
||||
uiManagerDidConfigureNextLayoutAnimation(LayoutAnimation{
|
||||
-1,
|
||||
0,
|
||||
false,
|
||||
*layoutAnimationConfig,
|
||||
successCallback,
|
||||
failureCallback,
|
||||
{}}};
|
||||
{}});
|
||||
} else {
|
||||
LOG(ERROR) << "Parsing LayoutAnimationConfig failed: "
|
||||
<< (folly::dynamic)config;
|
||||
@@ -323,6 +323,11 @@ void LayoutAnimationKeyFrameManager::uiManagerDidConfigureNextLayoutAnimation(
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimationKeyFrameManager::uiManagerDidConfigureNextLayoutAnimation(
|
||||
LayoutAnimation layoutAnimation) const {
|
||||
currentAnimation_ = better::optional<LayoutAnimation>{layoutAnimation};
|
||||
}
|
||||
|
||||
void LayoutAnimationKeyFrameManager::setLayoutAnimationStatusDelegate(
|
||||
LayoutAnimationStatusDelegate *delegate) const {
|
||||
std::lock_guard<std::mutex> lock(layoutAnimationStatusDelegateMutex_);
|
||||
@@ -733,6 +738,11 @@ void LayoutAnimationKeyFrameManager::getAndEraseConflictingAnimations(
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimationKeyFrameManager::setClockNow(
|
||||
std::function<uint64_t()> now) {
|
||||
now_ = now;
|
||||
}
|
||||
|
||||
better::optional<MountingTransaction>
|
||||
LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
SurfaceId surfaceId,
|
||||
@@ -740,10 +750,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
TransactionTelemetry const &telemetry,
|
||||
ShadowViewMutationList mutations) const {
|
||||
// Current time in milliseconds
|
||||
uint64_t now =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch())
|
||||
.count();
|
||||
uint64_t now = now_();
|
||||
|
||||
bool inflightAnimationsExistInitially = !inflightAnimations_.empty();
|
||||
|
||||
@@ -906,7 +913,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
bool haveComponentDescriptor =
|
||||
hasComponentDescriptorForShadowView(baselineShadowView);
|
||||
|
||||
bool executeMutationImmediately = false;
|
||||
better::optional<ShadowViewMutation> executeMutationImmediately{};
|
||||
|
||||
bool isRemoveReinserted =
|
||||
mutation.type == ShadowViewMutation::Type::Remove &&
|
||||
@@ -972,7 +979,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
if (isRemoveReinserted || !haveConfiguration || isReparented ||
|
||||
mutation.type == ShadowViewMutation::Type::Create ||
|
||||
mutation.type == ShadowViewMutation::Type::Insert) {
|
||||
executeMutationImmediately = true;
|
||||
executeMutationImmediately = mutation;
|
||||
|
||||
// It is possible, especially in the case of "moves", that we have a
|
||||
// sequence of operations like:
|
||||
@@ -1007,6 +1014,36 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mutation.type == ShadowViewMutation::Type::Remove) {
|
||||
for (auto &keyframe : keyFramesToAnimate) {
|
||||
if (keyframe.tag == baselineShadowView.tag) {
|
||||
// If there's already an animation queued up, followed by this
|
||||
// Insert, it *must* be an Update mutation animation. Other
|
||||
// sequences should not be possible.
|
||||
react_native_assert(
|
||||
keyframe.type == AnimationConfigurationType::Update);
|
||||
|
||||
// The mutation is a "remove", so it must have a
|
||||
// "oldChildShadowView"
|
||||
react_native_assert(mutation.oldChildShadowView.tag > 0);
|
||||
|
||||
// Those asserts don't run in prod. If there's some edge-case
|
||||
// that we haven't caught yet, we'd crash in debug; make sure we
|
||||
// don't mutate the prevView in prod.
|
||||
// Since normally the UPDATE would have been executed first and
|
||||
// now it's deferred, we need to change the `oldChildShadowView`
|
||||
// that is being referenced by the REMOVE mutation.
|
||||
if (keyframe.type == AnimationConfigurationType::Update &&
|
||||
mutation.oldChildShadowView.tag > 0) {
|
||||
executeMutationImmediately = ShadowViewMutation{
|
||||
mutation.type,
|
||||
mutation.parentShadowView,
|
||||
keyframe.viewPrev,
|
||||
{},
|
||||
mutation.index};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1282,10 +1319,10 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
||||
keyFramesToAnimate.push_back(keyFrame);
|
||||
}
|
||||
|
||||
if (executeMutationImmediately) {
|
||||
if (executeMutationImmediately.hasValue()) {
|
||||
PrintMutationInstruction(
|
||||
"Queue Up Animation For Immediate Execution", mutation);
|
||||
immediateMutations.push_back(mutation);
|
||||
"Queue Up For Immediate Execution", *executeMutationImmediately);
|
||||
immediateMutations.push_back(*executeMutationImmediately);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -166,24 +166,35 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
LayoutAnimationStatusDelegate *delegate)
|
||||
: runtimeExecutor_(runtimeExecutor),
|
||||
layoutAnimationStatusDelegate_(delegate) {}
|
||||
layoutAnimationStatusDelegate_(delegate),
|
||||
now_([]() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::high_resolution_clock::now()
|
||||
.time_since_epoch())
|
||||
.count();
|
||||
}) {}
|
||||
~LayoutAnimationKeyFrameManager() {}
|
||||
|
||||
#pragma mark UIManagerAnimationDelegate methods
|
||||
|
||||
void uiManagerDidConfigureNextLayoutAnimation(
|
||||
jsi::Runtime &runtime,
|
||||
RawValue const &config,
|
||||
const jsi::Value &successCallbackValue,
|
||||
const jsi::Value &failureCallbackValue) const override;
|
||||
|
||||
void setComponentDescriptorRegistry(SharedComponentDescriptorRegistry const &
|
||||
componentDescriptorRegistry) override;
|
||||
|
||||
// TODO: add SurfaceId to this API as well
|
||||
bool shouldAnimateFrame() const override;
|
||||
|
||||
bool shouldOverridePullTransaction() const override;
|
||||
|
||||
void stopSurface(SurfaceId surfaceId) override;
|
||||
|
||||
#pragma mark MountingOverrideDelegate methods
|
||||
|
||||
bool shouldOverridePullTransaction() const override;
|
||||
|
||||
// This is used to "hijack" the diffing process to figure out which mutations
|
||||
// should be animated. The mutations returned by this function will be
|
||||
// executed immediately.
|
||||
@@ -193,6 +204,11 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
TransactionTelemetry const &telemetry,
|
||||
ShadowViewMutationList mutations) const override;
|
||||
|
||||
// Exposed for testing.
|
||||
public:
|
||||
void uiManagerDidConfigureNextLayoutAnimation(
|
||||
LayoutAnimation layoutAnimation) const;
|
||||
|
||||
// LayoutAnimationStatusDelegate - this is for the platform to get
|
||||
// signal when animations start and complete. Setting and resetting this
|
||||
// delegate is protected by a mutex; ALL method calls into this delegate are
|
||||
@@ -207,6 +223,9 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
mutable std::mutex layoutAnimationStatusDelegateMutex_;
|
||||
mutable LayoutAnimationStatusDelegate *layoutAnimationStatusDelegate_{};
|
||||
|
||||
// Function that returns current time in milliseconds
|
||||
std::function<uint64_t()> now_;
|
||||
|
||||
void adjustImmediateMutationIndicesForDelayedMutations(
|
||||
SurfaceId surfaceId,
|
||||
ShadowViewMutation &mutation,
|
||||
@@ -275,6 +294,9 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
|
||||
mutable std::mutex callbackWrappersPendingMutex_;
|
||||
mutable std::vector<std::unique_ptr<LayoutAnimationCallbackWrapper>>
|
||||
callbackWrappersPending_{};
|
||||
|
||||
public:
|
||||
void setClockNow(std::function<uint64_t()> now);
|
||||
};
|
||||
|
||||
static inline bool shouldFirstComeBeforeSecondRemovesOnly(
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorProvider.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
|
||||
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <react/renderer/components/root/RootComponentDescriptor.h>
|
||||
#include <react/renderer/components/view/ViewComponentDescriptor.h>
|
||||
#include <react/renderer/mounting/Differentiator.h>
|
||||
#include <react/renderer/mounting/ShadowViewMutation.h>
|
||||
#include <react/renderer/mounting/stubs.h>
|
||||
|
||||
#include <react/test_utils/Entropy.h>
|
||||
#include <react/test_utils/MockClock.h>
|
||||
#include <react/test_utils/shadowTreeGeneration.h>
|
||||
|
||||
// Uncomment when random test blocks are uncommented below.
|
||||
// #include <algorithm>
|
||||
// #include <random>
|
||||
|
||||
#include "LayoutAnimationDriver.h"
|
||||
|
||||
MockClock::time_point MockClock::time_ = {};
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static void testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
uint_fast32_t seed,
|
||||
int treeSize,
|
||||
int repeats,
|
||||
int stages,
|
||||
int animation_duration,
|
||||
int animation_frames,
|
||||
int delay_ms_between_frames,
|
||||
int delay_ms_between_stages,
|
||||
int delay_ms_between_repeats) {
|
||||
auto entropy = seed == 0 ? Entropy() : Entropy(seed);
|
||||
|
||||
auto eventDispatcher = EventDispatcher::Shared{};
|
||||
auto contextContainer = std::make_shared<ContextContainer>();
|
||||
auto componentDescriptorParameters =
|
||||
ComponentDescriptorParameters{eventDispatcher, contextContainer, nullptr};
|
||||
auto viewComponentDescriptor =
|
||||
ViewComponentDescriptor(componentDescriptorParameters);
|
||||
auto rootComponentDescriptor =
|
||||
RootComponentDescriptor(componentDescriptorParameters);
|
||||
auto noopEventEmitter =
|
||||
std::make_shared<ViewEventEmitter const>(nullptr, -1, eventDispatcher);
|
||||
|
||||
// Create a RuntimeExecutor
|
||||
RuntimeExecutor runtimeExecutor =
|
||||
[](std::function<void(jsi::Runtime & runtime)> fn) {};
|
||||
|
||||
// Create component descriptor registry for animation driver
|
||||
auto providerRegistry =
|
||||
std::make_shared<ComponentDescriptorProviderRegistry>();
|
||||
auto componentDescriptorRegistry =
|
||||
providerRegistry->createComponentDescriptorRegistry(
|
||||
componentDescriptorParameters);
|
||||
providerRegistry->add(
|
||||
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
|
||||
providerRegistry->add(
|
||||
concreteComponentDescriptorProvider<RootComponentDescriptor>());
|
||||
|
||||
// Create Animation Driver
|
||||
auto animationDriver =
|
||||
std::make_shared<LayoutAnimationDriver>(runtimeExecutor, nullptr);
|
||||
animationDriver->setComponentDescriptorRegistry(componentDescriptorRegistry);
|
||||
|
||||
// Mock animation timers
|
||||
animationDriver->setClockNow([]() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
MockClock::now().time_since_epoch())
|
||||
.count();
|
||||
});
|
||||
|
||||
auto allNodes = std::vector<ShadowNode::Shared>{};
|
||||
|
||||
for (int i = 0; i < repeats; i++) {
|
||||
allNodes.clear();
|
||||
|
||||
int surfaceIdInt = 1;
|
||||
auto surfaceId = SurfaceId(surfaceIdInt);
|
||||
|
||||
auto family = rootComponentDescriptor.createFamily(
|
||||
{Tag(surfaceIdInt), surfaceId, nullptr}, nullptr);
|
||||
|
||||
// Creating an initial root shadow node.
|
||||
auto emptyRootNode = std::const_pointer_cast<RootShadowNode>(
|
||||
std::static_pointer_cast<RootShadowNode const>(
|
||||
rootComponentDescriptor.createShadowNode(
|
||||
ShadowNodeFragment{RootShadowNode::defaultSharedProps()},
|
||||
family)));
|
||||
|
||||
// Applying size constraints.
|
||||
emptyRootNode = emptyRootNode->clone(
|
||||
LayoutConstraints{
|
||||
Size{512, 0}, Size{512, std::numeric_limits<Float>::infinity()}},
|
||||
LayoutContext{});
|
||||
|
||||
// Generation of a random tree.
|
||||
auto singleRootChildNode =
|
||||
generateShadowNodeTree(entropy, viewComponentDescriptor, treeSize);
|
||||
|
||||
// Injecting a tree into the root node.
|
||||
auto currentRootNode = std::static_pointer_cast<RootShadowNode const>(
|
||||
emptyRootNode->ShadowNode::clone(ShadowNodeFragment{
|
||||
ShadowNodeFragment::propsPlaceholder(),
|
||||
std::make_shared<SharedShadowNodeList>(
|
||||
SharedShadowNodeList{singleRootChildNode})}));
|
||||
|
||||
// Building an initial view hierarchy.
|
||||
auto viewTree = buildStubViewTreeWithoutUsingDifferentiator(*emptyRootNode);
|
||||
viewTree.mutate(
|
||||
calculateShadowViewMutations(*emptyRootNode, *currentRootNode, true));
|
||||
|
||||
for (int j = 0; j < stages; j++) {
|
||||
auto nextRootNode = currentRootNode;
|
||||
|
||||
// Mutating the tree.
|
||||
alterShadowTree(
|
||||
entropy,
|
||||
nextRootNode,
|
||||
{
|
||||
&messWithChildren,
|
||||
&messWithYogaStyles,
|
||||
&messWithLayoutableOnlyFlag,
|
||||
});
|
||||
|
||||
std::vector<LayoutableShadowNode const *> affectedLayoutableNodes{};
|
||||
affectedLayoutableNodes.reserve(1024);
|
||||
|
||||
// Laying out the tree.
|
||||
std::const_pointer_cast<RootShadowNode>(nextRootNode)
|
||||
->layoutIfNeeded(&affectedLayoutableNodes);
|
||||
|
||||
nextRootNode->sealRecursive();
|
||||
allNodes.push_back(nextRootNode);
|
||||
|
||||
// Calculating mutations.
|
||||
auto originalMutations =
|
||||
calculateShadowViewMutations(*currentRootNode, *nextRootNode, true);
|
||||
|
||||
// If tree randomization produced no changes in the form of mutations,
|
||||
// don't bother trying to animate because this violates a bunch of our
|
||||
// assumptions in this test
|
||||
if (originalMutations.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Configure animation
|
||||
animationDriver->uiManagerDidConfigureNextLayoutAnimation(
|
||||
{surfaceId,
|
||||
0,
|
||||
false,
|
||||
{(double)animation_duration,
|
||||
{/* Create */ AnimationType::EaseInEaseOut,
|
||||
AnimationProperty::Opacity,
|
||||
(double)animation_duration,
|
||||
0,
|
||||
0,
|
||||
0},
|
||||
{/* Update */ AnimationType::EaseInEaseOut,
|
||||
AnimationProperty::ScaleXY,
|
||||
(double)animation_duration,
|
||||
0,
|
||||
0,
|
||||
0},
|
||||
{/* Delete */ AnimationType::EaseInEaseOut,
|
||||
AnimationProperty::Opacity,
|
||||
(double)animation_duration,
|
||||
0,
|
||||
0,
|
||||
0}},
|
||||
{},
|
||||
{},
|
||||
{}});
|
||||
|
||||
// Get mutations for each frame
|
||||
for (int k = 0; k < animation_frames + 2; k++) {
|
||||
auto mutationsInput = ShadowViewMutation::List{};
|
||||
if (k == 0) {
|
||||
mutationsInput = originalMutations;
|
||||
}
|
||||
|
||||
if (k != (animation_frames + 1)) {
|
||||
EXPECT_TRUE(animationDriver->shouldOverridePullTransaction());
|
||||
} else {
|
||||
EXPECT_FALSE(animationDriver->shouldOverridePullTransaction());
|
||||
}
|
||||
|
||||
auto telemetry = TransactionTelemetry{};
|
||||
telemetry.willLayout();
|
||||
telemetry.willCommit();
|
||||
telemetry.willDiff();
|
||||
|
||||
auto transaction = animationDriver->pullTransaction(
|
||||
surfaceId, 0, telemetry, mutationsInput);
|
||||
|
||||
EXPECT_TRUE(transaction.has_value() || k == animation_frames);
|
||||
|
||||
// We have something to validate.
|
||||
if (transaction.has_value()) {
|
||||
auto mutations = transaction->getMutations();
|
||||
|
||||
// Mutating the view tree.
|
||||
viewTree.mutate(mutations);
|
||||
|
||||
// We don't do any validation on this until all animations are
|
||||
// finished!
|
||||
}
|
||||
|
||||
MockClock::advance_by(
|
||||
std::chrono::milliseconds(delay_ms_between_frames));
|
||||
}
|
||||
|
||||
// After the animation is completed...
|
||||
// Build a view tree to compare with.
|
||||
// After all the synthetic mutations, at the end of the animation,
|
||||
// the mutated and newly-constructed trees should be identical.
|
||||
auto rebuiltViewTree =
|
||||
buildStubViewTreeWithoutUsingDifferentiator(*nextRootNode);
|
||||
|
||||
// Comparing the newly built tree with the updated one.
|
||||
if (rebuiltViewTree != viewTree) {
|
||||
// Something went wrong.
|
||||
|
||||
LOG(ERROR)
|
||||
<< "Entropy seed: " << entropy.getSeed()
|
||||
<< ". To see why trees are different, define STUB_VIEW_TREE_VERBOSE and see logging in StubViewTree.cpp.\n";
|
||||
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
|
||||
currentRootNode = nextRootNode;
|
||||
|
||||
MockClock::advance_by(std::chrono::milliseconds(delay_ms_between_stages));
|
||||
}
|
||||
|
||||
MockClock::advance_by(std::chrono::milliseconds(delay_ms_between_repeats));
|
||||
}
|
||||
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
TEST(
|
||||
LayoutAnimationTest,
|
||||
stableSmallerTreeFewRepeatsFewStages_NonOverlapping_2029343357) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 2029343357, /* working seed found 5-10-2021 */
|
||||
/* size */ 128,
|
||||
/* repeats */ 128,
|
||||
/* stages */ 10,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
TEST(
|
||||
LayoutAnimationTest,
|
||||
stableSmallerTreeFewRepeatsFewStages_NonOverlapping_3619914559) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 3619914559, /* working seed found 5-10-2021 */
|
||||
/* size */ 128,
|
||||
/* repeats */ 128,
|
||||
/* stages */ 10,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
TEST(
|
||||
LayoutAnimationTest,
|
||||
stableSmallerTreeFewRepeatsFewStages_NonOverlapping_597132284) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 597132284, /* failing seed found 5-10-2021 */
|
||||
/* size */ 128,
|
||||
/* repeats */ 128,
|
||||
/* stages */ 10,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
TEST(
|
||||
LayoutAnimationTest,
|
||||
stableSmallerTreeFewRepeatsFewStages_NonOverlapping_774986518) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 774986518, /* failing seed found 5-10-2021 */
|
||||
/* size */ 128,
|
||||
/* repeats */ 128,
|
||||
/* stages */ 10,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
TEST(
|
||||
LayoutAnimationTest,
|
||||
stableSmallerTreeFewRepeatsFewStages_NonOverlapping_1450614414) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 1450614414, /* failing seed found 5-10-2021 */
|
||||
/* size */ 128,
|
||||
/* repeats */ 128,
|
||||
/* stages */ 10,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
TEST(LayoutAnimationTest, stableBiggerTreeFewRepeatsFewStages_NonOverlapping) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 2029343357,
|
||||
/* size */ 512,
|
||||
/* repeats */ 32,
|
||||
/* stages */ 10,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
TEST(LayoutAnimationTest, stableBiggerTreeFewRepeatsManyStages_NonOverlapping) {
|
||||
testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
/* seed */ 2029343357,
|
||||
/* size */ 512,
|
||||
/* repeats */ 32,
|
||||
/* stages */ 128,
|
||||
/* animation_duration */ 1000,
|
||||
/* animation_frames*/ 10,
|
||||
/* delay_ms_between_frames */ 100,
|
||||
/* delay_ms_between_stages */ 100,
|
||||
/* delay_ms_between_repeats */ 2000);
|
||||
}
|
||||
|
||||
// You may uncomment this - locally only! - to generate failing seeds.
|
||||
// TEST(LayoutAnimationTest, stableSmallerTreeFewRepeatsFewStages_Random) {
|
||||
// std::random_device device;
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// uint_fast32_t seed = device();
|
||||
// LOG(ERROR) << "Seed: " << seed;
|
||||
// testShadowNodeTreeLifeCycleLayoutAnimations(
|
||||
// /* seed */ seed,
|
||||
// /* size */ 128,
|
||||
// /* repeats */ 128,
|
||||
// /* stages */ 10,
|
||||
// /* animation_duration */ 1000,
|
||||
// /* animation_frames*/ 10,
|
||||
// /* delay_ms_between_frames */ 100,
|
||||
// /* delay_ms_between_stages */ 100,
|
||||
// /* delay_ms_between_repeats */ 2000);
|
||||
// }
|
||||
// // Fail if you want output to get seeds
|
||||
// LOG(ERROR) << "ALL RUNS SUCCESSFUL";
|
||||
// // react_native_assert(false);
|
||||
// }
|
||||
@@ -88,5 +88,6 @@ fb_xplat_cxx_test(
|
||||
react_native_xplat_target("react/renderer/components/root:root"),
|
||||
react_native_xplat_target("react/renderer/components/view:view"),
|
||||
react_native_xplat_target("react/renderer/components/scrollview:scrollview"),
|
||||
react_native_xplat_target("react/test_utils:test_utils"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <react/renderer/mounting/Differentiator.h>
|
||||
#include <react/renderer/mounting/stubs.h>
|
||||
|
||||
#include "shadowTreeGeneration.h"
|
||||
#include <react/test_utils/shadowTreeGeneration.h>
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
#include <react/renderer/mounting/ShadowViewMutation.h>
|
||||
#include <react/renderer/mounting/stubs.h>
|
||||
|
||||
#include <react/test_utils/Entropy.h>
|
||||
#include <react/test_utils/shadowTreeGeneration.h>
|
||||
|
||||
// Uncomment when random test blocks are uncommented below.
|
||||
// #include <algorithm>
|
||||
// #include <random>
|
||||
|
||||
#include "Entropy.h"
|
||||
#include "shadowTreeGeneration.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
||||
@@ -79,5 +79,6 @@ fb_xplat_cxx_test(
|
||||
":telemetry",
|
||||
"//xplat/folly:molly",
|
||||
"//xplat/third-party/gmock:gtest",
|
||||
react_native_xplat_target("react/test_utils:test_utils"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,29 +11,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <react/renderer/telemetry/TransactionTelemetry.h>
|
||||
#include <react/test_utils/MockClock.h>
|
||||
#include <react/utils/Telemetry.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
class MockClock {
|
||||
public:
|
||||
typedef std::chrono::
|
||||
time_point<std::chrono::steady_clock, std::chrono::nanoseconds>
|
||||
time_point;
|
||||
|
||||
static time_point now() noexcept {
|
||||
return time_;
|
||||
}
|
||||
|
||||
template <typename TDuration>
|
||||
static void advance_by(const TDuration duration) {
|
||||
time_ += duration;
|
||||
}
|
||||
|
||||
private:
|
||||
static time_point time_;
|
||||
};
|
||||
|
||||
MockClock::time_point MockClock::time_ = {};
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
load(
|
||||
"//tools/build_defs/oss:rn_defs.bzl",
|
||||
"ANDROID",
|
||||
"APPLE",
|
||||
"CXX",
|
||||
"get_apple_compiler_flags",
|
||||
"get_apple_inspector_flags",
|
||||
"get_preprocessor_flags_for_build_mode",
|
||||
"react_native_xplat_target",
|
||||
"rn_xplat_cxx_library",
|
||||
"subdir_glob",
|
||||
)
|
||||
|
||||
APPLE_COMPILER_FLAGS = get_apple_compiler_flags()
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "test_utils",
|
||||
srcs = [],
|
||||
headers = glob(
|
||||
["**/*.h"],
|
||||
exclude = glob(["tests/**/*.h"]),
|
||||
),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob(
|
||||
[
|
||||
("", "*.h"),
|
||||
],
|
||||
prefix = "react/test_utils",
|
||||
),
|
||||
compiler_flags = [
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
],
|
||||
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
|
||||
fbobjc_frameworks = ["Foundation"],
|
||||
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
|
||||
force_static = True,
|
||||
labels = ["supermodule:xplat/default/public.react_native.infra"],
|
||||
macosx_tests_override = [],
|
||||
platforms = (ANDROID, APPLE, CXX),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
],
|
||||
tests = [],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"//xplat/jsi:jsi",
|
||||
react_native_xplat_target("better:better"),
|
||||
react_native_xplat_target("react/debug:debug"),
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class MockClock {
|
||||
public:
|
||||
typedef std::chrono::
|
||||
time_point<std::chrono::steady_clock, std::chrono::nanoseconds>
|
||||
time_point;
|
||||
|
||||
static time_point now() noexcept {
|
||||
return time_;
|
||||
}
|
||||
|
||||
template <typename TDuration>
|
||||
static void advance_by(const TDuration duration) {
|
||||
time_ += duration;
|
||||
}
|
||||
|
||||
private:
|
||||
static time_point time_;
|
||||
};
|
||||
Reference in New Issue
Block a user