test-run-program-unix.script 25.9 KB
Newer Older
Elias Pipping's avatar
Elias Pipping committed
1
2
3
(unless (os-unix-p)
  (leave-test "This test can only be run on UNIX" 0))

4
5
(chdir *test-directory*)

Elias Pipping's avatar
Elias Pipping committed
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
#+abcl
(unless (version-satisfies
         (second (split-string (implementation-identifier) :separator '(#\-)))
         "1.4")
  (leave-test
   "This test is not meant to be run on versions of ABCL that predate 1.4" 0))

#+clasp
(leave-test "Clasp does not have a run-program function" 0)

#+cmucl
(let* ((v (first (uiop:split-string (lisp-implementation-version))))
       (v-main (subseq v 0 2))
       (v-sub (subseq v 2 3)))
  (when (and (= 3 (length v)) ; cannot use length=n-p
             (every #'digit-char-p v-main)
             (every #'alpha-char-p v-sub))
    (unless (or (version-satisfies v-main "22")
                (and (version-satisfies v-main "21")
                     (not (string-equal v-sub "a"))))
      (leave-test
       "This test is not meant to be run on versions of CMU CL that predate 21B" 0))))

#+mkcl
(unless (version-satisfies (lisp-implementation-version) "1.1.10")
  (leave-test
   "This test is not meant to be run on versions of MKCL that predate 1.1.10" 0))

#-(or abcl allegro clasp clisp clozure cmucl ecl lispworks mkcl sbcl)
(leave-test "This test has never been run on your lisp and would probably fail" 0)

;;; Helpers
(defvar *input-file*
  (subpathname *build-directory*
40
               (strcat (implementation-identifier) "-" "input")))
Elias Pipping's avatar
Elias Pipping committed
41
42
(defvar *output-file*
  (subpathname *build-directory*
43
               (strcat (implementation-identifier) "-" "output")))
Elias Pipping's avatar
Elias Pipping committed
44
45
(defvar *error-output-file*
  (subpathname *build-directory*
46
               (strcat (implementation-identifier) "-" "error-output")))
Elias Pipping's avatar
Elias Pipping committed
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

;;; Test setup and execution

(defvar *suite-number* -1)
(defvar *test-number*)
(defvar *suites* nil)
(defvar *suites-reversed* t)
(defvar *letters* "abcdefghijklmnopqrstuvwxyz")
(defvar *number-of-failed-tests* 0)
(defvar *number-of-skipped-tests* 0)
(defvar *number-of-unsupported-tests* 0)
(defvar *number-of-unimplemented-tests* 0)

(defun new-test-suite (label)
  (incf *suite-number*)
  (setf *test-number* -1)
  (push (list (format nil "~a  ~a" *suite-number* label)) *suites*))

(defun push-test (test)
  (push test (first *suites*)))

(defun run-tests ()
  (when *suites-reversed*
    (setf *suites* (reverse (mapcar #'reverse *suites*)))
    (setf *suites-reversed* nil)
    (dolist (suite *suites*)
73
74
75
76
77
      (format t "~a~%" (first suite))
      (dolist (test (cdr suite))
        (funcall test)
        (dolist (file (list *input-file* *output-file* *error-output-file*))
          (delete-file-if-exists file))))))
Elias Pipping's avatar
Elias Pipping committed
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


;; Defines a test that is automatically numbered. Within its body, the
;; following variables are available:
;;  - output-string, error-string
;;  - suite-number, test-number, test-letter
;; The description string str should not contain more than 57 characters
(defmacro define-test (str &body body)
  `(progn
     (incf *test-number*)
     (push-test
      (let ((suite-number *suite-number*)
            (test-number *test-number*)
            error-status
            error-description)
        #'(lambda ()
            (let* ((test-letter (aref *letters* test-number))
                   (output-string (format nil "output~a~a"
                                          suite-number test-number))
                   (error-string (format nil "error~a~a"
                                         suite-number test-number)))
              (declare (ignorable output-string error-string))
              (format t " ~a ~a~%" test-letter ,str)
              (block test-case
                (handler-bind ((parameter-error
                                #'(lambda (c)
                                    (declare (ignore c))
                                    (incf *number-of-unsupported-tests*)
                                    (setf error-status 'unsupported)
                                    (return-from test-case)))
                               (not-implemented-error
                                #'(lambda (c)
                                    (declare (ignore c))
                                    (incf *number-of-unimplemented-tests*)
                                    (setf error-status 'not-implemented)
                                    (return-from test-case)))
                               (test-skipped
                                #'(lambda (c)
                                    (incf *number-of-skipped-tests*)
                                    (setf error-status 'skipped)
                                    (setf error-description (format nil "~a" c))
                                    (return-from test-case)))
                               (test-failure
                                #'(lambda (c)
                                    (declare (ignore c))
                                    (incf *number-of-failed-tests*)
                                    (setf error-status 'failed)
                                    (return-from test-case)))
                               (error
                                #'(lambda (c)
                                    (incf *number-of-failed-tests*)
                                    (setf error-status 'general)
                                    (setf error-description (format nil "~a" c))
                                    (return-from test-case))))
                  ,@body))
              (case error-status
                (failed (incf *number-of-failed-tests*))
                (unsupported (report-result "" "NOT SUPPORTED"))
                (not-implemented (report-result "" "NOT IMPLEMENTED"))
                (skipped (report-result "" "SKIPPED")
                         (format t "   Skipped for the following reason: ~a~%"
                                 error-description))
                (general (report-result "" "ERROR")
                         (format t "   The following error was encountered: ~a~%"
                                 (string-trim (list #\Space #\  #\Newline)
                                              error-description))))))))))

(define-condition test-skipped (error)
  ((reason :initarg :reason))
  (:report (lambda (condition stream)
             (format stream "~a" (slot-value condition 'reason)))))
(defun skip-test (reason)
  (error 'test-skipped :reason reason))

(define-condition test-failure (error)
  ())

;;; Testing utilities

(defun file-contains-exactly (filename expected-content)
  (let ((actual-content (read-file-string filename)))
    (string= actual-content expected-content)))

(defun report-result (description outcome)
  (format t "   ~57,1,0,'.a ~a~%" description outcome))

(defun handle-result (description passed-or-not)
  (unless passed-or-not
    (report-result description "FAIL")
    (error 'test-failure)))

(defun check-output (str)
  (handle-result "output as expected?"
                 (file-contains-exactly *output-file* str)))
(defun check-error-output (str)
  (handle-result "error-output as expected?"
                 (file-contains-exactly *error-output-file* str)))
(defun check-strings (str1 str2)
  (handle-result "received what we sent?"
                 (string= str1 str2)))

(defun create-file-from-string (name string)
  (with-open-file (output name :direction :output :if-exists :supersede)
    (format output string)))

Elias Pipping's avatar
Elias Pipping committed
183
184
185
186
187
188
;; Skips the test if terminate-process cannot be called
(defun my-terminate-process (&rest rest)
  #+ecl (unless (find-symbol* '#:terminate-process :ext nil)
          (error 'test-skipped :reason "ext:terminate-process missing"))
  (apply #'terminate-process rest))

Elias Pipping's avatar
Elias Pipping committed
189
190
;;; The actual tests

191
(new-test-suite "run-program/launch-program")
Elias Pipping's avatar
Elias Pipping committed
192
193
194

(define-test
    ":input/:output/:error-output nil (default)"
195
196
    (run-program (format nil "./exiter.sh 0 ~a" output-string)
                 :input nil :output nil))
Elias Pipping's avatar
Elias Pipping committed
197
198
199

(define-test
    ":error-output :interactive"
200
201
    (run-program (format nil "./exiter.sh 0 ~a" output-string)
                 :error-output :interactive))
Elias Pipping's avatar
Elias Pipping committed
202
203
204

(define-test
    ":error-output :output"
205
206
    (run-program (format nil "./exiter.sh 0 ~a" output-string)
                 :error-output :output))
Elias Pipping's avatar
Elias Pipping committed
207

Robert Goldman's avatar
Robert Goldman committed
208
209


Elias Pipping's avatar
Elias Pipping committed
210
211
212
213
(define-test
    ":output <file> (file e.)"
    (progn
      (create-file-from-string *output-file* "")
214
215
      (run-program (format nil "./exiter.sh 0 ~a" output-string)
                   :output *output-file*)
Elias Pipping's avatar
Elias Pipping committed
216
217
218
219
220
221
222
      (check-output (format nil "~a~%" output-string))))

(define-test
    ":output <file> :error-output <file> (files e.)"
    (progn
      (create-file-from-string *output-file* "")
      (create-file-from-string *error-output-file* "")
223
224
225
226
      (run-program (format nil "./exiter.sh 0 ~a ~a"
                           output-string error-string)
                   :output *output-file*
                   :error-output *error-output-file*)
Elias Pipping's avatar
Elias Pipping committed
227
228
229
      (check-output (format nil "~a~%" output-string))
      (check-error-output (format nil "~a~%" error-string))))

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
(define-test
    ":input <file> (file m.) :i-i-d-n-e :error"
    (progn
      (delete-file-if-exists *input-file*)
      (with-expected-failure (t)
        (run-program "cat" :input *input-file*
                     :if-input-does-not-exist :error))))

(define-test
    ":input <file> (file m.) :i-i-d-n-e :create"
    (progn
      (delete-file-if-exists *input-file*)
      (run-program "cat" :input *input-file*
                   :if-input-does-not-exist :create)))

Elias Pipping's avatar
Elias Pipping committed
245
246
(define-test
    ":input <file> (file e.)"
247
248
249
    (progn
      (let ((in-string (format nil "A line.~%And another.~%")))
        (create-file-from-string *input-file* in-string))
250
251
      (run-program "cat" :input *input-file*
                   :if-input-does-not-exist :create)))
Elias Pipping's avatar
Elias Pipping committed
252
253
254

(define-test
    ":input <file> (as pathname; file e.)"
255
256
257
    (progn
      (let ((in-string (format nil "A line.~%And another.~%")))
        (create-file-from-string *input-file* in-string))
258
259
      (run-program "cat" :input (truename *input-file*)
                   :if-input-does-not-exist :create)))
Elias Pipping's avatar
Elias Pipping committed
260
261

(define-test
262
    ":input <file> :output <file> (files e.) :i-o-e :supersede"
Elias Pipping's avatar
Elias Pipping committed
263
264
265
    (let ((in-string (format nil "A line.~%And another.~%")))
      (create-file-from-string *input-file* in-string)
      (create-file-from-string *output-file* "")
266
      (run-program "cat" :input *input-file* :output *output-file*)
267
      (check-output in-string)))
Elias Pipping's avatar
Elias Pipping committed
268
269

(define-test
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
    ":input <file> :output <file> (files e.) :i-o-e :error"
    (progn
      (let ((in-string1 (format nil "A line.~%"))
            (in-string2 (format nil "And another.~%")))
        (delete-file-if-exists *output-file*)
        (create-file-from-string *input-file* in-string1)
        (run-program "cat" :input *input-file*
                     :output *output-file*)
        (create-file-from-string *input-file* in-string2)
        (with-expected-failure (t)
          (run-program "cat" :input *input-file*
                       :output *output-file* :if-output-exists :error))
        (check-output in-string1))))

(define-test
    ":input <file> :output <file> (files e.) :i-o-e :append"
    (progn
      (let ((in-string1 (format nil "A line.~%"))
            (in-string2 (format nil "And another.~%")))
        (delete-file-if-exists *output-file*)
        (create-file-from-string *input-file* in-string1)
        (run-program "cat" :input *input-file*
                     :output *output-file*)
        (create-file-from-string *input-file* in-string2)
        (run-program "cat" :input *input-file*
                     :output *output-file*
                     :if-output-exists :append)
        (check-output (concatenate 'string in-string1 in-string2)))))

(define-test
    ":input <file> :output <file> (files e./m.) :i-o-e :supersede"
Elias Pipping's avatar
Elias Pipping committed
301
302
303
    (let ((in-string (format nil "A line.~%And another.~%")))
      (create-file-from-string *input-file* in-string)
      (delete-file-if-exists *output-file*)
304
305
      (run-program "cat" :input *input-file*
                   :output *output-file*)
306
      (check-output in-string)))
Elias Pipping's avatar
Elias Pipping committed
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
(define-test
    ":input <file> :error-output <file> (files e.), :i-e-o-e :error"
    (progn
      (let ((in-string1 (format nil "A line.~%"))
            (in-string2 (format nil "And another.~%")))
        (delete-file-if-exists *output-file*)
        (create-file-from-string *input-file* in-string1)
        (run-program "./cat-to-stderr.sh" :input *input-file*
                     :error-output *error-output-file*)
        (create-file-from-string *input-file* in-string2)
        (with-expected-failure (t)
          (run-program "./cat-to-stderr.sh" :input *input-file*
                       :error-output *error-output-file*
                       :if-error-output-exists :error))
        (check-error-output in-string1))))

(define-test
    ":input <file> :error-output <file> (files e.), :i-e-o-e :append"
    (progn
      (let ((in-string1 (format nil "A line.~%"))
            (in-string2 (format nil "And another.~%")))
        (delete-file-if-exists *output-file*)
        (create-file-from-string *input-file* in-string1)
        (run-program "./cat-to-stderr.sh" :input *input-file*
                     :error-output *error-output-file*)
        (create-file-from-string *input-file* in-string2)
        (run-program "./cat-to-stderr.sh" :input *input-file*
                     :error-output *error-output-file*
                     :if-error-output-exists :append)
        (check-error-output (concatenate 'string in-string1 in-string2)))))

Elias Pipping's avatar
Elias Pipping committed
339
340
(define-test
    ":output <fstream> :error-output <fstream>"
341
342
343
344
345
346
347
    (progn
      (with-open-file (output *output-file* :direction :output
                              :if-exists :supersede
                              #+clozure :sharing #+clozure :lock)
        (with-open-file (error-output *error-output-file* :direction :output
                                      :if-exists :supersede
                                      #+clozure :sharing #+clozure :lock)
348
349
350
          (run-program (format nil "./exiter.sh 0 ~a ~a"
                               output-string error-string)
                       :output output :error-output error-output)))
351
352
      (check-output (format nil "~a~%" output-string))
      (check-error-output (format nil "~a~%" error-string))))
Elias Pipping's avatar
Elias Pipping committed
353
354
355

(define-test
    ":input <file> :output <sstream>"
356
357
358
    (let ((in-string (format nil "A line.~%And another.~%")))
      (create-file-from-string *input-file* in-string)
      (with-output-to-string (out-stream)
359
        (run-program "cat" :input *input-file* :output out-stream)
360
        (check-strings in-string (get-output-stream-string out-stream)))))
Elias Pipping's avatar
Elias Pipping committed
361
362
363

(define-test
    ":input <sstream> :output <sstream>"
364
365
366
    (let ((in-string (format nil "A line.~%And another.~%")))
      (with-output-to-string (out-stream nil)
        (with-input-from-string (in-stream in-string)
367
          (run-program "cat" :input in-stream :output out-stream))
368
        (check-strings in-string (get-output-stream-string out-stream)))))
Elias Pipping's avatar
Elias Pipping committed
369
370
371
372
373
374
375

(define-test
    ":input <file> :output :stream :wait nil"
    (let ((in-string (format nil "A line.~%And another.~%")))
      (with-open-file (input *input-file* :direction :output
                             :if-exists :supersede)
        (format input in-string))
376
377
      (let* ((process (launch-program "cat" :input *input-file*
                                       :output :stream))
Elias Pipping's avatar
Elias Pipping committed
378
379
380
381
382
383
384
             (output (process-info-output process))
             (out-string (make-string (length in-string))))
        (wait-process process)
        (read-sequence out-string output)
        (check-strings in-string out-string)
        (close-streams process))))

Robert Goldman's avatar
Robert Goldman committed
385
386
387
388
389
390
391
392
393
394
395
396
397
(define-test
    ":error-output :stream"
  (let* ((error-output-string "Output to stream.")
         (process
           (launch-program (format nil "./exiter.sh 0 \"~a\" \"~a\"" output-string error-output-string)
                           :error-output :stream))
         (error-output-stream (process-info-error-output process))
         error-output-line)
    (wait-process process)
    (setf error-output-line (read-line error-output-stream))
    (handle-result "Expected error output to with error output stream?"
                   (equal error-output-string error-output-line))))

Elias Pipping's avatar
Elias Pipping committed
398
399
400
401
402
(defvar *dynamic-input*)

(define-test
    ":input <fstream-synonym> :output <file>"
    (let ((in-string (format nil "A line.~%And another.~%")))
403
404
405
406
407
408
      (with-open-file (input *input-file* :direction :output
                             :if-exists :supersede)
        (format input in-string))
      (create-file-from-string *output-file* "")
      (with-open-file (input *input-file* :direction :input
                             :if-does-not-exist :error)
Elias Pipping's avatar
Elias Pipping committed
409
410
        (let* ((*dynamic-input* input)
               (input-synonym (make-synonym-stream '*dynamic-input*)))
411
412
413
          (run-program "cat"
                       :input input-synonym
                       :output *output-file*))
414
415
416
417
418
419
420
421
422
423
        (check-output in-string))))

(define-test
    ":input <sstream-synonym> :output <file>"
    (progn
      (create-file-from-string *output-file* "")
      (let ((in-string (format nil "A line.~%And another.~%")))
        (with-input-from-string (input in-string)
          (let* ((*dynamic-input* input)
                 (input-synonym (make-synonym-stream '*dynamic-input*)))
424
425
426
            (run-program "cat"
                         :input input-synonym
                         :output *output-file*)))
427
        (check-output in-string))))
Elias Pipping's avatar
Elias Pipping committed
428
429
430
431
432
433

(define-test
    ":directory"
    (let* ((in-string (format nil "A line.~%And another.~%"))
           (temporary-directory
            (subpathname *build-directory*
434
435
436
                         (format nil "test-run-program-unix/~a"
                                 (implementation-identifier))
                         :type :directory))
Elias Pipping's avatar
Elias Pipping committed
437
438
439
440
441
442
           (relative-filename "input")
           (temporary-file (subpathname temporary-directory relative-filename)))
      (ensure-directories-exist temporary-directory)
      (create-file-from-string temporary-file in-string)

      (delete-file-if-exists *output-file*)
443
444
      (run-program (format nil "cat ~a" relative-filename)
                   :output *output-file* :directory temporary-directory)
Elias Pipping's avatar
Elias Pipping committed
445
446
      (check-output in-string)))

Elias Pipping's avatar
Elias Pipping committed
447
(new-test-suite "process-info-pid")
Elias Pipping's avatar
Elias Pipping committed
448
449
450

(define-test
    "basic functionality"
451
    (let* ((process-info (launch-program "./sleeper.sh 12 1"))
Elias Pipping's avatar
Elias Pipping committed
452
           (pid (process-info-pid process-info)))
Elias Pipping's avatar
Elias Pipping committed
453
454
455
456
      (handle-result "obtainable and plausible?"
                     (and (numberp pid) (plusp pid)))
      (wait-process process-info)))

Elias Pipping's avatar
Elias Pipping committed
457
458
459
(new-test-suite "wait-process")

(define-test
460
461
462
463
    "exit code after exit: synchronous"
    (let ((exit-code (nth-value 2 (run-program "./exiter.sh 12"
                                               :ignore-error-status t))))
      (handle-result "exit code matches?" (equal 12 exit-code))))
Elias Pipping's avatar
Elias Pipping committed
464
465
466

(define-test
    "exit code after exit: asynchronous (repeated)"
467
    (let ((process-info (launch-program "./sleeper.sh 12 1")))
468
469
470
471
      (handle-result "exit code matches?"
                     (equal 12 (wait-process process-info)))
      (handle-result "exit code matches? (no. 2)"
                     (equal 12 (wait-process process-info)))))
Elias Pipping's avatar
Elias Pipping committed
472

473
(define-test
474
    "exit code after signal: synchronous"
475
476
    #+(and lispworks (not lispworks7+))
    (skip-test "Known to fail")
477
478
479
    (let ((exit-code (nth-value 2 (run-program "./killer.sh"
                                               :ignore-error-status t))))
      (handle-result "exit code matches?" (equal (+ 128 15) exit-code))))
480
481
482
483
484

(define-test
    "exit code after signal: asynchronous (repeated)"
    #+(and lispworks (not lispworks7+))
    (skip-test "Known to fail")
485
    (let ((process-info (launch-program "./killer.sh")))
486
487
488
489
490
      (handle-result "exit code matches?"
                     (equal (+ 128 15) (wait-process process-info)))
      (handle-result "exit code matches? (no. 2)"
                     (equal (+ 128 15) (wait-process process-info)))))

Elias Pipping's avatar
Elias Pipping committed
491
(new-test-suite "process-alive-p / terminate-process")
492
493
494

(define-test
    "not alive (we slept)"
495
    (let ((process-info (launch-program "./sleeper.sh 12 1")))
496
497
      (handle-result "alive?"
                     (process-alive-p process-info))
498
      (sleep 5)
499
500
501
502
503
504
505
      (handle-result "dead?"
                     (not (process-alive-p process-info)))
      (wait-process process-info)))


(define-test
    "not alive (we waited)"
506
    (let ((process-info (launch-program "./sleeper.sh 12 1")))
507
508
509
510
511
512
513
      (handle-result "alive?"
                     (process-alive-p process-info))
      (wait-process process-info)
      (handle-result "dead?"
                     (not (process-alive-p
                           process-info)))))

Elias Pipping's avatar
Elias Pipping committed
514
515
(define-test
    "not alive (we terminated it)"
516
    (let ((process-info (launch-program "./sleeper.sh 12 2")))
Elias Pipping's avatar
Elias Pipping committed
517
518
519
520
521
522
523
524
525
526
      (handle-result "alive?"
                     (process-alive-p process-info))
      (my-terminate-process process-info :urgent t)
      (sleep 1)
      (handle-result "dead?"
                     (not (process-alive-p process-info)))
      (wait-process process-info)))

(define-test
    "not alive (we terminated it repeatedly)"
527
    (let ((process-info (launch-program "./sleeper.sh 12 3")))
Elias Pipping's avatar
Elias Pipping committed
528
529
530
531
532
533
534
535
536
537
      (handle-result "alive?"
                     (process-alive-p process-info))
      (my-terminate-process process-info :urgent t)
      (sleep 1)
      (my-terminate-process process-info :urgent t)
      (sleep 1)
      (handle-result "dead?"
                     (not (process-alive-p process-info)))
      (wait-process process-info)))

538
539
(define-test
    "multiple processes: proper exit sequence"
540
541
    (let ((process-info1 (launch-program "./sleeper.sh 12 1"))
          (process-info2 (launch-program "./sleeper.sh 12 2")))
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
      (handle-result "#1 alive?"
                     (process-alive-p process-info1))
      (handle-result "#2 alive?"
                     (process-alive-p process-info2))
      (wait-process process-info1)
      (handle-result "#1 dead?"
                     (not (process-alive-p
                           process-info1)))
      (handle-result "#2 still alive?"
                     (process-alive-p process-info2))
      (wait-process process-info2)
      (handle-result "#1 still dead?"
                     (not (process-alive-p
                           process-info1)))
      (handle-result "#2 dead?"
                     (not (process-alive-p
                           process-info2)))))

Elias Pipping's avatar
Elias Pipping committed
560
(new-test-suite "%process-status / terminate-process")
561

562
563
564
(defun process-status (process-info)
  (uiop/launch-program::%process-status process-info))

565
566
(define-test
    ":exited (we slept; repeated query)"
567
    (let* ((process-info (launch-program "./sleeper.sh 12 1"))
568
           (status (process-status process-info)))
569
      (handle-result "running?" (equal :running status))
570
      (sleep 5)
571
      (multiple-value-bind (status exit-code)
572
          (process-status process-info)
573
574
575
        (handle-result "exited?" (equal :exited status))
        (handle-result "proper exit status?" (equal 12 exit-code)))
      (multiple-value-bind (status exit-code)
576
          (process-status process-info)
577
578
579
580
581
582
583
584
        (handle-result "exited? (no. 2)" (equal :exited status))
        (handle-result "proper exit status? (no. 2)" (equal 12 exit-code)))
      (wait-process process-info)))

(define-test
    ":exited/:signaled (it killed itself; repeated query)"
    #+(and lispworks (not lispworks7+))
    (skip-test "Known to fail")
585
    (let* ((process-info (launch-program "./killer.sh")))
586
      (sleep 5)
587
      (multiple-value-bind (status code)
588
          (process-status process-info)
589
590
591
592
593
594
        (handle-result "exited or signaled?"
                       (member status '(:exited :signaled)))
        (handle-result "signal/exit code as expected?"
                       (or (and (eq status :exited) (eql code 143))
                           (and (eq status :signaled) (eql code 15)))))
      (multiple-value-bind (status code)
595
          (process-status process-info)
596
597
598
599
600
601
602
603
604
        (handle-result "exited or signaled? (no. 2)"
                       (member status '(:exited :signaled)))
        (handle-result "signal/exit code as expected? (no. 2)"
                       (or (and (eq status :exited) (eql code 143))
                           (and (eq status :signaled) (eql code 15)))))
      (wait-process process-info)))

(define-test
    ":exited (it exited >128; repeated query)"
605
    (let* ((process-info (launch-program "./killercontainer.sh")))
606
      (sleep 5)
607
      (multiple-value-bind (status code)
608
          (process-status process-info)
609
610
611
        (handle-result "exited?" (eq status :exited))
        (handle-result "proper exit status?" (eql code (+ 128 15))))
      (multiple-value-bind (status code)
612
          (process-status process-info)
613
614
615
616
        (handle-result "exited (no. 2)?" (eq status :exited))
        (handle-result "proper exit status? (no. 2)?" (eql code (+ 128 15))))
      (wait-process process-info)))

Elias Pipping's avatar
Elias Pipping committed
617
618
619
620
(define-test
    ":signaled (we terminated it; repeated query)"
    #+(and lispworks (not lispworks7+))
    (skip-test "Known to fail")
621
    (let* ((process-info (launch-program "./sleeper.sh 12 2"))
622
           (status (process-status process-info)))
Elias Pipping's avatar
Elias Pipping committed
623
624
625
626
      (handle-result "running?" (equal :running status))
      (my-terminate-process process-info :urgent t)
      (sleep 1)
      (multiple-value-bind (status code)
627
          (process-status process-info)
Elias Pipping's avatar
Elias Pipping committed
628
629
630
        (handle-result "signaled?" (eq status :signaled))
        (handle-result "signal as expected?" (member code '(9 15))))
      (multiple-value-bind (status code)
631
          (process-status process-info)
Elias Pipping's avatar
Elias Pipping committed
632
633
634
635
        (handle-result "signaled (no. 2)?" (eq status :signaled))
        (handle-result "signal as expected (no. 2)?" (member code '(9 15))))
      (wait-process process-info)))

Elias Pipping's avatar
Elias Pipping committed
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
(fresh-line)
(run-tests)

(write-line "")
(when (plusp *number-of-failed-tests*)
  (format t "~2@a sub-tests failed.~%" *number-of-failed-tests*))
(when (plusp *number-of-skipped-tests*)
  (format t "~2@a sub-tests skipped because of known errors.~%"
          *number-of-skipped-tests*))
(when (plusp *number-of-unsupported-tests*)
  (format t "~2@a sub-tests could not be run on this platform (not supported).~%"
          *number-of-unsupported-tests*))
(when (plusp *number-of-unimplemented-tests*)
  (format t "~2@a sub-tests could not be run on this platform (not implemented).~%"
          *number-of-unimplemented-tests*))

(when (plusp *number-of-failed-tests*)
  (format *error-output*
          "Exiting with non-zero code because of unexpected test failures.~%")
  (exit-lisp 1))

(exit-lisp 0)

;; Local Variables:
;; mode:common-lisp
;; End: