1
0
mirror of synced 2026-04-26 12:18:05 +00:00
Files
Interlisp.medley/internal/test/env/program-analysis/hand/SPY.U.~1~

265 lines
10 KiB
Plaintext

;; Function To Be Tested: SPY (Part I) (Program Analysis)
;;
;; Source: Lisp Library Modules Manual (Lyric Beta Release 2)
;; Browser, Page 187
;; Section: Program Analysis (Library)
;;
;; Created By: John Park
;;
;; Creation Date: March 12, 1987
;;
;; Last Update: March 18, 1987
;;
;; Filed As: {ERIS}<lispcore>test>program-analysis>spy.u
;;
;;
;; Syntax: (See Spy documentation)
;;
;; Function Description: Spy is a tool to help programs run faster. Spy has two parts:
;; a "sampler" that one runs while running his program, which monitors what the program
;; is doing, anda "displayer" that displays the data gathered by the sampler.
;; The "displayer" uses the grapher package to display the data gathered by the sampler.
;; In the graph, the height of each node is adjusted to be proportional to the amount
;; of time. Just as Masterscope and Browser give an interactive picture of the static
;; structure of the program, Spy give an interactive picture of the dynamic structure.
;;
;; Required packages: Grapher, readnumber, imageobj, and tedit
;;
;; Functions: (SPY.BUTTON) - Turns spy on and off.
;; (SPY.START) - Reinitializes the internal Spy data structure and turns on
;; Sampling.
;; (SPY.END) - Turns off sampling, and cleans up the data structure
;; (SPY.TOGGLE) - If Spying is off, turn it on with (SPY.START). If it's on,
;; turn it off with (SPY.END) and then show the results with (SPY.TREE 10).
;; (WITH.SPY form) - Macro which calls (SPY.START), evaluates the form, calls
;; (SPY.END), and another one will turn it off.
;; (SPY.TREE threshold individualp mergetype depthlimit) - display the results
;; of the last "spy" in a grapher window. For argument description,
;; see SPY documentation.
;; (SPY.LEGEND) - This brings up a window that shows what they mean
;; (SPY.BORDER) - This brings up a window that shows the interpretation of
;; SPY.BORDERS
;; Variables: SPY.FREQUENCY - How many times per second to sample? Initially 10.
;; Max: 60
;; SPY.NOMERGEFNS - Functions on this list are not merged under
;; MergeDefault
;; SPY.TREE - This holds the data from the last sampling. One can save
;; and restore it using UGLYVARS.
;; SPY.BORDERS - This controls the border display on a tree.
;; SPY.FONT - Font used to display node labels. Initially (GACHA 10)
;; SPY.MAXLINES - Maximum height of a node in the graph, measured
;; in multiples of the font height of SPY.FONT.
;; Argument(s): (SEE Spy documentation)
;;
;; Returns: (SEE Spy documentation)
;;
;; Constraints/Limitations: Testing of SPY requires much user interface; however, may of the
;; functional tests are written in such a way that many of the top-level functions will be
;; automatically executed and test results will be recorded in the following file
;; {eris}<lispcore>test>program-analysis>browser.report. User interface is necessary for
;; some of the spy functions. Appropriate messages will be printed when user interface is
;; required during testing. Instructions for manually testing SPY (pages 189 - 193), should
;; be read carefully before testing the SPY display results (Using SPY,Merging, and Individual
;; vs Cumulative mode).
(DO-TEST "SPY-TEST-SETUP"
(PROGN
(SETQ TEST-START (GET-INTERNAL-RUN-TIME))
(SETQ TEST-RESULT "{ERIS}<LISPCORE>TEST>PROGRAM-ANALYSIS>SPY.REPORT")
(DEFUN S-FORMAT (TIME)
(FORMAT *OUTPUT* "~2%TOTAL TEST RUN TIME FOR SPY: ~F MINUTES ~%"
TIME))
(DEFUN ITEM-FORMAT-S (COMMAND-LANGUAGE)
(FORMAT *OUTPUT* "~%COMMAND: SPY TEST-ITEM: ~A~%LISP VERSION: ~A ~%STATUS: ~A DATE: ~A TESTER: ~A~%" COMMAND-LANGUAGE (LISP-IMPLEMENTATION-VERSION) 'SUCCESS (IL:DATE) IL:USERNAME))
(DEFUN ITEM-FORMAT-F (COMMAND-LANGUAGE)
(FORMAT *OUTPUT* "~%COMMAND: SPY TEST-ITEM: ~A~%LISP VERSION: ~A ~%STATUS: ~A DATE: ~A TESTER: ~A~%" COMMAND-LANGUAGE (LISP-IMPLEMENTATION-VERSION) 'FAIL (IL:DATE) IL:USERNAME))
(DEFUN PASS-FAIL (COMMAND-LANGUAGE TEST-ITEM)
(IF (EQ TEST-ITEM T) (ITEM-FORMAT-S COMMAND-LANGUAGE)
(ITEM-FORMAT-F COMMAND-LANGUAGE)))
(DEFUN PAUSE NIL (PROGN
(IL:PLAYTUNE '((262 . 15000) (440 . 15000) (349 . 15000)))
(SLEEP 2)))
(SETQ SPYW (IL:CREATEW '(100 100 325 90) NIL NIL T))
(SETQ SPY-COMMAND-STRING
"(IL:PAGEHEIGHT 0)
;Loading spy and other required package
; they are not already loaded...
(PAUSE)
; This part of the test will load spy and other required packages...
(IF (AND (MEMBER 'IL:SPY IL:FILELST)
(MEMBER 'IL:GRAPHER IL:FILELST)
(MEMBER 'IL:READNUMBER IL:FILELST)
(MEMBER 'IL:IMAGEOBJ IL:FILELST))
(PROGN (IL:PROMPTPRINT '(SPY and other necessary files are already loaded))
(SLEEP 2)
(IL:CLRPROMPT))
(PROGN (IL:LOAD? '{ERINYES}<LYRIC>LIBRARY>SPY.LCOM 'IL:SYSLOAD)
(IL:LOAD? '{ERINYES}<LYRIC>LIBRARY>GRAPHER.LCOM 'IL:SYSLOAD)
(IL:LOAD? '{ERINYES}<LYRIC>LIBRARY>READNUMBER.LCOM 'IL:SYSLOAD)
(IL:LOAD? '{ERINYES}<LYRIC>LIBRARY>IMAGEOBJ.LCOM 'IL:SYSLOAD)))
; This part determines if all spy functions are defined and variables bound ....
(PAUSE)
(IF (AND (NOTANY #'NULL
(MAPCAR #'FBOUNDP '(IL:SPY.BUTTON IL:SPY.START IL:SPY.END
IL:WITH.SPY IL:SPY.TREE IL:SPY.LEGEND)))
(NOTANY #'NULL
(MAPCAR #'BOUNDP '(IL:SPY.FREQUENCY IL:SPY.NOMERGEFNS
IL:SPY.TREE IL:SPY.BORDERS IL:SPY.FONT IL:SPY.MAXLINES)))
)
(SETQ IL:FUNCTIONS-VARIABLES-FLG T)
(SETQ IL:FUNCTIONS-VARIABLES-FLG NIL))
; Test to see if the SPY variables are bound to correct initial values
(IF (AND (EQ IL:SPY.FREQUENCY 10)
(PROGN (SETQ NOMERGEFNS-FLG NIL)
(DOLIST (Y '(IL:ERRORSET IL:\\\\EVAL IL:\\\\EVALFORM IL:APPLY IL:EVAL))
(IF (MEMBER Y IL:SPY.NOMERGEFNS) (PUSH T NOMERGEFNS-FLG)
(PUSH NIL NOMERGEFNS-FLG)))
(NOTANY #'NULL NOMERGEFNS-FLG))
(AND (EQ (IL:FONTPROP IL:SPY.FONT 'IL:FAMILY) 'IL:GACHA)
(= (IL:FONTPROP IL:SPY.FONT 'IL:SIZE) 8))
(ZEROP (MOD IL:SPY.MAXLINES (IL:FONTPROP IL:SPY.FONT 'IL:HEIGHT)))
)
(SETQ IL:SPY-INITIAL-FLG T)
(SETQ IL:SPY-INITIAL-FLG NIL)
)
; Test for SPY.BUTTON
; (SPY.BUTTON) will turn spy on/off
;
(CL:IN-PACKAGE 'INTERLISP)
(SPY.BUTTON '(90 . 5))
(CURSORPOSITION '(134 . -145))
; Clicking the left mouse button will turn it on...
(XCL-TEST::PAUSE)
(APPLY (WINDOWPROP SPY.BUTTON 'BUTTONEVENTFN))
(IF (EQ \\\\PERIODIC.INTERRUPT '\\\\SPY.INTERRUPT)
then (SETQ SPY-BUTTON-ON T)
else (SETQ SPY-BUTTON-ON NIL))
; Clicking it again will turn off the spy and display the results....
(XCL-TEST::PAUSE)
(PROMPTPRINT '(please indicate the spy.window position with left mouse button))
(APPLY (WINDOWPROP SPY.BUTTON 'BUTTONEVENTFN))
(CLOSEW SPY.BUTTON)
(IF (EQ \\\\PERIODIC.INTERRUPT NIL)
then (SETQ SPY-BUTTON-OFF T)
else (SETQ SPY-BUTTON-OFF NIL))
(SPY.END)
(CLOSEW SPY.WINDOW)
(CLRPROMPT)
; This part of the test is for (SPY.START) and (SPY.END)
; (SPY.START) will turns on the sampling
(XCL-TEST::PAUSE)
(SPY.START)
; Now SPY should be turned back on.
(If (EQUAL \\\\PERIODIC.INTERRUPT '\\\\SPY.INTERRUPT)
then (SETQ SPY-START T)
else (SETQ SPY-START NIL))
; (SPY.END) will turn off sampling.
(XCL-TEST::PAUSE)
(SPY.END)
; Now SPY should be turned off.
(If (EQ \\\\PERIODIC.INTERRUPT NIL)
then (SETQ SPY-END T)
else (SETQ SPY-END NIL))
; The following will test (SPY.TOGGLE)
; If SPY is off, it will turn it on; otherwise, it will turn it off
; with (SPY.END) and show the results.
(XCL-TEST::PAUSE)
(SETQ \\\\PERIODIC.INTERRUPT NIL)
(SPY.BUTTON '(100 . 100))
(SPY.TOGGLE)
(If (EQ \\\\PERIODIC.INTERRUPT '\\\\SPY.INTERRUPT)
then (SETQ SPY-TOGGLE-ON T)
else (SETQ SPY-TOGGLE-ON NIL))
; Invoking (SPY.TOGGLE) again will turn spy off and display the results...
(XCL-TEST::PAUSE)
(PROMPTPRINT '(please indicate the spy.window position with left mouse button))
(SPY.TOGGLE)
(If (EQ \\\\PERIODIC.INTERRUPT NIL)
then (SETQ SPY-TOGGLE-OFF T)
else (SETQ SPY-TOGGLE-OFF NIL))
(CLOSEW SPY.BUTTON)
(CLOSEW SPY.WINDOW)
(CLRPROMPT)
; The following will test (WITH.SPY form)
; This will evaluate the form with spy on
(XCL-TEST::PAUSE)
(WITH.SPY (FOR X FROM 1 TO 10 COLLECT (ADD1 X)))
(SETQ WITH-SPY-VAL IT)
(IF (EQUAL WITH-SPY-VAL
(PROGN (SPY.START) (PROG1 (FOR X FROM 1 TO 10 COLLECT (ADD1 X)) (SPY.END))))
then (SETQ WITH-SPY T)
else (SETQ WITH-SPY NIL))
; This following will test SPY.TREE, which display the results in a grapher window.
; (SPY.TREE 10) will display the last spy with threshold set to 10
(XCL-TEST::PAUSE)
(PROMPTPRINT '(please indicate the spy.window position with left mouse button))
(SPY.TREE 10)
(IF (EQ (NOT (MEMBER SPY.WINDOW (OPENWINDOWS))) NIL)
THEN (SETQ SPY-TREE1 T)
ELSE (SETQ SPY-TREE1 NIL))
(CLOSEW SPY.WINDOW)
; (SPY.TREE 10 T) Should display the spy graph in different format
(XCL-TEST::PAUSE)
(PROMPTPRINT '(please indicate the spy.window position with left mouse button))
(SPY.TREE 10 T)
(IF (EQ (NOT (MEMBER SPY.WINDOW (OPENWINDOWS))) NIL)
THEN (SETQ SPY-TREE2 T)
ELSE (SETQ SPY-TREE2 NIL))
(CLOSEW SPY.WINDOW)
; (SPY.TREE 10 T 'ALL 2) Should display the spy graph in with depthlimit set to 2
(XCL-TEST::PAUSE)
(PROMPTPRINT '(please indicate the spy.window position with left mouse button))
(SPY.TREE 10 T 'ALL 2)
(IF (EQ (NOT (MEMBER SPY.WINDOW (OPENWINDOWS))) NIL)
THEN (SETQ SPY-TREE3 T)
ELSE (SETQ SPY-TREE3 NIL))
(CLRPROMPT)
(CLOSEW SPY.WINDOW)
(CL:IN-PACKAGE 'XCL-TEST)
; Now do-test will analyze the results of testing
(DO-TEST 'SPY-TEST-RESULT
(PROGN (SETQ *OUTPUT* (OPEN TEST-RESULT :DIRECTION :OUTPUT
:IF-EXISTS :APPEND))
(PASS-FAIL 'IL:FUNCTION-VARIABLE-DEFINITION IL:FUNCTIONS-VARIABLES-FLG)
(PASS-FAIL 'IL:SPY-INITIAL-VALUES IL:SPY-INITIAL-FLG)
(PASS-FAIL 'IL:FUNCTION-VARIABLE-DEFINITION IL:FUNCTIONS-VARIABLES-FLG)
(PASS-FAIL 'IL:SPY-BUTTON-ON IL:SPY-BUTTON-ON)
(PASS-FAIL 'IL:SPY-BUTTON-OFF IL:SPY-BUTTON-OFF)
(PASS-FAIL 'IL:SPY-START IL:SPY-START)
(PASS-FAIL 'IL:SPY-END IL:SPY-END)
(PASS-FAIL 'IL:SPY-TOGGLE (AND IL:SPY-TOGGLE-ON IL:SPY-TOGGLE-OFF))
(PASS-FAIL 'IL:WITH-SPY IL:WITH-SPY)
(PASS-FAIL 'IL:SPY-TREE (AND IL:SPY-TREE1 IL:SPY-TREE2 IL:SPY-TREE3))
(SETQ TEST-END (GET-INTERNAL-RUN-TIME))
(SETQ TOTAL-TEST-TIME (FLOAT (/ (- TEST-END TEST-START) 60000)))
(S-FORMAT TOTAL-TEST-TIME)
(CLOSE *OUTPUT*)
(IDENTITY T)
)
)
")
(IL:BKSYSBUF SPY-COMMAND-STRING)
)
)
STOP