Skip to content

Commit

Permalink
test_randomized_sampling.cpp: fix matcher text for 4 samples
Browse files Browse the repository at this point in the history
  • Loading branch information
vlkale committed Feb 29, 2024
1 parent e1f7c22 commit d020036
Showing 1 changed file with 49 additions and 58 deletions.
107 changes: 49 additions & 58 deletions tests/sampler/test_randomized_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,55 @@

#include "Kokkos_Core.hpp"

#define NUMITERS 1000
struct Tester {
struct TagNamed {};
struct TagUnnamed {};

template <typename execution_space>
explicit Tester(const execution_space& space) {
//! Explicitly launch a kernel with a name and no tag, and run it NUM_ITERS times
//! Use a random sampling of 1 percent and use a random seed of 2.
//! With NUMITERS 1000, this should print out 10 invocations.
//! In the test, we match the invocations output from all three runs against each other, and ensure that each shows 10 invocations.

for (int trial = 0; trial < 3; trial++)
{
for (int iter = 0; iter < NUMITERS; iter++) {
Kokkos::parallel_for("named kernel",
Kokkos::RangePolicy<execution_space>(space, 0, 1),
*this);
}
}

KOKKOS_FUNCTION void operator()(const int) const {}

template <typename TagType>
KOKKOS_FUNCTION void operator()(const TagType, const int) const {}
};

static const std::vector<std::string> matchers{
};

/**
* @test This test checks that the tool effectively samples randomly.
*
*/
TEST(SamplerTest, randomized) {
//! Initialize @c Kokkos.
Kokkos::initialize();

//! Redirect output for later analysis.
std::cout.flush();
std::ostringstream output;
std::streambuf* coutbuf = std::cout.rdbuf(output.rdbuf());

//! Run tests. @todo Replace this with Google Test.
Tester tester(Kokkos::DefaultExecutionSpace{});

//! Finalize @c Kokkos.
Kokkos::finalize();

//! Restore output buffer.
std::cout.flush();
std::cout.rdbuf(coutbuf);
std::cout << output.str() << std::endl;

//! Analyze test output.
for (const auto& matcher : matchers) {
EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher));
} // end TEST

}
//! Explicitly launch a kernel with a name, and run it 4 times with kernel
//! logger. Use a periodic sampling with skip rate 2. This should print out
//! 1 invocation In the test, we match the invocations output from the
//! second invocation and make sure the first
// and third are not printed out, and the second and fourth are sequenced
// correctly in the print.

for (int iter = 0; iter < 4; iter++) {
Kokkos::parallel_for("named kernel",
Kokkos::RangePolicy<execution_space>(space, 0, 1),
*this);
}

KOKKOS_FUNCTION void operator()(const int) const {}
};

static const std::vector<std::string> matchers{
"[0-9,a-z]+ KokkosP: sample 2 [0-9]+ KokkosP: sample 4 [0-9,a-z]+"};

/**
* @test This test checks that the tool effectively samples randomly.
*
*/
TEST(SamplerTest, randomized) {
//! Initialize @c Kokkos.
Kokkos::initialize();

//! Redirect output for later analysis.
std::cout.flush();
std::ostringstream output;
std::streambuf* coutbuf = std::cout.rdbuf(output.rdbuf());

//! Run tests. @todo Replace this with Google Test.
Tester tester(Kokkos::DefaultExecutionSpace{});

//! Finalize @c Kokkos.
Kokkos::finalize();

//! Restore output buffer.
std::cout.flush();
std::cout.rdbuf(coutbuf);
std::cout << output.str() << std::endl;

//! Analyze test output.
for (const auto& matcher : matchers) {
EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher));
} // end TEST
}

0 comments on commit d020036

Please sign in to comment.