Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better tests (probabilistic and math?) #14

Open
martong opened this issue May 24, 2016 · 2 comments
Open

Add better tests (probabilistic and math?) #14

martong opened this issue May 24, 2016 · 2 comments

Comments

@martong
Copy link
Owner

martong commented May 24, 2016

Create a test framework, where we can synthesize different random thread interleavings and if there is an error, then at least we should be able to display the interleaving which caused the error. (relacy?)
Would be nice to come up with mathematical tests as well. E.g. for copy_update there is a nice test to check that we'd not missed any update:

void test_sum_add() {
    X x{};

    int sum = 0;
    std::thread t2{[&x, &sum]() {
        executeInLoop<1000>([&x, &sum]() {
            sum = x.sum();
        });
    }};

    std::thread t1{[&x]() {
        executeInLoop<1000>([&x]() {
            x.add(3);
        });
    }};

    std::thread t3{[&x]() {
        executeInLoop<1000>([&x]() {
            x.add(4);
        });
    }};

    t1.join();
    t2.join();
    t3.join();
    std::cout << x.sum() << std::endl;
    ASSERT(x.sum() == 7000);
}
@virgil-e
Copy link
Collaborator

virgil-e commented May 25, 2016

Another facility we might find handy to use is join_guard. We could either use the one in atomic_shared_ptr or implement another one. The key idea here would be to create a container of std::threads and pass them to a RAII object that would call join() on each of them if the givent thread is joinable().

auto threads = std::vector<std::thread>(3);
threads[1] = //...;
threads[0] = //...;
threads[2] = //..;

auto const _ = crf::make_join_guard(threads);

Please note: join_guard does not support move operations as of now but would be a good idea to extend it (in order to have a factory for it and reduce verbosity). which will happen soon enough. It would still remain NonCopyable.

What do you think?

@martong
Copy link
Owner Author

martong commented May 25, 2016

Good idea, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants