|
1 | 1 | #lang racket/base |
2 | 2 |
|
3 | | -(require racket/contract/base |
4 | | - racket/string |
5 | | - rackunit |
6 | | - resyntax/default-recommendations/analyzers/identifier-usage |
7 | | - resyntax/default-recommendations/analyzers/variable-mutability |
8 | | - resyntax/default-recommendations/analyzers/ignored-result-values |
9 | | - resyntax/default-recommendations/analyzers/function-expression-analyzer |
10 | | - resyntax/private/analysis |
11 | | - resyntax/private/source) |
12 | 3 |
|
13 | | -;; Load tests for expansion analyzers to ensure they can handle large files |
14 | | -;; within reasonable timeouts. These tests are designed to catch severe |
15 | | -;; performance regressions where analyzers would take minutes or hang on |
16 | | -;; moderately large files. |
| 4 | +(module+ test |
| 5 | + (require racket/string |
| 6 | + rackunit |
| 7 | + resyntax/default-recommendations/analyzers/identifier-usage |
| 8 | + resyntax/default-recommendations/analyzers/variable-mutability |
| 9 | + resyntax/default-recommendations/analyzers/ignored-result-values |
| 10 | + resyntax/default-recommendations/analyzers/function-expression-analyzer |
| 11 | + resyntax/private/analyzer |
| 12 | + resyntax/private/source) |
17 | 13 |
|
18 | | -(define timeout-ms 30000) ; 30 second timeout for load tests |
| 14 | + ;; Load tests for expansion analyzers to ensure they can handle large files |
| 15 | + ;; within reasonable timeouts. These tests are designed to catch severe |
| 16 | + ;; performance regressions where analyzers would take minutes or hang on |
| 17 | + ;; moderately large files. |
19 | 18 |
|
20 | | -;; Generate a large test file with many definitions and function calls. |
21 | | -;; This creates a file with approximately 300+ lines of code with various |
22 | | -;; constructs that analyzers need to process. The file is large enough to |
23 | | -;; exercise analyzer performance but small enough to complete in reasonable time. |
24 | | -(define (generate-large-test-program) |
25 | | - (string-join |
26 | | - (append |
27 | | - (list "#lang racket/base" |
28 | | - "" |
29 | | - "(require racket/list racket/string)" |
30 | | - "") |
31 | | - ;; Generate many function definitions |
32 | | - (for/list ([i (in-range 25)]) |
33 | | - (format "(define (func~a x y) |
| 19 | + (define timeout-ms 30000) ; 30 second timeout for load tests |
| 20 | + |
| 21 | + ;; Generate a large test file with many definitions and function calls. |
| 22 | + ;; This creates a file with approximately 300+ lines of code with various |
| 23 | + ;; constructs that analyzers need to process. The file is large enough to |
| 24 | + ;; exercise analyzer performance but small enough to complete in reasonable time. |
| 25 | + (define (generate-large-test-program) |
| 26 | + (string-join |
| 27 | + (append |
| 28 | + (list "#lang racket/base" |
| 29 | + "" |
| 30 | + "(require racket/list racket/string)" |
| 31 | + "") |
| 32 | + ;; Generate many function definitions |
| 33 | + (for/list ([i (in-range 25)]) |
| 34 | + (format "(define (func~a x y) |
34 | 35 | (let ([a (+ x y)] |
35 | 36 | [b (* x y)]) |
36 | 37 | (if (> a b) |
37 | 38 | (+ a b) |
38 | 39 | (* a b))))" i)) |
39 | | - (list "") |
40 | | - ;; Generate many variable definitions |
41 | | - (for/list ([i (in-range 30)]) |
42 | | - (format "(define var~a ~a)" i i)) |
43 | | - (list "") |
44 | | - ;; Generate many mutable variables with assignments |
45 | | - (for/list ([i (in-range 20)]) |
46 | | - (format "(define mut~a 0) |
| 40 | + (list "") |
| 41 | + ;; Generate many variable definitions |
| 42 | + (for/list ([i (in-range 30)]) |
| 43 | + (format "(define var~a ~a)" i i)) |
| 44 | + (list "") |
| 45 | + ;; Generate many mutable variables with assignments |
| 46 | + (for/list ([i (in-range 20)]) |
| 47 | + (format "(define mut~a 0) |
47 | 48 | (set! mut~a ~a)" i i i)) |
48 | | - (list "") |
49 | | - ;; Generate function calls with various patterns |
50 | | - (for/list ([i (in-range 25)]) |
51 | | - (format "(void (func~a var~a (+ var~a ~a)))" |
52 | | - (modulo i 25) |
53 | | - (modulo i 30) |
54 | | - (modulo (+ i 1) 30) |
55 | | - i)) |
56 | | - (list "") |
57 | | - ;; Generate nested expressions with ignored results |
58 | | - (for/list ([i (in-range 15)]) |
59 | | - (format "(begin |
| 49 | + (list "") |
| 50 | + ;; Generate function calls with various patterns |
| 51 | + (for/list ([i (in-range 25)]) |
| 52 | + (format "(void (func~a var~a (+ var~a ~a)))" |
| 53 | + (modulo i 25) |
| 54 | + (modulo i 30) |
| 55 | + (modulo (+ i 1) 30) |
| 56 | + i)) |
| 57 | + (list "") |
| 58 | + ;; Generate nested expressions with ignored results |
| 59 | + (for/list ([i (in-range 15)]) |
| 60 | + (format "(begin |
60 | 61 | (+ ~a ~a) |
61 | 62 | (void ~a))" i (+ i 1) i))) |
62 | | - "\n")) |
| 63 | + "\n")) |
63 | 64 |
|
64 | | -(define large-test-source (string-source (generate-large-test-program))) |
| 65 | + (define large-test-source (string-source (generate-large-test-program))) |
65 | 66 |
|
66 | | -(test-case "identifier-usage-analyzer load test" |
67 | | - ;; This test ensures the identifier-usage-analyzer can analyze a large file |
68 | | - ;; within the timeout period. |
69 | | - (define start-time (current-inexact-milliseconds)) |
70 | | - (define analysis |
71 | | - (source-analyze large-test-source |
72 | | - #:analyzers (list identifier-usage-analyzer) |
73 | | - #:timeout-ms timeout-ms)) |
74 | | - (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
75 | | - |
76 | | - ;; Verify the analysis completed successfully |
77 | | - (check-true (source-code-analysis? analysis)) |
78 | | - |
79 | | - ;; Verify it completed within the timeout (with some margin) |
80 | | - (check-true (< elapsed-ms timeout-ms) |
81 | | - (format "identifier-usage-analyzer took ~a ms, expected < ~a ms" |
82 | | - elapsed-ms |
83 | | - timeout-ms))) |
| 67 | + ;; Expand the test source once and reuse for all tests |
| 68 | + (define expanded-syntax |
| 69 | + (parameterize ([current-namespace (make-base-namespace)]) |
| 70 | + (source-expand large-test-source))) |
84 | 71 |
|
85 | | -(test-case "variable-mutability-analyzer load test" |
86 | | - ;; This test ensures the variable-mutability-analyzer can analyze a large file |
87 | | - ;; within the timeout period. |
88 | | - (define start-time (current-inexact-milliseconds)) |
89 | | - (define analysis |
90 | | - (source-analyze large-test-source |
91 | | - #:analyzers (list variable-mutability-analyzer) |
92 | | - #:timeout-ms timeout-ms)) |
93 | | - (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
94 | | - |
95 | | - ;; Verify the analysis completed successfully |
96 | | - (check-true (source-code-analysis? analysis)) |
97 | | - |
98 | | - ;; Verify it completed within the timeout (with some margin) |
99 | | - (check-true (< elapsed-ms timeout-ms) |
100 | | - (format "variable-mutability-analyzer took ~a ms, expected < ~a ms" |
101 | | - elapsed-ms |
102 | | - timeout-ms))) |
| 72 | + (test-case "identifier-usage-analyzer load test" |
| 73 | + ;; This test ensures the identifier-usage-analyzer can analyze a large file |
| 74 | + ;; within the timeout period. |
| 75 | + (define-values (result cpu-time real-time gc-time) |
| 76 | + (time-apply expansion-analyze (list identifier-usage-analyzer expanded-syntax))) |
| 77 | + |
| 78 | + ;; Verify it completed within the timeout |
| 79 | + (check-true (< real-time timeout-ms) |
| 80 | + (format "identifier-usage-analyzer took ~a ms, expected < ~a ms" |
| 81 | + real-time |
| 82 | + timeout-ms))) |
103 | 83 |
|
104 | | -(test-case "ignored-result-values-analyzer load test" |
105 | | - ;; This test ensures the ignored-result-values-analyzer can analyze a large file |
106 | | - ;; within the timeout period. |
107 | | - (define start-time (current-inexact-milliseconds)) |
108 | | - (define analysis |
109 | | - (source-analyze large-test-source |
110 | | - #:analyzers (list ignored-result-values-analyzer) |
111 | | - #:timeout-ms timeout-ms)) |
112 | | - (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
113 | | - |
114 | | - ;; Verify the analysis completed successfully |
115 | | - (check-true (source-code-analysis? analysis)) |
116 | | - |
117 | | - ;; Verify it completed within the timeout (with some margin) |
118 | | - (check-true (< elapsed-ms timeout-ms) |
119 | | - (format "ignored-result-values-analyzer took ~a ms, expected < ~a ms" |
120 | | - elapsed-ms |
121 | | - timeout-ms))) |
| 84 | + (test-case "variable-mutability-analyzer load test" |
| 85 | + ;; This test ensures the variable-mutability-analyzer can analyze a large file |
| 86 | + ;; within the timeout period. |
| 87 | + (define-values (result cpu-time real-time gc-time) |
| 88 | + (time-apply expansion-analyze (list variable-mutability-analyzer expanded-syntax))) |
| 89 | + |
| 90 | + ;; Verify it completed within the timeout |
| 91 | + (check-true (< real-time timeout-ms) |
| 92 | + (format "variable-mutability-analyzer took ~a ms, expected < ~a ms" |
| 93 | + real-time |
| 94 | + timeout-ms))) |
122 | 95 |
|
123 | | -(test-case "function-expression-analyzer load test" |
124 | | - ;; This test ensures the function-expression-analyzer can analyze a large file |
125 | | - ;; within the timeout period. |
126 | | - (define start-time (current-inexact-milliseconds)) |
127 | | - (define analysis |
128 | | - (source-analyze large-test-source |
129 | | - #:analyzers (list function-expression-analyzer) |
130 | | - #:timeout-ms timeout-ms)) |
131 | | - (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
132 | | - |
133 | | - ;; Verify the analysis completed successfully |
134 | | - (check-true (source-code-analysis? analysis)) |
135 | | - |
136 | | - ;; Verify it completed within the timeout (with some margin) |
137 | | - (check-true (< elapsed-ms timeout-ms) |
138 | | - (format "function-expression-analyzer took ~a ms, expected < ~a ms" |
139 | | - elapsed-ms |
140 | | - timeout-ms))) |
| 96 | + (test-case "ignored-result-values-analyzer load test" |
| 97 | + ;; This test ensures the ignored-result-values-analyzer can analyze a large file |
| 98 | + ;; within the timeout period. |
| 99 | + (define-values (result cpu-time real-time gc-time) |
| 100 | + (time-apply expansion-analyze (list ignored-result-values-analyzer expanded-syntax))) |
| 101 | + |
| 102 | + ;; Verify it completed within the timeout |
| 103 | + (check-true (< real-time timeout-ms) |
| 104 | + (format "ignored-result-values-analyzer took ~a ms, expected < ~a ms" |
| 105 | + real-time |
| 106 | + timeout-ms))) |
141 | 107 |
|
142 | | -(test-case "all analyzers together load test" |
143 | | - ;; This test ensures all analyzers can work together on a large file |
144 | | - ;; within the timeout period. |
145 | | - (define all-analyzers |
146 | | - (list identifier-usage-analyzer |
147 | | - variable-mutability-analyzer |
148 | | - ignored-result-values-analyzer |
149 | | - function-expression-analyzer)) |
150 | | - |
151 | | - (define start-time (current-inexact-milliseconds)) |
152 | | - (define analysis |
153 | | - (source-analyze large-test-source |
154 | | - #:analyzers all-analyzers |
155 | | - #:timeout-ms timeout-ms)) |
156 | | - (define elapsed-ms (- (current-inexact-milliseconds) start-time)) |
157 | | - |
158 | | - ;; Verify the analysis completed successfully |
159 | | - (check-true (source-code-analysis? analysis)) |
160 | | - |
161 | | - ;; Verify it completed within the timeout (with some margin) |
162 | | - (check-true (< elapsed-ms timeout-ms) |
163 | | - (format "all analyzers together took ~a ms, expected < ~a ms" |
164 | | - elapsed-ms |
165 | | - timeout-ms))) |
| 108 | + (test-case "function-expression-analyzer load test" |
| 109 | + ;; This test ensures the function-expression-analyzer can analyze a large file |
| 110 | + ;; within the timeout period. |
| 111 | + (define-values (result cpu-time real-time gc-time) |
| 112 | + (time-apply expansion-analyze (list function-expression-analyzer expanded-syntax))) |
| 113 | + |
| 114 | + ;; Verify it completed within the timeout |
| 115 | + (check-true (< real-time timeout-ms) |
| 116 | + (format "function-expression-analyzer took ~a ms, expected < ~a ms" |
| 117 | + real-time |
| 118 | + timeout-ms)))) |
0 commit comments