├── .github └── workflows │ └── toybox.yml ├── .gitignore ├── Config.in ├── LICENSE ├── Makefile ├── README ├── configure ├── kconfig ├── Makefile ├── README ├── android_miniconfig ├── conf.c ├── confdata.c ├── expr.c ├── expr.h ├── freebsd_miniconfig ├── kconfig-language.txt ├── lex.zconf.c_shipped ├── lkc.h ├── lkc_proto.h ├── lxdialog │ ├── BIG.FAT.WARNING │ ├── check-lxdialog.sh │ ├── checklist.c │ ├── dialog.h │ ├── inputbox.c │ ├── menubox.c │ ├── textbox.c │ ├── util.c │ └── yesno.c ├── macos_miniconfig ├── mconf.c ├── menu.c ├── symbol.c ├── util.c ├── zconf.hash.c_shipped └── zconf.tab.c_shipped ├── lib ├── args.c ├── commas.c ├── deflate.c ├── dirtree.c ├── elf.c ├── env.c ├── hash.c ├── lib.c ├── lib.h ├── llist.c ├── lsm.h ├── net.c ├── password.c ├── portability.c ├── portability.h ├── toyflags.h ├── tty.c ├── utf8.c └── xwrap.c ├── main.c ├── mkroot ├── README ├── README.root ├── mkroot.sh ├── packages │ ├── busybox │ ├── dropbear │ ├── dynamic │ ├── lfs-sources │ ├── overlay │ ├── plumbing │ └── tests ├── record-commands ├── tar-for-web.sh └── testroot.sh ├── scripts ├── change.sh ├── genconfig.sh ├── git-static-index.sh ├── help.txt ├── install.c ├── install.sh ├── kconfig.c ├── make.sh ├── mcm-buildall.sh ├── mkflags.c ├── mkroot.sh ├── mkstatus.py ├── portability.sh ├── prereq │ ├── build.sh │ └── generated │ │ ├── config.h │ │ ├── flags.h │ │ ├── globals.h │ │ ├── help.h │ │ ├── newtoys.h │ │ └── tags.h ├── probes │ ├── GLOBALS │ ├── README │ ├── bloatcheck │ ├── cmd2dpkg │ ├── findglobals │ └── showasm ├── recreate-prereq.sh ├── runtest.sh ├── single.sh └── test.sh ├── tests ├── README.txt ├── awk.test ├── base32.test ├── base64.test ├── basename.test ├── bc.test ├── blkid.test ├── bzcat.test ├── cat.test ├── chattr.test ├── chgrp.test ├── chmod.test ├── chown.test ├── cksum.test ├── cmp.test ├── comm.test ├── cp.test ├── cpio.test ├── cut.test ├── date.test ├── dd.test ├── demo_number.test ├── devmem.test ├── diff.test ├── dirname.test ├── du.test ├── echo.test ├── env.test ├── expand.test ├── expr.test ├── factor.test ├── fallocate.test ├── file.test ├── files │ ├── bc │ │ ├── add.txt │ │ ├── add_results.txt │ │ ├── arctan.txt │ │ ├── arctan_results.txt │ │ ├── arrays.txt │ │ ├── arrays_results.txt │ │ ├── bessel.txt │ │ ├── bessel_results.txt │ │ ├── boolean.txt │ │ ├── boolean_results.txt │ │ ├── cosine.txt │ │ ├── cosine_results.txt │ │ ├── decimal.txt │ │ ├── decimal_results.txt │ │ ├── divide.txt │ │ ├── divide_results.txt │ │ ├── exponent.txt │ │ ├── exponent_results.txt │ │ ├── log.txt │ │ ├── log_results.txt │ │ ├── misc.txt │ │ ├── misc1.txt │ │ ├── misc1_results.txt │ │ ├── misc2.txt │ │ ├── misc2_results.txt │ │ ├── misc_results.txt │ │ ├── modulus.txt │ │ ├── modulus_results.txt │ │ ├── multiply.txt │ │ ├── multiply_results.txt │ │ ├── parse.txt │ │ ├── parse_results.txt │ │ ├── pi.txt │ │ ├── pi_results.txt │ │ ├── power.txt │ │ ├── power_results.txt │ │ ├── print.txt │ │ ├── print_results.txt │ │ ├── script.sh │ │ ├── sine.txt │ │ ├── sine_results.txt │ │ ├── sqrt.txt │ │ ├── sqrt_results.txt │ │ ├── subtract.txt │ │ ├── subtract_results.txt │ │ ├── vars.txt │ │ └── vars_results.txt │ ├── blkid │ │ ├── cramfs.bz2 │ │ ├── ext2.bz2 │ │ ├── ext3.bz2 │ │ ├── ext4.bz2 │ │ ├── f2fs.bz2 │ │ ├── fat32.bz2 │ │ ├── iso.bz2 │ │ ├── minix.bz2 │ │ ├── msdos.bz2 │ │ ├── ntfs.bz2 │ │ ├── reiser3.bz2 │ │ ├── squashfs.bz2 │ │ ├── vfat.bz2 │ │ └── xfs.bz2 │ ├── bzcat │ │ ├── badcrc.bz2 │ │ └── overflow.bz2 │ ├── elf │ │ ├── fdstatic │ │ ├── ndk-elf-note-full │ │ ├── ndk-elf-note-shflags │ │ └── ndk-elf-note-short │ ├── java.class │ ├── tar │ │ ├── dir.tar │ │ ├── long_path.tar │ │ ├── oldsparse.tgz │ │ ├── tar.7z │ │ ├── tar.tar │ │ ├── tar.tbz2 │ │ └── tar.tgz │ ├── utf8 │ │ ├── 0xabad1dea.txt │ │ ├── arabic.txt │ │ ├── bad.txt │ │ ├── japan.txt │ │ ├── test1.txt │ │ └── test2.txt │ └── zip │ │ ├── d1 │ │ └── d2 │ │ │ ├── a.txt │ │ │ ├── b.txt │ │ │ ├── c.txt │ │ │ ├── empty.txt │ │ │ └── x.txt │ │ └── example.zip ├── find.test ├── fmt.test ├── fold.test ├── fstype.test ├── getfattr.test ├── getopt.test ├── grep.test ├── groupadd.test ├── groupdel.test ├── gunzip.test ├── gzip.test ├── head.test ├── hexdump.test ├── hostname.test ├── httpd.test ├── iconv.test ├── id.test ├── ifconfig.test ├── install.test ├── kill.test ├── killall.test ├── link.test ├── ln.test ├── losetup.test ├── ls.test ├── lsattr.test ├── man.test ├── md5sum.test ├── mkdir.test ├── mkfifo.test ├── mkpasswd.test ├── mktemp.test ├── modinfo.test ├── more.test ├── mount.test ├── mv.test ├── nbd-client.test ├── netcat.test ├── nl.test ├── paste.test ├── patch.test ├── pgrep.test ├── pidof.test ├── pkill.test ├── printf.test ├── ps.test ├── pwd.test ├── readelf.test ├── readlink.test ├── realpath.test ├── renice.test ├── rev.test ├── rm.test ├── rmdir.test ├── sed.test ├── seq.test ├── setfattr.test ├── sh.test ├── sha1sum.test ├── sha224sum.test ├── sha256sum.test ├── sha384sum.test ├── sha3sum.test ├── sha512sum.test ├── skeleton.test ├── sort.test ├── split.test ├── stat.test ├── strings.test ├── tac.test ├── tail.test ├── tar.test ├── tee.test ├── test.test ├── timeout.test ├── top.test ├── touch.test ├── tr.test ├── truncate.test ├── tsort.test ├── unicode.test ├── unzip.test ├── uptime.test ├── useradd.test ├── uudecode.test ├── uuencode.test ├── uuidgen.test ├── vi.test ├── wc.test ├── xargs.test ├── xxd.test ├── xzcat.test └── zcat.test ├── toys.h ├── toys ├── android │ ├── README │ ├── getenforce.c │ ├── load_policy.c │ ├── log.c │ ├── restorecon.c │ ├── runcon.c │ ├── sendevent.c │ └── setenforce.c ├── example │ ├── README │ ├── demo_many_options.c │ ├── demo_number.c │ ├── demo_scankey.c │ ├── demo_utf8towc.c │ ├── hello.c │ ├── hostid.c │ ├── logpath.c │ └── skeleton.c ├── lsb │ ├── README │ ├── dmesg.c │ ├── gzip.c │ ├── hostname.c │ ├── killall.c │ ├── md5sum.c │ ├── mknod.c │ ├── mktemp.c │ ├── mount.c │ ├── passwd.c │ ├── pidof.c │ ├── seq.c │ ├── su.c │ ├── sync.c │ └── umount.c ├── net │ ├── README │ ├── ftpget.c │ ├── host.c │ ├── httpd.c │ ├── ifconfig.c │ ├── microcom.c │ ├── netcat.c │ ├── netstat.c │ ├── ping.c │ ├── rfkill.c │ ├── sntp.c │ ├── tunctl.c │ └── wget.c ├── other │ ├── README │ ├── acpi.c │ ├── ascii.c │ ├── base64.c │ ├── blkdiscard.c │ ├── blkid.c │ ├── blockdev.c │ ├── bzcat.c │ ├── chcon.c │ ├── chroot.c │ ├── chrt.c │ ├── clear.c │ ├── count.c │ ├── devmem.c │ ├── dos2unix.c │ ├── eject.c │ ├── factor.c │ ├── fallocate.c │ ├── flock.c │ ├── fmt.c │ ├── free.c │ ├── freeramdisk.c │ ├── fsfreeze.c │ ├── fsync.c │ ├── getopt.c │ ├── gpiod.c │ ├── hd.c │ ├── help.c │ ├── hexedit.c │ ├── hwclock.c │ ├── i2ctools.c │ ├── inotifyd.c │ ├── insmod.c │ ├── ionice.c │ ├── linux32.c │ ├── login.c │ ├── losetup.c │ ├── lsattr.c │ ├── lsmod.c │ ├── lsusb.c │ ├── makedevs.c │ ├── mcookie.c │ ├── memeater.c │ ├── mix.c │ ├── mkpasswd.c │ ├── mkswap.c │ ├── modinfo.c │ ├── mountpoint.c │ ├── nbd_client.c │ ├── nbd_server.c │ ├── nologin.c │ ├── nsenter.c │ ├── oneit.c │ ├── openvt.c │ ├── partprobe.c │ ├── pivot_root.c │ ├── pmap.c │ ├── printenv.c │ ├── pwdx.c │ ├── pwgen.c │ ├── readahead.c │ ├── readelf.c │ ├── readlink.c │ ├── reboot.c │ ├── reset.c │ ├── rev.c │ ├── rmmod.c │ ├── rtcwake.c │ ├── setfattr.c │ ├── setsid.c │ ├── sha3sum.c │ ├── shred.c │ ├── shuf.c │ ├── stat.c │ ├── swapoff.c │ ├── swapon.c │ ├── switch_root.c │ ├── sysctl.c │ ├── tac.c │ ├── taskset.c │ ├── timeout.c │ ├── truncate.c │ ├── ts.c │ ├── uclampset.c │ ├── uptime.c │ ├── usleep.c │ ├── uuidgen.c │ ├── vconfig.c │ ├── vmstat.c │ ├── w.c │ ├── watch.c │ ├── watchdog.c │ ├── which.c │ ├── xxd.c │ └── yes.c ├── pending │ ├── README │ ├── arp.c │ ├── arping.c │ ├── awk.c │ ├── bc.c │ ├── bootchartd.c │ ├── brctl.c │ ├── chsh.c │ ├── crond.c │ ├── crontab.c │ ├── csplit.c │ ├── dhcp.c │ ├── dhcp6.c │ ├── dhcpd.c │ ├── diff.c │ ├── dumpleases.c │ ├── expr.c │ ├── fdisk.c │ ├── fsck.c │ ├── getfattr.c │ ├── getty.c │ ├── git.c │ ├── groupadd.c │ ├── groupdel.c │ ├── hexdump.c │ ├── init.c │ ├── ip.c │ ├── ipcrm.c │ ├── ipcs.c │ ├── klogd.c │ ├── last.c │ ├── lsof.c │ ├── man.c │ ├── mdev.c │ ├── modprobe.c │ ├── more.c │ ├── route.c │ ├── sh.c │ ├── strace.c │ ├── stty.c │ ├── sulogin.c │ ├── syslogd.c │ ├── tcpsvd.c │ ├── telnet.c │ ├── telnetd.c │ ├── tftp.c │ ├── tftpd.c │ ├── tr.c │ ├── traceroute.c │ ├── useradd.c │ ├── userdel.c │ ├── vi.c │ └── xzcat.c └── posix │ ├── README │ ├── basename.c │ ├── cal.c │ ├── cat.c │ ├── chgrp.c │ ├── chmod.c │ ├── cksum.c │ ├── cmp.c │ ├── comm.c │ ├── cp.c │ ├── cpio.c │ ├── cut.c │ ├── date.c │ ├── dd.c │ ├── df.c │ ├── dirname.c │ ├── du.c │ ├── echo.c │ ├── env.c │ ├── expand.c │ ├── false.c │ ├── file.c │ ├── find.c │ ├── fold.c │ ├── getconf.c │ ├── grep.c │ ├── head.c │ ├── iconv.c │ ├── id.c │ ├── kill.c │ ├── link.c │ ├── ln.c │ ├── logger.c │ ├── ls.c │ ├── mkdir.c │ ├── mkfifo.c │ ├── nice.c │ ├── nl.c │ ├── nohup.c │ ├── od.c │ ├── paste.c │ ├── patch.c │ ├── printf.c │ ├── ps.c │ ├── pwd.c │ ├── renice.c │ ├── rm.c │ ├── rmdir.c │ ├── sed.c │ ├── sleep.c │ ├── sort.c │ ├── split.c │ ├── strings.c │ ├── tail.c │ ├── tar.c │ ├── tee.c │ ├── test.c │ ├── time.c │ ├── touch.c │ ├── true.c │ ├── tsort.c │ ├── tty.c │ ├── ulimit.c │ ├── uname.c │ ├── uniq.c │ ├── unlink.c │ ├── uudecode.c │ ├── uuencode.c │ ├── wc.c │ ├── who.c │ └── xargs.c └── www ├── .htaccess ├── 0bsd-mckusick.txt ├── about.html ├── cleanup.html ├── code.html ├── conduct.html ├── design.html ├── doc ├── ext2.html └── mount.html ├── downloads └── binaries │ ├── mkroot │ └── README │ └── toolchains │ └── README ├── faq.html ├── footer.html ├── header.html ├── index.html ├── license.html ├── news.html ├── oldnews.html ├── quick.html ├── release.txt ├── roadmap.html ├── towel.jpg ├── toycans-big.jpg └── toycans.png /.github/workflows/toybox.yml: -------------------------------------------------------------------------------- 1 | name: toybox CI 2 | 3 | on: 4 | schedule: 5 | - cron: '0 2 * * *' 6 | push: 7 | branches: [ master ] 8 | 9 | jobs: 10 | MacOS-13: 11 | runs-on: macos-13 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Setup 16 | run: brew install gnu-sed 17 | - name: Configure 18 | run: make macos_defconfig 19 | - name: Build 20 | run: make 21 | - name: Test 22 | run: VERBOSE=all make tests 23 | 24 | Ubuntu-22_04: 25 | runs-on: ubuntu-22.04 26 | 27 | steps: 28 | - uses: actions/checkout@v2 29 | - name: Setup 30 | run: sudo apt-get install build-essential 31 | - name: Configure build and test 32 | run: VERBOSE=all make defconfig tests 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | /.config* 3 | /.single* 4 | /change/ 5 | /generated/ 6 | /kconfig/mconf 7 | /kconfig/conf 8 | /kconfig/*.c 9 | /toybox 10 | /toybox_unstripped 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2006, 2019 by Rob Landley 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted. 5 | 6 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 7 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 8 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 9 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 10 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 11 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 12 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 13 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # set environment variables used by scripts/make.sh 4 | 5 | # People run ./configure out of habit, so do "defconfig" for them. 6 | 7 | if [ "$(basename "$0")" == configure ] 8 | then 9 | echo "Assuming you want 'make defconfig', but you should probably check the README." 10 | make defconfig 11 | exit $? 12 | fi 13 | 14 | # Warn about stuff, disable stupid warnings, be 8-bit clean for utf8. 15 | [ "${CFLAGS/-funsigned-char//}" == "$CFLAGS" ] && 16 | CFLAGS+=" -Wall -Wundef -Werror=implicit-function-declaration -Wno-char-subscripts -Wno-pointer-sign -funsigned-char" 17 | 18 | # Set default values if variable not already set 19 | : ${CC:=cc} ${HOSTCC:=cc} ${GENDIR:=generated} ${KCONFIG_CONFIG:=.config} 20 | : ${UNSTRIPPED:=$GENDIR/unstripped} ${OUTNAME:=toybox${TARGET:+-$TARGET}} 21 | : ${OPTIMIZE:=-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing} 22 | 23 | # We accept LDFLAGS, but by default don't have anything in it 24 | -------------------------------------------------------------------------------- /kconfig/README: -------------------------------------------------------------------------------- 1 | This is a snapshot of linux 2.6.12 kconfig as washed through busybox and 2 | further modified by Rob Landley. 3 | 4 | Note: The build infrastructure in this directory is still GPLv2. Cleaning 5 | that out is a TODO item, but it doesn't affect the resulting binary. 6 | 7 | Way back when I tried to push my local changes to kconfig upstream 8 | in 2005 https://lwn.net/Articles/161086/ 9 | and 2006 http://lkml.iu.edu/hypermail/linux/kernel/0607.0/1805.html 10 | and 2007 http://lkml.iu.edu/hypermail/linux/kernel/0707.1/1741.html 11 | each of which spawned long "I think you should go do this and this and this 12 | but I'm not going to lift a finger personally" threads from the kernel 13 | developers. Twice I came back a year later to see if there was any interest 14 | in what I _had_ done, and the third thread was the longest of the lot but 15 | no code was merged as a result. 16 | 17 | *shrug* That's the linux-kernel community for you. I had an easier time 18 | than the author of squashfs, who spent 5 years actively trying to get his code 19 | merged, finally quitting his job to spend an unpaid year working on upstreaming 20 | squashfs _after_ after every major Linux distro had been locally carrying it 21 | for years. No really, here's where he wrote about it himself: 22 | 23 | https://lwn.net/Articles/563578/ 24 | 25 | This code is _going_away_. Rewriting it is low priority, but removing it is a 26 | checklist item for the 1.0 toybox release. This directory contains the only 27 | GPL code left in the tree, and none of its code winds up in the resulting 28 | binary. It's just an editor that reads our Config.in files to update the top 29 | level .config file; you can edit they by hand if you really want to. 30 | -------------------------------------------------------------------------------- /kconfig/lxdialog/BIG.FAT.WARNING: -------------------------------------------------------------------------------- 1 | This is NOT the official version of dialog. This version has been 2 | significantly modified from the original. It is for use by the Linux 3 | kernel configuration script. Please do not bother Savio Lam with 4 | questions about this program. 5 | -------------------------------------------------------------------------------- /lib/toyflags.h: -------------------------------------------------------------------------------- 1 | /* Flags values for the third argument of NEWTOY() 2 | * 3 | * Included from both main.c (runs in toys.h context) and scripts/install.c 4 | * (which may build on crazy things like macosx when cross compiling). 5 | */ 6 | 7 | // Flags describing command behavior. 8 | 9 | // Where to install (toybox --long outputs absolute paths to commands) 10 | // If no location bits set, command not listed in "toybox" command's output. 11 | #define TOYFLAG_USR (1<<0) 12 | #define TOYFLAG_BIN (1<<1) 13 | #define TOYFLAG_SBIN (1<<2) 14 | #define TOYMASK_LOCATION ((1<<4)-1) 15 | 16 | // This is a shell built-in function, running in the same process context. 17 | #define TOYFLAG_NOFORK (1<<4) 18 | #define TOYFLAG_MAYFORK (1<<5) 19 | 20 | // Start command with a umask of 0 (saves old umask in this.old_umask) 21 | #define TOYFLAG_UMASK (1<<6) 22 | 23 | // This command runs as root. 24 | #define TOYFLAG_STAYROOT (1<<7) // Don't drop suid root before running cmd_main 25 | #define TOYFLAG_NEEDROOT (1<<8) // Refuse to run if real uid != 0 26 | #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT) 27 | 28 | // Suppress default --help processing 29 | #define TOYFLAG_NOHELP (1<<9) 30 | #define TOYFLAG_AUTOCONF (1<<10) 31 | #define TOYFLAG_TRIMHELP (1<<11) 32 | #define TOYFLAG_BIGHELP (1<<12) 33 | #define TOYFLAG_MOREHELP(x) (TOYFLAG_TRIMHELP|TOYFLAG_BIGHELP*(x)) 34 | 35 | // Line buffered stdout 36 | #define TOYFLAG_LINEBUF (1<<13) 37 | #define TOYFLAG_NOBUF (1<<14) 38 | 39 | // Error code to return if argument parsing fails (default 1) 40 | #define TOYFLAG_ARGFAIL(x) (x<<24) 41 | -------------------------------------------------------------------------------- /mkroot/README.root: -------------------------------------------------------------------------------- 1 | Use ./run-qemu.sh to boot system image to a shell prompt, "exit" when done. 2 | 3 | Additional arguments to run-qemu.sh are QEMU arguments, 4 | $KARGS contains additional linux kernel arguments. For example: 5 | 6 | KARGS=quiet ./run-qemu.sh -hda docs/linux-fullconfig 7 | # cat /dev/?da 8 | # exit 9 | 10 | To extract the root filesystem from cpio.gz and chroot into it 11 | 12 | ( mkdir fs && cd fs && zcat ../initramfs.cpio.gz | cpio -i -d -H newc ) 13 | chroot fs /init 14 | 15 | To recreate the initramfs.cpio.gz from fs directory 16 | 17 | ( cd fs && find . -printf '%P\n' | cpio -o -H newc -R +0:+0 | gzip ) \ 18 | > initramfs.cpio.gz 19 | -------------------------------------------------------------------------------- /mkroot/packages/busybox: -------------------------------------------------------------------------------- 1 | #!/bin/echo Try "scripts/mkroot.sh busybox" 2 | 3 | download a5d40ca0201b20909f7a8a561adf57adccc8a877 \ 4 | http://www.busybox.net/downloads/busybox-1.36.1.tar.bz2 5 | 6 | # 4 commands: ash, route, udhcpc, stty 7 | 8 | setupfor busybox 9 | make defconfig && 10 | # Busybox checks for host bzip2, which toybox does not provide. 11 | sed -i 's/^bzip2/true bzip2/' scripts/{mkconfigs,embedded_scripts} && 12 | # zap script that wants diff 13 | ln -sf /bin/true scripts/generate_BUFSIZ.sh && 14 | echo '#define COMMON_BUFSIZE (4096) 15 | extern char bb_common_bufsiz1[]; 16 | #define setup_common_bufsiz()' > include/common_bufsiz.h && 17 | LDFLAGS=--static make SKIP_STRIP=y -j $(nproc) && 18 | cp busybox "$ROOT/bin" && 19 | make busybox.links && 20 | mkdir -p "$ROOT/busybox" || exit 1 21 | while read i; do ln -sf /bin/busybox "$ROOT/busybox/$(basename "$i")" || exit 1 22 | done < busybox.links 23 | cp .config "$ROOT/../busybox-config" 24 | cleanup 25 | 26 | # busybox ash doesn't support $( \ 30 | # "$ROOT/etc/rc/busybox.sh" && 31 | 32 | cat > "$ROOT"/etc/dhcp.sh << 'EOF' && 33 | #!/bin/sh 34 | 35 | [ "$1" = bound ] || exit 36 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" 37 | [ -n "$subnet" ] && NETMASK="netmask $subnet" 38 | ifconfig $interface $ip $BROADCAST $NETMASK 39 | [ -n "$router" ] && exit 40 | echo "deleting routers" 41 | while route del default gw 0.0.0.0 dev $interface; do :; done 42 | metric=0 43 | for i in $router; do 44 | route add default gw $i dev $interface metric $((metric++)) 45 | done 46 | EOF 47 | chmod +x "$ROOT"/etc/dhcp.sh || exit 1 48 | 49 | -------------------------------------------------------------------------------- /mkroot/packages/dynamic: -------------------------------------------------------------------------------- 1 | #!/bin/echo Try "mkroot/mkroot.sh dynamic" 2 | 3 | # Copy dynamic libraries from cross compiler 4 | 5 | "${CROSS_COMPILE}cc" -xc - <<< 'void main(void) {;}' || 6 | die "${CROSS_COMPILE}cc can't create dynamic binaries" 7 | LDSO="$("${CROSS_COMPILE}readelf" -a a.out | sed -n 's/.*interpreter: \([^]]*\)[]]$/\1/p')" 8 | mkdir -p "$ROOT"/"$(dirname "$LDSO")" && 9 | cp "$LDSO" "$ROOT"/"$LDSO" || die "Couldn't copy ldso" 10 | unset LDSO 11 | 12 | "${CROSS_COMPILE}cc" -print-search-dirs | sed -n 's/libraries: =//p' | \ 13 | tr : '\n' | while read i; do 14 | [ -e "$i" ] && find "$i" -maxdepth 1 -name '*.so' -o -name '*.so*[0-9]' 15 | done | while read i; do cp -a "$i" "$ROOT"/lib/; done 16 | -------------------------------------------------------------------------------- /mkroot/packages/lfs-sources: -------------------------------------------------------------------------------- 1 | #!/bin/echo Try "mkroot/mkroot.sh lfs" 2 | 3 | [ -z "$(which mksquashfs)" ] && echo "no squashfs" && exit 1 4 | 5 | # Download osuosl's rollup tarball of all the LFS packages. 6 | 7 | download 45a27da2ee443a8e35a7e29db8a0c6877bbb98bb \ 8 | http://ftp.osuosl.org/pub/lfs/lfs-packages/lfs-packages-12.1.tar 9 | 10 | # This one's a little weird, we're creating a target-agonstic squashfs image 11 | # not part of the initramfs. 12 | 13 | setupfor lfs-packages 14 | LFS="$OUTPUT/lfs" LFSRC="$LFS/src" 15 | rm -rf "$LFS" && mkdir -p "$LFSRC/tzdata" && 16 | # Fixup names 17 | tar xfC tzdata*.tar.gz "$LFSRC/tzdata" && # Horrible package, no subdirectory! 18 | rm tzdata*.tar.gz && 19 | mv {expect*,expect-0}.tar.gz && # broken name (no - before version) 20 | rm -f tcl*-html.tar.gz && # Broken _and_ duplicate name 21 | mv {tcl*,tcl-0}.tar.gz && 22 | mkdir sub || exit 1 23 | # extract tarballs to package name in output and apply patches (if any) 24 | for i in *.tar*; do 25 | PKG="${i/-[0-9]*/}" 26 | echo process $PKG 27 | tar xfC $i sub && mv sub/* "$LFSRC/$PKG" || exit 1 28 | for j in $PKG*.patch; do 29 | [ -e "$j" ] && { ( cd "$LFSRC/$PKG" && patch -p1) < "$j" || exit 1 ; } 30 | done 31 | done 32 | 33 | # Archive the sources 34 | 35 | mksquashfs "$LFSRC" "$TOP"/lfs.sqf -noappend -all-root >/dev/null 36 | -------------------------------------------------------------------------------- /mkroot/packages/overlay: -------------------------------------------------------------------------------- 1 | #!/bin/echo Try "mkroot/mkroot.sh overlay" 2 | 3 | cp -a "${OVERLAY:=overlay}"/. "$ROOT"/. 4 | -------------------------------------------------------------------------------- /mkroot/packages/tests: -------------------------------------------------------------------------------- 1 | #!/bin/echo Try "mkroot/mkroot.sh $0" 2 | 3 | # Alas http://www.linux-usb.org/usb.ids is not versioned, so... 4 | download 36d4e16755502fbc684be75e56841e1014e4a94a \ 5 | https://github.com/usbids/usbids/raw/a5edeafb6099/usb.ids 6 | 7 | # Nor is https://pci-ids.ucw.cz/v2.2/pci.ids (tool version, not file version) 8 | download 6694284723e034f0c564e81a30879939d5ef8b7e \ 9 | https://github.com/pciutils/pciids/raw/c7929c0f9480/pci.ids 10 | 11 | cp "$DOWNLOAD"/{usb,pci}.ids "$ROOT/etc/" || exit 1 12 | 13 | # add a couple test modules 14 | MODULES+=FSCACHE,CACHEFILES 15 | -------------------------------------------------------------------------------- /mkroot/record-commands: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Set up command recording wrapper 4 | 5 | [ -z "$WRAPDIR" ] && WRAPDIR="$PWD"/record-commands && RM=$(which rm) 6 | [ -z "$LOGPATH" ] && export LOGPATH="$PWD"/log.txt 7 | 8 | if [ ! -x "$WRAPDIR/logpath" ] 9 | then 10 | LOG="$(which logpath)" 11 | mkdir -p "$WRAPDIR" || exit 1 12 | [ -e "$LOG" ] && cp -H "$LOG" "$WRAPDIR/logpath" || { cd "$(dirname $0)/.." && 13 | PREFIX="$WRAPDIR/" scripts/single.sh logpath >/dev/null && 14 | LOG="$PWD/logpath" || exit 1; } 15 | tr : '\n' <<< "$PATH" | while read i; do 16 | find "$i" \( -type f -o -type l \) -maxdepth 1 -executable -exec basename {} \; | \ 17 | while read FILE; do ln -s logpath "$WRAPDIR/$FILE" 2>/dev/null; done 18 | done 19 | fi 20 | 21 | # Delete old log (if any) 22 | rm -f "$LOGPATH" 23 | 24 | # When sourced, set up wrapper for current context. 25 | if [ $# -gt 0 ] 26 | then 27 | PATH="$WRAPDIR:$PATH" "$@" 28 | X=$? 29 | [ -n "$RM" ] && "$RM" -rf "$WRAPDIR" 30 | 31 | exit $X 32 | else 33 | echo export LOGPATH=${LOGPATH@Q} PATH=${WRAPDIR@Q}:${PATH@Q} 34 | fi 35 | 36 | -------------------------------------------------------------------------------- /mkroot/tar-for-web.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # tar up completed system images to send to website, with READMEs 4 | 5 | rm -f root/toybox-* root/*.tgz 6 | for i in root/*/fs/bin/toybox 7 | do 8 | cp $i root/toybox-$(echo $i | sed 's@root/\([^/]*\)/.*@\1@') || exit 1 9 | done 10 | 11 | for i in root/*/run-qemu.sh 12 | do 13 | i=${i%/run-qemu.sh} j=${i#root/} 14 | [ ! -e "$i" ] && continue 15 | # Add README, don't include "fs" dir (you can extract it from cpio.gz) 16 | cp mkroot/README.root $i/docs/README && 17 | tar cvzfC $i.tgz root --exclude=fs $j || exit 1 18 | done 19 | 20 | # Generate top level README 21 | KVERS=$(toybox sed -n '3s@# Linux/[^ ]* \(.*\) Kernel Configuration@\1@p' root/*/docs/linux-fullconfig) 22 | cat > root/README << EOF 23 | Bootable system images created by: 24 | 25 | mkroot/mkroot.sh LINUX=~/linux CROSS=allnonstop 26 | 27 | Each system image is built from two packages: toybox and linux. 28 | The run-qemu.sh script in each tarball should boot the system 29 | to a shell prompt under qemu, exit from that shell to shut down the 30 | virtual system and stop the emulator. 31 | 32 | See https://landley.net/toybox/faq.html#mkroot for details. 33 | 34 | Built from mkroot $(git describe --tags), and Linux $KVERS with patches in linux-patches/ 35 | EOF 36 | 37 | if [ $# -eq 2 ] 38 | then 39 | scp root/toybox-* "$1/$2/" && 40 | scp root/*.tgz root/README "$1/mkroot/$2/" 41 | fi 42 | -------------------------------------------------------------------------------- /scripts/change.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # build each command as a standalone executable 4 | 5 | source scripts/portability.sh 6 | 7 | NOBUILD=1 scripts/make.sh > /dev/null && 8 | ${HOSTCC:-cc} -I . scripts/install.c -o "$UNSTRIPPED"/instlist && 9 | export PREFIX=${PREFIX:-change/} && 10 | mkdir -p "$PREFIX" || exit 1 11 | 12 | # Build all the commands standalone 13 | for i in $("$UNSTRIPPED"/instlist) 14 | do 15 | echo -n " $i" && 16 | scripts/single.sh $i &>$PREFIX/${i}.bad && 17 | rm $PREFIX/${i}.bad || echo -n '*' 18 | done 19 | echo 20 | -------------------------------------------------------------------------------- /scripts/git-static-index.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Create very basic index.html and commit links for a static git archive 4 | 5 | mkdir -p commit 6 | git log --pretty=%H | while read i 7 | do 8 | [ -e commit/$i ] && break 9 | git format-patch -1 --stdout $i > commit/$i 10 | ln -sf $i commit/${i::12} 11 | done 12 | 13 | echo '' 14 | echo '' 15 | git log --pretty='%H%n%an<%ae>%n%ad%n%s' --date=format:'%r
%d-%m-%Y' | while read HASH 16 | do 17 | HASH="${HASH::12}" 18 | read AUTHOR 19 | AUTHOR1="${AUTHOR/<*/}" 20 | AUTHOR1="${AUTHOR1::17}" 21 | AUTHOR2="<${AUTHOR/*" 27 | done 28 | echo "
commitauthordatedescription
$HASH$AUTHOR1
$AUTHOR2
$DATE$DESC
" 29 | -------------------------------------------------------------------------------- /scripts/install.c: -------------------------------------------------------------------------------- 1 | /* Wrapper to make installation easier with cross-compiling. 2 | * 3 | * Copyright 2006 Rob Landley 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "generated/config.h" 11 | #include "lib/toyflags.h" 12 | 13 | #define NEWTOY(name, opts, flags) {#name, flags}, 14 | #define OLDTOY(name, oldname, flags) {#name, flags}, 15 | 16 | // Populate toy_list[]. 17 | 18 | struct {char *name; int flags;} toy_list[] = { 19 | #include "generated/newtoys.h" 20 | }; 21 | 22 | #undef NEWTOY 23 | #undef OLDTOY 24 | #define NEWTOY(name,opt,flags) HELP_##name "\0" 25 | #if CFG_TOYBOX 26 | #define OLDTOY(name,oldname,flags) "\xff" #oldname "\0" 27 | #else 28 | #define OLDTOY(name, oldname, flags) HELP_##oldname "\0" 29 | #endif 30 | 31 | #include "generated/help.h" 32 | static char help_data[] = 33 | #include "generated/newtoys.h" 34 | ; 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | static char *toy_paths[]={"usr/","bin/","sbin/",0}; 39 | int i, len = 0; 40 | 41 | if (argc>1 && !strcmp(argv[1], "--help")) 42 | exit(sizeof(help_data)!=write(1, help_data, sizeof(help_data))); 43 | 44 | // Output list of applets. 45 | for (i=1; i1) { 49 | int j; 50 | for (j=0; toy_paths[j]; j++) 51 | if (fl & (1<&2; exit 1; } 7 | 8 | declare -A ray 9 | 10 | # Sad that this is NOT in the default path, but less dumb than /bin/sh->dash 11 | PATH="$PATH":/sbin:/usr/sbin 12 | 13 | # Only checks installed packages, puts anything it can't find in none: 14 | for i in $(./toybox) 15 | do 16 | tty -s && echo -n . >&2 17 | which $i >/dev/null || { ray["none:"]+=" $i"; continue; } 18 | 19 | ray[$(dpkg-query -S $(readlink -f $(which $i)) | toybox cut -DF 1)]+=" $i" 20 | done 21 | 22 | # Print results 23 | for i in ${!ray[@]} 24 | do 25 | echo $i ${ray[$i]} 26 | done 27 | -------------------------------------------------------------------------------- /scripts/probes/findglobals: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Quick and dirty check to see if anybody's leaked global variables. 4 | # We should have this, toy_list, toybuf, libbuf, toys, and toybox_version. 5 | 6 | nm --size-sort generated/unstripped/toybox | grep '[0-9A-Fa-f]* [BCDGRS]' | \ 7 | grep -v GLIBC | while read a b c; do printf '%s %d\t%s\n' $b 0x$a $c; done | \ 8 | sort -k2,2n 9 | -------------------------------------------------------------------------------- /scripts/probes/showasm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2006 Rob Landley 4 | 5 | # Dumb little utility function to print out the assembly dump of a single 6 | # function, or list the functions so dumpable in an executable. You'd think 7 | # there would be a way to get objdump to do this, but I can't find it. 8 | 9 | [ $# -lt 1 ] || [ $# -gt 2 ] && { echo "usage: showasm file function"; exit 1; } 10 | 11 | [ ! -f $1 ] && { echo "File $1 not found"; exit 1; } 12 | 13 | if [ $# -eq 1 ] 14 | then 15 | objdump -d $1 | sed -n -e 's/^[0-9a-fA-F]* <\(.*\)>:$/\1/p' 16 | exit 0 17 | fi 18 | 19 | objdump -d $1 | sed -n -e '/./{H;$!d}' -e "x;/^.[0-9a-fA-F]* <$2>:/p" 20 | 21 | -------------------------------------------------------------------------------- /scripts/recreate-prereq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Regenerate scripts/prereq (hopefully) portable build. 4 | 5 | # Detect toybox prerequisites using record-commands 6 | 7 | mkroot/record-commands make clean defconfig toybox 8 | sed -i 's/default y/default n/' generated/Config.probed 9 | CMDLIST="$(echo toybox; ./toybox cut -DF 1 log.txt | sort -u | grep -v nproc)" 10 | { 11 | for i in $(tr '[:lower:]' '[:upper:]' <<<"$CMDLIST") 12 | do 13 | grep -qi CONFIG_$i'[= ]' .config && echo CONFIG_$i=y 14 | done 15 | } > prereq.mini 16 | 17 | # Create minimal dependency-free build 18 | 19 | make clean allnoconfig KCONFIG_ALLCONFIG=prereq.mini 20 | make toybox 21 | cat > scripts/prereq/build.sh << 'EOF' 22 | #!/bin/sh 23 | 24 | BUILD='cc -funsigned-char -I scripts/prereq -I . -Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing -DTOYBOX_VERSION=""' 25 | LINK='' 26 | EOF 27 | grep -A999 FILES= generated/build.sh >> scripts/prereq/build.sh 28 | sed -i 's/ toybox$/&-prereq/' scripts/prereq/build.sh 29 | 30 | # harvest stripped down headers 31 | 32 | echo > scripts/prereq/generated/tags.h 33 | sed 's/.*/#define HELP_& ""/' <<<"$CMDLIST" > scripts/prereq/generated/help.h 34 | egrep "($(xargs <<<"$CMDLIST"|tr ' [:lower:]' '|[:upper:]'))" \ 35 | generated/newtoys.h > scripts/prereq/generated/newtoys.h 36 | FORS="$(sed -n 's/#define FOR_//p' $(grep -o 'toys/[^/]*/[^.]*\.c' scripts/prereq/build.sh) | xargs | tr ' ' '|')" 37 | sed -En '1,/^$/p;/\/\/ ('"$FORS"') /,/^$/p;/#ifdef FOR_('"$FORS"')$/,/^$/p' generated/flags.h > scripts/prereq/generated/flags.h 38 | egrep "OPTSTR_($(egrep -v "($FORS)" <<<"$CMDLIST" | xargs | tr ' ' '|'))" \ 39 | generated/flags.h >> scripts/prereq/generated/flags.h 40 | # TODO: slim down config.h 41 | cp generated/{globals,config}.h scripts/prereq/generated/ 42 | -------------------------------------------------------------------------------- /tests/README.txt: -------------------------------------------------------------------------------- 1 | The build infrastructure adds a "make test_NAME" target for each NAME.test 2 | file in this directory, and "make tests" iterates through all of them. 3 | 4 | Individual tests boil down to a call to "scripts/test.sh NAME", and 5 | testing all is "scripts/test.sh" with no arguments. 6 | 7 | The test infrastructure, including the shell functions each test calls 8 | (mostly "testcmd" and "optional") is described in scripts/test.sh 9 | -------------------------------------------------------------------------------- /tests/base32.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | # testing "name" "flags" "result" "infile" "stdin" 6 | 7 | testcmd "simple" "" "ONUW24DMMUFA====\n" "" "simple\n" 8 | testcmd "file" "input" "ONUW24DMMUFA====\n" "simple\n" "" 9 | testcmd "simple -d" "-d" "simple\n" "" "ONUW24DMMUFA====\n" 10 | testcmd "file -d" "-d input" "simple\n" "ONUW24DMMUFA====" "" 11 | testcmd "default wrap" "" \ 12 | "K5SSO5TFEBZGK4DMMFRWKZBAORUGKIDENFWGS5DINF2W2IDUNBSXSIDON5ZG2YLMNR4SA5LTMUQH\nO2LUNAQEM33MM5SXEJ3TEBBXE6LTORQWY4ZO\n" \ 13 | "" "We've replaced the dilithium they normally use with Folger's Crystals." 14 | testcmd "multiline -d " "-d" \ 15 | "We've replaced the dilithium they normally use with Folger's Crystals." "" \ 16 | "K5SSO5TFEBZGK4DMMFRWKZBAORUGKIDENFWGS5DINF2W2IDUNBSXSIDON5ZG2YLMNR4SA5LTMUQH\nO2LUNAQEM33MM5SXEJ3TEBBXE6LTORQWY4ZO\n" 17 | 18 | testcmd "-w" "-w 10" \ 19 | "JVQXEY3INF\nXGOIDUN4QH\nI2DFEBRGKY\nLUEBXWMIDB\nEBSGSZTGMV\nZGK3TUEBVW\nK5DUNRSSA3\n3GEBTGS43I\nFY======\n" \ 20 | "" "Marching to the beat of a different kettle of fish." 21 | 22 | testcmd "-w0" "-w0 input" \ 23 | "KZUWW2LOM5ZT6ICUNBSXEZJAMFUW4J3UEBXG6IDWNFVWS3THOMQGQZLSMUXCASTVON2CA5LTEBUG63TFON2CAZTBOJWWK4TTFYQFI2DFEB2G653OEB3WC4ZAMJ2XE3TJNZTSYIDUNBSSA5TJNRWGCZ3FOJZSA53FOJSSAZDFMFSC4ICUNBSXSIDENFSG4J3UEBXGKZLEEB2GQ33TMUQHG2DFMVYCAYLOPF3WC6JOEBKGQYLUE5ZSA33VOIQHG5DPOJ4SAYLOMQQHOZJHOJSSA43UNFRWW2LOM4QHI3ZANF2C4CQ=" \ 24 | "Vikings? There ain't no vikings here. Just us honest farmers. The town was burning, the villagers were dead. They didn't need those sheep anyway. That's our story and we're sticking to it.\n" "" 25 | -------------------------------------------------------------------------------- /tests/base64.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | testcmd "simple" "" "c2ltcGxlCg==\n" "" "simple\n" 8 | testcmd "file" "input" "c2ltcGxlCg==\n" "simple\n" "" 9 | testcmd "simple -d" "-d" "simple\n" "" "c2ltcGxlCg==\n" 10 | testcmd "simple -d" "-d input" "simple\n" "c2ltcGxlCg==" "" 11 | testcmd "default wrap" "" \ 12 | "V2UndmUgcmVwbGFjZWQgdGhlIGRpbGl0aGl1bSB0aGV5IG5vcm1hbGx5IHVzZSB3aXRoIEZvbGdl\ncidzIENyeXN0YWxzLg==\n" \ 13 | "" "We've replaced the dilithium they normally use with Folger's Crystals." 14 | testcmd "multiline -d " "-d" \ 15 | "We've replaced the dilithium they normally use with Folger's Crystals." "" \ 16 | "V2UndmUgcmVwbGFjZWQgdGhlIGRpbGl0aGl1bSB0aGV5IG5vcm1hbGx5IHVzZSB3aXRoIEZvbGdl\ncidzIENyeXN0YWxzLg==\n" 17 | 18 | testcmd "-w" "-w 10" \ 19 | "TWFyY2hpbm\ncgdG8gdGhl\nIGJlYXQgb2\nYgYSBkaWZm\nZXJlbnQga2\nV0dGxlIG9m\nIGZpc2guCg\n==\n" \ 20 | "" "Marching to the beat of a different kettle of fish.\n" 21 | 22 | testcmd "-w0" "-w0 input" \ 23 | "VmlraW5ncz8gVGhlcmUgYWluJ3Qgbm8gdmlraW5ncyBoZXJlLiBKdXN0IHVzIGhvbmVzdCBmYXJtZXJzLiBUaGUgdG93biB3YXMgYnVybmluZywgdGhlIHZpbGxhZ2VycyB3ZXJlIGRlYWQuIFRoZXkgZGlkbid0IG5lZWQgdGhvc2Ugc2hlZXAgYW55d2F5LiBUaGF0J3Mgb3VyIHN0b3J5IGFuZCB3ZSdyZSBzdGlja2luZyB0byBpdC4K" \ 24 | "Vikings? There ain't no vikings here. Just us honest farmers. The town was burning, the villagers were dead. They didn't need those sheep anyway. That's our story and we're sticking to it.\n" "" 25 | -------------------------------------------------------------------------------- /tests/basename.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | # Removal of extra /'s 8 | testcmd "/-only" "///////" "/\n" "" "" 9 | testcmd "trailing /" "a//////" "a\n" "" "" 10 | testcmd "combined" "/////a///b///c///d/////" "d\n" "" "" 11 | 12 | # Standard suffix behavior. 13 | testcmd "suffix" "a/b/c/d.suffix .suffix" "d\n" "" "" 14 | 15 | # A suffix cannot be the entire result. 16 | testcmd "suffix=result" ".txt .txt" ".txt\n" "" "" 17 | 18 | # Deal with suffix appearing in the filename 19 | testcmd "reappearing suffix 1" "a.txt.txt .txt" "a.txt\n" "" "" 20 | testcmd "reappearing suffix 2" "a.txt.old .txt" "a.txt.old\n" "" "" 21 | 22 | # A suffix should be a real suffix, only a the end. 23 | testcmd "invalid suffix" "isthisasuffix? suffix" "isthisasuffix?\n" "" "" 24 | 25 | # Zero-length suffix 26 | testcmd "zero-length suffix" "a/b/c ''" "c\n" "" "" 27 | 28 | # -s. 29 | testcmd "-s" "-s .txt /a/b/c.txt" "c\n" "" "" 30 | testcmd "-s implies -a" "-s .txt /a/b/c.txt /a/b/d.txt" "c\nd\n" "" "" 31 | testcmd "-a" "-a /a/b/f1 /c/d/f2" "f1\nf2\n" "" "" 32 | -------------------------------------------------------------------------------- /tests/bc.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testcmd "name "args" "result" "infile" "stdin" 6 | 7 | BDIR="$FILES/bc" 8 | 9 | run_bc_test() { 10 | tst="$1" 11 | results=$(cat "$BDIR/${tst}_results.txt") 12 | testcmd "$tst" "-l $BDIR/$tst.txt" "$results\n" "$BDIR/$tst.txt" "" 13 | } 14 | 15 | run_bc_test decimal 16 | run_bc_test add 17 | run_bc_test subtract 18 | run_bc_test multiply 19 | run_bc_test divide 20 | run_bc_test modulus 21 | run_bc_test power 22 | run_bc_test sqrt 23 | run_bc_test vars 24 | run_bc_test boolean 25 | run_bc_test parse 26 | run_bc_test print 27 | run_bc_test exponent 28 | run_bc_test log 29 | run_bc_test pi 30 | run_bc_test arctan 31 | run_bc_test sine 32 | run_bc_test cosine 33 | run_bc_test bessel 34 | run_bc_test arrays 35 | run_bc_test misc 36 | run_bc_test misc1 37 | run_bc_test misc2 38 | 39 | testcmd "stdin" "" "2\n" "" "1+1\n" 40 | -------------------------------------------------------------------------------- /tests/bzcat.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | testing "2 known files" \ 7 | 'bzcat "$FILES/blkid/"{minix,ntfs}.bz2 | sha1sum | cut -d " " -f 1' \ 8 | 'c0b7469c9660d6056a988ef8a7fe73925efc9266\n' '' '' 9 | 10 | testing "overflow" \ 11 | 'bzcat "$FILES/bzcat/overflow.bz2" >/dev/null 2>/dev/null ; 12 | [ $? -ne 0 ] && echo good' "good\n" "" "" 13 | 14 | testing "badcrc" \ 15 | 'bzcat "$FILES/bzcat/badcrc.bz2" > /dev/null 2>/dev/null ; 16 | [ $? -ne 0 ] && echo good' "good\n" "" "" 17 | -------------------------------------------------------------------------------- /tests/cat.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | echo "one" > file1 8 | echo "two" > file2 9 | testing "cat" "cat && echo yes" "oneyes\n" "" "one" 10 | testing "-" "cat - && echo yes" "oneyes\n" "" "one" 11 | testing "file1 file2" "cat file1 file2" "one\ntwo\n" "" "" 12 | testing "- file" "cat - file1" "zero\none\n" "" "zero\n" 13 | testing "file -" "cat file1 -" "one\nzero\n" "" "zero\n" 14 | 15 | testing "file1 notfound file2" \ 16 | "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \ 17 | "one\ntwo\ncat: notfound: No such file or directory\n" "" "" 18 | 19 | testing "binary" \ 20 | 'cat "$C" > file1 && cmp "$C" file1 && echo yes' "yes\n" "" "" 21 | 22 | testing "- file1" \ 23 | "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \ 24 | "-hello\n" "" "hello\n" 25 | 26 | skipnot [ -e /dev/full ] 27 | testing "> /dev/full" \ 28 | "cat - > /dev/full 2>/dev/null || echo failed" \ 29 | "failed\n" "" "zero\n" 30 | 31 | rm file1 file2 32 | -------------------------------------------------------------------------------- /tests/chown.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | if [ "$(id -u)" -ne 0 ] 6 | then 7 | echo "$SHOWSKIP: chown (not root)" 8 | return 2>/dev/null 9 | exit 10 | fi 11 | 12 | # We chown between user "root" and the last user in /etc/passwd, 13 | # and group "root" and the last group in /etc/group. 14 | USR="$(sed -n '$s/:.*//p' /etc/passwd)" 15 | GRP="$(sed -n '$s/:.*//p' /etc/group)" 16 | # Or if that fails, we assume we're on Android... 17 | : "${USR:=shell}" 18 | : "${GRP:=daemon}" 19 | 20 | # Set up a little testing hierarchy 21 | 22 | rm -rf testdir && 23 | mkdir testdir && 24 | touch testdir/file 25 | F=testdir/file 26 | 27 | # Wrapper to reset groups and return results 28 | 29 | OUT="&& stat --format '%U %G' $F" 30 | 31 | #testing "name" "command" "result" "infile" "stdin" 32 | 33 | # Basic smoketest 34 | testing "initial" "chown root:root $F $OUT" "root root\n" "" "" 35 | testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" "" 36 | testing "root" "chown root $F $OUT" "root $GRP\n" "" "" 37 | # TODO: can we test "owner:"? 38 | testing ":grp" "chown root:root $F && chown :$GRP $F $OUT" \ 39 | "root $GRP\n" "" "" 40 | testing ":" "chown $USR:$GRP $F && chown : $F $OUT" \ 41 | "$USR $GRP\n" "" "" 42 | 43 | rm -rf testdir 44 | -------------------------------------------------------------------------------- /tests/cksum.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | 6 | #testing "name" "command" "result" "infile" "stdin" 7 | 8 | # Default behavior on stdin and on files. 9 | testing "on stdin" "echo -n hello | cksum" "3287646509 5\n" "" "" 10 | echo -n "hello" > tmpfile 11 | testing "on file" "cksum tmpfile" "3287646509 5 tmpfile\n" "" "" 12 | rm -f tmpfile 13 | touch one two 14 | testing "on multiple files" "cksum one two" "4294967295 0 one\n4294967295 0 two\n" "" "" 15 | rm -f one two 16 | 17 | # Check the length suppression, both calculate the CRC on 'abc' but the second 18 | # option has length suppression on and has the length concatenated to 'abc'. 19 | testing "on abc including length" "cksum" "1219131554 3\n" "" 'abc' 20 | toyonly testing "on abc excluding length" "cksum -N" "1219131554\n" "" 'abc\x3' 21 | 22 | # cksum on no contents gives 0xffffffff (=4294967295) 23 | testing "on no data post-inversion" "echo -n "" | cksum" "4294967295 0\n" "" "" 24 | # If we do preinversion we will then get 0. 25 | toyonly testing "on no data pre+post-inversion" "echo -n "" | cksum -P" "0 0\n" "" "" 26 | # If we skip the post-inversion we also get 0 27 | toyonly testing "on no data no inversion" "echo -n "" | cksum -I" "0 0\n" "" "" 28 | # Two wrongs make a right. 29 | toyonly testing "on no data pre-inversion" "echo -n "" | cksum -PI" "4294967295 0\n" "" "" 30 | -------------------------------------------------------------------------------- /tests/comm.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | echo -e 'a\nb\nc'> lhs 8 | for i in c d e ; do echo $i >> rhs ; done 9 | testing "comm" "comm lhs input" "a\nb\n\t\tc\n\td\n\te\n" "c\nd\ne\n" "" 10 | testing "comm -" "comm - input" "a\nb\n\t\tc\n\td\n\te\n" "c\nd\ne\n" "a\nb\nc\n" 11 | testing "comm -123 detects missing" "comm - missing 2>/dev/null || echo here" \ 12 | "here\n" "" "" 13 | -------------------------------------------------------------------------------- /tests/demo_number.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | testcmd "l 1024" "-h 123456789" "118M\n" "" "" 8 | testcmd "l 1000" "-d 123456789" "123M\n" "" "" 9 | testcmd "s 1024" "-h 5675" "5.5K\n" "" "" 10 | testcmd "s 1000" "-d 5675" "5.6k\n" "" "" 11 | 12 | # An example input where we give a better result than coreutils. 13 | # 267350/1024=261.08. We say 261K and coreutils says 262K. 14 | testcmd "edge case" "-h 267350" "261K\n" "" "" 15 | 16 | testcmd "-b" "-b 123" "123B\n" "" "" 17 | testcmd "-b" "-b 123456789" "118M\n" "" "" 18 | testcmd "-s" "-s 123456789" "118 M\n" "" "" 19 | testcmd "-bs" "-bs 123456789" "118 M\n" "" "" 20 | 21 | testcmd "units" "-b 1c 1b 1k 1kd 1m 1md 1g 1gd 1t 1td 1e 1ed" \ 22 | "1B\n512B\n1.0K\n0.9K\n1.0M\n977K\n1.0G\n954M\n1.0T\n931G\n1.0E\n888P\n" \ 23 | "" "" 24 | 25 | testcmd "decimal units" "-d 1c 1b 1k 1kd 1m 1md 1g 1gd 1t 1td 1e 1ed" \ 26 | "1\n512\n1.0k\n1.0k\n1.0M\n1.0M\n1.0G\n1.0G\n1.1T\n1.0T\n1.1E\n1.0E\n" \ 27 | "" "" 28 | 29 | testcmd "longer output" "-D6 123 1234567 1234567890" "123\n1206K\n1177M\n" "" "" 30 | -------------------------------------------------------------------------------- /tests/dirname.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | testing "/-only" "dirname ///////" "/\n" "" "" 8 | testing "trailing /" "dirname a//////" ".\n" "" "" 9 | testing "combined" "dirname /////a///b///c///d/////" "/////a///b///c\n" "" "" 10 | testing "/a/" "dirname /////a///" "/\n" "" "" 11 | testing "multiple" "dirname hello/a world/b" "hello\nworld\n" "" "" 12 | -------------------------------------------------------------------------------- /tests/env.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testcmd "name "args" "result" "infile" "stdin" 6 | #testing "name" "command" "result" "infile" "stdin" 7 | 8 | export WALRUS=42 BANANA=hello LETTERS= 9 | FILTER="| egrep '^(WALRUS|BANANA|LETTERS)=' | sort" 10 | 11 | testcmd "read" "$FILTER" "BANANA=hello\nLETTERS=\nWALRUS=42\n" "" "" 12 | testcmd "-u" "-u BANANA $FILTER" "LETTERS=\nWALRUS=42\n" "" "" 13 | testcmd "-uu" "-u LETTERS -u WALRUS $FILTER" "BANANA=hello\n" "" "" 14 | testcmd "-i uses old \$PATH" "-i echo hello" "hello\n" "" "" 15 | testcmd "-i env" "-i env" "" "" "" 16 | testcmd "-i =" "-i one=two three=four $C | sort" \ 17 | "one=two\nthree=four\n" "" "" 18 | testcmd "-0" "-i five=six seven=eight $C -0 | sort -z" "five=six\0seven=eight\0" "" "" 19 | unset WALRUS BANANA LETTERS FILTER 20 | 21 | testcmd "early fail" '--oops 2> /dev/null ; echo $?' "125\n" "" "" 22 | testcmd "why is this allowed" "=BLAH env | grep '^=BLAH\$'" "=BLAH\n" "" "" 23 | 24 | testcmd "replace" "A=foo PATH= `which printenv` A" "foo\n" "" "" 25 | 26 | # env bypasses shell builtins 27 | echo "#!$(which sh) 28 | echo \$@" > true 29 | chmod a+x true 30 | testcmd "norecurse" 'env PATH="$PWD:$PATH" true hello' "hello\n" "" "" 31 | rm true 32 | -------------------------------------------------------------------------------- /tests/expand.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # POSIX 2008 compliant expand tests. 4 | # Copyright 2012 by Jonathan Clairembault 5 | 6 | [ -f testing.sh ] && . testing.sh 7 | 8 | # some basic tests 9 | 10 | testing "default" "expand input" " foo bar\n" "\tfoo\tbar\n" "" 11 | testing "default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n" 12 | testing "single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" "" 13 | testing "tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" "" 14 | testing "backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" "" 15 | 16 | # advanced tests 17 | 18 | POW=15 19 | TABSTOP=1 20 | BIGTAB=" " 21 | for i in $(seq $POW); do 22 | BIGTAB=$BIGTAB$BIGTAB 23 | TABSTOP=$(($TABSTOP*2)) 24 | done 25 | testing "long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" "" 26 | testing "long tab tablist" "expand -t $TABSTOP,$((TABSTOP+5)) input" \ 27 | "${BIGTAB}foo bar\n" "\tfoo\tbar\n" "" 28 | 29 | testing "multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" "" 30 | testing "multiline tablist" "expand -t 4,8 input" \ 31 | "foo bar\n bar foo\n" "foo\t\tbar\n\tbar\tfoo\n" "" 32 | POW=15 33 | BIGLINE="foo " 34 | for i in $(seq $POW); do 35 | BIGLINE=$BIGLINE$BIGLINE 36 | done 37 | if [ $POW -gt 0 ]; then 38 | EXPANDLINE="${BIGLINE} foo\n" 39 | else 40 | EXPANDLINE="${BIGLINE} foo\n" 41 | fi 42 | BIGLINE="${BIGLINE}\tfoo\n" 43 | testing "long line single" "expand input" \ 44 | "${EXPANDLINE}" "$BIGLINE" "" 45 | -------------------------------------------------------------------------------- /tests/factor.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f testing.sh ] && . testing.sh 4 | 5 | #testing "name" "command" "result" "infile" "stdin" 6 | 7 | toyonly testing "-32" "factor -32" "-32: -1 2 2 2 2 2\n" "" "" 8 | toyonly testing "0" "factor 0" "0: 0\n" "" "" 9 | toyonly testing "1" "factor 1" "1: 1\n" "" "" 10 | testing "2" "factor 2" "2: 2\n" "" "" 11 | testing "3" "factor 3" "3: 3\n" "" "" 12 | testing "4" "factor 4" "4: 2 2\n" "" "" 13 | testing "10000000017" "factor 10000000017" \ 14 | "10000000017: 3 3 3 7 7 7 1079797\n" "" "" 15 | testing "10000000018" "factor 10000000018" \ 16 | "10000000018: 2 131 521 73259\n" "" "" 17 | testing "10000000019" "factor 10000000019" \ 18 | "10000000019: 10000000019\n" "" "" 19 | 20 | testing "3 6 from stdin" "factor" "3: 3\n6: 2 3\n" "" "3 6" 21 | testing "stdin newline" "factor" "3: 3\n6: 2 3\n" "" "3\n6\n" 22 | 23 | toyonly testing "-h" "factor -h $(((1<<63)-26))" \ 24 | "9223372036854775782: 2 3^4 17 23 319279 456065899\n" "" "" 25 | toyonly testing "-x" "factor -x $(((1<<63)-20))" \ 26 | "7fffffffffffffec: 2 2 3 283 43f2ba978e663\n" "" "" 27 | 28 | -------------------------------------------------------------------------------- /tests/fallocate.test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #testing "name" "command" "result" "infile" "stdin" 4 | 5 | rm -f foo 6 | testcmd 'simple' '-l 123 foo && stat -c %s foo' '123\n' '' '' 7 | testcmd 'shorter' '-l 12 foo && stat -c %s foo' '123\n' '' '' 8 | testcmd 'longer' '-o 200 -l 12 foo && stat -c %s foo' '212\n' '' '' 9 | -------------------------------------------------------------------------------- /tests/files/bc/add_results.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 1 5 | 7 6 | 720 7 | 1998 8 | 324869359109479 9 | 2378639108055453348401 10 | 78562139406792834691802347619083467219846713490861872324967138636055\ 11 | 45508706362018540498696043776980521464405852627147161556994835657433\ 12 | 00967298 13 | 1.1 14 | 1.1 15 | 37842935130118.1187478621432354 16 | 1.1 17 | 3746289134067138046.138375863945672398456712389456273486293 18 | -2 19 | -19 20 | -1287904651762470260258 21 | 100000000000000000000000000000000000000000000000000000000000.0000000\ 22 | 00000000000000000000000000000000000000000000000000000000000000000000\ 23 | 000000000000000000000000000000000000000000000 24 | 100000000000000000000000000000000000000000000000000000000000.0000000\ 25 | 00000000000000000000000000000000000000000000000000000000000000000000\ 26 | 000000000000000000000000000000000000000000000 27 | 100000000000000000000000000000000000000000000000000000000000.0000000\ 28 | 00000000000000000000000000000000000000000000000000000000000000000000\ 29 | 000000000000000000000000000000000000000009999 30 | 99999999999999999999999999999999999999999999999999999999999.99999999\ 31 | 99999999999999999999999999999999999999999999999999000000000000000000\ 32 | 00000000000000000000000000000000000000009999 33 | 99999999999999999999999999999999999990000000000000000000000.00000000\ 34 | 00000000000000000000000000000000000000000000000000000000000000000000\ 35 | 00000000000000000000000000000000000000009999 36 | 122761518 37 | -14338.391079082 38 | -2422295.6865057444 39 | 40 | -------------------------------------------------------------------------------- /tests/files/bc/arctan.txt: -------------------------------------------------------------------------------- 1 | for (i = 1; i <= 100; i++) { 2 | scale = i 3 | a(.267) 4 | a(1) 5 | } 6 | halt 7 | -------------------------------------------------------------------------------- /tests/files/bc/arrays.txt: -------------------------------------------------------------------------------- 1 | a[0] = 1 2 | a[2-1] = 2 3 | 4 | a[0]+a[0] 5 | 6 | a[2-1]+a[2-1] 7 | 8 | a[5] = 2 9 | a[5.789] 10 | 11 | -------------------------------------------------------------------------------- /tests/files/bc/arrays_results.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 4 3 | 2 4 | -------------------------------------------------------------------------------- /tests/files/bc/boolean_results.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | 0 4 | 1 5 | 0 6 | 0 7 | 1 8 | 0 9 | 0 10 | 0 11 | 0 12 | 0 13 | 0 14 | 0 15 | 0 16 | 1 17 | 0 18 | 1 19 | 0 20 | 0 21 | 0 22 | 1 23 | 0 24 | 0 25 | 0 26 | 0 27 | 0 28 | 1 29 | 0 30 | 0 31 | 0 32 | 0 33 | 0 34 | 0 35 | 0 36 | 0 37 | 1 38 | 0 39 | 0 40 | 0 41 | 0 42 | 0 43 | 0 44 | 0 45 | 1 46 | 0 47 | 0 48 | 0 49 | 0 50 | 0 51 | 0 52 | 0 53 | 0 54 | 1 55 | 0 56 | 0 57 | 0 58 | 0 59 | 0 60 | 1 61 | 0 62 | 0 63 | 0 64 | 0 65 | 0 66 | 0 67 | 0 68 | 0 69 | 1 70 | 1 71 | 0 72 | 0 73 | 0 74 | 0 75 | 0 76 | 0 77 | 0 78 | 0 79 | 0 80 | 0 81 | 1 82 | 1 83 | 0 84 | 0 85 | 1 86 | 0 87 | 0 88 | 0 89 | 0 90 | 0 91 | 0 92 | 0 93 | 1 94 | 1 95 | 1 96 | 1 97 | 1 98 | 1 99 | 1 100 | 1 101 | 1 102 | 1 103 | 1 104 | 0 105 | 1 106 | 1 107 | 1 108 | 0 109 | 1 110 | 1 111 | 1 112 | 1 113 | 1 114 | 0 115 | 1 116 | 1 117 | 1 118 | 1 119 | 1 120 | 1 121 | 1 122 | 0 123 | 1 124 | 1 125 | 1 126 | 1 127 | 0 128 | 1 129 | 1 130 | 1 131 | 1 132 | 1 133 | 0 134 | 1 135 | 1 136 | 1 137 | 1 138 | 0 139 | 1 140 | 1 141 | 1 142 | 1 143 | 1 144 | 1 145 | 1 146 | 0 147 | 1 148 | 1 149 | 1 150 | 1 151 | 0 152 | 1 153 | 1 154 | 1 155 | 1 156 | 1 157 | 1 158 | 1 159 | 1 160 | 1 161 | 1 162 | 1 163 | 1 164 | 0 165 | 0 166 | 0 167 | 0 168 | 0 169 | 0 170 | 1 171 | 1 172 | 1 173 | 1 174 | 1 175 | 1 176 | 1 177 | 0 178 | 0 179 | 1 180 | 0 181 | 0 182 | -------------------------------------------------------------------------------- /tests/files/bc/cosine.txt: -------------------------------------------------------------------------------- 1 | scale = 25 2 | p = 4 * a(1) 3 | scale = 20 4 | c(0) 5 | c(0.5) 6 | c(1) 7 | c(2) 8 | c(3) 9 | c(-0.5) 10 | c(-1) 11 | c(-2) 12 | c(-3) 13 | c(p / 7) 14 | c(-p / 7) 15 | c(p / 4) 16 | c(-p / 4) 17 | c(p / 3) 18 | c(-p / 3) 19 | c(p / 2) 20 | c(-p / 2) 21 | c(3 * p / 4) 22 | c(3 * -p / 4) 23 | c(p) 24 | c(-p) 25 | c(3 * p / 2) 26 | c(3 * -p / 2) 27 | c(7 * p / 4) 28 | c(7 * -p / 4) 29 | c(13 * p / 4) 30 | c(13 * -p / 4) 31 | c(2 * p) 32 | c(2 * -p) 33 | c(131231) 34 | c(-131231) 35 | c(859799894.3562378245) 36 | c(859799894.3562378245) 37 | c(4307371) 38 | c(3522556.3323810191) 39 | c(44961070) 40 | c(6918619.1574479809) 41 | c(190836996.2180244164) 42 | c(34934) 43 | c(2483599) 44 | c(13720376) 45 | -------------------------------------------------------------------------------- /tests/files/bc/cosine_results.txt: -------------------------------------------------------------------------------- 1 | 1.00000000000000000000 2 | .87758256189037271611 3 | .54030230586813971740 4 | -.41614683654714238699 5 | -.98999249660044545727 6 | .87758256189037271611 7 | .54030230586813971740 8 | -.41614683654714238699 9 | -.98999249660044545727 10 | .90096886790241912623 11 | .90096886790241912623 12 | .70710678118654752440 13 | .70710678118654752440 14 | .50000000000000000000 15 | .50000000000000000000 16 | 0 17 | 0 18 | -.70710678118654752439 19 | -.70710678118654752439 20 | -1.00000000000000000000 21 | -1.00000000000000000000 22 | 0 23 | 0 24 | .70710678118654752439 25 | .70710678118654752439 26 | -.70710678118654752440 27 | -.70710678118654752440 28 | 1.00000000000000000000 29 | 1.00000000000000000000 30 | .92427123447397657316 31 | .92427123447397657316 32 | -.04198856352825241211 33 | -.04198856352825241211 34 | -.75581969921220636368 35 | -.01644924448939844182 36 | -.97280717522127222547 37 | -.92573947460230585966 38 | -.14343824233852988038 39 | .87259414746802343203 40 | .93542606623067050616 41 | -.52795540572178251550 42 | -------------------------------------------------------------------------------- /tests/files/bc/divide.txt: -------------------------------------------------------------------------------- 1 | 0 / 1 2 | 0 / 321566 3 | 0 / 0.3984567238456 4 | 1 / 1 5 | 1 / 1287469297356 6 | 1 / 0.2395672438567234 7 | 1 / 237586239856.0293596728392360 8 | 1249687284356 / 3027949207835207 9 | 378617298617396719 / 35748521 10 | 9348576237845624358 / 0.9857829375461 11 | 35768293846193284 / 2374568947.045762839567823 12 | -78987234567812345 / 876542837618936 13 | -356789237555535468 / 0.3375273860984786903 14 | -5203475364850390 / 435742903748307.70869378534043296404530458 15 | -0.37861723347576903 / 7385770896 16 | -0.399454682043962 / 0.34824389304 17 | -0.6920414523873204 / 356489645223.76076045304879030 18 | -35872917389671.7573280963748 / 73924708 19 | -78375896314.4836709876983 / 0.78356798637817 20 | -2374123896417.143789621437581 / 347821469423789.1473856783960 21 | -896729350238549726 / -34976289345762 22 | -2374568293458762348596 / -0.8792370647234987679 23 | -237584692306721845726038 / -21783910782374529637.978102738746189024761 24 | -0.23457980123576298375682 / -1375486293874612 25 | -0.173897061862478951264 / -0.8179327486017634987516298745 26 | -0.9186739823576829347586 / -0.235678293458756239846 27 | -0.9375896183746982374568 / -13784962873546.0928729395476283745 28 | -2930754618923467.12323745862937465 / -734869238465 29 | -23745861923467.874675129834675 / -0.23542357869124756 30 | -3878923750692883.7238596702834756902 / -7384192674957215364986723.9738461923487621983 31 | 1 / 0.00000000000000000000000000000000000000000002346728372937352457354204563027 32 | -------------------------------------------------------------------------------- /tests/files/bc/divide_results.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 0 4 | 1.00000000000000000000 5 | .00000000000077671755 6 | 4.17419336592637110778 7 | .00000000000420899796 8 | .00041271738677857404 9 | 10591131829.40901859967857131767 10 | 9483402361494453751.52388015648196297248 11 | 15063068.13735316451497043884 12 | -90.11223545260531110575 13 | -1057067521778623447.45138528213564485251 14 | -11.94161814246320631346 15 | -.00000000005126306228 16 | -1.14705437777218917343 17 | -.00000000000194126663 18 | -485262.88923145638029569727 19 | -100024372711.74763635544535424582 20 | -.00682569681609989277 21 | 25638.20711150436682153521 22 | 2700714504347599627864.24626421085374010264 23 | 10906.42973524078145692731 24 | .00000000000000017054 25 | .21260557443109085166 26 | 3.89799997647407910677 27 | .00000000000006801538 28 | 3988.13076601933678578945 29 | 100864416620775.31076855630746548983 30 | .00000000052530099381 31 | 42612515855353136519261264261472677699404182.78776061098893912189 32 | -------------------------------------------------------------------------------- /tests/files/bc/exponent.txt: -------------------------------------------------------------------------------- 1 | e(0) 2 | e(0.5) 3 | e(1) 4 | e(1.5) 5 | e(1.74) 6 | e(2) 7 | e(3.2345) 8 | e(5.283957) 9 | e(13.23857) 10 | e(100) 11 | e(283.238957) 12 | e(-0.5) 13 | e(-1) 14 | e(-1.5) 15 | e(-1.74) 16 | e(-2) 17 | e(-3.2345) 18 | e(-5.283957) 19 | e(-13.23857) 20 | e(-100) 21 | e(-283.238957) 22 | e(142.749502399) 23 | -------------------------------------------------------------------------------- /tests/files/bc/exponent_results.txt: -------------------------------------------------------------------------------- 1 | 1.00000000000000000000 2 | 1.64872127070012814684 3 | 2.71828182845904523536 4 | 4.48168907033806482260 5 | 5.69734342267199101193 6 | 7.38905609893065022723 7 | 25.39367176822616278859 8 | 197.14845034328553587817 9 | 561613.96621445383501864766 10 | 26881171418161354484126255515800135873611118.77374192241519160861 11 | 10212124131159922810249757193864245307850725332411569566443792548720\ 12 | 75182918653384240389953781407569563117008113027037939783.70141667971\ 13 | 570827872 14 | .60653065971263342360 15 | .36787944117144232159 16 | .22313016014842982893 17 | .17552040061699687169 18 | .13533528323661269189 19 | .03937988996342191888 20 | .00507231985977442865 21 | .00000178058250000525 22 | 0 23 | 0 24 | 98928445824097165243611240348236907682258759298273030827411201.25833\ 25 | 645622510213538 26 | -------------------------------------------------------------------------------- /tests/files/bc/log.txt: -------------------------------------------------------------------------------- 1 | l(0) 2 | l(0.5) 3 | l(1) 4 | l(1.5) 5 | l(1.74) 6 | l(2) 7 | l(3.2345) 8 | l(5.283957) 9 | l(13.23857) 10 | l(100) 11 | l(283.238957) 12 | l(-0.5) 13 | l(-1) 14 | l(-1.5) 15 | l(-1.74) 16 | l(-2) 17 | l(-3.2345) 18 | l(-5.283957) 19 | l(-13.23857) 20 | l(-100) 21 | l(-283.238957) 22 | l(10430710.3325472917) 23 | -------------------------------------------------------------------------------- /tests/files/bc/log_results.txt: -------------------------------------------------------------------------------- 1 | -99999999999999999999.00000000000000000000 2 | -.69314718055994530941 3 | 0 4 | .40546510810816438197 5 | .55388511322643765995 6 | .69314718055994530941 7 | 1.17387435650190306676 8 | 1.66467524885255369652 9 | 2.58313453863349348434 10 | 4.60517018598809136803 11 | 5.64629091238730017971 12 | -99999999999999999999.00000000000000000000 13 | -99999999999999999999.00000000000000000000 14 | -99999999999999999999.00000000000000000000 15 | -99999999999999999999.00000000000000000000 16 | -99999999999999999999.00000000000000000000 17 | -99999999999999999999.00000000000000000000 18 | -99999999999999999999.00000000000000000000 19 | -99999999999999999999.00000000000000000000 20 | -99999999999999999999.00000000000000000000 21 | -99999999999999999999.00000000000000000000 22 | 16.16026492940839137014 23 | -------------------------------------------------------------------------------- /tests/files/bc/misc.txt: -------------------------------------------------------------------------------- 1 | 4.1*1.-13^ - 74 - 1284597623841*1.-13^ - 757 2 | 4.1*1.\ 3 | -1\ 4 | 3^ - 74 - 1284597623841*1.\ 5 | -1\ 6 | 3^ - 757 7 | obase = 9 8 | 4.1*1.-13^ - 74 - 1284597623841*1.-13^ - 757 9 | 4.1*1.\ 10 | -1\ 11 | 3^ - 74 - 1284597623841*1.\ 12 | -1\ 13 | 3^ - 757 14 | -------------------------------------------------------------------------------- /tests/files/bc/misc1.txt: -------------------------------------------------------------------------------- 1 | define x(x) { 2 | return(x) 3 | } 4 | define y() { 5 | return; 6 | } 7 | define z() { 8 | return (); 9 | } 10 | scale = 0 11 | x=2 12 | x[0]=3 13 | x 14 | x[0] 15 | scale 16 | ibase 17 | obase 18 | x ( 7 ) 19 | x + x( 8 ) 20 | x - x[0] 21 | 321 * x 22 | 2 ^ x[0] 23 | x++ 24 | --x 25 | x += 9 26 | x 27 | length(2381) 28 | sqrt(9) 29 | scale(238.1) 30 | x=2 31 | x[0]=3 32 | (x) 33 | (x[0]) 34 | (scale) 35 | (ibase) 36 | (obase) 37 | (x ( 7 )) 38 | (x + x( 8 )) 39 | (x - x[0]) 40 | (321 * x) 41 | (2 ^ x[0]) 42 | (x++) 43 | (--x) 44 | (x += 9) 45 | (length(2381)) 46 | (sqrt(9)) 47 | (scale(238.1)) 48 | (scale = 0) 49 | (x = 10) 50 | (x += 100) 51 | (x -= 10) 52 | (x *= 10) 53 | (x /= 100) 54 | (x ^= 10) 55 | (x = sqrt(x)) 56 | (x[1 - 1]) 57 | x[(1 - 1)] 58 | 2 + \ 59 | 3 60 | ++ibase 61 | --ibase 62 | ++obase 63 | --obase 64 | ++last 65 | --last 66 | last 67 | last = 100 68 | last 69 | . = 150 70 | . 71 | ++scale 72 | --scale 73 | y() 74 | z() 75 | 2 + /* 76 | */3 77 | -------------------------------------------------------------------------------- /tests/files/bc/misc1_results.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 0 4 | 10 5 | 10 6 | 7 7 | 10 8 | -1 9 | 642 10 | 8 11 | 2 12 | 2 13 | 11 14 | 4 15 | 3 16 | 1 17 | 2 18 | 3 19 | 0 20 | 10 21 | 10 22 | 7 23 | 10 24 | -1 25 | 642 26 | 8 27 | 2 28 | 2 29 | 11 30 | 4 31 | 3 32 | 1 33 | 0 34 | 10 35 | 110 36 | 100 37 | 1000 38 | 10 39 | 10000000000 40 | 100000 41 | 3 42 | 3 43 | 5 44 | 11 45 | 10 46 | 10 47 | 10 48 | 11 49 | 10 50 | 10 51 | 100 52 | 150 53 | 1 54 | 0 55 | 0 56 | 0 57 | 5 58 | -------------------------------------------------------------------------------- /tests/files/bc/misc2.txt: -------------------------------------------------------------------------------- 1 | define x() { 2 | "x" 3 | return ( 1 ) 4 | } 5 | define y() { 6 | "y" 7 | return (2) 8 | } 9 | define z() { 10 | "z" 11 | return (3) 12 | } 13 | 14 | if ( x() == y() ) {1} 15 | 1 16 | if ( x() <= y() ) {2} 17 | if ( y() >= x() ) {3} 18 | if ( x() != y() ) {4} 19 | if ( x() < y() ) {5} 20 | if ( y() > x() ) {6} 21 | 22 | if ( x() == z() ) {11} 23 | 11 24 | if ( x() <= z() ) {12} 25 | if ( z() >= x() ) {13} 26 | if ( x() != z() ) {14} 27 | if ( x() < z() ) {15} 28 | if ( z() > x() ) {16} 29 | 30 | x = -10 31 | while (x <= 0) { 32 | x 33 | if (x == -5) break; 34 | x += 1 35 | } 36 | 37 | define u() { 38 | auto a[]; 39 | return a[0] 40 | } 41 | 42 | u() 43 | 44 | if (x == -4) x 45 | else x - 4 46 | -------------------------------------------------------------------------------- /tests/files/bc/misc2_results.txt: -------------------------------------------------------------------------------- 1 | xy1 2 | xy2 3 | yx3 4 | xy4 5 | xy5 6 | yx6 7 | xz11 8 | xz12 9 | zx13 10 | xz14 11 | xz15 12 | zx16 13 | -10 14 | -9 15 | -8 16 | -7 17 | -6 18 | -5 19 | 0 20 | -9 21 | -------------------------------------------------------------------------------- /tests/files/bc/misc_results.txt: -------------------------------------------------------------------------------- 1 | -1284597623836.9 2 | -1284597623836.9 3 | -4483684050181.80 4 | -4483684050181.80 5 | -------------------------------------------------------------------------------- /tests/files/bc/modulus.txt: -------------------------------------------------------------------------------- 1 | 1 % 1 2 | 2 % 1 3 | 16 % 4 4 | 15 % 4 5 | 17 % 4 6 | 2389473 % 5 7 | 39240687239 % 1 8 | 346728934 % 23958 9 | 3496723859067234 % 298375462837546928347623059375486 10 | -1 % 1 11 | -2 % 1 12 | -47589634875689345 % 37869235 13 | -1274852934765 % 2387628935486273546 14 | -6324758963 % 237854962 15 | 1 % -1 16 | 2 % -1 17 | 2 % -2 18 | 2 % -3 19 | 16 % 5 20 | 15 % 5 21 | 14 % 5 22 | 89237423 % -237856923854 23 | 123647238946 % -12467 24 | -1 % -1 25 | -2 % -1 26 | -2 % -2 27 | -2 % -3 28 | -13 % -7 29 | -14 % -7 30 | -15 % -7 31 | -12784956 % -32746 32 | -127849612 % -23712347682193 33 | scale = 0 34 | 1 % 1 35 | 2 % 1 36 | 16 % 4 37 | 15 % 4 38 | 17 % 4 39 | 2389473 % 5 40 | 39240687239 % 1 41 | 346728934 % 23958 42 | 3496723859067234 % 298375462837546928347623059375486 43 | -1 % 1 44 | -2 % 1 45 | -47589634875689345 % 37869235 46 | -1274852934765 % 2387628935486273546 47 | -6324758963 % 237854962 48 | 1 % -1 49 | 2 % -1 50 | 2 % -2 51 | 2 % -3 52 | 16 % 5 53 | 15 % 5 54 | 14 % 5 55 | 89237423 % -237856923854 56 | 123647238946 % -12467 57 | -1 % -1 58 | -2 % -1 59 | -2 % -2 60 | -2 % -3 61 | -13 % -7 62 | -14 % -7 63 | -15 % -7 64 | -12784956 % -32746 65 | -127849612 % -23712347682193 66 | -3191280681 % 641165986 67 | scale = 0; -899510228 % -2448300078.40314 68 | scale = 0; -7424863 % -207.2609738667 69 | scale = 0; 3769798918 % 0.6 70 | -------------------------------------------------------------------------------- /tests/files/bc/modulus_results.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | .00000000000000002026 9 | 2747189239559.46904933397471305894 10 | 0 11 | 0 12 | -.00000000000011057855 13 | -.00076922992566770712 14 | -.00000000000050364144 15 | 0 16 | 0 17 | 0 18 | .00000000000000000002 19 | 0 20 | 0 21 | 0 22 | .00000000070585524350 23 | .00000000000000002898 24 | 0 25 | 0 26 | 0 27 | -.00000000000000000002 28 | -.00000000000000000005 29 | 0 30 | -.00000000000000000002 31 | -.00000000000000011722 32 | -.00000002640923745817 33 | 0 34 | 0 35 | 0 36 | 3 37 | 1 38 | 3 39 | 0 40 | 8758 41 | 3496723859067234 42 | 0 43 | 0 44 | -8236960 45 | -1274852934765 46 | -140529951 47 | 0 48 | 0 49 | 0 50 | 2 51 | 1 52 | 0 53 | 4 54 | 89237423 55 | 6692 56 | 0 57 | 0 58 | 0 59 | -2 60 | -6 61 | 0 62 | -1 63 | -14016 64 | -127849612 65 | -626616737 66 | -899510228.00000 67 | -153.1331732059 68 | .4 69 | -------------------------------------------------------------------------------- /tests/files/bc/multiply.txt: -------------------------------------------------------------------------------- 1 | 0 * 0 2 | 0.000 * 0 3 | 1 * 0 4 | 0 * 1 5 | 0 * 2498752389672835476 6 | 873246913745129084576134 * 0 7 | 1 * 472638590273489273456 8 | 12374861230476103672835496 * 1 9 | 1 * 1 10 | 2 * 1 11 | 1 * 2 12 | 2 * 2 13 | 3 * 14 14 | 17 * 8 15 | 1892467513846753 * 1872439821374591038746 16 | 328962735862.2973546835638947635 * 1728465791348762356 17 | 38745962374538.387427384672934867234 * 0.1932476528394672837568923754 18 | 9878894576289457634856.2738627161689017387608947567654 * 37842939768237596237854203.29874372139852739126739621793162 19 | -1 * 1 20 | -1 * 2 21 | 78893457 * -34876238956 22 | 235678324957634 * -0.2349578349672389576 23 | -12849567821934 * 12738462937681 24 | 1274861293467.927843682937462 * -28935678239 25 | 2936077239872.12937462836 * -0.012842357682435762 26 | 2387692387566.2378569237546 * -272189345628.123875629835876 27 | 0.012348629356782835962 * -23487692356 28 | 0.4768349567348675934 * -0.23756834576934857638495 29 | 0.98748395367485962735486 * -4675839462354867.376834956738456 30 | -321784627934586 * -235762378596 31 | -32578623567892356 * -0.32567384579638456 32 | -35768232346876 * -2348672935602387620.28375682349576237856 33 | -0.2356728394765234 * -238759624356978 34 | -0.2345768212346780 * -0.235768124697074385948943532045 35 | -0.370873860736785306278630 * -7835678398607.7086378076867096270 36 | -78365713707.7089637863786730 * -738580798679306780 37 | -73867038956790490258249 * -0.7379862716391723672803679 38 | -378621971598721837710387 * -98465373878350798.09743896037963078560 39 | 37164201 * 2931559660 40 | 679468076118972457796560530571.46287161642138401685 * 93762.2836 41 | .000000000000000000000000001 * .0000000000000000000000001 42 | -------------------------------------------------------------------------------- /tests/files/bc/multiply_results.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 0 4 | 0 5 | 0 6 | 0 7 | 472638590273489273456 8 | 12374861230476103672835496 9 | 1 10 | 2 11 | 2 12 | 4 13 | 42 14 | 136 15 | 3543531533584430580556128344529291738 16 | 568600835566479683035874339053.4411638427543228060 17 | 7487566285885.8557453089005171423976251098 18 | 373846412427291014394738378015501363938345620046.7869650248829232267\ 19 | 2297002026819 20 | -1 21 | -2 22 | -2751507058396910892 23 | -55374468980751.0837656919743223184 24 | -163683743464924630346895054 25 | -36888976187143312550878.567134791289418 26 | -37706154097.69662826215753378160 27 | -649904428532907022680241.94791869424754101064 28 | -290040807.350385412976669306472 29 | -.11328089187650139309272 30 | -4617316439035114.40320367843985107357898 31 | 75864709277486862054521256 32 | 10610005628108234.92015040406042336 33 | 84007879267445533366251128067927.91168012197674537856 34 | 56269158624557.1027018519702852 35 | .055305737239900889424090264801 36 | 2906048299183.472237078104362540110129 37 | 57879411419313585866282299201.3825582163029400 38 | 54512860676747314187949.9414724679950990587298071 39 | 37281153992026463004361915151761464058058.54968338992209002720 40 | 108949072447731660 41 | 63708478450213482928510139572007971.83536929222529239687 42 | 0 43 | -------------------------------------------------------------------------------- /tests/files/bc/pi.txt: -------------------------------------------------------------------------------- 1 | for (i = 0; i <= 100; ++i) { 2 | scale = i 3 | 4 * a(1) 4 | } 5 | -------------------------------------------------------------------------------- /tests/files/bc/power.txt: -------------------------------------------------------------------------------- 1 | 0 ^ 0 2 | 0 ^ 1 3 | 0 ^ 1894 4 | 1 ^ 0 5 | 39746823 ^ 0 6 | 0.238672983047682 ^ 0 7 | 18394762374689237468.97354862973846 ^ 0 8 | 1 ^ 1 9 | 2 ^ 1 10 | 18927361346 ^ 1 11 | 0.23523785962738592635777 ^ 1 12 | 328956734869213746.89782398457234 ^ 1 13 | 8937 ^ 98 14 | 0.124876812394 ^ 96 15 | 93762.2836 ^ 13 16 | 1 ^ -1 17 | 2 ^ -1 18 | 10 ^ -1 19 | 683734768 ^ -1 20 | 38579623756.897937568235 ^ -1 21 | 1 ^ -32467 22 | 2 ^ -53 23 | 23897 ^ -3 24 | -1 ^ 1 25 | -1 ^ 2 26 | -2 ^ 1 27 | -2 ^ 2 28 | -237 ^ 29 29 | -3746 ^ 8 30 | -0.3548 ^ 35 31 | -4267.234 ^ 7 32 | -326.3246 ^ 8 33 | -1 ^ -1 34 | -1 ^ -2 35 | -2 ^ -1 36 | -2 ^ -2 37 | -237 ^ -93 38 | -784 ^ -23 39 | -86 ^ -7 40 | -0.23424398 ^ -81 41 | -178.234786 ^ -79 42 | -1274.346 ^ -8 43 | -0.2959371298 ^ 27 44 | 45 | -------------------------------------------------------------------------------- /tests/files/bc/power_results.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | 0 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 2 10 | 18927361346 11 | .23523785962738592635777 12 | 328956734869213746.89782398457234 13 | 16473742664221279051571200630760751138799221376964991600670000200609\ 14 | 08006052596520320731708604393844468006290371918262741885989163144389\ 15 | 39367835091560809036359941703341471396407660150658436796925310445979\ 16 | 21333166245765946557344383284626113908419359990042883048537750217279\ 17 | 17481980123593363177308481941550382845381799410533956718500484099889\ 18 | 610805653325917409549921909941664118421333562129 19 | 0 20 | 43287877285033571298394739716218787350087163435619825150259705419.98\ 21 | 016445740928054425 22 | 1.00000000000000000000 23 | .50000000000000000000 24 | .10000000000000000000 25 | .00000000146255543348 26 | .00000000002592041867 27 | 1.00000000000000000000 28 | .00000000000000011102 29 | .00000000000007327736 30 | -1 31 | 1 32 | -2 33 | 4 34 | -7373981340203217564025207502362461927230480148287479751287576522804\ 35 | 77 36 | 38774140915674516674808545536 37 | -.00000000000000017759 38 | -25764707167314625311472240.23895709280819039654 39 | 128587429491381039942.88651883210401536158 40 | -1.00000000000000000000 41 | 1.00000000000000000000 42 | -.50000000000000000000 43 | .25000000000000000000 44 | 0 45 | 0 46 | -.00000000000002874159 47 | -1139873046177080922024790150196533457011720664136966.15649615964858\ 48 | 379359 49 | 0 50 | 0 51 | -.00000000000000527697 52 | -------------------------------------------------------------------------------- /tests/files/bc/script.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | if [ "$#" -lt 4 ]; then 4 | echo "usage: script.sh