|
Boost : |
Subject: Re: [boost] [test] Really deactivate test
From: Florian Lindner (mailinglists_at_[hidden])
Date: 2016-12-14 05:20:04
Am 12.12.2016 um 09:24 schrieb Florian Lindner:
> Hello,
>
> I need to conditionally decativate tests and use a custom decorator for that, like that:
>
> virtual void apply(bt::test_unit& tu)
> {
> [...]
> if (std::find(_ranks.begin(), _ranks.end(), rank) == _ranks.end()) {
> std::cout << rank << " Disable, because of rank, test: " << tu.full_name() << std::endl;
> tu.p_default_status.value = bt::test_unit::RS_DISABLED;
> return;
> }
> }
>
> (i'm happy to provide full source code, if anyone is interested)
> As you can see it's deativated on some MPI ranks only.
>
> However, if a user uses -t "testname" it is activated again.
>
> Is there a way to really deactivate the test? Or delete it from the test tree?
Seems to be next to impossible:
test_suite.remove(tu.p_id); has no effect.
bt::framework::deregister_test_unit(&tu); causes a SIGSEGV within boost.
tu.p_default_status.value = bt::test_unit::RS_DISABLED; as I said above, only disables if not enabled otherwise.
Any ideas anyone to completely disable / delete a test case from within a decorator?
Thanks,
Florian
/// Boost.Test decorator that makes the test run only on specfic ranks
class OnRanks : public bt::decorator::base
{
public:
explicit OnRanks(const std::vector<int> & ranks) :
_ranks(ranks)
{}
private:
virtual void apply(bt::test_unit& tu)
{
size_t rank = precice::utils::Parallel::getProcessRank();
size_t size = precice::utils::Parallel::getCommunicatorSize();
if (_ranks.size() > size) {
auto& test_suite = bt::framework::master_test_suite();
// std::cout << "Removed: " << tu.full_name() << " with ID " << tu.p_id
// << " from test suite " << test_suite.full_name() << std::endl;
test_suite.remove(tu.p_id);
// bt::framework::deregister_test_unit(&tu);
// tu.p_default_status.value = bt::test_case::RS_DISABLED;
return;
}
if (std::find(_ranks.begin(), _ranks.end(), rank) == _ranks.end()) {
auto& test_suite = bt::framework::master_test_suite();
// std::cout << "Removed: " << tu.full_name() << " with ID " << tu.p_id
// << " from test suite " << test_suite.full_name() << std::endl;
test_suite.remove(tu.p_id);
// bt::framework::deregister_test_unit(&tu);
// tu.p_default_status.value = bt::test_case::RS_DISABLED;
return;
}
}
virtual bt::decorator::base_ptr clone() const
{
return bt::decorator::base_ptr(new OnRanks(_ranks));
}
std::vector<int> _ranks;
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk