Skip to content

Commit 504f56d

Browse files
jplehrmhalk
authored andcommitted
[ompTest] Adds initial unit tests w/ gTest
Enable unit testing of ompTest library to guarantee functioning correctly. This is mostly important for the comparison operators. Since they are used to determine if records match during ompTest test execution. Change-Id: I00ba95cec9b96afb63ad642fc093680df66ee0b2
1 parent 36a844b commit 504f56d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

offload/test/ompTest/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ endif()
1010

1111
option(LIBOMPTEST_USE_GOOGLETEST "If set to 'ON' build ompTest upon GoogleTest, otherwise 'standalone'." OFF)
1212

13+
option(LIBOMPTEST_BUILD_UNITTESTS "Build unit tests for ompTest, requires GoogleTest" OFF)
14+
1315
cmake_minimum_required(VERSION 3.22)
1416
project(omptest LANGUAGES CXX)
1517

@@ -59,6 +61,13 @@ target_include_directories(omptest
5961
${LIBOMPTARGET_INCLUDE_DIR}
6062
)
6163

64+
if(LIBOMPTEST_BUILD_UNITTESTS)
65+
include(GoogleTest)
66+
add_executable(omptest-unittests test/main-test.cpp)
67+
target_link_libraries(omptest-unittests omptest)
68+
target_link_libraries(omptest-unittests gtest gtest_main)
69+
endif()
70+
6271
# Include local include directory, so we do not need relative paths
6372
include_directories(./include)
6473
target_compile_features(omptest PRIVATE cxx_std_17)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "OmptAssertEvent.h"
2+
#include <omp-tools.h>
3+
4+
#include "gtest/gtest.h"
5+
6+
TEST(CompareOperatorTests, BufferRecordIdentity) {
7+
8+
using namespace omptest;
9+
10+
// Default, no time limit or anything
11+
auto BRDflt = OmptAssertEvent::BufferRecord("dflt", "", ObserveState::always,
12+
ompt_callback_target_submit);
13+
14+
// Minimum time set, no max time
15+
auto BRMinSet = OmptAssertEvent::BufferRecord(
16+
"minset", "", ObserveState::always, ompt_callback_target_submit, 10);
17+
18+
// Minimum time and maximum time set
19+
auto BRMinMaxSet =
20+
OmptAssertEvent::BufferRecord("minmaxset", "", ObserveState::always,
21+
ompt_callback_target_submit, {10, 100});
22+
23+
ASSERT_EQ(BRDflt, BRDflt);
24+
ASSERT_EQ(BRMinSet, BRMinSet);
25+
ASSERT_EQ(BRMinMaxSet, BRMinMaxSet);
26+
}

0 commit comments

Comments
 (0)