forked from LLNL/Caliper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_json.py
168 lines (109 loc) · 5.69 KB
/
test_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# JSON output test cases
import json
import unittest
import calipertest as cat
class CaliperJSONTest(unittest.TestCase):
""" Caliper JSON formatters test cases """
def test_jsonobject(self):
""" Test json object layout """
target_cmd = [ './ci_test_macros' ]
query_cmd = [ '../../src/tools/cali-query/cali-query',
'-q', 'SELECT count(),* group by path where region format json(object)' ]
caliper_config = {
'CALI_CONFIG_PROFILE' : 'serial-trace',
'CALI_RECORDER_FILENAME' : 'stdout',
'CALI_LOG_VERBOSITY' : '0'
}
obj = json.loads( cat.run_test_with_query(target_cmd, query_cmd, caliper_config ) )
self.assertTrue( { 'records', 'globals', 'attributes' }.issubset(set(obj.keys())) )
self.assertEqual(len(obj['records']), 10)
self.assertTrue('path' in obj['records'][0].keys())
self.assertTrue('cali.caliper.version' in obj['globals'].keys())
self.assertTrue('count' in obj['attributes'].keys())
self.assertEqual(obj['attributes']['cali.caliper.version']['is_global'], 1)
def test_jsonobject_pretty(self):
""" Test json object layout """
target_cmd = [ './ci_test_macros' ]
query_cmd = [ '../../src/tools/cali-query/cali-query',
'-q', 'SELECT count(),* group by path where region format json(object,pretty)' ]
caliper_config = {
'CALI_CONFIG_PROFILE' : 'serial-trace',
'CALI_RECORDER_FILENAME' : 'stdout',
'CALI_LOG_VERBOSITY' : '0'
}
obj = json.loads( cat.run_test_with_query(target_cmd, query_cmd, caliper_config ) )
self.assertTrue( { 'records', 'globals', 'attributes' }.issubset(set(obj.keys())) )
self.assertEqual(len(obj['records']), 10)
self.assertTrue('path' in obj['records'][0].keys())
self.assertTrue('cali.caliper.version' in obj['globals'].keys())
self.assertTrue('count' in obj['attributes'].keys())
self.assertEqual(obj['attributes']['cali.caliper.version']['is_global'], True)
def test_jsontree(self):
""" Test basic json-tree formatter """
target_cmd = [ './ci_test_macros' ]
query_cmd = [ '../../src/tools/cali-query/cali-query',
'-q', 'SELECT count(),sum(time.inclusive.duration.ns),loop,iteration#main\\ loop group by loop,iteration#main\\ loop format json-split' ]
caliper_config = {
'CALI_CONFIG_PROFILE' : 'serial-trace',
'CALI_RECORDER_FILENAME' : 'stdout',
'CALI_LOG_VERBOSITY' : '0'
}
obj = json.loads( cat.run_test_with_query(target_cmd, query_cmd, caliper_config) )
self.assertTrue( { 'data', 'columns', 'column_metadata', 'nodes' }.issubset(set(obj.keys())) )
columns = obj['columns']
self.assertEqual( { 'path', 'iteration#main loop', 'count', 'sum#time.inclusive.duration.ns' }, set(columns) )
data = obj['data']
self.assertEqual(len(data), 10)
self.assertEqual(len(data[0]), 4)
meta = obj['column_metadata']
self.assertEqual(len(meta), 4)
self.assertTrue(meta[columns.index('count')]['is_value'])
self.assertFalse(meta[columns.index('path')]['is_value'])
nodes = obj['nodes']
self.assertEqual(nodes[0]['label' ], 'main loop')
self.assertEqual(nodes[0]['column'], 'path')
self.assertEqual(nodes[1]['label' ], 'fooloop')
self.assertEqual(nodes[1]['column'], 'path')
self.assertEqual(nodes[1]['parent'], 0)
iterindex = columns.index('iteration#main loop')
# Note: this is a pretty fragile test
self.assertEqual(data[9][iterindex], 3)
def test_hatchetcontroller(self):
""" Test hatchet-region-profile controller """
target_cmd = [ './ci_test_macros', '0', 'hatchet-region-profile,use.mpi=false,output=stdout,output.format=json-split,node.order=false' ]
caliper_config = {
'CALI_LOG_VERBOSITY' : '0'
}
obj = json.loads( cat.run_test(target_cmd, caliper_config)[0] )
self.assertTrue( { 'data', 'columns', 'column_metadata', 'nodes' }.issubset(set(obj.keys())) )
columns = obj['columns']
self.assertEqual( { 'path', 'time' }, set(columns) )
data = obj['data']
self.assertEqual(len(data), 11)
self.assertEqual(len(data[0]), 2)
meta = obj['column_metadata']
self.assertEqual(len(meta), 2)
time_idx = columns.index('time')
path_idx = columns.index('path')
self.assertTrue( meta[time_idx]['is_value'])
self.assertEqual(meta[time_idx]['attribute.unit'], 'sec')
self.assertFalse(meta[path_idx]['is_value'])
def test_esc(self):
target_cmd = [ './ci_test_basic' ]
query_cmd = [ '../../src/tools/cali-query/cali-query',
'-q', 'select *,count() format json-split' ]
caliper_config = {
'CALI_CONFIG_PROFILE' : 'serial-trace',
'CALI_RECORDER_FILENAME' : 'stdout',
'CALI_LOG_VERBOSITY' : '0'
}
obj = json.loads( cat.run_test_with_query(target_cmd, query_cmd, caliper_config) )
columns = obj['columns']
self.assertTrue('event.set# =\\weird ""attribute"= ' in columns)
data = obj['data']
nodes = obj['nodes']
index = columns.index('event.set# =\\weird ""attribute"= ')
self.assertEqual(nodes[data[0][index]]['label'], ' \\\\ weird," name",' )
self.assertEqual(obj[' =\\weird "" global attribute"= '], ' \\\\ weird," name",')
if __name__ == "__main__":
unittest.main()