File: posix_sys_msg_spec.yaml

package info (click to toggle)
lua-posix 36.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,720 kB
  • sloc: ansic: 5,462; makefile: 21; sh: 6
file content (181 lines) | stat: -rw-r--r-- 6,239 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
71
72
73
74
75
76
77
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
before:
  this_module = 'posix.sys.msg'
  global_table = '_G'

  M = require(this_module)

specify posix.sys.msg:
- context when required:
  - it does not touch the global table:
      expect(show_apis {added_to=global_table, by=this_module}).
         to_equal {}


- before:
    errno = require 'posix.errno'
    msg = require 'posix.sys.msg'
    st = require 'posix.sys.stat'
    unistd = require 'posix.unistd'

    EPOCH = require 'posix.time'.time()
    EEXIST = errno.EEXIST
    msgget, msgsnd, msgrcv = M.msgget, M.msgsnd, M.msgrcv
    IPC_CREAT, IPC_EXCL = M.IPC_CREAT, M.IPC_EXCL
    S_IRUSR, S_IRGRP, S_IROTH = st.S_IRUSR, st.S_IRGRP, st.S_IROTH
    S_IWUSR, S_IWGRP, S_IWOTH = st.S_IWUSR, st.S_IWGRP, st.S_IWOTH

    mode = bor(S_IRUSR, S_IRGRP, S_IROTH, S_IWUSR, S_IWGRP, S_IWOTH)
    mq, err, errnum = msgget(100, bor(IPC_CREAT, IPC_EXCL, mode))
    if errnum == EEXIST then
       mq, err = msgget(100, mode)
    end

    mtype = 42
    mdata = 'Answer to the Ultimate Question of Life'


- describe msgget:
  - context with bad arguments:
      badargs.diagnose(msgget, ' (int, ?int)')

  - it creates a queue:
      expect(mq).not_to_be(nil)
      expect(err).to_be(nil)


- describe msgsnd:
  - context with bad arguments:
      badargs.diagnose(msgsnd, ' (int, int, string, ?int)')

  - it sends a message:
      ok, err = msgsnd(mq, mtype, mdata)
      expect(ok).not_to_be(err)


- describe msgrcv:
  - context with bad arguments:
      badargs.diagnose(msgrcv, ' (int, int, ?int, ?int)')

  - it receives a message:
      expect({msgrcv(mq, 128)}).to_equal {mtype, mdata, nil}


- describe msgctl:
  - before:
      msgctl = M.msgctl
      IPC_RMID, IPC_SET, IPC_STAT = M.IPC_RMID, M.IPC_SET, M.IPC_STAT

      objtype = function(x) return(getmetatable(x) or {})._type end

  - context with bad arguments:
      # Not really 'any*' for arg3, but that's all we can do without knowing arg2!
      badargs.diagnose(msgctl, ' (int, int, any*)')

  - context with IPC_STAT:
    - it diagnoses too many arguments:
        expect(msgctl(mq, IPC_STAT, false)).
           to_raise 'no more than 2 arguments expected, got 3'

    - it returns a new table on each invocation:
        expect(msgctl(mq, IPC_STAT)).not_to_be(msgctl(mq, IPC_STAT))

    - it returns correctly populated PosixMsqid table:
        msqid = msgctl(mq, IPC_STAT)
        expect(objtype(msqid)).to_be 'PosixMsqid'
        expect(type(msqid.msg_qnum)).to_be 'number'
        expect(type(msqid.msg_qbytes)).to_be 'number'
        expect(msqid.msg_lspid).to_be(unistd.getpid())
        expect(msqid.msg_lrpid).to_be(unistd.getpid())
        expect(msqid.msg_stime).to_be_within_n_of {value=EPOCH, delta=1}
        expect(msqid.msg_rtime).to_be_within_n_of {value=EPOCH, delta=1}
        expect(msqid.msg_perm.uid).to_be(unistd.getuid())
        expect(msqid.msg_perm.gid).to_be(unistd.getgid())
        expect(msqid.msg_perm.cuid).to_be(msqid.msg_perm.uid)
        expect(msqid.msg_perm.cgid).to_be(msqid.msg_perm.gid)
        expect(msqid.msg_perm.mode).to_be(mode)

  - context with IPC_SET:
    - before:
        sleep = require 'posix.unistd'.sleep
        msqid = {
           msg_perm = {
              uid = unistd.getuid(),
              gid = unistd.getgid(),
              mode = mode,
           },
           msg_qbytes = 1024,
        }

    - 'it diagnoses missing argument #3':
        expect(msgctl(mq, IPC_SET)).to_raise 'table expected, got no value'

    - 'it diagnoses argument #3 type not table':
        expect(msgctl(mq, IPC_SET, false)).to_raise 'table expected, got boolean'

    - 'it diagnoses argument #3 with missing fields':
        msqid.msg_qbytes = nil
        expect(msgctl(mq, IPC_SET, msqid)).
           to_raise "integer expected for field 'msg_qbytes', got no value"
        expect(msgctl(mq, IPC_SET, {msg_qbytes=1024})).
           to_raise "table expected for field 'msg_perm', got no value"

    - 'it diagnoses argument #3 with bad field types':
        msqid.msg_qbytes = false
        expect(msgctl(mq, IPC_SET, msqid)).
           to_raise "integer expected for field 'msg_qbytes', got boolean"
        expect(msgctl(mq, IPC_SET, {msg_qbytes=1024, msg_perm=false})).
           to_raise "table expected for field 'msg_perm', got boolean"

    - 'it diagnoses argument #3 with bad field names':
        msqid.bogus = 1
        expect(msgctl(mq, IPC_SET, msqid)).
           to_raise "invalid field name 'bogus'"

    - 'it diagnoses argument #3 with missing subfields':
        msqid.msg_perm.mode = nil
        expect(msgctl(mq, IPC_SET, msqid)).
           to_raise "integer expected for field 'mode', got no value"

    - 'it diagnoses argument #3 with bad subfield types':
        msqid.msg_perm.mode = false
        expect(msgctl(mq, IPC_SET, msqid)).
           to_raise "integer expected for field 'mode', got boolean"

    - 'it diagnoses argument #3 with bad subfield names':
        msqid.msg_perm.bogus = 1
        expect(msgctl(mq, IPC_SET, msqid)).
           to_raise "invalid field name 'bogus'"

    - it diagnoses too many arguments:
        expect(msgctl(mq, IPC_SET, {}, nil)).
           to_raise 'no more than 3 arguments expected, got 4'

    - it sets specified fields in the message queue:
        expect(msgctl(mq, IPC_SET, msqid)).not_to_be(nil)
        r = msgctl(mq, IPC_STAT)
        expect(r.msg_perm.uid).to_be(unistd.getuid())
        expect(r.msg_perm.gid).to_be(unistd.getgid())
        expect(r.msg_perm.mode).to_be(mode)
        expect(r.msg_qbytes).to_be(1024)

    - it updates ctime field:
        msqid.msg_qbytes = 666
        ctime = msgctl(mq, IPC_STAT).msg_ctime
        expect(ctime).not_to_be(nil)
        sleep(2)
        expect(msgctl(mq, IPC_SET, msqid)).not_to_be(nil)
        expect(msgctl(mq, IPC_STAT).msg_ctime).not_to_be(ctime)


  - context with IPC_RMID:
    - it diagnoses too many arguments to IPC_RMID cmd:
        expect(msgctl(mq, IPC_RMID, false)).to_raise 'no more than 2 arguments expected, got 3'

    - it removes a queue:
        ok, err = msgctl(mq, IPC_RMID)
        expect(ok).not_to_be(err)

    - it diagnoses a bad queue: |
        ok, err = msgctl(mq, IPC_RMID)
        expect(ok).to_be(nil)
        expect(err).to_contain 'msgctl: '