Make simple kernel timer stdout in ascii text with unit-tests#328
Make simple kernel timer stdout in ascii text with unit-tests#328
Conversation
…alize_library - Port print_ascii function from PR #323 to simple-kernel-timer - Modify kokkosp_finalize_library to use print_ascii by default - Add 7 death test files covering parallel_for, parallel_reduce, parallel_scan, region, and combinations with regions - All 17 tests pass (10 existing + 7 new) Co-authored-by: yasahi-hpc <57478230+yasahi-hpc@users.noreply.github.com>
Each test now uses a single EXPECT_EXIT with ::testing::AllOf to validate all assertions in one child process, instead of repeating the setup for each individual assertion. Co-authored-by: yasahi-hpc <57478230+yasahi-hpc@users.noreply.github.com>
yasahi-hpc
left a comment
There was a problem hiding this comment.
-
Merge all the proposed tests (
test_parfor_init_finalize.cpp,test_parreduce_init_finalize.cpp,test_parscan_init_finalize.cpp,test_region_init_finalize.cpp,test_parfor_region_init_finalize.cpp, ,test_parreduce_region_init_finalize.cpp,test_parscan_region_init_finalize.cpp) into a single test file named "test_simple_kernel_timer.cpp". CMake should be updated accordingly. -
Investigate the possible to introduce a single test fixture that performs
dup2(STDERR_FILENO, STDOUT_FILENO);inSetUp()and removedup2(STDERR_FILENO, STDOUT_FILENO);inside each tests. If this does not change the behavior, apply this change. -
Introduce
::testing::FLAGS_gtest_death_test_style = "threadsafe";at the first line of each test. -
Confirm that tests pass after changes
| ) | ||
|
|
||
| ## tests for simple kernel timer init/finalize with print_ascii output | ||
|
|
There was a problem hiding this comment.
Please merge all the proposed tests into a single test file named "test_simple_kernel_timer"
There was a problem hiding this comment.
Done in db16c5f — all tests merged into test_simple_kernel_timer.cpp with a single test_simple_kernel_timer CMake target.
| * The print_ascii output is captured and validated. | ||
| */ | ||
|
|
||
| TEST(SimpleKernelTimerParFor_DeathTest, parfor) { |
There was a problem hiding this comment.
Add ::testing::FLAGS_gtest_death_test_style = "threadsafe";. This should be added for all the proposed test functions.
There was a problem hiding this comment.
Added to all 7 test functions in db16c5f.
| *~ | ||
| *.so | ||
| /src/tools/simple-kernel-timer/kp_reader | ||
| build/ |
There was a problem hiding this comment.
These changes can be made in another PR
| EXPECT_EXIT( | ||
| { | ||
| // Redirect stdout to stderr so the death test captures the output. | ||
| dup2(STDERR_FILENO, STDOUT_FILENO); |
There was a problem hiding this comment.
If it does not change the behavior, I would like a single test fixture that performs dup2(STDERR_FILENO, STDOUT_FILENO); in SetUp() and then reuse that for all the proposed tests. Apply this change only if the behavior does not change
There was a problem hiding this comment.
Investigated — moving dup2 to SetUp() does change the behavior. SetUp() runs in the parent process, while EXPECT_EXIT forks a child process (especially with "threadsafe" style which re-execs). The dup2 redirect must happen inside the child's EXPECT_EXIT block. Added a SimpleKernelTimer_DeathTest fixture with SetUp() documenting this constraint. See db16c5f.
- Merge all 7 test files into test_simple_kernel_timer.cpp - Use SimpleKernelTimer_DeathTest test fixture with TEST_F - Add ::testing::FLAGS_gtest_death_test_style = "threadsafe" to each test - Document in fixture why dup2 must stay inside EXPECT_EXIT block - Update CMakeLists.txt to use single test target - Revert .gitignore changes (to be done in another PR) Co-authored-by: yasahi-hpc <57478230+yasahi-hpc@users.noreply.github.com>
Co-authored-by: yasahi-hpc <57478230+yasahi-hpc@users.noreply.github.com>
All 4 items addressed in
|
|
I have trouble understanding the title. Are these not two topics mixed into one pr? |
Sorry for confusion, I have rephrased. |
|
|
||
| if(NULL != outputDelimiter) { | ||
| free(outputDelimiter); | ||
| }*/ |
There was a problem hiding this comment.
It makes sense, but I would like to keep the changes minimal.
We can make refactor/cleanup PR after this one
|
This supersedes #323 |
Adrien-Tab
left a comment
There was a problem hiding this comment.
Maybe an option to print in ascii to a file, like google Benchmark do ?
Ports
print_asciifrom PR #323 and adds death tests validatingkokkosp_init_libraryandkokkosp_finalize_libraryfor the simple-kernel-timer tool.kp_kernel_timer.cppchanges (PR #323 port)print_ascii()— formats kernel/region timing to stdout as default outputkokkosp_finalize_library()now callsprint_ascii()unlessKOKKOS_TOOLS_TIMER_BINARYorKOKKOS_TOOLS_TIMER_JSONis set7 death tests in
tests/sampler/test_simple_kernel_timer.cppAll tests are consolidated into a single file using a
SimpleKernelTimer_DeathTesttest fixture withTEST_F. Each test runsKokkos::initialize()→ kernel work →Kokkos::finalize()in a child process viaEXPECT_EXIT, redirecting stdout→stderr withdup2for capture. Uses::testing::AllOfto validate multiple patterns per subprocess and::testing::FLAGS_gtest_death_test_style = "threadsafe"at the start of each test.Note:
dup2(STDERR_FILENO, STDOUT_FILENO)remains inside eachEXPECT_EXITblock becauseSetUp()runs in the parent process whileEXPECT_EXITforks a child — moving it to the fixture would not affect the child's file descriptors.parforparallel_forparreduceparallel_reduceparscanparallel_scanregionparfor_regionparallel_for+ Regionparreduce_regionparallel_reduce+ Regionparscan_regionparallel_scan+ RegionEach test validates:
ParFor,ParRed,ParScan,Region)[0-9]+\.[0-9]+)CMake
Single test registered via
kp_add_executable_and_testwithkp_kernel_timeras the tool library:💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.