Debian Codegraph @

test/runAllTests_leak.praat

raw
1 # Praat script runAllTests_leak.praat
2 # Paul Boersma 2020-12-28
3 # 2024-12-01 writing settings to UTF-8 for Praat 7
4 # 2025-08-16 make more reproducible
5 #
6 # This script runs all Praat scripts in its subdirectories twice,
7 # and reports its suspicions of memory leaks.
8 # To see whether a leak actually exists, run the suspected script
9 # multiple times from the script window, each time followed by `Report memory use`.
10
11 Text writing settings: "UTF-8"
12 if macintosh
13 Text reading settings: "try UTF-8, then MacRoman"
14 elif windows
15 Text reading settings: "try UTF-8, then Windows Latin-1"
16 elif unix
17 Text reading settings: "try UTF-8, then ISO Latin-1"
18 else
19 exitScript: "Unknown operating system."
20 endif
21
22 writeInfoLine: "Running all tests twice..."
23
24 # Warm up.
25 strings_before = 0
26 tensors_before = 0
27 things_before = 0
28 other_before = 0
29 strings_after = 0
30 tensors_after = 0
31 things_after = 0
32 other_after = 0
33
34 leakReport$ = ""
35
36 procedure doScript: .path$
37 runScript: .path$
38 Erase all
39 writeInfo ()
40
41 memoryReport$ = Report memory use
42 memoryReport$ = Report memory use
43 strings_before = extractNumber (memoryReport$, "Strings:")
44 arrays_before = extractNumber (memoryReport$, "Tensors:")
45 things_before = extractNumber (memoryReport$, "Things:")
46 other_before = extractNumber (memoryReport$, "Other:")
47
48 runScript: .path$
49 Erase all
50 writeInfo ()
51
52 memoryReport$ = Report memory use
53 strings_after = extractNumber (memoryReport$, "Strings:")
54 arrays_after = extractNumber (memoryReport$, "Tensors:")
55 things_after = extractNumber (memoryReport$, "Things:")
56 other_after = extractNumber (memoryReport$, "Other:")
57
58 if strings_after <> strings_before or arrays_after <> arrays_before or
59 ... things_after <> things_before or other_after <> other_before
60 appendInfoLine ()
61 leakReport$ = leakReport$ + "Leaking in " + .path$ + ":" + newline$
62 leakReport$ = leakReport$ + " Strings: " + string$ (strings_before) + " " + string$ (strings_after) + newline$
63 leakReport$ = leakReport$ + " Tensors: " + string$ (tensors_before) + " " + string$ (tensors_after) + newline$
64 leakReport$ = leakReport$ + " Things: " + string$ (things_before) + " " + string$ (things_after) + newline$
65 leakReport$ = leakReport$ + " Other: " + string$ (other_before) + " " + string$ (other_after) + newline$
66 endif
67 endproc
68
69 topPath$ = "."
70 topFolderNames$# = folderNames$# (topPath$)
71 for topFolder to size (topFolderNames$#)
72 topFolderName$ = topFolderNames$# [topFolder]
73 if topFolderName$ <> "manually" and topFolderName$ <> "speed"
74 topFolderPath$ = topPath$ + "/" + topFolderName$
75 @runFilesInFolder: topFolderPath$
76 subfolderNames$# = folderNames$# (topFolderPath$ + "/*")
77 for subfolder to size (subfolderNames$#)
78 subFolderPath$ = topFolderPath$ + "/" + subfolderNames$# [subfolder]
79 @runFilesInFolder: subFolderPath$
80 endfor
81 endif
82 endfor
83
84 procedure runFilesInFolder: .folderPath$
85 .fileNames$# = fileNames$# (.folderPath$ + "/*.praat")
86 for .file to size (.fileNames$#)
87 .filePath$ = .folderPath$ + "/" + .fileNames$# [.file]
88 appendInfoLine: "### executing ", .filePath$, ":"
89 #
90 # The following two lines aim at making the test reproducible.
91 # That is, the test should give the same result on different
92 # computers and different platforms and at different times.
93 # The random seed is allowed to change with the Praat release;
94 # just run all the tests if you change the random seed,
95 # even if there was no change in the Praat source code.
96 # This is because the success of some precision tests
97 # has been reported (by maintainers) to depend on the random state.
98 # Also make sure that the random seed is the same
99 # for the other two "runAlltests" scripts.
100 #
101 random_initializeWithSeedUnsafelyButPredictably (5489)
102 Debug multi-threading: "yes", 8, 0, "no" ; eight threads for everybody
103 @doScript: .filePath$
104 endfor
105 #
106 # Restore normal computer, platform- and time-specific behaviour.
107 #
108 random_initializeSafelyAndUnpredictably()
109 Debug multi-threading: "yes", 0, 0, "no"
110 endproc
111
112 writeInfoLine: " ALL PRAAT TESTS WENT OK"
113 appendInfoLine: ""
114 line$ [5] = " ##### ##### ##### #####"
115 line$ [8] = " ##### ##### #######"
116 line$ [1] = " ###### ##### #####"
117 line$ [2] = " ############## ##### #####"
118 line$ [4] = " ##### ##### ##### #####"
119 line$ [7] = " ##### ##### #########"
120 line$ [9] = " ##### ##### #####"
121 line$ [3] = " ##### ##### ##### #####"
122 line$ [6] = " ##### ##### ##### #####"
123 for line from 1 to 9
124 appendInfoLine: line$ [line]
125 endfor
126 for line from 1 to 8
127 appendInfoLine: line$ [9 - line]
128 endfor
129 appendInfoLine: leakReport$