-
Notifications
You must be signed in to change notification settings - Fork 0
/
_ydbposixtest.m
416 lines (390 loc) · 23.9 KB
/
_ydbposixtest.m
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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
301
302
303
304
305
306
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Copyright (c) 2012-2022 Fidelity National Information ;
; Services, Inc. and/or its subsidiaries. All rights reserved. ;
; ;
; Copyright (c) 2018-2023 YottaDB LLC and/or its subsidiaries. ;
; All rights reserved. ;
; ;
; This source code contains the intellectual property ;
; of its copyright holder(s), and is made available ;
; under a license. If you do not know the terms of ;
; the license, please stop and do not read further. ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
%ydbposixtest
; test POSIX plugin
; Initialization
new %ydbposix,arch,clock,computeddh1,ddzh,dh1,dh2,diffca,diffma,dir,file,errmsg,errno,gid
new hour,i,io,isdst,link,mask,mday,min,mode1,mode2,prevmode,mon,msg,msg1,os,oslist,out,out1,out2,path
new result,retval,sec,setenvtst,size,stat,tmp,tv,tvsec,tvusec,tvnsec,uid,value,ver1,ver2
new wday,yday,year
set io=$io
set os=$piece($zv," ",3)
set setenvtst=1
set arch=$piece($zv," ",4)
; Get version - check it later
set ver1=$$version^%ydbposix
set ver2=$$VERSION^%ydbposix
; Verify that command line invocation fails with error message
open "POSIX":(shell="/bin/sh":command="$ydb_dist/mumps -run %ydbposix":readonly:stderr="POSIXerr")::"pipe"
use "POSIX" for i=1:1 read tmp quit:$zeof set out1(i)=tmp
use "POSIXerr" for i=1:1 read tmp quit:$zeof set out2(i)=tmp
use io close "POSIX"
if "%ydbposix-F-BADINVOCATION Must call an entryref in %ydbposix"=$get(out1(1))&'$data(out2) write "PASS Invocation",!
else write "FAIL Invocation",! zwrite:$data(out1) out1 zwrite:$data(out2) out2
; Check $zhorolog/$ZHOROLOG
; retry until microsec returned by $zhorolog
for set dh1=$horolog,ddzh=$$zhorolog^%ydbposix,dh2=$horolog quit:(dh1=dh2)&$piece(ddzh,".",2)
if dh1'=$piece(ddzh,".",2) write "PASS $zhorolog",!
else write "FAIL $zhorolog $horolog=",dh1," $$zhorolog^%ydbposix=",ddzh,!
for set dh1=$horolog,ddzh=$$ZHOROLOG^%ydbposix,dh2=$horolog quit:(dh1=dh2)&$piece(ddzh,".",2)
if dh1=$piece(ddzh,".",2) write "FAIL $ZHOROLOG $horolog=",dh1," $$ZHOROLOG^%ydbposix=",ddzh,!
else write "PASS $ZHOROLOG",!
; Check mktime()
set tmp=$zdate(dh1,"YYYY:MM:DD:24:60:SS:DAY","","0,1,2,3,4,5,6"),isdst=-1
set retval=$&ydbposix.mktime($piece(tmp,":",1)-1900,$piece(tmp,":",2)-1,+$piece(tmp,":",3),+$piece(tmp,":",4),+$piece(tmp,":",5),+$piece(tmp,":",6),.wday,.yday,.isdst,.tvsec,.errno)
write "Daylight Savings Time is ",$select('isdst:"not ",1:""),"in effect",!
set retval=$&ydbposix.localtime(tvsec,.sec,.min,.hour,.mday,.mon,.year,.wday,.yday,.isdst,.errno)
set computeddh1=($$FUNC^%DATE(mon+1_"/"_mday_"/"_(1900+year))_","_($$FUNC^%TI($translate($justify(hour,2)_$justify(min,2)," ",0))+sec))
if $piece(tmp,":",7)=wday&(dh1=computeddh1) write "PASS mktime()",!
else write "FAIL mktime() $horolog=",dh1," Computed=",computeddh1,!
; Check that we get at least fractional second times - this test has 1 in 10**12 chance of failing incorrectly
set tmp="PASS Microsecond resolution"
for i=0:1 set retval=$&ydbposix.gettimeofday(.tvsec,.tvusec,.errno) quit:tvusec set:i $extract(tmp,1,4)="FAIL"
write tmp,!
set tv=tvusec/1E6+tvsec
; Check that getrlimit returns expected values; uses getuid to check values against /process
set file="/proc/"_$job_"/limits" ; get our values from /proc
open file:readonly
use file:rewind
do
. new bad,i,val ; parse out the getrlimit values
. read v ; don't want header
. for i=1:1:16 read v set val($piece($text(@$translate($piece(v," ",2,3)," ")),";",2))=$piece($extract(v,27,99)," ")
. close file ; then check some, using both lower and upper case forms, to see they match the /proc values
. for lim="MSGQUEUE","MEMLOCK" if $&ydbposix.getrlimit("RLIMIT_"_lim,.value,.errno),value'=val(lim),$increment(bad) zwrite val(lim),value
. for lim="SIGPENDING","NPROC" if $&ydbposix.getrlimit("RLIMIT_"_lim,.value,.errno),value'=val(lim),$increment(bad) zwrite val(lim),value
. write $select('$get(bad):"PASS",1:"FAIL")," GETRLIMIT",!
; table below used in the first FOR loop above helps match the /proc text to the corresponding RLIMIT keyword
addressspace;AS
corefile;CORE
cputime;CPU
datasize;DATA
filelocks;LOCKS
filesize;FSIZE
lockedmemory;MEMLOCK
msgqueuesize;MSGQUEUE
openfiles;NOFILE
pendingsignals;SIGPENDING
processes;NPROC
realtimepriority;RTPRIO
residentset;RSS
stacksize;STACK
; Check that getuid returns an appropriate value
do
. new id,pipe
. set pipe="pipe" open pipe:(command="id -u")::pipe use pipe read id close pipe
. if '$&ydbposix.getuid(.value),value
. write $select(id=value:"PASS",1:"FAIL")," GETUID",!
; Check regular expression pattern matching
set oslist="AIXHP-UXLinuxSolaris"
if $$regmatch^%ydbposix(oslist,"ux",,,.result,3)&("ux"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS regmatch^%ydbposix 1",!
else write "FAIL regmatch^%ydbposix 1",!
set tmp=$order(%ydbposix("regmatch","ux","")) do regfree^%ydbposix("%ydbposix(""regmatch"",""ux"","_tmp_")")
if $data(%ydbposix("regmatch","ux",tmp))#10 write "FAIL regfree^%ydbposix",!
else write "PASS regfree^%ydbposix",!
if $$REGMATCH^%ydbposix(oslist,"ux",,,.result,3)&("ux"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS REGMATCH^%ydbposix 1",!
else write "FAIL REGMATCH^%ydbposix 1",!
set tmp=$order(%ydbposix("regmatch","ux","")) do REGFREE^%ydbposix("%ydbposix(""regmatch"",""ux"","_tmp_")")
if $data(%ydbposix("regmatch","ux",tmp))#10 write "FAIL REGFREE^%ydbposix",!
else write "PASS REGFREE^%ydbposix",!
if $$regmatch^%ydbposix(oslist,"ux","REG_ICASE",,.result,3)&("UX"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS regmatch^%ydbposix 2",!
else write "FAIL regmatch^%ydbposix 2",!
do regfree^%ydbposix("%ydbposix(""regmatch"",""ux"","_$order(%ydbposix("regmatch","ux",""))_")")
if $$REGMATCH^%ydbposix(oslist,"ux","REG_ICASE",,.result,3)&("UX"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS REGMATCH^%ydbposix 2",!
else write "FAIL REGMATCH^%ydbposix 2",!
do REGFREE^%ydbposix("%ydbposix(""regmatch"",""ux"","_$order(%ydbposix("regmatch","ux",""))_")")
if $$regmatch^%ydbposix(oslist,"S$","REG_ICASE",,.result,3)&("s"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS regmatch^%ydbposix 3",!
else write "FAIL regmatch^%ydbposix 3",!
do regfree^%ydbposix("%ydbposix(""regmatch"",""S$"","_$order(%ydbposix("regmatch","S$",""))_")")
if $$REGMATCH^%ydbposix(oslist,"S$","REG_ICASE",,.result,3)&("s"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS REGMATCH^%ydbposix 3",!
else write "FAIL REGMATCH^%ydbposix 3",!
do REGFREE^%ydbposix("%ydbposix(""regmatch"",""S$"","_$order(%ydbposix("regmatch","S$",""))_")")
if $$regmatch^%ydbposix(oslist,"S$","REG_ICASE",,.result,3)&("s"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS regmatch^%ydbposix 3",!
else write "FAIL regmatch^%ydbposix 3",!
do regfree^%ydbposix("%ydbposix(""regmatch"",""S$"","_$order(%ydbposix("regmatch","S$",""))_")")
if $$REGMATCH^%ydbposix(oslist,"S$","REG_ICASE",,.result,3)&("s"=$extract(oslist,result(1,"start"),result(1,"end")-1)) write "PASS REGMATCH^%ydbposix 3",!
else write "FAIL REGMATCH^%ydbposix 3",!
do REGFREE^%ydbposix("%ydbposix(""regmatch"",""S$"","_$order(%ydbposix("regmatch","S$",""))_")")
if $$regmatch^%ydbposix(oslist,"\([[:alnum:]]*\)-\([[:alnum:]]*\)",,,.result,5)&(oslist=$extract(oslist,result(1,"start"),result(1,"end")-1))&("AIXHP"=$extract(oslist,result(2,"start"),result(2,"end")-1))&("UXLinuxSolaris"=$extract(oslist,result(3,"start"),result(3,"end")-1))&(3=$order(result(""),-1)) write "PASS regmatch^%ydbposix 4",!
else write "FAIL regmatch^%ydbposix 4",!
do regfree^%ydbposix("%ydbposix(""regmatch"",""\([[:alnum:]]*\)-\([[:alnum:]]*\)"","_$order(%ydbposix("regmatch","\([[:alnum:]]*\)-\([[:alnum:]]*\)",""))_")")
if $$REGMATCH^%ydbposix(oslist,"\([[:alnum:]]*\)-\([[:alnum:]]*\)",,,.result,5)&(oslist=$extract(oslist,result(1,"start"),result(1,"end")-1))&("AIXHP"=$extract(oslist,result(2,"start"),result(2,"end")-1))&("UXLinuxSolaris"=$extract(oslist,result(3,"start"),result(3,"end")-1))&(3=$order(result(""),-1)) write "PASS REGMATCH^%ydbposix 4",!
else write "FAIL REGMATCH^%ydbposix 4",!
do REGFREE^%ydbposix("%ydbposix(""regmatch"",""\([[:alnum:]]*\)-\([[:alnum:]]*\)"","_$order(%ydbposix("regmatch","\([[:alnum:]]*\)-\([[:alnum:]]*\)",""))_")")
if $$regmatch^%ydbposix(oslist,"^AIX",,"REG_NOTBOL",.result,3) write "FAIL regmatch^%ydbposix 5",!
else write "PASS regmatch^%ydbposix 5",!
do regfree^%ydbposix("%ydbposix(""regmatch"",""^AIX"","_$order(%ydbposix("regmatch","^AIX",""))_")")
if $$REGMATCH^%ydbposix(oslist,"^AIX",,"REG_NOTBOL",.result,3) write "FAIL REGMATCH^%ydbposix 5",!
else write "PASS REGMATCH^%ydbposix 5",!
do REGFREE^%ydbposix("%ydbposix(""regmatch"",""^AIX"","_$order(%ydbposix("regmatch","^AIX",""))_")")
; Check statfile - indirectly tests mkdtemp also. Note that not all stat parameters can be reliably tested
set dir="/tmp/posixtest"_$j_"_XXXXXX"
set retval=$$mktmpdir^%ydbposix(.dir) write:'retval "FAIL mktmpdir retval=",retval,!
set retval=$$statfile^%ydbposix(.dir,.stat) write:retval "FAIL statfile retval=",retval,!
if stat("ino") write "PASS mktmpdir",!
else write "FAIL mktmpdir stat(ino)=",stat("ino"),!
; Check that mtime atime and ctime atime are no more than 1 sec apart and tvsec is not greater that ctime
set diffma=(stat("mtime")-stat("atime"))*1E9+(stat("nmtime")-stat("natime"))
set:diffma<0 diffma=-diffma
set diffca=(stat("ctime")-stat("atime"))*1E9+(stat("nctime")-stat("natime"))
set:diffca<0 diffca=-diffca
; Normally tvsec is no greater than each of mtime, ctime and atime. However, we have seen one failure that made us change
; tvsec<=stat("ctime") to tvsec-1<=stat("ctime") <time_shift_ydbposix>
if ((diffma'>1E9)&(diffca'>1E9)&(tvsec-1'>stat("ctime"))) write "PASS statfile.times",!
else write "FAIL statfile.times dir=",dir," atime=",stat("atime")," natime=",stat("natime")," ctime=",stat("ctime")," nctime=",stat("nctime")," mtime=",stat("mtime")," nmtime=",stat("nmtime")," tv_sec=",tvsec,!
open "uid":(shell="/bin/sh":command="id -u":readonly)::"pipe"
use "uid" read uid use io close "uid"
open "gid":(shell="/bin/sh":command="id -g":readonly)::"pipe"
use "gid" read gid use io close "gid"
if stat("gid")=gid&(stat("uid")=uid) write "PASS statfile.ids",!
else write "FAIL statfile.ids gid=",gid," stat(""gid"")=",stat("gid")," uid=",uid," stat(""uid"")=",stat("uid"),!
; Check that mode from stat has directory bit set, but not regular file bit
set tmp=$$filemodeconst^%ydbposix("S_IFREG"),tmp=$$filemodeconst^%ydbposix("S_IFDIR")
if stat("mode")\%ydbposix("filemode","S_IFDIR")#2&'(stat("mode")\%ydbposix("filemode","S_IFREG")#2) write "PASS filemodeconst^%ydbposix",!
else write "FAIL filemodeconst^%ydbposix mode=",stat("mode")," S_IFDIR=",%ydbposix("filemode","S_IFDIR")," S_IFREG=",%ydbposix("filemode","S_IFREG"),!
; Check signal & STATFILE
set file="YDB_JOBEXAM.ZSHOW_DMP_"_$j_"_1"
if $&ydbposix.signalval("SIGUSR1",.result)!$zsigproc($j,result) write "FAIL signal",!
else write "PASS signal",!
set retval=$$STATFILE^%ydbposix(file,.stat) write:retval "FAIL STATFILE",!
if ((stat("mtime")-(stat("atime")+stat("ctime")/2)'>1)&(tvsec-1'>stat("ctime"))) write "PASS STATFILE.times",!
else write "FAIL STATFILE.times file=",file," atime=",stat("atime")," ctime=",stat("ctime")," mtime=",stat("mtime")," tv_sec=",tvsec,!
open "uid":(shell="/bin/sh":command="id -u":readonly)::"pipe"
use "uid" read uid use io close "uid"
open "gid":(shell="/bin/sh":command="id -g":readonly)::"pipe"
use "gid" read gid use io close "gid"
if stat("gid")=gid&(stat("uid")=uid) write "PASS STATFILE.ids",!
else write "FAIL STATFILE.ids gid=",gid," stat(""gid"")=",stat("gid")," uid=",uid," stat(""uid"")=",stat("uid"),!
zsystem "rm -f "_file
; Execute the syslog test; wait upto 60 seconds for messages to show up in syslog
if '$$hasSystemd() write "SKIP journalctl test on non-systemd system",!
else do
. set msg="Warning from process "_$j_" at "_ddzh,out="FAIL syslog1 - msg """_msg_""" not found in syslog"
. set msg1="Notice from process "_$j_" at "_ddzh,out1="FAIL syslog2 - msg """_msg1_""" not found in syslog"
. if $$syslog^%ydbposix(msg,"LOG_USER","LOG_WARNING")
. if $$SYSLOG^%ydbposix(msg1,"LOG_ERR","LOG_INFO")
. set dh1=60E6+$zut
. open "journalctl":(shell="/bin/sh":command="journalctl -f -S """_$zdate(ddzh,"YYYY-MM-DD 24:60:SS")_"""":readonly)::"pipe"
. use "journalctl"
. for read tmp do quit:"PASS syslog1"=out&("PASS syslog2"=out1)!(dh1<$zut)
. . set:$find(tmp,msg) out="PASS syslog1"
. . set:$find(tmp,msg1) out1="PASS syslog2"
. use io close "journalctl"
. write out,!,out1,!
; Check setenv and unsetenv
if 1=setenvtst do
. set retval=$&ydbposix.setenv("ydbposixtest",dir,0,.errno)
. set tmp=$ztrnlnm("ydbposixtest") if tmp=dir write "PASS setenv",!
. else write "FAIL setenv $ztrnlnm(""ydbposixtest"")=",tmp," should be ",dir,!
. set retval=$&ydbposix.unsetenv("ydbposixtest",.errno)
. set tmp=$ztrnlnm("ydbposixtest") if '$length(tmp) write "PASS unsetenv",!
. else write "FAIL unsetenv $ztrnlnm(""ydbposixtest"")=",tmp," should be unset",!
; Check rmdir
set retval=$&ydbposix.rmdir(dir,.errno)
if retval write "FAIL rmdir - return value from rmdir is ",retval,!
else do
. set retval=$$statfile^%ydbposix(dir,.errno)
. if 2'=retval write "FAIL rmdir – return value from statfile is ",retval,!
. else write "PASS rmdir",!
; Check MKTMPDIR
set dir="/tmp/posixtest"_$j_"_XXXXXX"
set retval=$$MKTMPDIR^%ydbposix(.dir) write:'retval "FAIL MKTMPDIR retval=",retval,!
set retval=$$STATFILE^%ydbposix(dir,.stat) write:retval "FAIL STATFILE retval=",retval,!
if stat("ino") write "PASS MKTMPDIR",!
else write "FAIL MKTMPDIR stat(ino)=",stat("ino"),!
set retval=$&ydbposix.rmdir(dir,.errno)
; Check mkdir
set dir="/tmp/posixtest"_$j_$$^%RANDSTR(6)
set retval=$$mkdir^%ydbposix(dir,"S_IRWXU") write:retval "FAIL MKTMPDIR retval=",retval,!
set retval=$$STATFILE^%ydbposix(dir,.stat) write:retval "FAIL STATFILE retval=",retval,!
if stat("ino") write "PASS mkdir",!
else write "FAIL mkdir stat(ino)=",stat("ino"),!
set retval=$&ydbposix.rmdir(dir,.errno)
; Check MKDIR
set dir="/tmp/posixtest"_$j_$$^%RANDSTR(6)
set retval=$$MKDIR^%ydbposix(dir,"S_IRWXU") write:retval "FAIL MKTMPDIR retval=",retval,!
set retval=$$STATFILE^%ydbposix(dir,.stat) write:retval "FAIL STATFILE retval=",retval,!
if stat("ino") write "PASS MKDIR",!
else write "FAIL MKDIR stat(ino)=",stat("ino"),!
set retval=$&ydbposix.rmdir(dir,.errno)
; Check UMASK and UTIMES
set mode1=$$filemodeconst^%ydbposix("S_IWUSR")
set retval=$$UMASK^%ydbposix(mode1,.prevmode) write:'retval "FAIL UMASK1 retval=",retval,!
set file="/tmp/posixtest"_$j_$$^%RANDSTR(6)
open file:newversion
close file
set retval=$$STATFILE^%ydbposix(file,.stat) write:retval "FAIL STATFILE retval=",retval,!
set tvsec=stat("mtime"),tvnsec=stat("nmtime")
hang 0.1 ; OSs cluster timestamps that are close to each other
set retval=$$UTIMES^%ydbposix(file) write:'retval "FAIL UTIMES retval=",retval,!
set retval=$$STATFILE^%ydbposix(file,.stat) write:retval "FAIL STATFILE retval=",retval,!
if ((0'=tmp)&(tvsec'=stat("mtime"))!(tvnsec'=stat("nmtime")!((0=tvnsec)&(0=stat("nmtime"))))) write "PASS UTIMES",!
else write "FAIL UTIMES stat(mtime)=",stat("mtime")," stat(nmtime)=",stat("nmtime"),!
set mode2=$$FUNC^%DO(stat("mode"))#1000 ; Get the last three digits
set mode1=$$FUNC^%DO(mode1)
set mask=$$octalAnd(mode1,mode2)
if (666=mask) write "PASS UMASK",! ; comparing with octal 0666
else write "FAIL UMASK stat(mode)=",stat("mode"),!
; Restore UMASK to previous value
set retval=$$UMASK^%ydbposix(prevmode,.tmp) write:'retval "FAIL UMASK2 retval=",retval,!
; Check CHMOD
set mode1=$$filemodeconst^%ydbposix("S_IXGRP")
set retval=$$CHMOD^%ydbposix(file,mode1) write:'retval "FAIL CHMOD retval=",retval,!
set retval=$$STATFILE^%ydbposix(file,.stat) write:retval "FAIL STATFILE retval=",retval,!
set mode2=$$FUNC^%DO(stat("mode"))#1000 ; Get the last three digits
set mode1=$$FUNC^%DO(mode1)
if (+mode1=+mode2) write "PASS CHMOD",!
else write "FAIL CHMOD stat(mode)=",stat("mode"),!
; Check SYMLINK and REALPATH
set link="/tmp/posixtest"_$j_$$^%RANDSTR(6)
set retval=$$SYMLINK^%ydbposix(file,link) write:'retval "FAIL SYMLINK retval=",retval,!
set retval=$$STATFILE^%ydbposix(link,.stat) write:retval "FAIL STATFILE retval=",retval,!
if stat("ino") write "PASS SYMLINK",!
else write "FAIL SYMLINK stat(ino)=",stat("ino"),!
set retval=$$REALPATH^%ydbposix(file,.path) write:'retval "FAIL REALPATH retval=",retval,!
if (file=path) write "PASS REALPATH",!
else write "FAIL REALPATH path=",path,!
set retval=$$CHMOD^%ydbposix(file,"S_IRWXU") write:'retval "FAIL CHMOD retval=",retval,!
open link
close link:delete
; Check CP
; Append to the existing (empty) file.
open file:append
use file
set value=""
for i=1:1:10 set tmp=$$^%RANDSTR(1000) set value=value_tmp_$char(10) write tmp,!
close file
set retval=$$STATFILE^%ydbposix(file,.stat) write:retval "FAIL STATFILE retval=",retval,!
set size=stat("size")
; Copy to a non-existent destination.
set retval=$$CP^%ydbposix(file,link) write:'retval "FAIL CP retval=",retval,!
set retval=$$STATFILE^%ydbposix(link,.stat) write:retval "FAIL STATFILE retval=",retval,!
; Verify the contents and size file of the copy.
open link
use link
set tmp=""
for read i quit:$zeof set tmp=tmp_i_$char(10)
close link
if ((tmp'=value)&(size'=stat("size"))) write "FAIL CP stat(size)=",stat("size")," content=",$zwrite(tmp),!
open link
close link:delete
; Create a smaller file.
open link:newversion
use link
set value="abc"
write value
close link
set value=value_$char(10)
set retval=$$STATFILE^%ydbposix(link,.stat) write:retval "FAIL STATFILE retval=",retval,!
set size=stat("size")
; Copy the new small file onto the existent destination.
set retval=$$CP^%ydbposix(link,file) write:'retval "FAIL CP retval=",retval,!
set retval=$$STATFILE^%ydbposix(file,.stat) write:retval "FAIL STATFILE retval=",retval,!
; Verify the contents and size file of the copy.
open file:readonly
use file
set tmp=""
for read i quit:$zeof set tmp=tmp_i_$char(10)
close file
if ((tmp=value)&(size=stat("size"))) write "PASS CP",!
else write "FAIL CP stat(size)=",stat("size")," content=",$zwrite(tmp),!
; Clean up.
open link:readonly
close link:delete
open file:readonly
close file:delete
; Check that we get at least fractional second times - this test has 1 in 10**18 chance of failing incorrectly
set tmp="PASS Nanosecond resolution"
for i=0:1 set retval=$$CLOCKGETTIME^%ydbposix("CLOCK_REALTIME",.tvsec,.tvnsec) quit:tvnsec set:i $extract(tmp,1,4)="FAIL"
write tmp,!
; Check SYSCONF
set retval=$$SYSCONF^%ydbposix("ARG_MAX",.value) write:'retval "FAIL SYSCONF retval=",retval,!
if (0<value) write "PASS SYSCONF",!
else write "FAIL SYSCONF ARG_MAX=",value,!
ydbmathtest ; FALLTHROUGH
; All done with posix test
; Check libmath output against a reference file
; We have two tests (one for M mode, one for UTF-8 mode, set-up in CMakeLists.txt).
; If they run concurrently, it's possible that the "libm.out" file will be overwritten by each other
; That's why we have $zchset here.
new outfile set outfile="libm."_$zchset_".out"
open outfile:newversion
use outfile
new x,y,z,t,out
for x=-2:0.5:2 set out=$$exp^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","exp:",x," ",out
for x=-2:0.5:2 set out=$$log^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","log:",x," ",out
for x=-2:0.5:2 set out=$$log10^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","log10:",x," ",out
for x=-2:0.5:2 set out=$$cos^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","cos:",x," ",out
for x=-2:0.5:2 set out=$$sin^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","sin:",x," ",out
for x=-2:0.5:2 set out=$$arcsin^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","arcsin:",x," ",out
for x=-2:0.5:2 set out=$$arccos^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","arccos:",x," ",out
for x=-2:0.5:2 set out=$$tan^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","tan:",x," ",out
for x=-2:0.5:2 set out=$$arctan^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","arctan:",x," ",out
for x=-2:0.5:2 set out=$$sqrt^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","sqrt:",x," ",out
for x=-2:0.5:2 set out=$$cosh^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","cosh:",x," ",out
for x=-2:0.5:2 set out=$$sinh^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","sinh:",x," ",out
for x=-2:0.5:2 set out=$$tanh^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","tanh:",x," ",out
for x=-2:0.5:2 set out=$$acosh^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","acosh:",x," ",out
for x=-2:0.5:2 set out=$$asinh^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","asinh:",x," ",out
for x=-2:0.5:2 set out=$$atanh^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","atanh:",x," ",out
for x=-2:0.5:2 set out=$$ceil^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","ceil:",x," ",out
for x=-2:0.5:2 set out=$$fabs^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","fabs:",x," ",out
for x=-2:0.5:2 set out=$$floor^%ydbposix(x,.t) write !,$s(t=0:"ok",1:"er"),":","floor:",x," ",out
for x=-2:0.5:2 for y=-2:0.5:2 set out=$$pow^%ydbposix(x,y,.t) write !,$s(t=0:"ok",1:"er"),":","pow:",x," ",y," ",out
for x=-2:0.5:2 for y=-2:0.5:2 set out=$$fmod^%ydbposix(x,y,.t) write !,$s(t=0:"ok",1:"er"),":","fmod:",x," ",y," ",out
for x=-2:0.5:2 for y=-2:0.5:2 set out=$$fdim^%ydbposix(x,y,.t) write !,$s(t=0:"ok",1:"er"),":","fdim:",x," ",y," ",out
for x=-2:0.5:2 for y=-2:0.5:2 set out=$$fmax^%ydbposix(x,y,.t) write !,$s(t=0:"ok",1:"er"),":","fmax:",x," ",y," ",out
for x=-2:0.5:2 for y=-2:0.5:2 set out=$$fmin^%ydbposix(x,y,.t) write !,$s(t=0:"ok",1:"er"),":","fmin:",x," ",y," ",out
for x=-2:0.5:2 for y=-2:0.5:2 for z=-2:0.5:2 set out=$$fma^%ydbposix(x,y,z,.t) write !,$s(t=0:"ok",1:"er"),":","fma:",x," ",y," ",z," ",out
close outfile
zsystem "diff "_outfile_" libmath.ref"
if $zsystem'=0 write "FAIL LIBM",!
else write "PASS LIBM",!
quit
BADOPEN
use $p
write "Cannot open "_tname_" for reading. Check permissions",!
quit
hasSystemd()
; if the os init system is systemd:
; - /proc/1/cmdline would start with "/lib/systemd/systemd" followed by arguments
; - /proc/1/comm would be equal to "systemd"_$C(10)
new comm,f
set f="/proc/1/comm" open f:readonly use f read comm close f
quit $extract(comm,1,7)="systemd"
octalAnd(num1,num2)
new i,j,num,bnum1,bnum2,len1,len2,digit,piece,bnum
set (bnum1,bnum2,bnum,result)=""
for i=1:1:2 do
. set num=$select(1=i:num1,1:num2)
. for set digit=num#10,num=num\10 do quit:(0=num)
. . set piece=""
. . for j=4,2,1 do
. . . if (j'>digit) set digit=digit-j,piece=piece_"1"
. . . else set piece=piece_"0"
. . if (1=i) set bnum1=piece_bnum1
. . else set bnum2=piece_bnum2
set len1=$length(bnum1)
set len2=$length(bnum2)
if (len1>len2) for i=1:1:(len1-len2) set bnum2="0"_bnum2
else set len1=len2 for i=1:1:(len2-len1) set bnum1="0"_bnum1
for i=1:1:len1 set bnum=bnum_$select((1=+$extract(bnum1,i))!(1=+$extract(bnum2,i)):1,1:0)
for i=1:3:$length(bnum)-1 do
. set digit=0
. set:(1=+$extract(bnum,i)) digit=digit+4
. set:(1=+$extract(bnum,i+1)) digit=digit+2
. set:(1=+$extract(bnum,i+2)) digit=digit+1
. set result=result_digit
quit result