Skip to content

Commit

Permalink
Add CI test for GDB pretty-prints
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Sep 14, 2023
1 parent 6fe664c commit 3d62e7b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/celerity_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ jobs:
# We build examples twice, but only run the installed version (which probably has more failure modes)
working-directory: ${{ env.examples-build-dir }}
run: ${{ env.container-workspace }}/ci/run-examples.sh /data/Lenna.png 1 2 4
- name: Run debugging tests
if: matrix.build-type == 'Debug' && matrix.sycl == 'hipsycl' # newer DPC++ generates DWARF5 which is incompatible with Ubuntu 20.04's GDB
run: ${{ env.container-workspace }}/test/debug/pretty-print-test.py ${{ env.build-dir }}/test/debug/pretty_printables
- name: Run system tests
working-directory: ${{ env.build-dir }}
run: ${{ env.container-workspace }}/ci/run-system-tests.sh 2 4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ install
.vscode/
.idea/
/tags
__pycache__/
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ if(CAIRO_INCLUDE_DIRS AND CAIRO_LIBRARIES)
endforeach()
target_link_libraries(all_tests PRIVATE ${CAIRO_LIBRARIES})
endif()

if(CMAKE_BUILD_TYPE STREQUAL Debug)
add_subdirectory(debug)
endif()
2 changes: 2 additions & 0 deletions test/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(pretty_printables pretty_printables.cc)
add_celerity_to_target(TARGET pretty_printables SOURCES pretty_printables.cc)
32 changes: 32 additions & 0 deletions test/debug/pretty-print-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import subprocess
import sys

EXPECTED = b'''// tell GDB to break here so we can examine locals
tid = 10
bid = 11
nid = 12
cid = 13
cgid = 14
rid = 15
hoid = 16
hyid = 17
trid = 18
id = [1, 2, 3]
range = [1, 2, 3]
subrange = [1, 2, 3] + [4, 5, 6]
chunk = celerity::chunk<3> = {offset = [1, 2, 3], range = [4, 5, 6], global_size = [7, 8, 9]}
nd_range = celerity::nd_range<3> = {global_range = [2, 4, 6], local_range = [1, 2, 3], offset = [7, 8, 9]}
box = [1, 2, 3] - [4, 5, 6]
region = celerity::detail::region<3> = {[1, 2, 3] - [4, 5, 6], [11, 2, 3] - [14, 5, 6], [21, 2, 3] - [24, 5, 6]}
region_map = celerity::detail::region_map<int> = {extent = [0, 0, 0] - [10, 10, 10], [[0, 0, 0] - [10, 10, 1]] = 0, [[0, 0, 5] - [10, 10, 10]] = 0, [[0, 0, 1] - [10, 1, 5]] = 0, [[0, 5, 1] - [10, 10, 5]] = 0, [[0, 1, 1] - [1, 5, 5]] = 0, [[1, 1, 1] - [2, 2, 2]] = 1337, [[1, 1, 2] - [3, 3, 3]] = 69, [[1, 2, 1] - [3, 3, 2]] = 69, [[2, 1, 1] - [3, 2, 2]] = 69, [[1, 1, 3] - [5, 5, 5]] = 42, [[3, 1, 1] - [5, 3, 3]] = 42, [[1, 3, 1] - [5, 5, 3]] = 42, [[5, 1, 1] - [10, 5, 5]] = 0}
'''

# invoke as `pretty-print-test.py build/test/debug/pretty_printables`
assert len(sys.argv) == 2

out = subprocess.check_output(['gdb', '-batch', sys.argv[1], '-ex', 'r', '-ex', 'i locals'])
if not out.endswith(EXPECTED):
print(f'=== pretty-print test FAILED: expected GDB output to end with\n\n{EXPECTED}\n\n=== but got\n\n{out}\n', file=sys.stderr)
sys.exit(1)
37 changes: 37 additions & 0 deletions test/debug/pretty_printables.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <csignal>
#include <iostream>
#include <string>

#include <celerity.h>
#include <region_map.h>

int main() {
celerity::detail::task_id tid = 10;
celerity::detail::buffer_id bid = 11;
celerity::detail::node_id nid = 12;
celerity::detail::command_id cid = 13;
celerity::detail::collective_group_id cgid = 14;
celerity::detail::reduction_id rid = 15;
celerity::detail::host_object_id hoid = 16;
celerity::detail::hydration_id hyid = 17;
celerity::detail::transfer_id trid = 18;

celerity::id<3> id(1, 2, 3);
celerity::range<3> range(1, 2, 3);
celerity::subrange<3> subrange(celerity::id(1, 2, 3), celerity::range(4, 5, 6));
celerity::chunk<3> chunk(celerity::id(1, 2, 3), celerity::range(4, 5, 6), celerity::range(7, 8, 9));
celerity::nd_range<3> nd_range(celerity::range(2, 4, 6), celerity::range(1, 2, 3), celerity::id(7, 8, 9));
celerity::detail::box<3> box(celerity::id(1, 2, 3), celerity::id(4, 5, 6));
celerity::detail::region<3> region({
celerity::detail::box(celerity::id(1, 2, 3), celerity::id(4, 5, 6)),
celerity::detail::box(celerity::id(11, 2, 3), celerity::id(14, 5, 6)),
celerity::detail::box(celerity::id(21, 2, 3), celerity::id(24, 5, 6)),
});

celerity::detail::region_map<int> region_map(celerity::range<3>(10, 10, 10), 3);
region_map.update_region(celerity::detail::box<3>({1, 1, 1}, {5, 5, 5}), 42);
region_map.update_region(celerity::detail::box<3>({1, 1, 1}, {3, 3, 3}), 69);
region_map.update_region(celerity::detail::box<3>({1, 1, 1}, {2, 2, 2}), 1337);

__builtin_trap(); // tell GDB to break here so we can examine locals
}

0 comments on commit 3d62e7b

Please sign in to comment.