beta-0.89.2
[luatex.git] / source / texk / web2c / triptrap / tripman.tex
blob7634c8c9e78b9fa11a75d69127d0629749a3882a
1 % The TRIP manual: How to validate TeX --- last updated by D E Knuth on 4 Dec 89
2 \font\eighttt= cmtt8
3 \font\eightrm= cmr8
4 \font\titlefont= cmr7 scaled\magstep5
5 \let\mc=\eightrm
6 \rm
7 \let\mainfont=\tenrm
9 \def\.#1{\hbox{\tt#1}}
10 \def\\#1{\hbox{\it#1\/\hskip.05em}} % italic type for identifiers
12 \parskip 2pt plus 1pt
13 \baselineskip 12pt plus .25pt
15 \def\verbatim#1{\begingroup \frenchspacing
16 \def\do##1{\catcode`##1=12 } \dospecials
17 \parskip 0pt \parindent 0pt
18 \catcode`\ =\active \catcode`\^^M=\active
19 \tt \def\par{\ \endgraf} \obeylines \obeyspaces
20 \input #1 \endgroup}
21 % a blank line will be typeset at the end of the file;
22 % if you're unlucky it will appear on a page by itself!
23 {\obeyspaces\global\let =\ }
25 \output{\shipout\box255\global\advance\pageno by 1} % for the title page only
26 \null
27 \vfill
28 \centerline{\titlefont A torture test for \TeX}
29 \vskip 18pt
30 \centerline{by Donald E. Knuth}
31 \centerline{Stanford University}
32 \vskip 6pt
33 \centerline{({\sl Version 3, January 1990\/})}
34 \vfill
35 \centerline{\vbox{\hsize 4in
36 \noindent Programs that claim to be implementations of \TeX82 are
37 supposed to be able to process the test routine contained in this
38 report, producing the outputs contained in this report.}}
39 \vskip 24pt
40 {\baselineskip 9pt
41 \eightrm\noindent
42 The preparation of this report was supported in part by the National Science
43 Foundation under grants IST-8201926 and MCS-8300984,
44 and by the System Development Foundation.
45 `\TeX' is a trademark of the American Mathematical Society.
47 }\pageno=0\eject
49 \output{\shipout\vbox{ % for subsequent pages
50 \baselineskip0pt\lineskip0pt
51 \hbox to\hsize{\strut
52 \ifodd\pageno \hfil\eightrm\firstmark\hfil
53 \mainfont\the\pageno
54 \else\mainfont\the\pageno\hfil
55 \eightrm\firstmark\hfil\fi}
56 \vskip 10pt
57 \box255}
58 \global\advance\pageno by 1}
59 \let\runninghead=\mark
60 \outer\def\section#1.{\noindent{\bf#1.}\quad
61 \runninghead{\uppercase{#1} }\ignorespaces}
63 \section Introduction.
64 People often think that their programs are ``debugged'' when large applications
65 have been run successfully. But system programmers know that a typical large
66 application tends to use at most about 50 per cent of the instructions
67 in a typical compiler. Although the other half of the code---which tends
68 to be the ``harder half''---might be riddled with errors, the system seems
69 to be working quite impressively until an unusual case shows up on the
70 next day. And on the following day another error manifests itself, and so on;
71 months or years go by before certain parts of the compiler are even
72 activated, much less tested in combination with other portions of the system,
73 if user applications provide the only tests.
75 How then shall we go about testing a compiler? Ideally we would like to
76 have a formal proof of correctness, certified by a computer.
77 This would give us a lot of confidence,
78 although of course the formal verification program might itself be incorrect.
79 A more serious drawback of automatic verification is that the formal
80 specifications of the compiler are likely to be wrong, since they aren't
81 much easier to write than the compiler itself. Alternatively, we can
82 substitute an informal proof of correctness: The programmer writes his or
83 her code in a structured manner and checks that appropriate relations
84 remain invariant, etc. This helps greatly to reduce errors, but it cannot
85 be expected to remove them completely; the task of checking a large
86 system is sufficiently formidable that human beings cannot do it without
87 making at least a few slips here and there.
89 Thus, we have seen that test programs are unsatisfactory if they are simply
90 large user applications; yet some sort of test program is needed because
91 proofs of correctness aren't adequate either. People have proposed schemes
92 for constructing test data automatically from a program text, but such
93 approaches run the risk of circularity, since they cannot assume that a
94 given program has the right structure.
96 I have been having good luck with a somewhat different approach,
97 first used in 1960 to debug an {\mc ALGOL} compiler. The idea is to
98 construct a test file that is about as different from a typical user
99 application as could be imagined. Instead of testing things that people
100 normally want to do, the file tests complicated things that people would
101 never dare to think of, and it embeds these complexities in still
102 more arcane constructions. Instead of trying to make the compiler do the
103 right thing, the goal is to make it fail (until the bugs have all been found).
105 To write such a fiendish test routine, one simply gets into a nasty frame
106 of mind and tries to do everything in the unexpected way. Parameters
107 that are normally positive are set negative or zero; borderline cases
108 are pushed to the limit; deliberate errors are made in hopes that the
109 compiler will not be able to recover properly from them.
111 A user's application tends to exercise 50\%\ of a compiler's logic,
112 but my first fiendish tests tend to improve this to about 90\%. As the
113 next step I generally make use of frequency-counting software to identify
114 the instructions that have still not been called upon. Then I add ever more
115 fiendishness to the test routine, until more than 99\%\ of the code
116 has been used at least once. (The remaining bits are things that
117 can occur only if the source program is really huge, or if certain
118 fatal errors are detected; or they are cases so similar to other well-tested
119 things that there can be little doubt of their validity.)
121 Of course, this is not guaranteed to work. But my experience in 1960 was
122 that only two bugs were ever found in that {\mc ALGOL} compiler after it
123 correctly translated that original fiendish test. And one of those bugs
124 was actually present in the results of the test; I simply had failed to
125 notice that the output was incorrect. Similar experiences occurred later
126 during the 60s and 70s, with respect to a few assemblers, compilers,
127 and simulators that I wrote.
129 This method of debugging, combined with the methodology of structured
130 programming and informal proofs (otherwise known as careful desk checking),
131 leads to greater reliability of production software than any other
132 method I know. Therefore I have used it in developing \TeX82, and the
133 main bulk of this report is simply a presentation of the test program
134 that was used to get the bugs out of \TeX.
136 Such a test file is useful also after a program has been debugged, since
137 it can be used to give some assurance that subsequent modifications don't
138 mess things up.
140 The test file is called \.{TRIP.TEX}, because of my warped sense of humor:
141 \TeX\ is pronounced ``techhh'', so the name reminded me of a
142 triptych (and besides, I wanted to take a trip through the program while
143 tripping it up, etc.).
145 The contents of this test file are so remote from what people actually
146 do with \TeX, I feel apologetic if I have to explain the correct
147 translation of \.{TRIP.TEX}; nobody really cares about most of the
148 nitty-gritty rules that are involved. Yet I believe \.{TRIP} exemplifies
149 the sort of test program that has outstanding diagnostic ability, as
150 explained above.
152 If somebody claims to have a correct implementation of \TeX, I will not
153 believe it until I see that \.{TRIP.TEX} is translated properly.
154 I propose, in fact, that a program must meet two criteria before it
155 can justifiably be called \TeX: (1)~The person who wrote it must be
156 happy with the way it works at his or her installation; and (2)~the
157 program must produce the correct results from \.{TRIP.TEX}.
159 \TeX\ is in the public domain, and its algorithms are published;
160 I've done this since I do not want to discourage its use by placing
161 proprietary restrictions on the software. However, I don't want
162 faulty imitations to masquerade as \TeX\ processors, since users
163 want \TeX\ to produce identical results on different machines.
164 Hence I am planning to do whatever I can to suppress any systems that
165 call themselves \TeX\ without meeting conditions (1) and~(2).
166 I have copyrighted the programs so that I have some chance to forbid
167 unauthorized copies; I explicitly authorize copying of correct
168 \TeX\ implementations, and not of incorrect ones!
170 The remainder of this report consists of appendices, whose contents ought
171 to be described briefly here:
173 Appendix A explains in detail how to carry out a test of \TeX, given
174 a tape that contains copies of the other appendices.
176 Appendix B is \.{TRIP.TEX}, the fiendish test file that has already
177 been mentioned. People who think that they understand \TeX\ are challenged
178 to see if they know what \TeX\ is supposed to do with this file.
179 People who know only a little about \TeX\ might still find it
180 interesting to study Appendix~B, just to get some insights into the
181 methodology advocated here.
183 Appendix C is \.{TRIP.PL}, the property-list description of a
184 special font called \.{trip}. This is the only font used by \.{TRIP.TEX}.
185 There are no graphic characters associated with \.{trip} that could
186 possibly be printed; indeed, \.{TRIP.PL} describes the properties of a font
187 that is as weird as the ``document'' described by \.{TRIP.TEX}.
189 Appendix D is \.{TRIPIN.LOG}, a correct transcript file \.{TRIP.LOG}
190 that results if \.{INITEX} is applied to \.{TRIP.TEX}. (\.{INITEX} is
191 the name of a version of \TeX\ that does certain initializations;
192 this run of \.{INITEX} also creates a binary format file called \.{TRIP.FMT}.)
194 Appendix E is a correct transcript file \.{TRIP.LOG} that results if
195 \.{INITEX} or any other version of \TeX\ is applied to \.{TRIP.TEX}
196 with format \.{TRIP.FMT}.
198 Appendix F is \.{TRIP.TYP}, the symbolic version of a correct output
199 file \.{TRIP.DVI} that was produced at the same time as the \.{TRIP.LOG}
200 file of Appendix~E.
202 Appendix G is \.{TRIPOS.TEX}, a short file written out and read in
203 by \TeX\ when it processes \.{TRIP.TEX}.
205 Appendix H is \.{TRIP.FOT}, an abbreviated version of Appendix E that
206 appears on the user's terminal during the run that produces \.{TRIP.LOG}
207 and \.{TRIP.DVI}.
209 The debugging of \TeX\ and the testing of the adequacy of \.{TRIP.TEX}
210 could not have been done nearly as well as reported here except for
211 the magnificent software support provided by my colleague David R. Fuchs.
212 In particular, he extended our local Pascal compiler so that
213 frequency counting and a number of other important features were added
214 to its online debugging abilities.
216 The method of testing advocated here has one chief difficulty that deserves
217 comment: I had to verify by hand that \TeX\ did the right things
218 to \.{TRIP.TEX}. This took many hours, and perhaps I have missed
219 something (as I did in 1960); I must confess that I have not checked
220 every single number in Appendices E and~F. However, I'm willing to pay
221 \$327.68 to the first finder of any remaining bug in \TeX, and I will
222 be surprised if that bug doesn't show up also in Appendix~E. (I plan to
223 write a technical report about all of the errors ultimately found in \TeX; that
224 report will tell whether any bugs are discovered between now and~then!)
226 \vfill\eject
228 \section Appendix A: How to test \TeX.
230 \item{0.} Let's assume that you have a tape containing \.{TRIP.TEX},
231 \.{TRIP.PL}, \.{TRIPIN.LOG}, \.{TRIP.LOG}, \.{TRIP.TYP}, and \.{TRIP.FOT},
232 as in Appendices B, C, D, E, F, and~G. Furthermore, let's suppose that you
233 have a working \.{WEB} system, and that you have working programs \.{TFtoPL},
234 \.{PLtoTF}, \.{DVItype}, as described in the \TeX ware report.
236 \item{1.} Use \.{PLtoTF} to convert \.{TRIP.PL} into \.{TRIP.TFM}.
237 Then use \.{TFtoPL} to convert \.{TRIP.TFM} into \.{TMP.PL}. Check that
238 \.{TMP.PL} is identical to \.{TRIP.PL} (this is a partial test of \.{PLtoTF}
239 and \.{TFtoPL}). Install \.{TRIP.TFM} in the standard file area for
240 \TeX\ font metric files.
242 \item{2.} Prepare a special version of \.{INITEX}. (This means that your \.{WEB}
243 change file should have {\bf init} and {\bf tini} defined to be null.)
244 The {\bf stat} and {\bf tats} macros should also be null, so that
245 statistics are kept and other special features are enabled. Set
246 \\{mem\_min} and \\{mem\_bot} equal to~1, and set \\{mem\_top} and
247 \\{mem\_max} equal to~3000, for purposes of this test version. Also set
248 $\\{error\_line}=64$, $\\{half\_error\_line}=32$, and
249 $\\{max\_print\_line}=72$; these parameters affect many of the lines of
250 the test output, so your job will be much easier if you use the same
251 settings that were used to produce Appendix~E. You probably should also
252 use the ``normal'' settings of other parameters found in \.{TEX.WEB}
253 (e.g., $\\{stack\_size}=200$, $\\{font\_max}=75$, etc.), since these show
254 up in a few lines of the test output. Your test version should not
255 change the default definition of unprintable characters (\S49 of the program).
257 \item{3.} Run the \.{INITEX} prepared in step 2. In response to the first
258 `\.{**}' prompt, type carriage return (thus getting another `\.{**}').
259 Then type `\.{\char`\\input trip}'. You should get an output that matches
260 the file \.{TRIPIN.LOG} (Appendix~D). Don't be alarmed by the error
261 messages that you see, unless they are different from those in Appendix~D.
263 \def\sp{{\char'40}}
264 \item{4.} Run \.{INITEX} again. This time type `\.{\sp\&trip\sp\sp trip\sp}'.
265 (The spaces in this input help to check certain parts of \TeX\ that
266 aren't otherwise used.) You should get outputs \.{TRIP.LOG}, \.{TRIP.DVI},
267 and \.{TRIPOS.TEX}; there will also be an empty file \.{8TERMINAL.TEX}.
268 Furthermore, your terminal should receive output that matches \.{TRIP.FOT}
269 (Appendix~H). During the middle part of this test, however, the terminal
270 will not be getting output, because \.{\char'134batchmode} is being
271 tested; don't worry if nothing seems to be happening for a while---nothing
272 is supposed to.
274 \item{5.} Compare the \.{TRIP.LOG} file from step 4 with the ``master''
275 \.{TRIP.LOG} file of step~0. (Let's hope you put that master file in a
276 safe place so that it wouldn't be clobbered.) There should be perfect
277 agreement between these files except in the following respects:
279 \itemitem{a)} The dates and possibly the file names will
280 naturally be different.
282 \itemitem{b)} Glue settings in the displays of \TeX\ boxes are subject
283 to system-dependent rounding, so slight deviations are permissible. However,
284 such deviations apply only to the `\.{glue set}' values that appear at the
285 end of an \.{\char'134hbox} or \.{\char'134vbox} line;
286 all other numbers should agree exactly, since they are computed with
287 integer arithmetic in a prescribed system-independent manner.
289 \itemitem{c)} The amount of space in kerns that are marked ``for accent''
290 are, similarly, subject to system-dependent rounding.
292 \itemitem{d)} If you had different values for \\{stack\_size}, \\{buf\_size},
293 etc., the corresponding capacity values will be different when they
294 are printed out at the end.
296 \itemitem{e)} Help messages may be different; indeed, the author encourages
297 non-English help messages in versions of \TeX\ for people who don't
298 understand English as well as some other language.
300 \itemitem{f)} The total number and length of strings at the end may well
301 be different.
303 \itemitem{g)} If your \TeX\ uses a different memory allocation or
304 packing scheme or \.{DVI} output logic, the memory usage statistics may change.
306 \item{6.} Use \.{DVItype} to convert your file \.{TRIP.DVI} to a file
307 \.{TRIP.TYP}. The following options should be set when using \.{DVItype}:
308 $$\vbox{\halign{#\hfil&\hfil#\cr
309 Output level = 2\cr
310 Starting page = \.{*.*.*.*.*.*.*.*.*.*}\hskip-20pt\cr
311 Number of pages = 1000000&(this is the default)\cr
312 Resolution = 7227/100&(this is one point per pixel)\cr
313 New magnification = 0&(this is the default)\cr}}$$
314 The resulting file should agree with the master \.{TRIP.TYP} file of step~0,
315 except that some of the values might be a little off due to floating-point
316 rounding discrepancies. Furthermore there may be differences between
317 `\\{right}' and `\\w' and `\\x' commands, and between `\\{down}' and `\\y'
318 and `\\z'; the key thing is that all characters and rules and \\{xxx}'s should
319 be in almost the same positions as specified in Appendix~F.
320 (If your \.{DVI}-writing routines differ substantially from those in
321 \.{TEX.WEB}, you may want to write a \.{DVIcompare} program that
322 detects any substantive differences between two given \.{DVI} files. Such
323 a routine would be of general use besides.
324 On the other hand, if you have set \\{dvi\_buf\_size} to 800, then your
325 \.{DVI} file should be virtually identical to the one supplied.)
327 \item{7.} You might also wish to test \.{TRIP} with other versions of
328 \TeX\ (i.e., \.{VIRTEX} or a production version with other fonts and
329 macros preloaded). It should work unless \TeX's primitives have been
330 redefined. However, this step isn't essential, since all the code of
331 \.{VIRTEX} appears in \.{INITEX}; you probably won't catch any more errors
332 this way, unless they would already become obvious from normal use of
333 the~system.
335 \vfill\eject
337 \section Appendix B: The \.{TRIP.TEX} file.
338 The contents of the test routine are prefixed here with line numbers, for
339 ease in comparing this file with the error messages printed later; the
340 line numbers aren't actually present.
341 \runninghead{APPENDIX B: \.{TRIP.TEX} (CONTINUED)}
343 \vskip 8pt
344 \begingroup\count255=0
345 \everypar{\global\advance\count255 by 1
346 \hbox to 20pt{\sevenrm\hfil\the\count255\ \ }}
347 \verbatim{trip.tex}
348 \endgroup
349 \vfill\eject
351 \section Appendix C: The \.{TRIP.PL} file.
352 The ``font'' defined here has only a few characters, but they include all
353 the complexities that \TeX\ must deal with: ligatures, kerns,
354 lists of characters, and extensible characters. Some of the dimensions
355 are negative, just to make things worse yet. (The format of property-list
356 files like this is explained in the documentation to \.{PLtoTF}, in
357 the \TeX ware report.)
358 \runninghead{APPENDIX C: \.{TRIP.PL} (CONTINUED)}
360 \vskip8pt
361 \verbatim{trip.pl}
362 \vfill\eject
364 \section Appendix D: The \.{TRIPIN.LOG} file.
365 When \.{INITEX} makes the \.{TRIP.FMT} file, it also creates a file called
366 \.{TRIP.LOG} that looks like this.
367 \runninghead{APPENDIX D: \.{TRIPIN.LOG} (CONTINUED)}
369 \vskip8pt
370 \verbatim{tripin.log}
371 \vfill\eject
373 \section Appendix E: The \.{TRIP.LOG} file.
374 Here is the major output of the \.{TRIP} test; it is generated by running
375 \.{INITEX} and loading \.{TRIP.FMT}, then reading \.{TRIP.TEX}.
376 \runninghead{APPENDIX E: \.{TRIP.LOG} (CONTINUED)}
378 {\let\tt=\eighttt\leftskip 1in\baselineskip 9pt plus .1pt minus .1pt
379 \vskip8pt
380 \verbatim{trip.log}
382 \vfill\eject
384 \section Appendix F: The \.{TRIP.TYP} file.
385 Here is another major component of the test. It shows the output of \.{DVItype}
386 applied to the file \.{TRIP.DVI} that was created at the same time
387 Appendix E was produced.
388 \runninghead{APPENDIX F: \.{TRIP.TYP} (CONTINUED)}
390 {\let\tt=\eighttt\leftskip 1in\baselineskip 9pt plus .1pt minus .1pt
391 \vskip8pt
392 \verbatim{trip.typ}
394 \vfill\eject
396 \section Appendix G: The \.{TRIPOS.TEX} file.
397 This short file was written out once and read in twice, during the time
398 Appendix E was being produced. There are only three lines, the first of
399 which is blank.
400 \runninghead{APPENDIX G: \.{TRIPOS.TEX} (CONTINUED)}
402 \vskip8pt
403 \verbatim{tripos.tex}
404 \vfill\eject
406 \section Appendix H: The \.{TRIP.FOT} file.
407 This shows what appeared on the terminal while Appendix E was being produced.
408 \runninghead{APPENDIX H: \.{TRIP.FOT} (CONTINUED)}
410 \vskip8pt
411 \verbatim{trip.fot}
413 \vfill\end