forked from kokkos/kokkos-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_sampler.cpp: put in code for sampler test
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,66 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
#include <vector> | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
#include "Kokkos_Core.hpp" | ||
|
||
struct Tester { | ||
template <typename execution_space> | ||
explicit Tester(const execution_space& space) { | ||
//! Explicitly launch a kernel with a name, and run it 150 times with kernel | ||
//! logger. Use a periodic sampling with skip rate 51. This should print | ||
//! out 2 invocation, and there is a single matcher with a regular | ||
//! expression to check this. | ||
|
||
for (int iter = 0; iter < 150; 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{ | ||
"(.*)KokkosP: sample 51 calling child-begin function...(.*)", | ||
"(.*)KokkosP: sample 51 finished with child-begin function.(.*)", | ||
"(.*)KokkosP: sample 51 calling child-end function...(.*)", | ||
"(.*)KokkosP: sample 51 calling child-end function.(.*)", | ||
"(.*)KokkosP: sample 102 calling child-begin function...(.*)", | ||
"(.*)KokkosP: sample 102 finished with child-begin function.(.*)", | ||
"(.*)KokkosP: sample 102 calling child-end function...(.*)", | ||
"(.*)KokkosP: sample 102 calling child-end function.(.*)"}; | ||
|
||
/** | ||
* @test This test checks that the tool effectively samples. | ||
* | ||
*/ | ||
TEST(SamplerTest, ktoEnvVarDefault) { | ||
//! 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 | ||
} |