Skip to content

Commit

Permalink
using profilerhook not stream to check number
Browse files Browse the repository at this point in the history
MSVC does not contain enough function information.
  • Loading branch information
yhmtsai committed Apr 7, 2023
1 parent ebfbd5a commit 3f03803
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions core/test/solver/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include <ginkgo/core/base/executor.hpp>
#include <ginkgo/core/log/stream.hpp>
#include <ginkgo/core/log/profiler_hook.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/stop/combined.hpp>
#include <ginkgo/core/stop/iteration.hpp>
Expand All @@ -53,22 +53,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace {


int count_occurrence(const std::string& str, const std::string& substr)
{
int occurrence = 0;
std::string::size_type pos = 0;
while (pos < str.length()) {
// no overlapped cases
pos = str.find(substr, pos);
if (pos != std::string::npos) {
pos += substr.length();
occurrence++;
}
}
return occurrence;
}


template <typename T>
class Ir : public ::testing::Test {
protected:
Expand Down Expand Up @@ -475,24 +459,40 @@ TYPED_TEST(Ir, SmootherBuildWithFactory)
}


struct TestSummaryWriter : gko::log::ProfilerHook::SummaryWriter {
void write(const std::vector<gko::log::ProfilerHook::summary_entry>& e,
gko::int64 overhead_ns) override
{
int matched = 0;
for (const auto& data : e) {
if (data.name == "residual_norm::residual_norm") {
matched++;
// Contains make_residual_norm 3 times: The last 4-th iteration
// exits due to iteration limit.
EXPECT_EQ(data.count, 3);
}
}
// ensure matching once
EXPECT_EQ(matched, 1);
}
};


TYPED_TEST(Ir, RunResidualNormCheckCorrectTimes)
{
using value_type = typename TestFixture::value_type;
using Solver = typename TestFixture::Solver;
using Mtx = typename TestFixture::Mtx;
auto b = gko::initialize<Mtx>({2, -1.0, 1.0}, this->exec);
auto x = gko::initialize<Mtx>({0.0, 0.0, 0.0}, this->exec);
std::stringstream out;
auto logger = gko::share(gko::log::Stream<TypeParam>::create(
gko::log::Logger::operation_launched_mask, out));
auto logger = gko::share(gko::log::ProfilerHook::create_summary(
std::make_unique<TestSummaryWriter>()));
this->exec->add_logger(logger);

// solver reaches the iteration limit
this->solver->apply(b, x);

// Contains make_residual_norm 3 times: check in initialization and two
// iterations. The last iteration exits due to iteration limit.
ASSERT_EQ(count_occurrence(out.str(), "make_residual_norm"), 3);
// The assertions happen in the destructor of `logger`
}


Expand Down

0 comments on commit 3f03803

Please sign in to comment.