about summary refs log tree commit homepage
path: root/devel
diff options
context:
space:
mode:
Diffstat (limited to 'devel')
-rw-r--r--devel/README2
-rwxr-xr-xdevel/longest-tests7
-rwxr-xr-xdevel/syscall-list65
-rwxr-xr-xdevel/sysdefs-list188
4 files changed, 196 insertions, 66 deletions
diff --git a/devel/README b/devel/README
index 8f9a0485..c4be5141 100644
--- a/devel/README
+++ b/devel/README
@@ -1 +1 @@
-scripts use for public-inbox development that don't belong in t/
+scripts used for public-inbox development that don't belong in t/
diff --git a/devel/longest-tests b/devel/longest-tests
new file mode 100755
index 00000000..bf46e166
--- /dev/null
+++ b/devel/longest-tests
@@ -0,0 +1,7 @@
+eval 'exec perl -wS $0 ${1+"$@"}' # this script is too short to copyright
+if 0; # running under some shell
+use v5.12; use autodie; use YAML::XS qw(Load);
+open(my $fh, '<', shift // '.prove');
+my $t = Load(do { local $/; <$fh> })->{tests};
+my @t = sort { $t->{$b}->{elapsed} <=> $t->{$a}->{elapsed} } keys %$t;
+printf "%0.6f %s\n", $t->{$_}->{elapsed}, $_ for @t;
diff --git a/devel/syscall-list b/devel/syscall-list
deleted file mode 100755
index d33a8a78..00000000
--- a/devel/syscall-list
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright all contributors <meta@public-inbox.org>
-# License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
-# Dump syscall numbers under Linux and any other kernel which
-# promises stable syscall numbers.  This is to maintain
-# PublicInbox::Syscall
-# DO NOT USE this for *BSDs, none of the current BSD kernels
-# we know about promise stable syscall numbers, we'll use
-# Inline::C to support them.
-eval 'exec perl -S $0 ${1+"$@"}' # no shebang
-        if 0; # running under some shell
-use strict;
-use v5.10.1;
-use File::Temp 0.19;
-use POSIX qw(uname);
-say '$machine='.(POSIX::uname())[-1];
-my $cc = $ENV{CC} // 'cc';
-my @cflags = split(/\s+/, $ENV{CFLAGS} // '-Wall');
-my $str = do { local $/; <DATA> };
-my $tmp = File::Temp->newdir('syscall-list-XXXX', TMPDIR => 1);
-my $f = "$tmp/sc.c";
-my $x = "$tmp/sc";
-open my $fh, '>', $f or die "open $f $!";
-print $fh $str or die "print $f $!";
-close $fh or die "close $f $!";
-system($cc, '-o', $x, $f, @cflags) == 0 or die "cc failed \$?=$?";
-exec($x);
-__DATA__
-#define _GNU_SOURCE
-#include <sys/syscall.h>
-#include <sys/ioctl.h>
-#include <linux/fs.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#define D(x) printf("$" #x " = %ld;\n", (long)x)
-
-int main(void)
-{
-#ifdef __linux__
-        D(SYS_epoll_create1);
-        D(SYS_epoll_ctl);
-#ifdef SYS_epoll_wait
-        D(SYS_epoll_wait);
-#endif
-        D(SYS_epoll_pwait);
-        D(SYS_signalfd4);
-        D(SYS_inotify_init1);
-        D(SYS_inotify_add_watch);
-        D(SYS_inotify_rm_watch);
-        D(SYS_prctl);
-        D(SYS_fstatfs);
-        D(SYS_sendmsg);
-        D(SYS_recvmsg);
-#ifdef FS_IOC_GETFLAGS
-        printf("FS_IOC_GETFLAGS=%#lx\nFS_IOC_SETFLAGS=%#lx\n",
-                (unsigned long)FS_IOC_GETFLAGS, (unsigned long)FS_IOC_SETFLAGS);
-#endif
-
-#ifdef SYS_renameat2
-        D(SYS_renameat2);
-#endif
-#endif /* Linux, any other OSes with stable syscalls? */
-        printf("size_t=%zu off_t=%zu\n", sizeof(size_t), sizeof(off_t));
-        return 0;
-}
diff --git a/devel/sysdefs-list b/devel/sysdefs-list
new file mode 100755
index 00000000..ba51de6c
--- /dev/null
+++ b/devel/sysdefs-list
@@ -0,0 +1,188 @@
+# Copyright all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
+# Dump system-specific constant numbers this is to maintain
+# PublicInbox::Syscall and any other system-specific pieces.
+# However, sysconf(3) constants are stable ABI on all safe to dump.
+eval 'exec perl -S $0 ${1+"$@"}' # no shebang
+        if 0; # running under some shell
+use v5.12;
+use File::Temp 0.19;
+use POSIX qw(uname);
+use Config;
+print STDERR '# $machine='.(POSIX::uname())[-1]."\n";
+my $cc = $ENV{CC} // $Config{cc} // 'cc';
+my @cflags = split(/\s+/, $ENV{CFLAGS} // $Config{ccflags} // '-Wall');
+my $str = do { local $/; <DATA> };
+$str =~ s/^\s*MAYBE\s*([DX])\((\w+)\)/
+#ifdef $2
+        $1($2);
+#endif
+/sgxm;
+my $tmp = File::Temp->newdir('sysdefs-list-XXXX', TMPDIR => 1);
+my $f = "$tmp/sysdefs.c";
+my $x = "$tmp/sysdefs";
+open my $fh, '>', $f or die "open $f $!";
+print $fh $str or die "print $f $!";
+close $fh or die "close $f $!";
+system($cc, '-o', $x, $f, @cflags) == 0 or die "$cc failed \$?=$?";
+print STDERR '# %Config',
+        (map { " $_=$Config{$_}" } qw(ptrsize sizesize lseeksize)), "\n";
+exit(system($x)); # exit is to ensure File::Temp::Dir->DESTROY fires
+__DATA__
+#ifndef _GNU_SOURCE
+#  define _GNU_SOURCE
+#endif
+#include <assert.h>
+#include <signal.h>
+#include <stddef.h>
+#include <sys/socket.h>
+#include <sys/syscall.h>
+#include <sys/ioctl.h>
+#ifdef __linux__
+#        include <linux/fs.h>
+#        include <sys/epoll.h>
+#        include <sys/inotify.h>
+#        include <sys/vfs.h>
+#endif
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define STRUCT_BEGIN(t) do { t x; printf("'"#t"' => '%zu bytes\n", sizeof(x))
+#define STRUCT_END puts("',"); } while (0)
+
+// prints the struct field name, @offset, and signed/unsigned bit size
+#define PR_NUM(f) do { \
+        x.f = ~0; \
+        printf("\t.%s @%zu %c%zu\n", #f, \
+                offsetof(typeof(x),f), \
+                x.f > 0 ? 'u' : 's', \
+                sizeof(x.f) * 8); \
+} while (0)
+
+#define PR_PTR(f) do { \
+        assert(sizeof(x.f) == sizeof(void *)); \
+        printf("\t.%s @%zu ptr\n", #f, offsetof(typeof(x),f)); \
+} while (0)
+
+#define PR_OFF(f) do { \
+        printf("\t.%s @%zu\n", #f, offsetof(typeof(x),f)); \
+} while (0)
+
+#define D(x) printf(#x " => %ld,\n", (long)x)
+#define X(x) printf(#x " => 0x%lx,\n", (unsigned long)x)
+
+int main(void)
+{
+        // verify Config{(ptr|size|lseek)size} entries match:
+        printf("'sizeof(ptr)' => %zu,\n", sizeof(void *));
+        printf("'sizeof(size_t)' => %zu,\n", sizeof(size_t));
+        printf("'sizeof(off_t)' => %zu,\n", sizeof(off_t));
+
+#ifdef __linux__
+        D(SYS_epoll_create1);
+        D(SYS_epoll_ctl);
+        MAYBE D(SYS_epoll_wait);
+        D(SYS_epoll_pwait);
+        D(SYS_signalfd4);
+
+        X(IN_CLOEXEC);
+        X(IN_ACCESS);
+        X(IN_ALL_EVENTS);
+        X(IN_ATTRIB);
+        X(IN_CLOSE);
+        X(IN_CLOSE_NOWRITE);
+        X(IN_CLOSE_WRITE);
+        X(IN_CREATE);
+        X(IN_DELETE);
+        X(IN_DELETE_SELF);
+        X(IN_DONT_FOLLOW);
+        X(IN_EXCL_UNLINK);
+        X(IN_IGNORED);
+        X(IN_ISDIR);
+        X(IN_MASK_ADD);
+        X(IN_MODIFY);
+        X(IN_MOVE);
+        X(IN_MOVED_FROM);
+        X(IN_MOVED_TO);
+        X(IN_MOVE_SELF);
+        X(IN_ONESHOT);
+        X(IN_ONLYDIR);
+        X(IN_OPEN);
+        X(IN_Q_OVERFLOW);
+        X(IN_UNMOUNT);
+
+        D(SYS_inotify_init1);
+        D(SYS_inotify_add_watch);
+        D(SYS_inotify_rm_watch);
+
+        D(SYS_prctl);
+        D(SYS_fstatfs);
+
+        MAYBE X(FS_IOC_GETFLAGS);
+        MAYBE X(FS_IOC_SETFLAGS);
+
+        MAYBE D(SYS_renameat2);
+
+        STRUCT_BEGIN(struct epoll_event);
+                PR_NUM(events);
+                PR_NUM(data.u64);
+        STRUCT_END;
+
+        STRUCT_BEGIN(struct inotify_event);
+                PR_NUM(wd);
+                PR_NUM(mask);
+                PR_NUM(cookie);
+                PR_NUM(len);
+                PR_OFF(name);
+        STRUCT_END;
+
+        STRUCT_BEGIN(struct statfs);
+                PR_NUM(f_type);
+        STRUCT_END;
+#endif /* Linux, any other OSes with stable syscalls? */
+
+        D(SIGWINCH);
+        MAYBE D(SO_ACCEPTFILTER);
+        MAYBE D(_SC_NPROCESSORS_ONLN);
+        MAYBE D(_SC_AVPHYS_PAGES);
+        MAYBE D(_SC_PAGE_SIZE);
+        MAYBE D(_SC_PAGESIZE);
+
+        D(SYS_sendmsg);
+        D(SYS_recvmsg);
+
+        STRUCT_BEGIN(struct flock);
+                PR_NUM(l_start);
+                PR_NUM(l_len);
+                PR_NUM(l_pid);
+                PR_NUM(l_type);
+                PR_NUM(l_whence);
+        STRUCT_END;
+
+        STRUCT_BEGIN(struct msghdr);
+                PR_PTR(msg_name);
+                PR_NUM(msg_namelen);
+                PR_PTR(msg_iov);
+                PR_NUM(msg_iovlen);
+                PR_PTR(msg_control);
+                PR_NUM(msg_controllen);
+                PR_NUM(msg_flags);
+        STRUCT_END;
+
+        STRUCT_BEGIN(struct cmsghdr);
+                PR_NUM(cmsg_len);
+                PR_NUM(cmsg_level);
+                PR_NUM(cmsg_type);
+        STRUCT_END;
+
+        {
+                struct cmsghdr cmsg;
+                uintptr_t cmsg_data_off;
+                cmsg_data_off = (uintptr_t)CMSG_DATA(&cmsg) - (uintptr_t)&cmsg;
+                D(cmsg_data_off);
+        }
+
+        return 0;
+}