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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
ref -D_def_map_ast=1
cmd universe
hdr dirent,direntry,filio,fmtmsg,fnmatch,jioctl,libgen,limits
hdr locale,ndir,nl_types,process,spawn,syslog,utime,vfork,wctype
hdr wchar note{ <wchar.h> and isw*() really work }end execute{
#include <wchar.h>
int
main()
{
wchar_t w = 'a';
return iswalnum(w) == 0;
}
}end
dat _tzname,tzname
lib BSDsetpgrp
lib _cleanup
lib atexit,bcopy,bzero,catclose,catgets,catopen,confstr,dirread,dup2
lib execlp,execve,execvp,execvpe
lib fchmod,fcntl,fmtmsg,fnmatch,fork,fsync
lib getconf,getdents,getdirentries,getdtablesize,getdate
lib getgroups,gethostname,getlogin,getpagesize,getrlimit,getuniverse
lib getopt,getsubopt,getopt_long,getopt_long_only
lib glob,index,iswblank,iswctype,killpg,link,localeconv,madvise
lib mbtowc,mbrtowc,memalign,memchr,memcpy,memdup,memmove,memset
lib mkdir,mkfifo,mktemp,mktime
lib mount,on_exit,onexit,opendir,pathconf
lib readlink,remove,rename,rewinddir,rindex,rmdir,setlocale
lib setpgid,setpgrp,setpgrp2,setreuid,setsid,setuid,sigaction
lib sigprocmask,sigsetmask,sigunblock,sigvec,socketpair
lib spawn,spawnve,spawnveg
lib strchr,strcoll,strdup,strerror,strcasecmp,strncasecmp,strrchr,strstr
lib strmode,strxfrm,strftime,swab,symlink,sysconf,sysinfo,syslog
lib telldir,tmpnam,tzset,universe,unlink,utime,wctype
lib ftruncate,truncate
lib creat64,fstat64,fstatvfs64,ftruncate64 -D_LARGEFILE64_SOURCE
lib lseek64,lstat64 -D_LARGEFILE64_SOURCE
lib open64,readdir64,stat64,statvfs64,truncate64 -D_LARGEFILE64_SOURCE
lib,npt strtod,strtold,strtol,strtoll,strtoul,strtoull stdlib.h
mem direct.d_reclen sys/types.h sys/dir.h
mem dirent.d_fileno,dirent.d_ino,dirent.d_namlen,dirent.d_off,dirent.d_reclen,dirent.d_type sys/types.h dirent.h
mem DIR sys/types.h - dirent.h - sys/dir.h
mem DIR.dd_fd sys/types.h - dirent.h - sys/dir.h
mem inheritance.pgroup spawn.h
sys dir,filio,jioctl,localedef,ptem,resource
sys socket,stream,systeminfo,universe,vfork
typ off64_t -D_LARGEFILE64_SOURCE
typ struct.dirent64 -D_LARGEFILE64_SOURCE dirent.h
tst tst_errno note{ errno can be assigned }end link{
_BEGIN_EXTERNS_
#define error ______error
#define strerror ______strerror
#include <errno.h>
#undef error
#undef strerror
#ifndef errno
extern int errno;
#endif
error() { }
strerror() { }
_END_EXTERNS_
int main() { errno = 0; error(); strerror(); return 0; }
}end
tst lib_poll_fd_1 note{ fd is first arg to poll() }end execute{
#include <poll.h>
_BEGIN_EXTERNS_
extern int pipe _ARG_((int*));
_END_EXTERNS_
int
main()
{ int rw[2];
struct pollfd fd;
if (pipe(rw) < 0) return 1;
fd.fd = rw[0];
fd.events = POLLIN;
fd.revents = 0;
if (poll(&fd, 1, 0) < 0 || fd.revents != 0) return 1;
if (write(rw[1], "x", 1) != 1) return 1;
if (poll(&fd, 1, 0) < 0 || fd.revents == 0) return 1;
return 0;
}
}end
tst lib_poll_fd_2 note{ fd is second arg to poll() }end execute{
#include <poll.h>
_BEGIN_EXTERNS_
extern int pipe _ARG_((int*));
_END_EXTERNS_
int
main()
{ int rw[2];
struct pollfd fd;
if (pipe(rw) < 0) return 1;
fd.fd = rw[0];
fd.events = POLLIN;
fd.revents = 0;
return poll(1, &fd, 0) < 0;
if (poll(1, &fd, 0) < 0 || fd.revents != 0) return 1;
if (write(rw[1], "x", 1) != 1) return 1;
if (poll(1, &fd, 0) < 0 || fd.revents == 0) return 1;
return 0;
}
}end
exp _lib_poll _lib_poll_fd_1||_lib_poll_fd_2
tst lib_poll_notimer note{ poll with no fds ignores timeout }end execute{
#include <sys/types.h>
#include <poll.h>
_BEGIN_EXTERNS_
extern time_t time _ARG_((time_t*));
_END_EXTERNS_
#define TIMEOUT 4
int
main()
{
unsigned long start;
unsigned long finish;
struct pollfd fd;
start = time((time_t*)0);
if (poll(&fd, 0, TIMEOUT * 1000) < 0)
return 0;
finish = time((time_t*)0);
return (finish - start) > (TIMEOUT / 2);
}
}end
tst lib_select note{ select() has standard 5 arg interface }end link{
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
int
main()
{ struct timeval tmb;
fd_set rd;
FD_ZERO(&rd);
FD_SET(0,&rd);
tmb.tv_sec = 0;
tmb.tv_usec = 0;
select(1,&rd,(fd_set*)0,(fd_set*)0,&tmb);
return 0;
}
}end
tst pipe_rw note{ full duplex pipes }end execute{
_BEGIN_EXTERNS_
extern int pipe _ARG_((int*));
extern int read _ARG_((int, void*, int));
extern int strcmp _ARG_((const char*, const char*));
extern int write _ARG_((int, void*, int));
_END_EXTERNS_
int
main()
{
#if defined(__sgi) || defined(_sgi) || defined(sgi)
/* boot tuneable pipes force one way for bin compatibility */
return 1;
#else
static char test[] = "test\n";
int io[2];
char buf[sizeof(test)];
if (pipe(io)) return 1;
if (write(io[1], test, sizeof(test)) != sizeof(test)) return 1;
if (read(io[0], buf, sizeof(test)) != sizeof(test)) return 1;
if (strcmp(test, buf)) return 1;
if (write(io[0], test, sizeof(test)) != sizeof(test)) return 1;
if (read(io[1], buf, sizeof(test)) != sizeof(test)) return 1;
if (strcmp(test, buf)) return 1;
return 0;
#endif
}
}end
tst lib_vfork unistd.h stdlib.h vfork.h note{ vfork exists and it works }end execute{
#include <signal.h>
int
main(argc, argv)
int argc;
char** argv;
{
int status;
char* cmd[3];
if (argv[1])
_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
signal(SIGHUP, SIG_IGN);
switch (vfork())
{
case -1:
_exit(1);
case 0:
cmd[0] = argv[0];
cmd[1] = "test";
cmd[2] = 0;
execv(cmd[0], cmd);
_exit(2);
}
status = 1;
_exit(wait(&status) < 0 || status != 0);
}
}end
tst real_vfork note{ vfork child shares data with parent }end execute{
_BEGIN_EXTERNS_
extern int _exit _ARG_((int));
extern int vfork _ARG_((void));
_END_EXTERNS_
int code;
int
main()
{
code = 1;
if (!vfork())
code = 0;
_exit(code);
}
}end
tst lib_posix_spawn unistd.h stdlib.h spawn.h -Dfork=______fork note{ posix_spawn exists and it works and its worth using }end status{
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <spawn.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#undef fork
/* if it uses fork() why bother? */
pid_t fork _ARG_((void)) { return -1; }
pid_t _fork _ARG_((void)) { return -1; }
pid_t __fork _ARG_((void)) { return -1; }
int
main(argc, argv)
int argc;
char** argv;
{
char* s;
pid_t pid;
posix_spawnattr_t attr;
int n;
int status;
char* cmd[3];
char tmp[1024];
if (argv[1])
_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
signal(SIGHUP, SIG_IGN);
if (posix_spawnattr_init(&attr))
_exit(0);
if (posix_spawnattr_setpgroup(&attr, 0))
_exit(0);
if (posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP))
_exit(0);
/* first try an a.out and verify that SIGHUP is ignored */
cmd[0] = argv[0];
cmd[1] = "test";
cmd[2] = 0;
if (posix_spawn(&pid, cmd[0], 0, &attr, cmd, 0))
_exit(0);
status = 1;
if (wait(&status) < 0 || status != 0)
_exit(0);
/* passing ENOEXEC to the shell is bogus */
n = strlen(cmd[0]);
if (n >= (sizeof(tmp) - 3))
_exit(0);
strcpy(tmp, cmd[0]);
tmp[n] = '.';
tmp[n+1] = 's';
tmp[n+2] = 'h';
tmp[n+3] = 0;
if (close(open(tmp, O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO)) < 0 || chmod(tmp, S_IRWXU|S_IRWXG|S_IRWXO) < 0)
_exit(0);
cmd[0] = tmp;
n = 0;
pid = -1;
if (posix_spawn(&pid, cmd[0], 0, &attr, cmd, 0))
n = 2;
else
{
n = pid != -1 && waitpid(pid, &status, WNOHANG|WNOWAIT) == pid && ((status>>8)&0x7f) == 127;
wait(&status);
}
_exit(n);
}
}end
tst lib_spawn_mode unistd.h stdlib.h note{ first spawn arg is mode and it works }end execute{
#include <signal.h>
#include <process.h>
#ifndef P_NOWAIT
#define P_NOWAIT _P_NOWAIT
#endif
int
main(argc, argv)
int argc;
char** argv;
{
int status;
char* cmd[3];
if (argv[1])
_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
signal(SIGHUP, SIG_IGN);
cmd[0] = argv[0];
cmd[1] = "test";
cmd[2] = 0;
if (spawnv(P_NOWAIT, cmd[0], cmd) < 0)
_exit(1);
status = 1;
_exit(wait(&status) < 0 || status != 0);
}
}end
tst stream_peek note{ ioctl(I_PEEK) works }end link{
#include <sys/types.h>
#include <stropts.h>
int
main()
{ struct strpeek pbuf;
pbuf.flags = 0;
pbuf.ctlbuf.maxlen = pbuf.databuf.maxlen =
pbuf.ctlbuf.len = pbuf.databuf.len = 0;
pbuf.ctlbuf.buf = pbuf.databuf.buf = 0;
ioctl(0,I_PEEK,&pbuf);
return 0;
}
}end
tst socket_peek note{ recv(MSG_PEEK) works }end execute{
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main()
{
int i;
int fds[2];
char buf[128];
static char msg[] = "abcd";
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
return 1;
if (write(fds[1], msg, sizeof(msg)) != sizeof(msg))
return 1;
if (recv(fds[0], buf, sizeof(buf), MSG_PEEK) != sizeof(msg))
return 1;
for (i = 0; i < sizeof(msg); i++)
if (buf[i] != msg[i])
return 1;
if (read(fds[0], buf, sizeof(msg)) != sizeof(msg))
return 1;
for (i = 0; i < sizeof(msg); i++)
if (buf[i] != msg[i])
return 1;
return 0;
}
}end
tst lib_memcmp string.h note{ standard memcmp interface that works }end execute{
/* sgi again -- we're sick of being their regression test */
#define L 8
char a[L] = { '0' };
char b[L] = { '1' };
int
main()
{
return memcmp(a, b, L) >= 0;
}
}end
tst lib_memccpy string.h unistd.h stdlib.h fcntl.h signal.h sys/types.h sys/stat.h sys/mman.h fcntl.h note{ standard memccpy interface that works }end execute{
#if _STD_
static void gotcha(int sig)
#else
static int gotcha(sig) int sig;
#endif
{
exit(1);
}
#ifdef MAP_PRIVATE
static const char x[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN";
#if _STD_
static int indict_sgi_ia64_4Q_2004(int n)
#else
static int indict_sgi_ia64_4Q_2004(n) int n;
#endif
{
char* b;
char* s;
char* e;
char* t;
long m;
int d;
char u[1024];
static char p[32] = {'/','t','m','p','/','m','m'};
for (d = 7; d < 13; d++)
p[d] = 'X';
p[d] = 0;
if ((d = mkstemp(p)) < 0)
return 1;
remove(p);
for (m = 0; m < n; m++)
if (write(d, x, sizeof(x)-1) != sizeof(x)-1)
{
close(d);
return 1;
}
if (lseek(d, (off_t)0, SEEK_SET))
{
close(d);
return 1;
}
m = n * (sizeof(x)-1);
if (!(b = mmap((void*)0, m, PROT_READ|PROT_WRITE, MAP_PRIVATE, d, (off_t)0)))
{
close(d);
return 1;
}
for (e = (s = b) + m; s < e && (t = memccpy(u, s, 'N', (e-s) > sizeof(u) ? sizeof(u) : (e-s))); s += (t-u))
if ((t-u) != (sizeof(x)-1) || memcmp(u, s, t-u))
{
close(d);
return 1;
}
if (s < e)
{
close(d);
return 1;
}
close(d);
return 0;
}
#endif
int
main ()
{
char buf[1024];
#ifdef MAP_PRIVATE
char* srcbuf;
char* dstbuf;
int fd;
size_t siz;
int i;
#endif
#if defined(__ia64) || defined(__ia64__) || defined(__itanium__)
/*
* 0 faith that the itanium coders will ever get this right
* prove me wrong
*/
return 1;
#endif
/*
* early mac osx failed here -- fixed 3Q 2001
*/
if (memccpy(buf, "abc", 0, sizeof(buf)) != (buf + 4))
return 1;
#ifdef MAP_PRIVATE
siz = 64 * 1024;
if (!(dstbuf = malloc(2 * siz)))
return 0;
if ((fd = open("/dev/zero", O_RDWR)) < 0)
return 0;
if (!(srcbuf = (char*)mmap(NULL, siz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)))
return 0;
if (!mmap(srcbuf + siz, siz, PROT_NONE, MAP_PRIVATE, fd, 0))
return 0;
for (i = 0; i < siz; i++)
srcbuf[i] = 'x';
srcbuf[siz - 1] = 0;
alarm(10);
signal(SIGSEGV, gotcha);
signal(SIGBUS, gotcha);
signal(SIGALRM, gotcha);
/*
* sgi ia64 dumps here as of 3Q 2001
* bug acknowleged 1Q 2003
*/
memccpy(dstbuf, srcbuf, 0, siz + 10);
alarm(0);
if (strcmp(srcbuf, dstbuf))
return 1;
if (indict_sgi_ia64_4Q_2004(1))
return 1;
if (indict_sgi_ia64_4Q_2004(257))
return 1;
#endif
return 0;
}
}end
tst lib_utime_now note{ utime works with 0 time vector }end execute{
#include <sys/types.h>
_BEGIN_EXTERNS_
extern int utime _ARG_((const char*, void*));
_END_EXTERNS_
int
main()
{
return utime(".", (void*)0) == -1;
}
}end
tst cross{
u=att
case `/bin/cat -s /dev/null/foo 2>&1` in
'') ;;
*) case `/bin/echo '\\t'` in
'\t') u=ucb ;;
esac
;;
esac
echo "#define _UNIV_DEFAULT \"$u\" /* default universe name */"
}end
std cleanup note{ stuck with standard _cleanup }end noexecute{
_BEGIN_EXTERNS_
extern void exit _ARG_((int));
extern void _exit _ARG_((int));
extern void _cleanup();
void _cleanup() { _exit(0); }
_END_EXTERNS_
int main() { printf("cleanup\n"); exit(1); }
}end
std remove note{ stuck with standard remove() }end nostatic{
_BEGIN_EXTERNS_
extern int unlink _ARG_((const char*));
_END_EXTERNS_
#if _STD_
int remove(const char* path) { return 0; }
#else
int remove(path) char* path; { return 0; }
#endif
int main() { return unlink("foo"); }
}end
std signal note{ stuck with standard signal }end nolink{
_BEGIN_EXTERNS_
extern int abort();
int signal() { return 0; }
_END_EXTERNS_
int main() { signal(); abort(); return 0; }
}end
std strcoll note{ standard strcoll works }end execute{
#include <string.h>
#define S "hello world"
int
main()
{
char s[] = S;
char t[] = S;
return strcoll(s, t) || strcmp(s, t);
}
}end
std strtod stdlib.h note{ stuck with standard strtod }end nostatic{
_BEGIN_EXTERNS_
#if _STD_
double strtod(const char* s, char** e) { return 0.0; }
#else
double strtod(s, e) char* s; char** e; { return 0.0; }
#endif
_END_EXTERNS_
int main() { printf(""); return strtod("1",0) != 0; }
}end
std strtold stdlib.h note{ stuck with standard strtold }end nostatic{
_BEGIN_EXTERNS_
#if _STD_
long double strtold(const char* s, char** e) { return 0.0; }
#else
long double strtold(s, e) char* s; char** e; { return 0.0; }
#endif
_END_EXTERNS_
int main() { printf(""); return strtold("1",0) != 0; }
}end
std strtol note{ stuck with standard strtol }end nostatic{
_BEGIN_EXTERNS_
#if _STD_
extern long atol(const char*);
long strtol(const char* s, char** e, int b) { return 0; }
#else
extern long atol();
long strtol(s, e, b) char* s; char** e; int b; { return 0; }
#endif
_END_EXTERNS_
int main() { printf(""); return (atol("1") + strtol("1",(char**)0,0)) != 0; }
}end
tst - output{
int
main()
{
#if _UWIN
printf("\n");
printf("/* override some uwin feature tests */\n");
printf("#undef _lib_execlp\n");
printf("#undef _lib_execvp\n");
printf("#undef _lib_execvpe\n");
printf("#undef _lib_fork\n");
printf("#undef _std_string\n");
printf("#define _std_string 1\n");
printf("#undef _stream_peek\n");
printf("\n");
#endif
#if _lib_spawnveg || _lib_posix_spawn || _lib_spawn_mode || _lib_spawn && _hdr_spawn && _mem_pgroup_inheritance || _lib_vfork && _real_vfork
printf("#if !_AST_no_spawnveg\n");
printf("#define _use_spawnveg 1\n");
printf("#endif\n");
printf("\n");
#endif
return 0;
}
}end
tst no64 -D_LARGEFILE64_SOURCE note{ largefile 64 broken }end execute{
#include <sys/types.h>
#include <sys/stat.h>
int
main()
{
struct stat64 st;
return !stat64(".", &st) && st.st_mode && st.st_mtime;
}
}end pass{
echo "/* can we at least agree that a successful return means success? */"
echo "#undef _lib_creat64"
echo "#undef _lib_fstat64"
echo "#undef _lib_fstatvfs64"
echo "#undef _lib_ftruncate64"
echo "#undef _lib_lseek64"
echo "#undef _lib_lstat64"
echo "#undef _lib_mmap64"
echo "#undef _lib_stat64"
echo "#undef _lib_statvfs64"
echo "#undef _lib_truncate64"
}end
|