-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_tsp.py
More file actions
498 lines (420 loc) · 20.5 KB
/
test_tsp.py
File metadata and controls
498 lines (420 loc) · 20.5 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# The MIT License (MIT)
#
# Copyright (C) 2021, 2023 - Ericsson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""TestTspClient class file."""
import os
import time
import uuid
import pytest
import requests
from tsp.response import ResponseStatus
from tsp.tsp_client import TspClient
STATISTICS_DP_ID = (
"org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsDataProvider:"
"org.eclipse.linuxtools.lttng2.ust.analysis.callstack"
)
REQUESTED_TIME_START = 1332170682440133097
REQUESTED_TIME_END = 1332170692664579801
REQUESTED_TIME_LENGTH = 10
REQUESTED_TIME_STEP = (REQUESTED_TIME_END -
REQUESTED_TIME_START) / REQUESTED_TIME_LENGTH
CONFIG_SOURCE_TYPE = 'org.eclipse.tracecompass.tmf.core.config.xmlsourcetype'
# pylint: disable=too-many-public-methods
class TestTspClient:
"""TspClient test methods.
[1] Each test below has a specific TSP endpoint focus, coming with its minimal assertions kit.
[2] This means that some asserts only appear in the test that specifically exercises them.
[3] Asserts for teardown test steps are otherwise repeated to confirm data deletions.
[4] This is to diagnose potential subsequent test failures caused by uncleaned server data.
[5] Should data get corrupted by test runs, ./tsp_cli_client can be used to manually clean it.
[6] Some setup steps are minimized where the test method scope doesn't require more data.
"""
def _delete_experiments(self):
"""To be called at the end of tests opening experiments, before deleting traces."""
response = self.tsp_client.fetch_experiments()
for experiment in response.model.experiments:
self.tsp_client.delete_experiment(experiment.UUID)
assert response.status_code == 200
def _delete_traces(self):
"""To be called at the end of tests opening traces, after deleting experiments."""
response = self.tsp_client.fetch_traces()
for trace in response.model.traces:
# Do not also delete the trace from disk; file part of this repo.
self.tsp_client.delete_trace(trace.UUID, False)
assert response.status_code == 200
# Not a pytest fixture so that VS Code may find its definitions.
tsp_client = TspClient('http://localhost:8080/tsp/api/')
name = 'FunctionGraph.xml'
@pytest.fixture(scope='module')
def extension(self):
"""Absolute xml analysis file path."""
return (f'{os.getcwd()}/org.eclipse.tracecompass.incubator/tracetypes/'
f'org.eclipse.tracecompass.incubator.ftrace.core/xml_analyses/{self.name}')
@staticmethod
@pytest.fixture(scope='module')
def kernel():
"""Absolute kernel test trace path."""
return f'{os.getcwd()}/tracecompass-test-traces/ctf/src/main/resources/kernel'
@staticmethod
@pytest.fixture(scope='module')
def other():
"""Absolute kernel-vm test trace path."""
return f'{os.getcwd()}/tracecompass-test-traces/ctf/src/main/resources/kernel_vm'
@staticmethod
@pytest.fixture(scope='module')
def switches():
"""Absolute switches test trace path."""
return (f'{os.getcwd()}/tracecompass-test-traces/ctf/src/main/resources/context-switches/'
f'context-switches-kernel')
@staticmethod
@pytest.fixture(scope='module')
def ust():
"""Absolute ust test trace path."""
return (f'{os.getcwd()}/tracecompass-test-traces/ctf/src/main/resources/context-switches/'
f'context-switches-ust')
@pytest.fixture(scope="module", autouse=True)
def test_fetch_traces(self):
"""Check server availability before each test; don't fail all tests if none, but exit."""
try:
self.tsp_client.fetch_traces()
except requests.exceptions.ConnectionError as ex:
pytest.exit(str(ex))
# Deleting left-over data here doesn't work consistently, but remains handy if tests fail.
self._delete_experiments()
self._delete_traces()
def test_fetch_traces_none(self):
"""Expect no traces without opening any."""
response = self.tsp_client.fetch_traces()
assert response.status_code == 200
assert not response.model.traces
def test_open_trace_twice(self, kernel, other):
"""Expect two traces after opening them."""
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
assert response.status_code == 200
response = self.tsp_client.open_trace(os.path.basename(other), other)
assert response.status_code == 200
response = self.tsp_client.fetch_traces()
assert len(response.model.traces) == 2
self._delete_traces()
def test_fetch_opened_trace(self, kernel):
"""Expect trace that was opened."""
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
assert response.status_code == 200
expected_uuid = response.model.UUID
response = self.tsp_client.fetch_trace(expected_uuid)
assert response.status_code == 200
assert response.model.UUID == expected_uuid
self._delete_traces()
def test_opened_trace_deleted(self, kernel):
"""Expect no trace after deletion."""
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
assert response.status_code == 200
trace_uuid = response.model.UUID
response = self.tsp_client.delete_trace(trace_uuid, False)
assert response.status_code == 200
response = self.tsp_client.fetch_trace(trace_uuid)
assert response.status_code == 404
def test_opened_trace_deleted_with_cache(self, kernel):
"""Expect trace deleted while removing cache."""
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
assert response.status_code == 200
trace_uuid = response.model.UUID
# Also remove cache for this trace, but still not its file on disk.
response = self.tsp_client.delete_trace(trace_uuid, False, True)
assert response.status_code == 200
def test_fetch_experiments_none(self):
"""Expect no experiments without opening any (nor traces)."""
response = self.tsp_client.fetch_experiments()
assert response.status_code == 200
assert not response.model.experiments
def test_open_experiment(self, kernel, other):
"""Expect experiment after opening it with traces."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_trace(os.path.basename(other), other)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
exp_uuid = response.model.UUID
response = self.tsp_client.fetch_experiments()
assert len(response.model.experiments) == 1
response = self.tsp_client.close_experiment(exp_uuid)
assert response.model.indexin_status == "CLOSED"
self._delete_experiments()
self._delete_traces()
def test_open_experiment_unopened_trace(self, kernel):
"""Expect 204 after opening experiment with unopened trace."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
unopened = str(uuid.uuid4())
traces.append(unopened)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 204
response = self.tsp_client.fetch_experiments()
assert len(response.model.experiments) == 0
self._delete_traces()
def test_fetch_opened_experiment(self, kernel):
"""Expect experiment that was opened."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
expected_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment(expected_uuid)
assert response.status_code == 200
assert response.model.UUID == expected_uuid
self._delete_experiments()
self._delete_traces()
def test_opened_experiment_deleted(self, kernel):
"""Expect no experiment after deletion."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.delete_experiment(experiment_uuid)
assert response.status_code == 200
self._delete_traces()
response = self.tsp_client.fetch_experiment(experiment_uuid)
assert response.status_code == 404
def test_fetch_experiment_outputs(self, kernel):
"""Expect some experiment outputs."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
assert response.status_code == 200
assert len(response.model.descriptors) > 0
self._delete_experiments()
self._delete_traces()
def test_fetch_experiment_output(self, kernel):
"""Expect opened experiment output."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
expected_id = response.model.descriptors[0].id
response = self.tsp_client.fetch_experiment_output(
experiment_uuid, expected_id)
assert response.status_code == 200
assert response.model.id == expected_id
self._delete_experiments()
self._delete_traces()
def test_open_experiment_context_switches(self, switches, ust):
"""Expect experiment based on context-switches traces."""
traces = []
response = self.tsp_client.open_trace(
os.path.basename(switches), switches)
traces.append(response.model.UUID)
response = self.tsp_client.open_trace(os.path.basename(ust), ust)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename("context"), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment(experiment_uuid)
assert response.status_code == 200
for trace in response.model.traces.traces:
response = self.tsp_client.fetch_trace(trace.UUID)
assert response.status_code == 200
self._delete_experiments()
self._delete_traces()
def test_fetch_data_tree(self, ust):
"""Expect data tree out of opened trace experiment."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(ust), ust)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(ust), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
output_id = STATISTICS_DP_ID
response = self.tsp_client.fetch_datatree(experiment_uuid, output_id)
assert response.status_code == 200
assert response.model.model_type == response.model.model_type.DATA_TREE
self._delete_experiments()
self._delete_traces()
def test_fetch_timegraph_tree(self, kernel):
"""Expect timegraph tree out of opened trace experiment."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
output_id = response.model.descriptors[0].id
response = self.tsp_client.fetch_timegraph_tree(
experiment_uuid, output_id)
assert response.status_code == 200
assert response.model.model_type == response.model.model_type.TIME_GRAPH_TREE
self._delete_experiments()
self._delete_traces()
def test_fetch_xy_tree(self, kernel):
"""Expect XY tree out of opened trace experiment."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
output_id = response.model.descriptors[0].id
response = self.tsp_client.fetch_xy_tree(experiment_uuid, output_id)
assert response.status_code == 200
assert response.model.model_type == response.model.model_type.XY_TREE
self._delete_experiments()
self._delete_traces()
def test_fetch_xy(self, kernel):
"""Expect XY data out of completed trace experiment."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
output_id = response.model.descriptors[0].id
status = ResponseStatus.RUNNING.name
while status == ResponseStatus.RUNNING.name:
time.sleep(1)
response = self.tsp_client.fetch_xy_tree(
experiment_uuid, output_id)
assert response.model is not None
status = response.model.status.upper()
params = self.__requested_parameters(response)
response = self.tsp_client.fetch_xy(experiment_uuid, output_id, params)
assert response.status_code == 200
assert response.model.model_type == response.model.model_type.XY
self._delete_experiments()
self._delete_traces()
def test_fetch_timegraph_tree_complete(self, kernel):
"""Expect completing timegraph tree."""
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
output_id = response.model.descriptors[0].id
status = ResponseStatus.RUNNING.name
while status == ResponseStatus.RUNNING.name:
time.sleep(1)
response = self.tsp_client.fetch_timegraph_tree(
experiment_uuid, output_id)
assert response.model is not None
status = response.model.status.upper()
params = self.__requested_parameters(response)
response = self.tsp_client.fetch_timegraph_tree(
experiment_uuid, output_id, params)
assert response.status_code == 200
self._delete_experiments()
self._delete_traces()
def test_fetch_configuration_sources(self):
"""Expect at least configuration source ."""
response = self.tsp_client.fetch_configuration_sources()
assert response.status_code == 200
assert response.model.configuration_source_set
response = self.tsp_client.fetch_configuration_source(CONFIG_SOURCE_TYPE)
assert response.status_code == 200
assert response.model
def test_fetch_configurations_none(self):
"""Expect no configurations without posting any."""
response = self.tsp_client.fetch_configurations(CONFIG_SOURCE_TYPE)
assert response.status_code == 200
assert response.model.configuration_set
response = self.tsp_client.fetch_configuration(CONFIG_SOURCE_TYPE, self.name)
assert response.status_code == 404
def test_post_configuration(self, extension):
"""Expect configuration after posting it."""
params = {}
params['path'] = extension
response = self.tsp_client.post_configuration(CONFIG_SOURCE_TYPE, params)
assert response.status_code == 200
response = self.tsp_client.fetch_configurations(CONFIG_SOURCE_TYPE)
assert len(response.model.configuration_set) > 0
found = False
for config in response.model.configuration_set:
if config.id == self.name:
found = True
assert found
response = self.tsp_client.fetch_configuration(CONFIG_SOURCE_TYPE, self.name)
assert response.status_code == 200
assert response.model
assert response.model.id == self.name
response = self.tsp_client.delete_configuration(CONFIG_SOURCE_TYPE, self.name)
assert response.status_code == 200
assert response.model
assert response.model.id == self.name
def test_posted_configuration_deleted(self, extension):
"""Expect no configuration after deletion."""
params = {}
params['path'] = extension
self.tsp_client.post_configuration(CONFIG_SOURCE_TYPE, params)
response = self.tsp_client.delete_configuration(CONFIG_SOURCE_TYPE, self.name)
assert response.status_code == 200
response = self.tsp_client.fetch_configurations(CONFIG_SOURCE_TYPE)
assert response.model.configuration_set
def test_put_configuration(self, extension):
"""Expect successful update of configuartion."""
params = {}
params['path'] = extension
self.tsp_client.post_configuration(CONFIG_SOURCE_TYPE, params)
response = self.tsp_client.put_configuration(CONFIG_SOURCE_TYPE, self.name, params)
assert response.status_code == 200
assert response.model
assert response.model.id == self.name
self.tsp_client.delete_configuration(CONFIG_SOURCE_TYPE, self.name)
@staticmethod
def __requested_parameters(response):
parameters = {}
requested_items = []
for entry in response.model.model.entries:
requested_items.append(entry.id)
parameters[TspClient.REQUESTED_ITEM_KEY] = requested_items
requested_times = []
requested_time = REQUESTED_TIME_START
while len(requested_times) < REQUESTED_TIME_LENGTH:
requested_time += REQUESTED_TIME_STEP
requested_times.append(int(requested_time))
parameters[TspClient.REQUESTED_TIME_KEY] = requested_times
return {TspClient.PARAMETERS_KEY: parameters}