Skip to content

Commit

Permalink
Add test for GDB pretty-printers
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Nov 8, 2023
1 parent 4e4302a commit 47bee9c
Show file tree
Hide file tree
Showing 5 changed files with 92 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
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,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)
40 changes: 40 additions & 0 deletions test/debug/pretty-print-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

import subprocess
import sys

EXPECTED = b'''__builtin_trap();
tid = T10
bid = B11
nid = N12
cid = C13
cgid = CG14
rid = R15
hoid = H16
hyid = HY17
trid = TR18
id = [1, 2, 3]
range = [1, 2, 3]
subrange = [1, 2, 3] + [4, 5, 6]
chunk = {offset = [1, 2, 3], range = [4, 5, 6], global_size = [7, 8, 9]}
nd_range = {global_range = [2, 4, 6], local_range = [1, 2, 3], offset = [7, 8, 9]}
box = [1, 2, 3] - [4, 5, 6]
empty_region = {}
region = {[1, 2, 3] - [4, 5, 6], [11, 2, 3] - [14, 5, 6], [21, 2, 3] - [24, 5, 6]}
region_map = region_map([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}
wcs_fresh = C123 (fresh)
wcs_stale = C123 (stale)
wcs_replicated = C123 (fresh, replicated)
'''

# 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('-*- pretty-print test FAILED: expected GDB output to end with', file=sys.stderr)
print(EXPECTED.decode('utf-8'), file=sys.stderr)
print('-*- but got', file=sys.stderr)
print(out.decode('utf-8'), file=sys.stderr)
print('-*-', file=sys.stderr)
sys.exit(1)
43 changes: 43 additions & 0 deletions test/debug/pretty_printables.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "distributed_graph_generator.h"
#include "grid.h"
#include "ranges.h"
#include "region_map.h"
#include "types.h"

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

[[maybe_unused]] celerity::id<3> id(1, 2, 3);
[[maybe_unused]] celerity::range<3> range(1, 2, 3);
[[maybe_unused]] celerity::subrange<3> subrange(celerity::id(1, 2, 3), celerity::range(4, 5, 6));
[[maybe_unused]] celerity::chunk<3> chunk(celerity::id(1, 2, 3), celerity::range(4, 5, 6), celerity::range(7, 8, 9));
[[maybe_unused]] celerity::nd_range<3> nd_range(celerity::range(2, 4, 6), celerity::range(1, 2, 3), celerity::id(7, 8, 9));
[[maybe_unused]] celerity::detail::box<3> box(celerity::id(1, 2, 3), celerity::id(4, 5, 6));
[[maybe_unused]] celerity::detail::region<3> empty_region;
[[maybe_unused]] 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)),
});

[[maybe_unused]] 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);

[[maybe_unused]] celerity::detail::write_command_state wcs_fresh(celerity::detail::command_id(123));
[[maybe_unused]] celerity::detail::write_command_state wcs_stale(celerity::detail::command_id(123));
wcs_stale.mark_as_stale();
[[maybe_unused]] celerity::detail::write_command_state wcs_replicated(celerity::detail::command_id(123), true /* replicated */);

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

0 comments on commit 47bee9c

Please sign in to comment.