mirror of
https://github.com/facebook/zstd.git
synced 2025-07-16 20:24:32 +02:00
[pzstd] Add logging statements to tests
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -34,16 +35,19 @@ TEST(ThreadPool, AllJobsFinished) {
|
|||||||
std::atomic<unsigned> numFinished{0};
|
std::atomic<unsigned> numFinished{0};
|
||||||
std::atomic<bool> start{false};
|
std::atomic<bool> start{false};
|
||||||
{
|
{
|
||||||
|
std::cerr << "Creating executor" << std::endl;
|
||||||
ThreadPool executor(5);
|
ThreadPool executor(5);
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
executor.add([ &numFinished, &start ] {
|
executor.add([ &numFinished, &start ] {
|
||||||
while (!start.load()) {
|
while (!start.load()) {
|
||||||
// spin
|
std::this_thread::yield();
|
||||||
}
|
}
|
||||||
++numFinished;
|
++numFinished;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
std::cerr << "Starting" << std::endl;
|
||||||
start.store(true);
|
start.store(true);
|
||||||
|
std::cerr << "Finishing" << std::endl;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(10, numFinished.load());
|
EXPECT_EQ(10, numFinished.load());
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "utils/WorkQueue.h"
|
#include "utils/WorkQueue.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@ -201,11 +202,13 @@ TEST(WorkQueue, BoundedSizeMPMC) {
|
|||||||
WorkQueue<int> queue(10);
|
WorkQueue<int> queue(10);
|
||||||
std::vector<int> results(200, -1);
|
std::vector<int> results(200, -1);
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
|
std::cerr << "Creating popperThreads" << std::endl;
|
||||||
std::vector<std::thread> popperThreads;
|
std::vector<std::thread> popperThreads;
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
popperThreads.emplace_back(Popper{&queue, results.data(), &mutex});
|
popperThreads.emplace_back(Popper{&queue, results.data(), &mutex});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr << "Creating pusherThreads" << std::endl;
|
||||||
std::vector<std::thread> pusherThreads;
|
std::vector<std::thread> pusherThreads;
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
auto min = i * 100;
|
auto min = i * 100;
|
||||||
@ -218,15 +221,19 @@ TEST(WorkQueue, BoundedSizeMPMC) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr << "Joining pusherThreads" << std::endl;
|
||||||
for (auto& thread : pusherThreads) {
|
for (auto& thread : pusherThreads) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
std::cerr << "Finishing queue" << std::endl;
|
||||||
queue.finish();
|
queue.finish();
|
||||||
|
|
||||||
|
std::cerr << "Joining popperThreads" << std::endl;
|
||||||
for (auto& thread : popperThreads) {
|
for (auto& thread : popperThreads) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr << "Inspecting results" << std::endl;
|
||||||
for (int i = 0; i < 200; ++i) {
|
for (int i = 0; i < 200; ++i) {
|
||||||
EXPECT_EQ(i, results[i]);
|
EXPECT_EQ(i, results[i]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user