forked from LLNL/Caliper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_python_api.py
96 lines (79 loc) · 2.74 KB
/
test_python_api.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
# Tests of the Python API
import sys
import unittest
import calipertest as cat
class CaliperPythonAPITest(unittest.TestCase):
"""Caliper Python API test cases"""
def test_py_ann_trace(self):
target_cmd = [
sys.executable,
"./ci_test_py_ann.py",
"event-trace,output=stdout",
]
query_cmd = ["../../src/tools/cali-query/cali-query", "-e"]
caliper_config = {"CALI_LOG_VERBOSITY": "0"}
query_output = cat.run_test_with_query(target_cmd, query_cmd, caliper_config)
snapshots = cat.get_snapshots_from_text(query_output)
self.assertTrue(len(snapshots) >= 10)
self.assertTrue(
cat.has_snapshot_with_keys(
snapshots, {"iteration", "phase", "time.duration.ns", "global.int"}
)
)
self.assertTrue(
cat.has_snapshot_with_attributes(
snapshots, {"event.end#phase": "loop", "phase": "loop"}
)
)
self.assertTrue(
cat.has_snapshot_with_attributes(
snapshots,
{"event.end#iteration": "3", "iteration": "3", "phase": "loop"},
)
)
self.assertTrue(
cat.has_snapshot_with_keys(
snapshots,
{"attr.int", "attr.dbl", "attr.str", "ci_test_c_ann.setbyname"},
)
)
self.assertTrue(
cat.has_snapshot_with_attributes(
snapshots, {"attr.int": "20", "attr.str": "fidibus"}
)
)
def test_py_ann_globals(self):
target_cmd = [sys.executable, "./ci_test_py_ann.py"]
query_cmd = ["../../src/tools/cali-query/cali-query", "-e", "--list-globals"]
caliper_config = {
"CALI_CONFIG_PROFILE": "serial-trace",
"CALI_RECORDER_FILENAME": "stdout",
"CALI_LOG_VERBOSITY": "0",
}
query_output = cat.run_test_with_query(target_cmd, query_cmd, caliper_config)
snapshots = cat.get_snapshots_from_text(query_output)
self.assertTrue(len(snapshots) == 1)
self.assertTrue(
cat.has_snapshot_with_keys(
snapshots,
{
"global.double",
"global.string",
"global.int",
"global.uint",
"cali.caliper.version",
},
)
)
self.assertTrue(
cat.has_snapshot_with_attributes(
snapshots,
{
"global.int": "1337",
"global.string": "my global string",
"global.uint": "42",
},
)
)
if __name__ == "__main__":
unittest.main()