unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob c838c7278088076f035aa5f9230815c9d30d8345 1772 bytes (raw)
name: test/lisp/emacs-lisp/elp-tests.el 	 # note: path name is non-authoritative(*)

 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
 
(require 'elp)

(defun g (n)
  (f (abs n)))

(defun f (n)
  (when (not (= n 0))
    (f (1- n))))

(defun get-timer-info (funsym caller)
  (let ((info-plist (get funsym elp-timer-info-property)))
    (or info-plist (error "%s is not instrumented for profiling" funsym))
    (plist-get info-plist caller)))

(defun call-count (funsym caller)
  (let ((info (get-timer-info funsym caller)))
    (or info
        (error "%s is not instrumented for profiling" caller))
    (aref info 0)))

(ert-deftest root-function-is-profiled ()
  (elp-instrument-function 'g)
  (g 3)
  ;; f(3) -> f(2) -> f(1) -> f(0)
  (should (= (call-count #'g t) 1))
  (should (= (call-count #'g #'g) 0))
  (elp-restore-all))

(ert-deftest recursive-calls-not-profiled ()
  (elp-instrument-function 'f)
  (elp-instrument-function 'g)
  (g 3)
  ;; f(3) -> f(2) -> f(1) -> f(0)
  (should (= (call-count #'f #'g) 1))
  (should (= (call-count #'f #'f) 3))
  (should (= (call-count #'f t) 0))
  (elp-restore-all))

(ert-deftest print-elp-result ()
  (setq elp--instrumented-functions `(g f))
  (let ((res-plist
         `(g (,(vector 1 2 3 "g")
              ,(vector 4 5 6 "f")
              ,(vector 0 0 0 "g"))
              f (,(vector 3 2 1 "f")
                 ,(vector 9 9 9 "f"))
              ))
        (elp-field-len 2)
        (elp-cc-len 2)
        (elp-et-len 2)
        (elp-at-len 2))
    (with-temp-buffer
      (message (format "elp-field-len: %s" elp-field-len))
      (elp-output-function res-plist)
      (let ((first-line (buffer-substring-no-properties
                         (point-min) (point))))
        (should (equal first-line
                       "")))))
  (elp-restore-all))

(ert-deftest elp-reset-test ()
  (elp-instrument-list `(g f))
  (g 3)
  (elp-reset-function 'g))

debug log:

solving c838c72780 ...
found c838c72780 in https://yhetil.org/emacs-devel/CALYEEYyp_O0P5V3dKxkm26JBiduONUn7-0qoCw8Cx0+0DvpPLQ@mail.gmail.com/

applying [1/1] https://yhetil.org/emacs-devel/CALYEEYyp_O0P5V3dKxkm26JBiduONUn7-0qoCw8Cx0+0DvpPLQ@mail.gmail.com/
diff --git a/test/lisp/emacs-lisp/elp-tests.el b/test/lisp/emacs-lisp/elp-tests.el
new file mode 100644
index 0000000000..c838c72780

Checking patch test/lisp/emacs-lisp/elp-tests.el...
Applied patch test/lisp/emacs-lisp/elp-tests.el cleanly.

index at:
100644 c838c7278088076f035aa5f9230815c9d30d8345	test/lisp/emacs-lisp/elp-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).