-
Notifications
You must be signed in to change notification settings - Fork 91
/
0test.el
212 lines (192 loc) · 7.3 KB
/
0test.el
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
;; DESCRIPTION: Run verilog-mode tests, as part of "make test"
;;
;; Copyright 2008-2024 by Michael McNamara and Wilson Snyder. This package
;; is free software; you can redistribute it and/or modify it under the
;; terms of either the GNU Lesser General Public License or the Perl
;; Artistic License.
;;
;; VERILOG_MODE_DEBUG=1 # Enable verilog-debug
;; VERILOG_MODE_NO_INDENTS=1 # Disable indent checks
;; VERILOG_MODE_TEST_FILE=filename.v # Run only specified test
;; VERILOG_MODE_START_FILE=filename.v # Start at specified test
;; VERILOG_MODE_THREAD=#of# # Multithreaded testing
;; VERILOG_MODE_PROFILE=1 # Profile - see batch_prof.el
;; HARNESS_UPDATE_GOLDEN=1 # Update golden reference files
(defvar diff-flags "-u")
(defvar vl-threading (and (not (getenv "VERILOG_MODE_TEST_FILE"))
(getenv "VERILOG_MODE_THREAD")))
(defun global-replace-regexp (from to)
(goto-char (point-min))
(while (re-search-forward from nil t)
(replace-match to nil nil)))
(defun verilog-test-file (file temp-file)
(save-excursion
(message (concat file ": finding..."))
(find-file (concat "tests/" file))
(verilog-mode)
(message (concat file ": deleting indent..."))
(global-replace-regexp "[ \t]+$" "")
(message (concat file ": deleting autos..."))
(verilog-delete-auto)
(cond
((string-match "^inject_" file)
(message (concat file ": testing inject-auto..."))
(verilog-inject-auto))
(t
(message (concat file ": testing auto..."))
(verilog-auto)))
(message (concat file ": auto OK..."))
(when (string-match "^label_" file)
(message (concat file ": testing auto labeling of begin/end..."))
(verilog-label-be))
(unless (or (string-match "^noindent_" file)
(getenv "VERILOG_MODE_NO_INDENTS"))
(verilog-test-indent-buffer file)
(untabify (point-min) (point-max)))
(write-file (concat "../" temp-file))
(kill-buffer nil))
;;
(vl-diff-file (concat "tests_ok/" file) temp-file))
(defun verilog-test-indent-buffer (file )
(interactive)
(message (concat file ": testing indent..."))
(save-excursion
(goto-char (point-min))
(let* ((ln 0))
(while (not (eobp))
;;(message (format "%d" ln))
;;(message (format "%s : %d - indent" file ln))
(electric-verilog-tab)
;;(message (format "%s : %d - pretty-declaration" file ln))
(verilog-pretty-declarations t)
;;(message (format "%s : %d - pretty-expr" file ln))
(verilog-pretty-expr t )
(forward-line 1)
(setq ln (1+ ln))
)
(message (format "Indented %d lines" ln))
))
(message (concat file ": indents OK...")))
(defun vl-diff-file (golden-file temp-file)
(message (concat golden-file ": running diff of " golden-file " and " temp-file ))
(with-temp-buffer
(let* ((status
(call-process "diff" nil t t diff-flags "--label" "GOLDEN_REFERENCE" golden-file "--label" "CURRENT_BEHAVIOR" temp-file )))
(cond ((and (not (equal status 0))
(getenv "HARNESS_UPDATE_GOLDEN"))
(message "***HARNESS_UPDATE_GOLDEN set - updating Golden Reference File")
(call-process "cp" nil t t temp-file golden-file))
((not (equal status 0))
(message (concat "diff -c " golden-file " " temp-file))
(message "***Golden Reference File\n---Generated Test File")
(message "%s" (buffer-string))
(message "To promote current to golden, in shell buffer hit newline anywhere in next line (^P RETURN):")
(message (concat "cp " temp-file " " golden-file "; VERILOG_MODE_START_FILE=" golden-file " " again ))
(error ""))
(t
(message "Verified %s" golden-file))))))
(defun vl-do-on-thread (file-num)
"Return true to process due to multithreading"
(cond (vl-threading
(or (string-match "\\([0-9]+\\)of\\([0-9]+\\)" vl-threading)
(error "VERILOG_MODE_THREAD not in #of# form"))
(let ((th (string-to-number (match-string 1 vl-threading)))
(numth (string-to-number (match-string 2 vl-threading))))
(equal (1+ (mod file-num numth)) th)))
(t t)))
(defun verilog-test ()
(let ((files (directory-files "tests"))
(tests-run 0)
(file-num 0)
file cf temp-file)
(when (getenv "VERILOG_MODE_DEBUG")
(setq verilog-debug t))
(when (getenv "VERILOG_MODE_TEST_FILE")
(setq files (list (getenv "VERILOG_MODE_TEST_FILE")))
(message "**** Only testing files in $VERILOG_MODE_TEST_FILE"))
(when (getenv "VERILOG_MODE_START_FILE")
(let* ((startfiles (list (getenv "VERILOG_MODE_START_FILE")))
(startfile (car startfiles)))
(message (concat "Starting from file " startfile))
(catch 'done
(while files
(setq file (car files))
(if (or (string-equal file startfile)
(string-equal (concat "tests_ok/" file) startfile))
(progn
(message (concat "matched " file))
(throw 'done 0))
(progn
(setq files (cdr files))))))))
(message "emacs-version %s" emacs-version)
(while files
(setq file (car files))
(setq temp-file (concat (if running-on-xemacs "x/t/" "e/t/")
file))
(cond ((equal "." file))
((equal ".." file))
((string-match "#" file)) ;; Backups
((string-match "~$" file))
((string-match "\.f$" file))
((string-match "\.dontrun$" file))
((file-directory-p (concat "tests/" file)))
((progn (setq file-num (1+ file-num))
(not (vl-do-on-thread file-num))))
(t
(message (concat "Considering test " file ))
(if running-on-xemacs
(progn
(setq cf (concat "skip_for_xemacs/" file))
(if (file-exists-p cf ) ;
(message (concat "Skipping testing " file " on Xemacs because file " cf "exists"))
(progn
(verilog-test-file file temp-file)
(setq tests-run (1+ tests-run))
)
))
(progn
(verilog-test-file file temp-file)
(setq tests-run (1+ tests-run))
))
(message (format " %d tests run so far, %d left... %s"
tests-run (length files)
(if vl-threading (concat "Thread " vl-threading) "")))
))
(setq files (cdr files))))
(message "Tests Passed on %s" (emacs-version))
"Tests Passed")
(defun vl-indent-file ()
"Reindent file"
(interactive)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(electric-verilog-tab)
(end-of-line)
(delete-char (- (skip-chars-backward " \t")))
(forward-line 1)
)
)
(write-file (buffer-file-name))
)
(progn
(save-excursion
(with-temp-buffer
(verilog-mode)))
;; Setup
(require `compile)
(defun ask-user-about-lock() nil) ;; XEmacs - Disable lock conflicts
(setq running-on-xemacs (string-match "XEmacs" emacs-version))
(setq make-backup-files nil)
(setq-default make-backup-files nil)
(setq diff-flags (if (getenv "VERILOG_MODE_NO_INDENTS") "-wBu" "-u"))
;;(setq verilog-auto-lineup 'all)
(setq enable-local-variables t)
(setq enable-local-eval t)
(setq auto-mode-alist (cons '("\\.v\\'" . verilog-mode) auto-mode-alist))
(setq-default fill-column 100)
(if running-on-xemacs
(setq again "make test_xemacs")
(setq again "make test_emacs"))
(verilog-test)
)