Skip to content

Commit 6b77b37

Browse files
committed
Some CI app test refactoring, add C API test cases
1 parent fff39fb commit 6b77b37

12 files changed

+108
-12
lines changed

CMakeLists.txt

+13-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ option(BUILD_SHARED_LIBS "Build shared libraries" TRUE)
2828
# RPATH setup. By default, rpath everything.
2929
option(CMAKE_INSTALL_RPATH_USE_LINK_PATH "Add rpath for all dependencies" TRUE)
3030

31-
option(WITH_TOOLS "Build Caliper tools" TRUE)
32-
option(WITH_TESTS "Build Caliper test apps" TRUE)
33-
option(WITH_DOCS "Build Caliper documentation" FALSE)
34-
option(WITH_CUDA "Enable Caliper CUDA services" FALSE)
31+
option(WITH_TOOLS "Build Caliper tools" TRUE)
32+
option(WITH_TEST_APPS "Build Caliper test apps" TRUE)
33+
option(WITH_DOCS "Build Caliper documentation" FALSE)
34+
option(WITH_CUDA "Enable Caliper CUDA services" FALSE)
35+
36+
# configure testing explicitly rather than with include(CTest) - avoids some clutter
37+
option(BUILD_TESTING "Build continuous integration app and unit tests" ON)
38+
39+
if (BUILD_TESTING)
40+
enable_testing()
41+
endif()
3542

3643
if(WITH_CUDA)
3744
find_package(CUDA)
@@ -104,7 +111,7 @@ endif()
104111

105112
# Find Python
106113

107-
find_package(PythonLibs)
114+
find_package(PythonInterp REQUIRED)
108115

109116
# Sampler is currently Linux-specific: check for Linux
110117
if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
@@ -148,7 +155,7 @@ install(FILES ${PROJECT_BINARY_DIR}/caliper.pc
148155

149156
add_subdirectory(src)
150157

151-
if (WITH_TESTS)
158+
if (WITH_TEST_APPS)
152159
add_subdirectory(test)
153160
endif()
154161
if (WITH_DOCS)

src/services/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ configure_file(
8585
${CMAKE_CURRENT_BINARY_DIR}/gen_services_inc.py
8686
)
8787

88-
find_package(PythonInterp REQUIRED)
89-
9088
add_custom_target(services.inc.cpp
9189
COMMAND ${PYTHON_EXECUTABLE} gen_services_inc.py
9290
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

test/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ target_link_libraries(cali-test-c caliper)
2626

2727
target_link_libraries(cali-simplereader-test caliper-reader)
2828

29-
add_subdirectory(apptests)
29+
if (BUILD_TESTING)
30+
add_subdirectory(ci_app_tests)
31+
endif()
32+

test/ci_tests/CMakeLists.txt test/ci_app_tests/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ include_directories("../../src/caliper")
55
set(CALIPER_CI_CXX_TEST_APPS
66
ci_test_basic)
77
set(CALIPER_CI_C_TEST_APPS
8-
ci_test_ann_c)
8+
ci_test_c_ann
9+
ci_test_c_snapshot)
910

1011
foreach(app ${CALIPER_CI_CXX_TEST_APPS})
1112
add_executable(${app} ${app}.cpp)
@@ -21,6 +22,7 @@ endforeach()
2122
# add symlinks to the python test driver scripts
2223
set(PYTHON_SCRIPTS
2324
test_basictrace.py
25+
test_c_api.py
2426
calipertest.py)
2527

2628
foreach(file ${PYTHON_SCRIPTS})
@@ -29,3 +31,5 @@ foreach(file ${PYTHON_SCRIPTS})
2931
${CMAKE_CURRENT_SOURCE_DIR}/${file}
3032
${CMAKE_CURRENT_BINARY_DIR}/${file})
3133
endforeach()
34+
35+
add_test(NAME CI_app_tests COMMAND ${PYTHON_EXECUTABLE} -m unittest discover -p "test_*.py")

test/ci_tests/README.md test/ci_app_tests/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Automated continuous integration application tests for Caliper
22
========================
33

44
This directory contains driver scripts and test cases for automated
5-
full application/workflow tests for continuous integration.
5+
continuous integration full application/workflow tests.
File renamed without changes.

test/ci_app_tests/calipertest.pyc

2.66 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Caliper continuous integration test app for C snapshot interface
2+
3+
#include <cali.h>
4+
5+
#include <string.h>
6+
7+
int main()
8+
{
9+
cali_begin_string_byname("ci_test_c", "snapshot");
10+
11+
/* Test w/o event trigger info */
12+
cali_push_snapshot(CALI_SCOPE_PROCESS | CALI_SCOPE_THREAD,
13+
0, NULL, NULL, NULL);
14+
15+
cali_id_t event_str_attr =
16+
cali_create_attribute("string_arg", CALI_TYPE_STRING, CALI_ATTR_DEFAULT);
17+
cali_id_t event_val_attr =
18+
cali_create_attribute("int_arg", CALI_TYPE_INT, CALI_ATTR_ASVALUE);
19+
20+
int64_t event_val = 42;
21+
const char* event_str = "teststring";
22+
23+
cali_id_t event_attr[2] = { event_str_attr,
24+
event_val_attr };
25+
const void* event_data[2] = { event_str,
26+
&event_val };
27+
size_t event_size[2] = { strlen(event_str),
28+
sizeof(int64_t) };
29+
30+
cali_push_snapshot(CALI_SCOPE_PROCESS | CALI_SCOPE_THREAD,
31+
2, event_attr, event_data, event_size);
32+
33+
cali_end_byname("ci_test_c");
34+
}

test/ci_tests/test_basictrace.py test/ci_app_tests/test_basictrace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Basic smoke tests using the cali-basic example app
1+
# Basic smoke tests: create and read a simple trace
22

33
import unittest
44

test/ci_app_tests/test_c_api.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Tests of the C API
2+
3+
import unittest
4+
5+
import calipertest as calitest
6+
7+
class CaliperCAPITest(unittest.TestCase):
8+
""" Caliper C API test cases """
9+
10+
def test_c_ann_trace(self):
11+
target_cmd = [ './ci_test_c_ann' ]
12+
query_cmd = [ '../../src/tools/cali-query/cali-query', '-e' ]
13+
14+
caliper_config = {
15+
'CALI_CONFIG_PROFILE' : 'serial-trace',
16+
'CALI_RECORDER_FILENAME' : 'stdout',
17+
'CALI_LOG_VERBOSITY' : '0'
18+
}
19+
20+
query_output = calitest.run_test_with_query(target_cmd, query_cmd, caliper_config)
21+
snapshots = calitest.get_snapshots_from_text(query_output)
22+
23+
self.assertTrue(len(snapshots) >= 10)
24+
25+
self.assertTrue(calitest.has_snapshot_with_keys(
26+
snapshots, {'iteration', 'phase', 'time.inclusive.duration'}))
27+
self.assertTrue(calitest.has_snapshot_with_attributes(
28+
snapshots, {'event.end#phase': 'initialization', 'phase': 'initialization'}))
29+
self.assertTrue(calitest.has_snapshot_with_attributes(
30+
snapshots, {'event.end#iteration': 3, 'iteration': 3, 'phase': 'loop'}))
31+
32+
def test_c_ann_snapshot(self):
33+
target_cmd = [ './ci_test_c_snapshot' ]
34+
query_cmd = [ '../../src/tools/cali-query/cali-query', '-e' ]
35+
36+
caliper_config = {
37+
'CALI_CONFIG_PROFILE' : 'serial-trace',
38+
'CALI_RECORDER_FILENAME' : 'stdout',
39+
'CALI_LOG_VERBOSITY' : '0'
40+
}
41+
42+
query_output = calitest.run_test_with_query(target_cmd, query_cmd, caliper_config)
43+
snapshots = calitest.get_snapshots_from_text(query_output)
44+
45+
self.assertTrue(len(snapshots) >= 4)
46+
self.assertTrue(calitest.has_snapshot_with_attributes(
47+
snapshots, {'ci_test_c': 'snapshot', 'string_arg': 'teststring', 'int_arg': 42 }))
48+
49+
if __name__ == "__main__":
50+
unittest.main()

0 commit comments

Comments
 (0)