Skip to content

Commit 1e8315b

Browse files
authored
Fixes bug with variable naming in a couple of macros (LLNL#596)
* Fixes a bug in some Caliper macros that caused repeat variable names due to lack of macro expansion * Fixes unit tests and adds CALI prefix to new macros
1 parent 3542073 commit 1e8315b

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

include/caliper/cali_macros.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818

1919
#include "Annotation.h"
2020

21+
// Macros for building variable names with other macros
22+
// These macros were obtained from:
23+
// https://stackoverflow.com/a/71899854
24+
#define CALI_CONCAT_(prefix, suffix) perfix##suffix
25+
#define CALI_CREATE_VAR_NAME(prefix, suffix) CALI_CONCAT_(prefix, suffix)
26+
2127
/// \brief C++ macro to mark a function
2228
///
2329
/// Mark begin and end of a function. Should be placed at the top of the
2430
/// function, and will automatically "close" the function at any return
2531
/// point. Will export the annotated function by name in the pre-defined
2632
/// `function` attribute. Only available in C++.
2733
#define CALI_CXX_MARK_FUNCTION \
28-
cali::Function __cali_ann##__func__(__func__)
34+
cali::Function CALI_CREATE_VAR_NAME(__cali_ann, __func__)(__func__)
2935

3036
/// \brief C++ macro marking a scoped region
3137
///
@@ -34,7 +40,7 @@
3440
/// point. Will export the annotated function by name in the pre-defined
3541
/// `annotation` attribute. Only available in C++.
3642
#define CALI_CXX_MARK_SCOPE(name) \
37-
cali::ScopeAnnotation __cali_ann_scope##__LINE__(name)
43+
cali::ScopeAnnotation CALI_CREATE_VAR_NAME(__cali_ann_scope, __LINE__)(name)
3844

3945
/// \brief Mark loop in C++
4046
/// \copydetails CALI_MARK_LOOP_BEGIN

test/ci_app_tests/ci_test_macros.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ int main(int argc, char* argv[])
6161

6262
{
6363
CALI_CXX_MARK_SCOPE("before_loop");
64+
CALI_CXX_MARK_SCOPE("inner_before_loop");
6465

6566
if (argc > 3)
6667
count = std::max(1, std::stoi(argv[3]));

test/ci_app_tests/test_basictrace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def test_inclusive_region_filter(self):
297297
}))
298298

299299
def test_exclusive_region_filter(self):
300-
target_cmd = [ './ci_test_macros', '0', 'hatchet-region-profile,exclude_regions=before_loop,output.format=cali,output=stdout' ]
300+
target_cmd = [ './ci_test_macros', '0', 'hatchet-region-profile,exclude_regions="before_loop,inner_before_loop",output.format=cali,output=stdout' ]
301301
query_cmd = [ '../../src/tools/cali-query/cali-query', '-e' ]
302302

303303
caliper_config = {

test/ci_app_tests/test_json.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_jsonobject(self):
2525

2626
self.assertTrue( { 'records', 'globals', 'attributes' }.issubset(set(obj.keys())) )
2727

28-
self.assertEqual(len(obj['records']), 9)
28+
self.assertEqual(len(obj['records']), 10)
2929
self.assertTrue('path' in obj['records'][0].keys())
3030

3131
self.assertTrue('cali.caliper.version' in obj['globals'].keys())
@@ -50,7 +50,7 @@ def test_jsonobject_pretty(self):
5050

5151
self.assertTrue( { 'records', 'globals', 'attributes' }.issubset(set(obj.keys())) )
5252

53-
self.assertEqual(len(obj['records']), 9)
53+
self.assertEqual(len(obj['records']), 10)
5454
self.assertTrue('path' in obj['records'][0].keys())
5555

5656
self.assertTrue('cali.caliper.version' in obj['globals'].keys())
@@ -123,7 +123,7 @@ def test_hatchetcontroller(self):
123123

124124
data = obj['data']
125125

126-
self.assertEqual(len(data), 10)
126+
self.assertEqual(len(data), 11)
127127
self.assertEqual(len(data[0]), 2)
128128

129129
meta = obj['column_metadata']

test/ci_app_tests/test_report.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_report_aggregate(self):
4343
snapshots = cat.get_snapshots_from_text(query_output)
4444

4545
self.assertTrue(cat.has_snapshot_with_attributes(
46-
snapshots, { 'region': 'main', 'count': '19', 'inclusive#count': '81' }))
46+
snapshots, { 'region': 'main', 'count': '19', 'inclusive#count': '83' }))
4747
self.assertTrue(cat.has_snapshot_with_attributes(
4848
snapshots, { 'region': 'main/foo', 'count': '48', 'inclusive#count': '60' }))
4949

@@ -127,14 +127,15 @@ def test_report_tree_formatter(self):
127127
}
128128

129129
report_targets = [
130-
'Path Count',
131-
'main 1',
132-
' main loop 5',
133-
' foo 4',
134-
' fooloop 20',
135-
' pre-loop 4',
136-
' foo.init 4',
137-
' before_loop 1'
130+
'Path Count',
131+
'main 1',
132+
' main loop 5',
133+
' foo 4',
134+
' fooloop 20',
135+
' pre-loop 4',
136+
' foo.init 4',
137+
' before_loop 1',
138+
' inner_before_loop 1'
138139
]
139140

140141
report_output,_ = cat.run_test(target_cmd, caliper_config)

0 commit comments

Comments
 (0)