100068
|
1 ;;; bytecomp-testsuite.el
|
|
2
|
|
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Shigeru Fukaya <shigeru.fukaya@gmail.com>
|
|
6 ;; Created: November 2008
|
|
7 ;; Keywords: internal
|
|
8 ;; Human-Keywords: internal
|
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation, either version 3 of the License, or
|
|
15 ;; (at your option) any later version.
|
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;;; Code:
|
|
28 (defconst byte-opt-testsuite-arith-data
|
|
29 '(
|
|
30 ;; some functional tests
|
|
31 (let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c))
|
|
32 (let ((a most-positive-fixnum) (b -2) (c 1.0)) (- a b c))
|
|
33 (let ((a most-positive-fixnum) (b 2) (c 1.0)) (* a b c))
|
|
34 (let ((a 3) (b 2) (c 1.0)) (/ a b c))
|
|
35 (let ((a (+ 1 (expt 2 -64))) (b (expt 2 -65))) (+ a -1 b))
|
|
36 (let ((a (+ 1 (expt 2 -64))) (b (expt 2 -65))) (- a 1 (- b)))
|
|
37 (let ((a (expt 2 -1074)) (b 0.125)) (* a 8 b))
|
|
38 (let ((a 1.0)) (* a 0))
|
|
39 (let ((a 1.0)) (* a 2.0 0))
|
|
40 (let ((a 1.0)) (/ 0 a))
|
|
41 (let ((a 1.0)) (/ 3 a 2))
|
|
42 (let ((a most-positive-fixnum) (b 2.0)) (* a 2 b))
|
|
43 (let ((a 3) (b 2)) (/ a b 1.0))
|
|
44 (/ 3 -1)
|
|
45 (+ 4 3 2 1)
|
|
46 (+ 4 3 2.0 1)
|
|
47 (- 4 3 2 1) ; not new, for reference
|
|
48 (- 4 3 2.0 1) ; not new, for reference
|
|
49 (* 4 3 2 1)
|
|
50 (* 4 3 2.0 1)
|
|
51 (/ 4 3 2 1)
|
|
52 (/ 4 3 2.0 1)
|
|
53 (let ((a 3) (b 2)) (+ a b 1))
|
|
54 (let ((a 3) (b 2)) (+ a b -1))
|
|
55 (let ((a 3) (b 2)) (- a b 1))
|
|
56 (let ((a 3) (b 2)) (- a b -1))
|
|
57 (let ((a 3) (b 2)) (+ a b a 1))
|
|
58 (let ((a 3) (b 2)) (+ a b a -1))
|
|
59 (let ((a 3) (b 2)) (- a b a 1))
|
|
60 (let ((a 3) (b 2)) (- a b a -1))
|
|
61 (let ((a 3) (b 2)) (* a b -1))
|
|
62 (let ((a 3) (b 2)) (* a -1))
|
|
63 (let ((a 3) (b 2)) (/ a b 1))
|
|
64 (let ((a 3) (b 2)) (/ (+ a b) 1))
|
|
65
|
|
66 ;; coverage test
|
|
67 (let ((a 3) (b 2) (c 1.0)) (+))
|
|
68 (let ((a 3) (b 2) (c 1.0)) (+ 2))
|
|
69 (let ((a 3) (b 2) (c 1.0)) (+ 2 0))
|
|
70 (let ((a 3) (b 2) (c 1.0)) (+ 2 0.0))
|
|
71 (let ((a 3) (b 2) (c 1.0)) (+ 2.0))
|
|
72 (let ((a 3) (b 2) (c 1.0)) (+ 2.0 0))
|
|
73 (let ((a 3) (b 2) (c 1.0)) (+ 2.0 0.0))
|
|
74 (let ((a 3) (b 2) (c 1.0)) (+ 0 2))
|
|
75 (let ((a 3) (b 2) (c 1.0)) (+ 0 2.0))
|
|
76 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 2))
|
|
77 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 2.0))
|
|
78 (let ((a 3) (b 2) (c 1.0)) (+ a))
|
|
79 (let ((a 3) (b 2) (c 1.0)) (+ a 0))
|
|
80 (let ((a 3) (b 2) (c 1.0)) (+ a 0.0))
|
|
81 (let ((a 3) (b 2) (c 1.0)) (+ 0 a))
|
|
82 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 a))
|
|
83 (let ((a 3) (b 2) (c 1.0)) (+ c 0))
|
|
84 (let ((a 3) (b 2) (c 1.0)) (+ c 0.0))
|
|
85 (let ((a 3) (b 2) (c 1.0)) (+ 0 c))
|
|
86 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 c))
|
|
87 (let ((a 3) (b 2) (c 1.0)) (+ a b 0 c 0))
|
|
88 (let ((a 3) (b 2) (c 1.0)) (+ 0 a))
|
|
89 (let ((a 3) (b 2) (c 1.0)) (+ 0 a b))
|
|
90 (let ((a 3) (b 2) (c 1.0)) (+ 0 a b c))
|
|
91 (let ((a 3) (b 2) (c 1.0)) (+ 1 2 3))
|
|
92 (let ((a 3) (b 2) (c 1.0)) (+ 3.0 2.0 1))
|
|
93 (let ((a 3) (b 2) (c 1.0)) (+ 3.0 2.0 1 4))
|
|
94 (let ((a 3) (b 2) (c 1.0)) (+ a 1))
|
|
95 (let ((a 3) (b 2) (c 1.0)) (+ a -1))
|
|
96 (let ((a 3) (b 2) (c 1.0)) (+ 1 a))
|
|
97 (let ((a 3) (b 2) (c 1.0)) (+ -1 a))
|
|
98 (let ((a 3) (b 2) (c 1.0)) (+ c 1))
|
|
99 (let ((a 3) (b 2) (c 1.0)) (+ c -1))
|
|
100 (let ((a 3) (b 2) (c 1.0)) (+ 1 c))
|
|
101 (let ((a 3) (b 2) (c 1.0)) (+ -1 c))
|
|
102 (let ((a 3) (b 2) (c 1.0)) (+ a b 0))
|
|
103 (let ((a 3) (b 2) (c 1.0)) (+ a b 1))
|
|
104 (let ((a 3) (b 2) (c 1.0)) (+ a b -1))
|
|
105 (let ((a 3) (b 2) (c 1.0)) (+ a b 2))
|
|
106 (let ((a 3) (b 2) (c 1.0)) (+ 1 a b c))
|
|
107 (let ((a 3) (b 2) (c 1.0)) (+ a b c 0))
|
|
108 (let ((a 3) (b 2) (c 1.0)) (+ a b c 1))
|
|
109 (let ((a 3) (b 2) (c 1.0)) (+ a b c -1))
|
|
110
|
|
111 (let ((a 3) (b 2) (c 1.0)) (-))
|
|
112 (let ((a 3) (b 2) (c 1.0)) (- 2))
|
|
113 (let ((a 3) (b 2) (c 1.0)) (- 2 0))
|
|
114 (let ((a 3) (b 2) (c 1.0)) (- 2 0.0))
|
|
115 (let ((a 3) (b 2) (c 1.0)) (- 2.0))
|
|
116 (let ((a 3) (b 2) (c 1.0)) (- 2.0 0))
|
|
117 (let ((a 3) (b 2) (c 1.0)) (- 2.0 0.0))
|
|
118 (let ((a 3) (b 2) (c 1.0)) (- 0 2))
|
|
119 (let ((a 3) (b 2) (c 1.0)) (- 0 2.0))
|
|
120 (let ((a 3) (b 2) (c 1.0)) (- 0.0 2))
|
|
121 (let ((a 3) (b 2) (c 1.0)) (- 0.0 2.0))
|
|
122 (let ((a 3) (b 2) (c 1.0)) (- a))
|
|
123 (let ((a 3) (b 2) (c 1.0)) (- a 0))
|
|
124 (let ((a 3) (b 2) (c 1.0)) (- a 0.0))
|
|
125 (let ((a 3) (b 2) (c 1.0)) (- 0 a))
|
|
126 (let ((a 3) (b 2) (c 1.0)) (- 0.0 a))
|
|
127 (let ((a 3) (b 2) (c 1.0)) (- c 0))
|
|
128 (let ((a 3) (b 2) (c 1.0)) (- c 0.0))
|
|
129 (let ((a 3) (b 2) (c 1.0)) (- 0 c))
|
|
130 (let ((a 3) (b 2) (c 1.0)) (- 0.0 c))
|
|
131 (let ((a 3) (b 2) (c 1.0)) (- a b 0 c 0))
|
|
132 (let ((a 3) (b 2) (c 1.0)) (- 0 a))
|
|
133 (let ((a 3) (b 2) (c 1.0)) (- 0 a b))
|
|
134 (let ((a 3) (b 2) (c 1.0)) (- 0 a b c))
|
|
135 (let ((a 3) (b 2) (c 1.0)) (- 1 2 3))
|
|
136 (let ((a 3) (b 2) (c 1.0)) (- 3.0 2.0 1))
|
|
137 (let ((a 3) (b 2) (c 1.0)) (- 3.0 2.0 1 4))
|
|
138 (let ((a 3) (b 2) (c 1.0)) (- a 1))
|
|
139 (let ((a 3) (b 2) (c 1.0)) (- a -1))
|
|
140 (let ((a 3) (b 2) (c 1.0)) (- 1 a))
|
|
141 (let ((a 3) (b 2) (c 1.0)) (- -1 a))
|
|
142 (let ((a 3) (b 2) (c 1.0)) (- c 1))
|
|
143 (let ((a 3) (b 2) (c 1.0)) (- c -1))
|
|
144 (let ((a 3) (b 2) (c 1.0)) (- 1 c))
|
|
145 (let ((a 3) (b 2) (c 1.0)) (- -1 c))
|
|
146 (let ((a 3) (b 2) (c 1.0)) (- a b 0))
|
|
147 (let ((a 3) (b 2) (c 1.0)) (- a b 1))
|
|
148 (let ((a 3) (b 2) (c 1.0)) (- a b -1))
|
|
149 (let ((a 3) (b 2) (c 1.0)) (- a b 2))
|
|
150 (let ((a 3) (b 2) (c 1.0)) (- 1 a b c))
|
|
151 (let ((a 3) (b 2) (c 1.0)) (- a b c 0))
|
|
152 (let ((a 3) (b 2) (c 1.0)) (- a b c 1))
|
|
153 (let ((a 3) (b 2) (c 1.0)) (- a b c -1))
|
|
154
|
|
155 (let ((a 3) (b 2) (c 1.0)) (*))
|
|
156 (let ((a 3) (b 2) (c 1.0)) (* 2))
|
|
157 (let ((a 3) (b 2) (c 1.0)) (* 2 0))
|
|
158 (let ((a 3) (b 2) (c 1.0)) (* 2 0.0))
|
|
159 (let ((a 3) (b 2) (c 1.0)) (* 2.0))
|
|
160 (let ((a 3) (b 2) (c 1.0)) (* 2.0 0))
|
|
161 (let ((a 3) (b 2) (c 1.0)) (* 2.0 0.0))
|
|
162 (let ((a 3) (b 2) (c 1.0)) (* 0 2))
|
|
163 (let ((a 3) (b 2) (c 1.0)) (* 0 2.0))
|
|
164 (let ((a 3) (b 2) (c 1.0)) (* 0.0 2))
|
|
165 (let ((a 3) (b 2) (c 1.0)) (* 0.0 2.0))
|
|
166 (let ((a 3) (b 2) (c 1.0)) (* a))
|
|
167 (let ((a 3) (b 2) (c 1.0)) (* a 0))
|
|
168 (let ((a 3) (b 2) (c 1.0)) (* a 0.0))
|
|
169 (let ((a 3) (b 2) (c 1.0)) (* 0 a))
|
|
170 (let ((a 3) (b 2) (c 1.0)) (* 0.0 a))
|
|
171 (let ((a 3) (b 2) (c 1.0)) (* c 0))
|
|
172 (let ((a 3) (b 2) (c 1.0)) (* c 0.0))
|
|
173 (let ((a 3) (b 2) (c 1.0)) (* 0 c))
|
|
174 (let ((a 3) (b 2) (c 1.0)) (* 0.0 c))
|
|
175 (let ((a 3) (b 2) (c 1.0)) (* a b 0 c 0))
|
|
176 (let ((a 3) (b 2) (c 1.0)) (* 0 a))
|
|
177 (let ((a 3) (b 2) (c 1.0)) (* 0 a b))
|
|
178 (let ((a 3) (b 2) (c 1.0)) (* 0 a b c))
|
|
179 (let ((a 3) (b 2) (c 1.0)) (* 1 2 3))
|
|
180 (let ((a 3) (b 2) (c 1.0)) (* 3.0 2.0 1))
|
|
181 (let ((a 3) (b 2) (c 1.0)) (* 3.0 2.0 1 4))
|
|
182 (let ((a 3) (b 2) (c 1.0)) (* a 1))
|
|
183 (let ((a 3) (b 2) (c 1.0)) (* a -1))
|
|
184 (let ((a 3) (b 2) (c 1.0)) (* 1 a))
|
|
185 (let ((a 3) (b 2) (c 1.0)) (* -1 a))
|
|
186 (let ((a 3) (b 2) (c 1.0)) (* c 1))
|
|
187 (let ((a 3) (b 2) (c 1.0)) (* c -1))
|
|
188 (let ((a 3) (b 2) (c 1.0)) (* 1 c))
|
|
189 (let ((a 3) (b 2) (c 1.0)) (* -1 c))
|
|
190 (let ((a 3) (b 2) (c 1.0)) (* a b 0))
|
|
191 (let ((a 3) (b 2) (c 1.0)) (* a b 1))
|
|
192 (let ((a 3) (b 2) (c 1.0)) (* a b -1))
|
|
193 (let ((a 3) (b 2) (c 1.0)) (* a b 2))
|
|
194 (let ((a 3) (b 2) (c 1.0)) (* 1 a b c))
|
|
195 (let ((a 3) (b 2) (c 1.0)) (* a b c 0))
|
|
196 (let ((a 3) (b 2) (c 1.0)) (* a b c 1))
|
|
197 (let ((a 3) (b 2) (c 1.0)) (* a b c -1))
|
|
198
|
|
199 (let ((a 3) (b 2) (c 1.0)) (/))
|
|
200 (let ((a 3) (b 2) (c 1.0)) (/ 2))
|
|
201 (let ((a 3) (b 2) (c 1.0)) (/ 2 0))
|
|
202 (let ((a 3) (b 2) (c 1.0)) (/ 2 0.0))
|
|
203 (let ((a 3) (b 2) (c 1.0)) (/ 2.0))
|
|
204 (let ((a 3) (b 2) (c 1.0)) (/ 2.0 0))
|
|
205 (let ((a 3) (b 2) (c 1.0)) (/ 2.0 0.0))
|
|
206 (let ((a 3) (b 2) (c 1.0)) (/ 0 2))
|
|
207 (let ((a 3) (b 2) (c 1.0)) (/ 0 2.0))
|
|
208 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 2))
|
|
209 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 2.0))
|
|
210 (let ((a 3) (b 2) (c 1.0)) (/ a))
|
|
211 (let ((a 3) (b 2) (c 1.0)) (/ a 0))
|
|
212 (let ((a 3) (b 2) (c 1.0)) (/ a 0.0))
|
|
213 (let ((a 3) (b 2) (c 1.0)) (/ 0 a))
|
|
214 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 a))
|
|
215 (let ((a 3) (b 2) (c 1.0)) (/ c 0))
|
|
216 (let ((a 3) (b 2) (c 1.0)) (/ c 0.0))
|
|
217 (let ((a 3) (b 2) (c 1.0)) (/ 0 c))
|
|
218 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 c))
|
|
219 (let ((a 3) (b 2) (c 1.0)) (/ a b 0 c 0))
|
|
220 (let ((a 3) (b 2) (c 1.0)) (/ 0 a))
|
|
221 (let ((a 3) (b 2) (c 1.0)) (/ 0 a b))
|
|
222 (let ((a 3) (b 2) (c 1.0)) (/ 0 a b c))
|
|
223 (let ((a 3) (b 2) (c 1.0)) (/ 1 2 3))
|
|
224 (let ((a 3) (b 2) (c 1.0)) (/ 3.0 2.0 1))
|
|
225 (let ((a 3) (b 2) (c 1.0)) (/ 3.0 2.0 1 4))
|
|
226 (let ((a 3) (b 2) (c 1.0)) (/ a 1))
|
|
227 (let ((a 3) (b 2) (c 1.0)) (/ a -1))
|
|
228 (let ((a 3) (b 2) (c 1.0)) (/ 1 a))
|
|
229 (let ((a 3) (b 2) (c 1.0)) (/ -1 a))
|
|
230 (let ((a 3) (b 2) (c 1.0)) (/ c 1))
|
|
231 (let ((a 3) (b 2) (c 1.0)) (/ c -1))
|
|
232 (let ((a 3) (b 2) (c 1.0)) (/ 1 c))
|
|
233 (let ((a 3) (b 2) (c 1.0)) (/ -1 c))
|
|
234 (let ((a 3) (b 2) (c 1.0)) (/ a b 0))
|
|
235 (let ((a 3) (b 2) (c 1.0)) (/ a b 1))
|
|
236 (let ((a 3) (b 2) (c 1.0)) (/ a b -1))
|
|
237 (let ((a 3) (b 2) (c 1.0)) (/ a b 2))
|
|
238 (let ((a 3) (b 2) (c 1.0)) (/ 1 a b c))
|
|
239 (let ((a 3) (b 2) (c 1.0)) (/ a b c 0))
|
|
240 (let ((a 3) (b 2) (c 1.0)) (/ a b c 1))
|
|
241 (let ((a 3) (b 2) (c 1.0)) (/ a b c -1)))
|
|
242 "List of expression for test.
|
|
243 Each element will be executed by interpreter and with
|
|
244 bytecompiled code, and their results are compared.")
|
|
245
|
|
246
|
|
247 (defun bytecomp-testsuite-run ()
|
|
248 "Run bytecomp test suite."
|
|
249 (interactive)
|
|
250 (with-output-to-temp-buffer "*bytecomp test*"
|
|
251 (byte-opt-testsuite--run-arith)
|
|
252 (message "All byte-opt tests finished successfully.")))
|
|
253
|
|
254
|
|
255 (defun byte-opt-testsuite--run-arith (&optional arg)
|
|
256 "Unit test for byte-opt arithmetic operations.
|
|
257 Subtests signal errors if something goes wrong."
|
|
258 (interactive "P")
|
|
259 (let ((print-escape-nonascii t)
|
|
260 (print-escape-newlines t)
|
|
261 (print-quoted t)
|
|
262 v0 v1
|
|
263 indent-tabs-mode
|
|
264 (patterns byte-opt-testsuite-arith-data))
|
|
265 (mapc
|
|
266 (lambda (pat)
|
|
267 (condition-case nil
|
|
268 (setq v0 (eval pat))
|
|
269 (error (setq v0 nil)))
|
|
270 (condition-case nil
|
|
271 (setq v1 (funcall (byte-compile (list 'lambda nil pat))))
|
|
272 (error (setq v1 nil)))
|
|
273 (princ (format "%s" pat))
|
|
274 (if (equal v0 v1)
|
|
275 (princ (format " --> %s, OK\n" v1))
|
|
276 (princ (format " --> %s, NG\n" v0))
|
|
277 (princ (format " --> %s\n" v1))
|
|
278 (error "Arithmetic test failed!")))
|
|
279 patterns)))
|
|
280
|
|
281 (provide 'byte-opt-testsuite)
|
100087
|
282
|
|
283 ;; arch-tag: 01cb2664-5e7f-4213-ace0-91447d70b7dc
|