File: asynctest.lsp

package info (click to toggle)
fusefile 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: ansic: 976; lisp: 194; makefile: 28; sh: 25
file content (70 lines) | stat: -rwxr-xr-x 2,042 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
#!/usr/bin/newlisp
#
# This is a test script for the overlay function of fusefile.
#
# 1) prepare a base image
# 2) set up a fusefile 
# 3) run tests
# 4) dismantle the fusefile 
# 5) remove test images


; ID is hour, minute and second values packed into a string
(constant
 'ID (apply string (3 3 (now)))
 'BASE (format "%s.raw" ID) 'SEGSZ 17000 'SEGN 40
 'FILE (join (map (fn (R) (format "%s/%d:%d" (cons BASE R)))
                  (map (curry map (curry * SEGSZ) R)
                       '((14 22) (0 3) (22 40) (3 22))))
             " ")
 'LIBC6 "/lib/x86_64-linux-gnu/libc.so.6"
 'MINE "mine"
 )
(import LIBC6 "on_exit" "int" "void*" "void*")

;; BASE is set up as a holes file with SEGN segments of size SEGSZ
(! (format "dd if=/dev/zero of=%s bs=%d seek=%d count=0 status=none"
           BASE SEGSZ SEGN))

;; Set up the fusefile
(unless (= (! (format "fusefile %s %s %s"
                      "-ononempty -oallow_other" BASE FILE)))
  (exit 1))

(println (list BASE FILE))

(define (writer CODE ADDR)
  (println "writer " (char (CODE 0)) " " ADDR)
  (let ((FD (open BASE "u")))
    (when (> FD)
      (seek FD ADDR)
      (write FD CODE)
      (close FD))))

(define (reader CODE ADDR)
  (println "reader " (char (CODE 0)) " " ADDR)
  (let ((FD (open BASE "u")) (TODO (length CODE)) (BUFFER "") (B ""))
    (if (when (> FD)
          (seek FD ADDR)
          (while (and (> TODO) (> (setf N (read FD B TODO))))
            (extend BUFFER B)
            (dec TODO (length B)))
          (close FD)
          (and (= TODO) (= CODE BUFFER)))
        (println "reader " (char (CODE 0)) " done")
      (println "reader " (char (CODE 0)) " failed")
      )))

(define (forking FN I)
  (letex ((FN FN) (CODE (dup (char I) (/ SEGSZ 2))) (ADDR (* (- I 1) SEGSZ)))
    (fork (FN CODE ADDR))))

(map wait-pid (map (curry forking writer) (sequence 1 SEGN)))
(map wait-pid (map (curry forking reader) (sequence 1 SEGN)))

;; On exit: unmount the fusefile and delete the BASE
(! (format "fusermount -u %s" BASE))
(delete-file BASE)

(exit 0)