-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
executable file
·1459 lines (1310 loc) · 55.5 KB
/
test.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
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Unit tests for OOMAnalyser
#
# Copyright (c) 2021-2024 Carsten Grohmann
# License: MIT (see LICENSE.txt)
# THIS PROGRAM COMES WITH NO WARRANTY
import http.server
import os
import re
import socketserver
import threading
import unittest
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium.common.exceptions import *
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import warnings
import OOMAnalyser
class MyRequestHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, request, client_address, server, directory=None):
self.directory = os.getcwd()
super().__init__(request, client_address, server)
# suppress all HTTP request messages
def log_message(self, format, *args):
# super().log_message(format, *args)
pass
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
class TestBase(unittest.TestCase):
text_alloc_failed_below_low_watermark = (
"The request failed because the free memory would be below the memory low "
"watermark after its completion."
)
text_alloc_failed_no_free_chunks = (
"The request failed because there is no free chunk in the current or "
"higher order."
)
text_alloc_failed_unknown_reason = "The request failed, but the reason is unknown."
text_mem_not_heavily_fragmented = "The system memory is not heavily fragmented"
text_mem_heavily_fragmented = "The system memory is heavily fragmented"
text_oom_triggered_manually = "OOM killer was manually triggered"
text_oom_triggered_automatically = "OOM killer was automatically triggered"
text_swap_space_not_in_use = "physical memory and no swap space"
text_swap_space_are_in_use = "swap space are in use"
test_swap_no_space = "No swap space available"
test_swap_swap_total = "Swap Total"
text_with_an_oom_score_of = "with an OOM score of"
def get_lines(self, text, count):
"""
Return the number of lines specified by count from given text
@type text: str
@type count: int
"""
lines = text.splitlines()
if count < 0:
lines.reverse()
count = count * -1
lines = lines[:count]
res = "\n".join(lines)
return res
def get_first_line(self, text):
"""
Return the first line of the given text
@type text: str
"""
return self.get_lines(text, 1)
def get_last_line(self, text):
"""
Return the last line of the given text
@type text: str
"""
return self.get_lines(text, -1)
def check_meminfo_format_rhel7(self, prefix, oom_text):
"""
Check if the example contains a proper formatted "Mem-Info:" block
@param str prefix: Prefix for error message
@param str oom_text: Whole OOM block as text
@see: OOMAnalyser.OOMDisplay.example_rhel7
"""
found = False
for line in oom_text.split("\n"):
if "active_file:1263 " in line:
found = True
self.assertTrue(
line.startswith(" active_file:1263 "),
f'{prefix}: Unexpected prefix for third "Mem-Info:" block line: >>>{line}<<<',
)
self.assertTrue(
found,
f'{prefix}: Missing content "active_file:1263 " in "Mem-Info:" block of\n{oom_text}',
)
class TestInBrowser(TestBase):
"""Test OOM web page in a browser"""
def setUp(self):
warnings.simplefilter("ignore", ResourceWarning)
ThreadedTCPServer.allow_reuse_address = True
self.httpd = ThreadedTCPServer(("127.0.0.1", 8000), MyRequestHandler)
server_thread = threading.Thread(target=self.httpd.serve_forever, args=(0.1,))
server_thread.daemon = True
server_thread.start()
# silent Webdriver Manager
os.environ["WDM_LOG_LEVEL"] = "0"
# store driver locally
os.environ["WDM_LOCAL"] = "1"
s = Service(ChromeDriverManager().install())
self.driver = webdriver.Chrome(service=s)
self.driver.get("http://127.0.0.1:8000/OOMAnalyser.html")
def tearDown(self):
self.driver.close()
self.httpd.shutdown()
self.httpd.server_close()
def assert_on_warn(self):
notify_box = self.driver.find_element(By.ID, "notify_box")
try:
warning = notify_box.find_element(
By.CLASS_NAME, "js-notify_box__msg--warning"
)
except NoSuchElementException:
pass
else:
self.fail('Unexpected warning message: "%s"' % warning.text)
def assert_on_error(self):
error = self.get_first_error_msg()
if error:
self.fail('Unexpected error message: "%s"' % error)
for event in self.driver.get_log("browser"):
# ignore favicon.ico errors
if "favicon.ico" in event["message"]:
continue
self.fail('Error on browser console reported: "%s"' % event)
def assert_on_warn_error(self):
self.assert_on_warn()
self.assert_on_error()
def click_analyse_button(self):
analyse = self.driver.find_element(
By.XPATH, '//button[text()="Analyse OOM block"]'
)
analyse.click()
def click_reset_button(self):
reset = self.driver.find_element(By.XPATH, '//button[text()="Reset form"]')
if reset.is_displayed():
reset.click()
else:
new_analysis = self.driver.find_element(
By.XPATH, '//a[contains(text(), "Step 1 - Enter your OOM message")]'
)
new_analysis.click()
self.assert_on_warn_error()
def get_first_error_msg(self):
"""
Return first (oldest) error message from error notification box or an empty
string if no error message exists.
@rtype: str
"""
notify_box = self.driver.find_element(By.ID, "notify_box")
try:
first_error_msg = notify_box.find_element(
By.CLASS_NAME, "js-notify_box__msg--error"
)
return first_error_msg.text
except NoSuchElementException:
return ""
def insert_example(self, select_value):
"""
Select and insert example from the combobox
@param str select_value: Option value to specify the example
"""
textarea = self.driver.find_element(By.ID, "textarea_oom")
self.assertEqual(textarea.get_attribute("value"), "", "Empty textarea expected")
select_element = self.driver.find_element(By.ID, "examples")
select = Select(select_element)
option_values = [o.get_attribute("value") for o in select.options]
self.assertTrue(
select_value in option_values,
"Missing proper option for example %s" % select_value,
)
select.select_by_value(select_value)
self.assertNotEqual(
textarea.get_attribute("value"), "", "Missing OOM text in textarea"
)
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertFalse(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be not displayed",
)
def analyse_oom(self, text):
"""
Insert text and run analysis
:param str text: OOM text to analyse
"""
textarea = self.driver.find_element(By.ID, "textarea_oom")
self.assertEqual(textarea.get_attribute("value"), "", "Empty textarea expected")
textarea.send_keys(text)
self.assertNotEqual(
textarea.get_attribute("value"), "", "Missing OOM text in textarea"
)
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertFalse(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be not displayed",
)
self.click_analyse_button()
def check_results_archlinux_6_1_1(self):
"""Check the results of the analysis of the ArchLinux 6.1.1 example"""
self.assert_on_warn_error()
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertTrue(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be displayed",
)
trigger_proc_name = self.driver.find_element(By.CLASS_NAME, "trigger_proc_name")
self.assertEqual(
trigger_proc_name.text, "doxygen", "Unexpected trigger process name"
)
trigger_proc_pid = self.driver.find_element(By.CLASS_NAME, "trigger_proc_pid")
self.assertEqual(
trigger_proc_pid.text,
"473206",
"Unexpected trigger process pid: --%s--" % trigger_proc_pid.text,
)
trigger_proc_gfp_mask = self.driver.find_element(
By.CLASS_NAME, "trigger_proc_gfp_mask"
)
# 0x140dca will split into
# GFP_HIGHUSER_MOVABLE -> 0x100cca
# (GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKIP_KASAN_POISON | __GFP_SKIP_KASAN_UNPOISON)
# GFP_HIGHUSER
# GFP_USER
# __GFP_RECLAIM
# ___GFP_DIRECT_RECLAIM 0x400
# ___GFP_KSWAPD_RECLAIM 0x800
# __GFP_IO 0x40
# __GFP_FS 0x80
# __GFP_HARDWALL 0x100000
# __GFP_HIGHMEM 0x02
# __GFP_MOVABLE 0x08
# __GFP_SKIP_KASAN_POISON 0x00
# __GFP_SKIP_KASAN_UNPOISON 0x00
# __GFP_COMP 0x40000
# __GFP_ZERO 0x100
# sum: 0x140dca
self.assertEqual(
trigger_proc_gfp_mask.text,
"0x140dca (GFP_HIGHUSER_MOVABLE|__GFP_COMP|__GFP_ZERO)",
"Unexpected GFP Mask",
)
killed_proc_score = self.driver.find_element(By.CLASS_NAME, "killed_proc_score")
self.assertTrue(
not killed_proc_score.text,
"Unexpected statement for OOM score of killed process",
)
swap_cache_kb = self.driver.find_element(By.CLASS_NAME, "swap_cache_kb")
self.assertEqual(swap_cache_kb.text, "99452 kBytes")
swap_used_kb = self.driver.find_element(By.CLASS_NAME, "swap_used_kb")
self.assertEqual(swap_used_kb.text, "25066284 kBytes")
swap_free_kb = self.driver.find_element(By.CLASS_NAME, "swap_free_kb")
self.assertEqual(swap_free_kb.text, "84 kBytes")
swap_total_kb = self.driver.find_element(By.CLASS_NAME, "swap_total_kb")
self.assertEqual(swap_total_kb.text, "25165820 kBytes")
explanation = self.driver.find_element(By.ID, "explanation")
for expected in [
self.text_alloc_failed_below_low_watermark,
self.text_mem_not_heavily_fragmented,
self.text_oom_triggered_automatically,
self.text_swap_space_are_in_use,
]:
self.assertTrue(
expected in explanation.text,
'Missing statement in OOM summary: "%s"' % expected,
)
for unexpected in [
self.text_alloc_failed_no_free_chunks,
self.text_alloc_failed_unknown_reason,
self.text_mem_heavily_fragmented,
self.text_oom_triggered_manually,
self.text_swap_space_not_in_use,
self.text_with_an_oom_score_of,
]:
self.assertTrue(
unexpected not in explanation.text,
'Unexpected statement in OOM summary: "%s"' % unexpected,
)
result_table = self.driver.find_element(By.CLASS_NAME, "result__table")
for expected in [
self.test_swap_swap_total,
]:
self.assertTrue(
expected in result_table.text,
'Missing statement in result table: "%s"' % expected,
)
for unexpected in [
self.test_swap_no_space,
]:
self.assertTrue(
unexpected not in result_table.text,
'Unexpected statement in result table: "%s"' % unexpected,
)
self.assertTrue(
"system has 16461600 kBytes physical memory and 25165820 kBytes swap space."
in explanation.text,
"Physical and swap memory in summary not found",
)
self.assertTrue(
"That's 41627420 kBytes total." in explanation.text,
"Total memory in summary not found",
)
self.assertTrue(
"69 % (11513452 kBytes out of 16461600 kBytes) physical memory"
in explanation.text,
"Used physical memory in summary not found",
)
self.assertTrue(
"99 % (25066284 kBytes out of 25165820 kBytes) swap space"
in explanation.text,
"Used swap space in summary not found",
)
mem_node_info = self.driver.find_element(By.CLASS_NAME, "mem_node_info")
self.assertEqual(
mem_node_info.text[:44],
"Node 0 DMA: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB",
"Unexpected memory chunks",
)
self.assertEqual(
mem_node_info.text[-80:],
"Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB",
"Unexpected memory information about hugepages",
)
mem_watermarks = self.driver.find_element(By.CLASS_NAME, "mem_watermarks")
self.assertEqual(
mem_watermarks.text[:51],
"Node 0 DMA free:13312kB boost:0kB min:64kB low:80kB",
"Unexpected memory watermarks",
)
self.assertEqual(
mem_watermarks.text[-27:],
"lowmem_reserve[]: 0 0 0 0 0",
"Unexpected lowmem_reserve values",
)
header = self.driver.find_element(By.ID, "pstable_header")
self.assertTrue(
"Page Table Bytes" in header.text,
'Missing column header "Page Table Bytes"',
)
self.check_swap_active()
def check_results_rhel7(self):
"""Check the results of the analysis of the RHEL7 example"""
self.assert_on_warn_error()
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertTrue(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be displayed",
)
trigger_proc_name = self.driver.find_element(By.CLASS_NAME, "trigger_proc_name")
self.assertEqual(
trigger_proc_name.text, "sed", "Unexpected trigger process name"
)
trigger_proc_pid = self.driver.find_element(By.CLASS_NAME, "trigger_proc_pid")
self.assertEqual(
trigger_proc_pid.text, "29481", "Unexpected trigger process pid"
)
trigger_proc_gfp_mask = self.driver.find_element(
By.CLASS_NAME, "trigger_proc_gfp_mask"
)
# 0x201da will split into
# GFP_HIGHUSER_MOVABLE 0x200da
# (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL | __GFP_HIGHMEM | __GFP_MOVABLE)
# __GFP_WAIT 0x10
# __GFP_IO 0x40
# __GFP_FS 0x80
# __GFP_HARDWALL 0x20000
# __GFP_HIGHMEM 0x02
# __GFP_MOVABLE 0x08
# __GFP_COLD 0x100
# sum: 0x201da
self.assertEqual(
trigger_proc_gfp_mask.text,
"0x201da (GFP_HIGHUSER_MOVABLE | __GFP_COLD)",
"Unexpected GFP Mask",
)
killed_proc_score = self.driver.find_element(By.CLASS_NAME, "killed_proc_score")
self.assertEqual(
killed_proc_score.text, "651", "Unexpected OOM score of killed process"
)
swap_cache_kb = self.driver.find_element(By.CLASS_NAME, "swap_cache_kb")
self.assertEqual(swap_cache_kb.text, "45368 kBytes")
swap_used_kb = self.driver.find_element(By.CLASS_NAME, "swap_used_kb")
self.assertEqual(swap_used_kb.text, "8343236 kBytes")
swap_free_kb = self.driver.find_element(By.CLASS_NAME, "swap_free_kb")
self.assertEqual(swap_free_kb.text, "0 kBytes")
swap_total_kb = self.driver.find_element(By.CLASS_NAME, "swap_total_kb")
self.assertEqual(swap_total_kb.text, "8388604 kBytes")
explanation = self.driver.find_element(By.ID, "explanation")
for expected in [
self.text_alloc_failed_below_low_watermark,
self.text_mem_not_heavily_fragmented,
self.text_oom_triggered_automatically,
self.text_swap_space_are_in_use,
self.text_with_an_oom_score_of,
]:
self.assertTrue(
expected in explanation.text,
'Missing statement in OOM summary: "%s"' % expected,
)
for unexpected in [
self.text_alloc_failed_no_free_chunks,
self.text_alloc_failed_unknown_reason,
self.text_mem_heavily_fragmented,
self.text_oom_triggered_manually,
self.text_swap_space_not_in_use,
]:
self.assertTrue(
unexpected not in explanation.text,
'Unexpected statement in OOM summary: "%s"' % unexpected,
)
result_table = self.driver.find_element(By.CLASS_NAME, "result__table")
for expected in [
self.test_swap_swap_total,
]:
self.assertTrue(
expected in result_table.text,
'Missing statement in result table: "%s"' % expected,
)
for unexpected in [
self.test_swap_no_space,
]:
self.assertTrue(
unexpected not in result_table.text,
'Unexpected statement in result table: "%s"' % unexpected,
)
self.assertTrue(
"system has 33519336 kBytes physical memory and 8388604 kBytes swap space."
in explanation.text,
"Physical and swap memory in summary not found",
)
self.assertTrue(
"That's 41907940 kBytes total." in explanation.text,
"Total memory in summary not found",
)
self.assertTrue(
"94 % (31705788 kBytes out of 33519336 kBytes) physical memory"
in explanation.text,
"Used physical memory in summary not found",
)
self.assertTrue(
"99 % (8343236 kBytes out of 8388604 kBytes) swap space"
in explanation.text,
"Used swap space in summary not found",
)
mem_node_info = self.driver.find_element(By.CLASS_NAME, "mem_node_info")
self.assertEqual(
mem_node_info.text[:44],
"Node 0 DMA: 0*4kB 0*8kB 0*16kB 0*32kB 2*64kB",
"Unexpected memory chunks",
)
self.assertEqual(
mem_node_info.text[-80:],
"Node 1 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB",
"Unexpected memory information about hugepages",
)
mem_watermarks = self.driver.find_element(By.CLASS_NAME, "mem_watermarks")
self.assertEqual(
mem_watermarks.text[:51],
"Node 0 DMA free:15872kB min:40kB low:48kB high:60kB",
"Unexpected memory watermarks",
)
self.assertEqual(
mem_watermarks.text[-25:],
"lowmem_reserve[]: 0 0 0 0",
"Unexpected lowmem_reserve values",
)
header = self.driver.find_element(By.ID, "pstable_header")
self.assertTrue(
"Page Table Entries" in header.text,
'Missing column header "Page Table Entries"',
)
self.check_swap_active()
def check_results_ubuntu2110(self):
"""Check the results of the analysis of the Ubuntu example"""
trigger_proc_gfp_mask = self.driver.find_element(
By.CLASS_NAME, "trigger_proc_gfp_mask"
)
# 0xcc0 will split into
# GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS)
# __GFP_RECLAIM (___GFP_DIRECT_RECLAIM | ___GFP_KSWAPD_RECLAIM)
# ___GFP_DIRECT_RECLAIM 0x400
# ___GFP_KSWAPD_RECLAIM 0x800
# __GFP_IO 0x40
# __GFP_FS 0x80
# sum: 0xCC0
self.assertEqual(
trigger_proc_gfp_mask.text, "0xcc0 (GFP_KERNEL)", "Unexpected GFP Mask"
)
dirty_pages = self.driver.find_element(By.CLASS_NAME, "dirty_pages")
self.assertEqual(
dirty_pages.text, "633 pages", "Unexpected number of dirty pages"
)
ram_pages = self.driver.find_element(By.CLASS_NAME, "ram_pages")
self.assertEqual(
ram_pages.text, "524158 pages", "Unexpected number of RAM pages"
)
explanation = self.driver.find_element(By.ID, "explanation")
for expected in [
self.text_oom_triggered_manually,
self.text_swap_space_not_in_use,
]:
self.assertTrue(
expected in explanation.text,
'Missing statement in OOM summary: "%s"' % expected,
)
for unexpected in [
self.text_alloc_failed_below_low_watermark,
self.text_alloc_failed_no_free_chunks,
self.text_alloc_failed_unknown_reason,
self.text_mem_heavily_fragmented,
self.text_mem_not_heavily_fragmented,
self.text_oom_triggered_automatically,
self.text_with_an_oom_score_of,
]:
self.assertTrue(
unexpected not in explanation.text,
'Unexpected statement in OOM summary: "%s"' % unexpected,
)
result_table = self.driver.find_element(By.CLASS_NAME, "result__table")
for expected in [
self.test_swap_no_space,
]:
self.assertTrue(
expected in result_table.text,
'Missing statement in result table: "%s"' % expected,
)
for unexpected in [
self.test_swap_swap_total,
]:
self.assertTrue(
unexpected not in result_table.text,
'Unexpected statement in result table: "%s"' % unexpected,
)
self.assertTrue(
"system has 2096632 kBytes physical memory" in explanation.text,
"Physical memory in summary not found",
)
self.assertTrue(
"9 % (209520 kBytes out of 2096632 kBytes) physical memory"
in explanation.text,
"Used physical memory in summary not found",
)
mem_node_info = self.driver.find_element(By.CLASS_NAME, "mem_node_info")
self.assertEqual(
mem_node_info.text[:49],
"Node 0 DMA: 1*4kB (U) 1*8kB (U) 1*16kB (U) 1*32kB",
"Unexpected memory chunks",
)
self.assertEqual(
mem_node_info.text[-80:],
"Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB",
"Unexpected memory information about hugepages",
)
mem_watermarks = self.driver.find_element(By.CLASS_NAME, "mem_watermarks")
self.assertEqual(
mem_watermarks.text[:54],
"Node 0 DMA free:15036kB min:352kB low:440kB high:528kB",
"Unexpected memory watermarks",
)
self.assertEqual(
mem_watermarks.text[-27:],
"lowmem_reserve[]: 0 0 0 0 0",
"Unexpected lowmem_reserve values",
)
header = self.driver.find_element(By.ID, "pstable_header")
self.assertTrue(
"Page Table Bytes" in header.text,
'Missing column header "Page Table Bytes"',
)
self.check_swap_inactive()
def check_swap_inactive(self):
explanation = self.driver.find_element(By.ID, "explanation")
self.assertTrue(
self.text_swap_space_not_in_use in explanation.text,
'Missing statement "%s"' % self.text_swap_space_not_in_use,
)
self.assertTrue(
self.text_swap_space_are_in_use not in explanation.text,
'Unexpected statement "%s"' % self.text_swap_space_are_in_use,
)
def check_swap_active(self):
explanation = self.driver.find_element(By.ID, "explanation")
self.assertTrue(
self.text_swap_space_are_in_use in explanation.text,
'Missing statement "%s"' % self.text_swap_space_are_in_use,
)
def test_010_load_page(self):
"""Test if the page is loading"""
assert "OOMAnalyser" in self.driver.title
def test_020_load_js(self):
"""Test if JS is loaded"""
elem = self.driver.find_element(By.ID, "version")
self.assertIsNotNone(elem.text, "Version statement not set - JS not loaded")
def test_030_insert_and_analyse_rhel7_example(self):
"""Test loading and analysing RHEL7 example"""
self.insert_example("RHEL7")
self.click_analyse_button()
self.check_results_rhel7()
def test_031_insert_and_analyse_ubuntu_example(self):
"""Test loading and analysing Ubuntu 21.10 example"""
self.insert_example("Ubuntu_2110")
self.click_analyse_button()
self.check_results_ubuntu2110()
def test_032_insert_and_analyse_archlinux_example(self):
"""Test loading and analysing ArchLinux 6.1.1 example"""
self.insert_example("ArchLinux")
self.click_analyse_button()
self.check_results_archlinux_6_1_1()
def test_033_empty_textarea(self):
"""Test "Analyse" with empty textarea"""
textarea = self.driver.find_element(By.ID, "textarea_oom")
self.assertEqual(textarea.get_attribute("value"), "", "Empty textarea expected")
# textarea.send_keys(text)
self.assertEqual(
textarea.get_attribute("value"),
"",
"Expected empty text area, but text found",
)
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertFalse(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be not displayed",
)
self.click_analyse_button()
self.assertEqual(
self.get_first_error_msg(),
"ERROR: Empty OOM text. Please insert an OOM message block.",
)
self.click_reset_button()
def test_034_begin_but_no_end(self):
"""Test incomplete OOM text - just the beginning"""
example = """\
sed invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0
sed cpuset=/ mems_allowed=0-1
CPU: 4 PID: 29481 Comm: sed Not tainted 3.10.0-514.6.1.el7.x86_64 #1
"""
self.analyse_oom(example)
self.assertEqual(
self.get_first_error_msg(),
"ERROR: The inserted OOM is incomplete! The initial pattern was "
"found but not the final.",
)
self.click_reset_button()
def test_035_no_begin_but_end(self):
"""Test incomplete OOM text - just the end"""
example = """\
Out of memory: Kill process 6576 (java) score 651 or sacrifice child
Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0kB, shmem-rss:0kB
"""
self.analyse_oom(example)
self.assertEqual(
self.get_first_error_msg(),
"ERROR: Failed to extract kernel version from OOM text",
)
self.click_reset_button()
def test_036_loading_journalctl_input(self):
"""Test loading input from journalctl
The second part of the "Mem-Info:" block as starting with the third
line has not a prefix like the lines before and after it. It is
indented only by a single space.
"""
for prefix in [
"Apr 01 14:13:32 mysrv <kern.warning> kernel:",
"[1234567.654321]",
]:
# prepare example
example_lines = OOMAnalyser.OOMDisplay.example_rhel7.split("\n")
res = []
# unescape #012 - see OOMAnalyser.OOMEntity._rsyslog_unescape_lf()
for line in example_lines:
if "#012" in line:
res.extend(line.split("#012"))
else:
res.append(line)
example_lines = res
res = []
# add date/time prefix except for "Mem-Info:" block
for line in example_lines:
if not OOMAnalyser.OOMEntity.REC_MEMINFO_BLOCK_SECOND_PART.search(line):
line = f"{prefix} {line}"
res.append(line)
example = "\n".join(res)
self.check_meminfo_format_rhel7(
f'Unprocessed example with prefix "{prefix}"', example
)
oom = OOMAnalyser.OOMEntity(example)
self.check_meminfo_format_rhel7(
f'Processed example after OOMEntity() with prefix "{prefix}"', oom.text
)
self.analyse_oom(example)
self.check_results_rhel7()
self.click_reset_button()
def test_040_trigger_proc_space(self):
"""Test trigger process name contains a space"""
example = OOMAnalyser.OOMDisplay.example_rhel7
example = example.replace("sed", "VM Monitoring Task")
self.analyse_oom(example)
self.assert_on_warn_error()
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertTrue(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be displayed",
)
def test_050_kill_proc_space(self):
"""Test killed process name contains a space"""
example = OOMAnalyser.OOMDisplay.example_rhel7
example = example.replace("mysqld", "VM Monitoring Task")
self.analyse_oom(example)
self.assert_on_warn_error()
h3_summary = self.driver.find_element(By.XPATH, '//h3[text()="Summary"]')
self.assertTrue(
h3_summary.is_displayed(),
"Analysis details incl. <h3>Summary</h3> should be displayed",
)
def test_060_removal_of_leading_but_useless_columns_rhel7(self):
"""
Test removal of leading but useless columns with RHEL7 example
In this test, the lines of the "Mem-Info:" block are joined
together with #012 to form a single line. Therefore, the prefix
test must handle the additional leading spaces in these lines.
The selected example tests this behavior.
@see: test_061_removal_of_leading_but_useless_columns_archlinux()
"""
self.analyse_oom(OOMAnalyser.OOMDisplay.example_rhel7)
self.check_results_rhel7()
self.click_reset_button()
for prefix in [
"[11686.888109] ",
"Apr 01 14:13:32 mysrv: ",
"Apr 01 14:13:32 mysrv kernel: ",
"Apr 01 14:13:32 mysrv <kern.warning> kernel: ",
"Apr 01 14:13:32 mysrv kernel: [11686.888109] ",
"kernel:",
"Apr 01 14:13:32 mysrv <kern.warning> kernel:",
]:
lines = OOMAnalyser.OOMDisplay.example_rhel7.split("\n")
lines = ["{}{}".format(prefix, line) for line in lines]
oom_text = "\n".join(lines)
self.analyse_oom(oom_text)
self.check_results_rhel7()
self.click_reset_button()
def test_061_removal_of_leading_but_useless_columns_archlinux(self):
"""
Test removal of leading but useless columns with ArchLinux example
In this test, the lines of the "Mem-Info:" block are not joined
together with #012 to form a line, but are separate lines. Therefore,
the prefix test must handle the additional leading spaces in these
lines. The selected example tests this behavior.
@see: test_060_removal_of_leading_but_useless_columns_rhel7()
"""
self.analyse_oom(OOMAnalyser.OOMDisplay.example_archlinux_6_1_1)
self.check_results_archlinux_6_1_1()
self.click_reset_button()
for prefix in [
"[11686.888109] ",
"Apr 01 14:13:32 mysrv: ",
"Apr 01 14:13:32 mysrv kernel: ",
"Apr 01 14:13:32 mysrv <kern.warning> kernel: ",
"Apr 01 14:13:32 mysrv kernel: [11686.888109] ",
"kernel:",
"Apr 01 14:13:32 mysrv <kern.warning> kernel:",
]:
lines = OOMAnalyser.OOMDisplay.example_archlinux_6_1_1.split("\n")
new_lines = []
for line in lines:
if OOMAnalyser.OOMEntity.REC_MEMINFO_BLOCK_SECOND_PART.search(line):
new_line = "{}{}".format(" " * len(prefix), line)
else:
new_line = "{}{}".format(prefix, line)
new_lines.append(new_line)
oom_text = "\n".join(new_lines)
self.analyse_oom(oom_text)
self.check_results_archlinux_6_1_1()
self.click_reset_button()
def test_070_manually_triggered_OOM(self):
"""Test for manually triggered OOM"""
example = OOMAnalyser.OOMDisplay.example_rhel7
example = example.replace("order=0", "order=-1")
self.analyse_oom(example)
self.assert_on_warn_error()
explanation = self.driver.find_element(By.ID, "explanation")
self.assertTrue(
self.text_oom_triggered_manually in explanation.text,
'Missing statement "%s"' % self.text_oom_triggered_manually,
)
self.assertTrue(
self.text_oom_triggered_automatically not in explanation.text,
'Unexpected statement "%s"' % self.text_oom_triggered_automatically,
)
def test_080_swap_deactivated(self):
"""Test w/o swap or with deactivated swap"""
example = OOMAnalyser.OOMDisplay.example_rhel7
example = example.replace("Total swap = 8388604kB", "Total swap = 0kB")
self.analyse_oom(example)
self.assert_on_warn_error()
self.check_swap_inactive()
self.click_reset_button()
example = OOMAnalyser.OOMDisplay.example_rhel7
example = re.sub(r"\d+ pages in swap cac.*\n*", "", example, re.MULTILINE)
example = re.sub(r"Swap cache stats.*\n*", "", example)
example = re.sub(r"Free swap.*\n*", "", example)
example = re.sub(r"Total swap.*\n*", "", example)
self.analyse_oom(example)
self.assert_on_warn_error()
self.check_swap_inactive()
class TestPython(TestBase):
def test_001_trigger_proc_space(self):
"""Test RE to find name of trigger process"""
first = self.get_first_line(OOMAnalyser.OOMDisplay.example_rhel7)
pattern = OOMAnalyser.OOMAnalyser.oom_result.kconfig.EXTRACT_PATTERN[
"invoked oom-killer"
][0]
rec = re.compile(pattern, re.MULTILINE)
match = rec.search(first)
self.assertTrue(
match,
"Error: re.search('invoked oom-killer') failed for simple process name",
)
first = first.replace("sed", "VM Monitoring Task")
match = rec.search(first)
self.assertTrue(
match,
"Error: re.search('invoked oom-killer') failed for process name with space",
)
def test_002_killed_proc_space(self):
"""Test RE to find name of killed process"""
text = self.get_lines(OOMAnalyser.OOMDisplay.example_rhel7, -2)
pattern = OOMAnalyser.OOMAnalyser.oom_result.kconfig.EXTRACT_PATTERN[
"Process killed by OOM"
][0]
rec = re.compile(pattern, re.MULTILINE)
match = rec.search(text)
self.assertTrue(
match,
"Error: re.search('Process killed by OOM') failed for simple process name",
)
text = text.replace("sed", "VM Monitoring Task")
match = rec.search(text)
self.assertTrue(
match,
"Error: re.search('Process killed by OOM') failed for process name with space",
)
def test_003_OOMEntity_number_of_columns_to_strip(self):
"""Test stripping useless / leading columns"""
oom_entity = OOMAnalyser.OOMEntity(OOMAnalyser.OOMDisplay.example_rhel7)
for pos, line in [
(
1,
"[11686.888109] CPU: 4 PID: 29481 Comm: sed Not tainted 3.10.0-514.6.1.el7.x86_64 #1",
),
(
5,
"Apr 01 14:13:32 mysrv kernel: CPU: 4 PID: 29481 Comm: sed Not tainted 3.10.0-514.6.1.el7.x86_64 #1",
),
(
6,
"Apr 01 14:13:32 mysrv kernel: [11686.888109] CPU: 4 PID: 29481 Comm: sed Not tainted 3.10.0-514.6.1.el7.x86_64 #1",
),
]:
to_strip = oom_entity._number_of_columns_to_strip(line)
self.assertEqual(
to_strip,
pos,
'Calc wrong number of columns to strip for "%s": got: %d, expect: %d'
% (line, to_strip, pos),
)
def test_004_extract_block_from_next_pos(self):
"""Test extracting a single block (all lines till the next line with a colon)"""
oom = OOMAnalyser.OOMEntity(OOMAnalyser.OOMDisplay.example_rhel7)
analyser = OOMAnalyser.OOMAnalyser(oom)
text = analyser._extract_block_from_next_pos("Hardware name:")
expected = """\
Hardware name: HP ProLiant DL385 G7, BIOS A18 12/08/2012
ffff880182272f10 00000000021dcb0a ffff880418207938 ffffffff816861ac
ffff8804182079c8 ffffffff81681157 ffffffff810eab9c ffff8804182fe910
ffff8804182fe928 0000000000000202 ffff880182272f10 ffff8804182079b8