blob: d2048ff2812225ef653e66d6adff2663438d93d6 [file] [log] [blame]
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Yarn_test.hpp"
#include "Yarn/WaitGroup.hpp"
TEST(WithoutBoundScheduler, WaitGroupDone)
{
yarn::WaitGroup wg(2); // Should not require a scheduler.
wg.done();
wg.done();
}
#if YARN_DEBUG_ENABLED
TEST(WithoutBoundScheduler, WaitGroupDoneTooMany)
{
yarn::WaitGroup wg(2); // Should not require a scheduler.
wg.done();
wg.done();
EXPECT_DEATH(wg.done(), "done\\(\\) called too many times");
}
#endif // YARN_DEBUG_ENABLED
TEST_P(WithBoundScheduler, WaitGroup_OneTask)
{
yarn::WaitGroup wg(1);
std::atomic<int> counter = {0};
yarn::schedule([&counter, wg] {
counter++;
wg.done();
});
wg.wait();
ASSERT_EQ(counter.load(), 1);
}
TEST_P(WithBoundScheduler, WaitGroup_10Tasks)
{
yarn::WaitGroup wg(10);
std::atomic<int> counter = {0};
for (int i = 0; i < 10; i++)
{
yarn::schedule([&counter, wg] {
counter++;
wg.done();
});
}
wg.wait();
ASSERT_EQ(counter.load(), 10);
}