Coverage report: /home/ellis/comp/core/lib/io/tests.lisp

KindCoveredAll%
expression025 0.0
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 (defpackage :io/tests
2
   (:use :cl :std :rt :io :uring :zstd :sb-gray :disk :disk/btrfs :io/stream :io/deflate))
3
 
4
 (in-package :io/tests)
5
 (defsuite :io)
6
 (in-suite :io)
7
 
8
 (load-uring)
9
 (load-zstd)
10
 (btrfs:load-btrfs)
11
 (deftest sanity () (uring::io-uring-major-version))
12
 
13
 ;; (deftest uring-serve-event ()
14
 ;;   "See 'tests/serve-event.pure.lisp'"
15
 ;;   nil)
16
 
17
 (deftest streams ()
18
   "IO/STREAM tests"
19
   ;; bound
20
   ;; peeking
21
   ;; buffer? currently in dat/serde
22
   (istype 'bound-input-stream (make-instance 'bound-input-stream))
23
   (with-input-from-string (s "foobarbaz")
24
     (isequal "fo" (concatenate 'string (peeked (make-instance 'peeking-input-stream :stream s :count 2))))))
25
 
26
 (deftest chunky ()
27
   "Tests for CHUNKED-STREAM"
28
   (let ((input (make-chunked-stream 
29
                 (make-instance 'fundamental-binary-input-stream)))
30
         (output (make-chunked-stream 
31
                  (make-instance 'fundamental-binary-output-stream))))
32
     (istype 'chunked-stream 
33
             (make-chunked-stream 
34
              (make-instance 'fundamental-binary-stream)))
35
     (istype 'chunked-input-stream input)
36
     (istype 'chunked-output-stream output)
37
     (istype 'chunked-io-stream (make-chunked-stream (make-two-way-stream input output)))
38
     (istype 'blocked-input-stream (make-instance 'blocked-input-stream))))
39
 
40
 (defparameter *data-size* (* 10 1024))
41
 
42
 (deftest zstd-simple ()
43
   (let ((data (make-array *data-size* :element-type 'octet :initial-contents (random-bytes *data-size*)))
44
         (round-trip-data (make-octets *data-size*))
45
         compressed-data)
46
     (setf compressed-data
47
           (with-zstd-buffer (b data :direction :output) b))
48
     (setf round-trip-data
49
           (with-zstd-buffer (b compressed-data :direction :input) b))
50
     (is (equalp round-trip-data data))))
51
 
52
 ;; FIX 2025-03-27: 
53
 (deftest zstd-stream ()
54
   (let* ((bsize 4096)
55
          (ssize (* 20 bsize))
56
          (data (make-octets ssize :initial-contents (random-bytes ssize)))
57
          (compressor (make-instance 'zstd-compressor))
58
          (decompressor (make-instance 'zstd-decompressor)))
59
     (unwind-protect
60
          (progn
61
            (loop for x below (/ ssize bsize)
62
                  with i = (* x bsize)
63
                  with v = (subseq data i (+ i bsize))
64
                  do (compress-with compressor v))
65
            (finish-output compressor) ;; endstream
66
            ;; (stream-force-output compressor) ;; flush
67
            ;; (setf (output-size compressor) (output-position compressor))
68
                  ;; (output-position compressor) 0)
69
            (log:info! :in.pos (input-position compressor)
70
                       :in.size (input-size compressor)
71
                       :out.pos (output-position compressor)
72
                       :out.size (output-size compressor))
73
            (let ((compressed (make-array (output-position compressor) :element-type 'octet))
74
                  (decompressed (make-array (output-size compressor) :element-type 'octet)))
75
              (clone-octets-from-alien (output-buffer compressor) compressed)
76
              (println compressed)
77
              (decompress-with decompressor compressed)
78
              (clone-octets-from-alien
79
               (output-buffer decompressor)
80
               decompressed)
81
              (log:info! data)
82
              (log:info! decompressed)
83
              (is (equalp data decompressed))))
84
       ;; (close (stream-of decompressor))
85
       ;; (close (stream-of compressor))
86
       )))
87
 
88
 ;;; Deflate
89
 (deftest gzip-stream ()
90
   "Test the compressing stream by round tripping random data."
91
   (let ((data (make-array *data-size* :element-type '(unsigned-byte 8)
92
                                               :initial-contents (loop repeat *data-size*
93
                                                                       collect (random 256))))
94
         (round-trip-data (make-array *data-size* :element-type '(unsigned-byte 8)
95
                                                          :initial-element 0))
96
         compressed-data)
97
     (setf compressed-data
98
           (with-output-to-string (s)
99
             (with-open-stream (out-stream (make-compressing-stream :gzip s))
100
               (write-sequence data out-stream))))
101
     (with-input-from-string (s compressed-data)
102
       (with-open-stream (in-stream (make-decompressing-stream :gzip s))
103
         (read-sequence round-trip-data in-stream)
104
         (is eql :eof (read-byte in-stream nil :eof))))
105
     (is equalp data round-trip-data)))
106
 
107
 (deftest gzip-stream-closed-error ()
108
   (with-output-to-string (s)
109
     (let ((out-stream (make-compressing-stream :gzip s)))
110
       (write-byte 1 out-stream)
111
       (close out-stream)
112
       (signals 'error (write-byte 2 out-stream)))))
113
 
114
 (deftest bzip2 ())
115
 (deftest zlib ())
116
 
117
 ;;; Static Vectors
118
 (deftest static-vector ()
119
   (with-static-vector (v 4)
120
     (isequalp #(0 0 0 0) v))
121
   (isequalp #(0 0 0 0) (make-static-vector 4)))
122
 
123
 ;;; Smart Buffers
124
 (deftest smart-buffer ()
125
   (let ((sb (make-smart-buffer)))
126
     (istype 'smart-buffer sb)))
127
 
128
 ;;; XSubseq
129
 (deftest xsubseq ()
130
   (istype 'string
131
           (with-xsubseqs (ret)
132
             (iszero (xlength ret))
133
             (xnconcf ret (xsubseq "test" 0))
134
             (is= 4 (xlength ret)))))
135
 
136
 ;;; Disk
137
 (deftest disk-generic ()
138
   (let ((disk (make-instance 'disk)))
139
     (istype 'disk disk)))
140
 
141
 (deftest disk-btrfs ()
142
   (is (load-filesystem-backend :btrfs))
143
   (let ((disk (make-instance 'btrfs-disk)))
144
     (issubclass 'disk (class-of disk)))
145
   ;; will return NIL on non-btrfs file systems
146
   (islist (btrfs-subvolumes "/tmp")))