1The goal of the libc crate is to have CI running everywhere to have the 2strongest guarantees about the definitions that this library contains, and as a 3result the CI is pretty complicated and also pretty large! Hopefully this can 4serve as a guide through the sea of scripts in this directory and elsewhere in 5this project. 6 7# Files 8 9First up, let's talk about the files in this directory: 10 11* `run-travis.sh` - a shell script run by all Travis builders, this is 12 responsible for setting up the rest of the environment such as installing new 13 packages, downloading Rust target libraries, etc. 14 15* `run.sh` - the actual script which runs tests for a particular architecture. 16 Called from the `run-travis.sh` script this will run all tests for the target 17 specified. 18 19* `cargo-config` - Cargo configuration of linkers to use copied into place by 20 the `run-travis.sh` script before builds are run. 21 22* `dox.sh` - script called from `run-travis.sh` on only the linux 64-bit nightly 23 Travis bots to build documentation for this crate. 24 25* `landing-page-*.html` - used by `dox.sh` to generate a landing page for all 26 architectures' documentation. 27 28* `run-qemu.sh` - see discussion about QEMU below 29 30* `mips`, `rumprun` - instructions to build the docker image for each respective 31 CI target 32 33# CI Systems 34 35Currently this repository leverages a combination of Travis CI and AppVeyor for 36running tests. The triples tested are: 37 38* AppVeyor 39 * `{i686,x86_64}-pc-windows-{msvc,gnu}` 40* Travis 41 * `{i686,x86_64,mips,aarch64}-unknown-linux-gnu` 42 * `{x86_64,aarch64}-unknown-linux-musl` 43 * `arm-unknown-linux-gnueabihf` 44 * `arm-linux-androideabi` 45 * `{i686,x86_64}-apple-{darwin,ios}` 46 * `x86_64-rumprun-netbsd` 47 * `x86_64-unknown-freebsd` 48 * `x86_64-unknown-openbsd` 49 50The Windows triples are all pretty standard, they just set up their environment 51then run tests, no need for downloading any extra target libs (we just download 52the right installer). The Intel Linux/OSX builds are similar in that we just 53download the right target libs and run tests. Note that the Intel Linux/OSX 54builds are run on stable/beta/nightly, but are the only ones that do so. 55 56The remaining architectures look like: 57 58* Android runs in a [docker image][android-docker] with an emulator, the NDK, 59 and the SDK already set up. The entire build happens within the docker image. 60* The MIPS, ARM, and AArch64 builds all use the QEMU userspace emulator to run 61 the generated binary to actually verify the tests pass. 62* The MUSL build just has to download a MUSL compiler and target libraries and 63 then otherwise runs tests normally. 64* iOS builds need an extra linker flag currently, but beyond that they're built 65 as standard as everything else. 66* The rumprun target builds an entire kernel from the test suite and then runs 67 it inside QEMU using the serial console to test whether it succeeded or 68 failed. 69* The BSD builds, currently OpenBSD and FreeBSD, use QEMU to boot up a system 70 and compile/run tests. More information on that below. 71 72[android-docker]: https://github.com/rust-lang/rust-buildbot/blob/master/slaves/android/Dockerfile 73 74## QEMU 75 76Lots of the architectures tested here use QEMU in the tests, so it's worth going 77over all the crazy capabilities QEMU has and the various flavors in which we use 78it! 79 80First up, QEMU has userspace emulation where it doesn't boot a full kernel, it 81just runs a binary from another architecture (using the `qemu-<arch>` wrappers). 82We provide it the runtime path for the dynamically loaded system libraries, 83however. This strategy is used for all Linux architectures that aren't intel. 84Note that one downside of this QEMU system is that threads are barely 85implemented, so we're careful to not spawn many threads. 86 87For the rumprun target the only output is a kernel image, so we just use that 88plus the `rumpbake` command to create a full kernel image which is then run from 89within QEMU. 90 91Finally, the fun part, the BSDs. Quite a few hoops are jumped through to get CI 92working for these platforms, but the gist of it looks like: 93 94* Cross compiling from Linux to any of the BSDs seems to be quite non-standard. 95 We may be able to get it working but it might be difficult at that point to 96 ensure that the libc definitions align with what you'd get on the BSD itself. 97 As a result, we try to do compiles within the BSD distro. 98* On Travis we can't run a VM-in-a-VM, so we resort to userspace emulation 99 (QEMU). 100* Unfortunately on Travis we also can't use KVM, so the emulation is super slow. 101 102With all that in mind, the way BSD is tested looks like: 103 1041. Download a pre-prepared image for the OS being tested. 1052. Generate the tests for the OS being tested. This involves running the `ctest` 106 library over libc to generate a Rust file and a C file which will then be 107 compiled into the final test. 1083. Generate a disk image which will later be mounted by the OS being tested. 109 This image is mostly just the libc directory, but some modifications are made 110 to compile the generated files from step 2. 1114. The kernel is booted in QEMU, and it is configured to detect the libc-test 112 image being available, run the test script, and then shut down afterwards. 1135. Look for whether the tests passed in the serial console output of the kernel. 114 115There's some pretty specific instructions for setting up each image (detailed 116below), but the main gist of this is that we must avoid a vanilla `cargo run` 117inside of the `libc-test` directory (which is what it's intended for) because 118that would compile `syntex_syntax`, a large library, with userspace emulation. 119This invariably times out on Travis, so we can't do that. 120 121Once all those hoops are jumped through, however, we can be happy that we're 122testing almost everything! 123 124Below are some details of how to set up the initial OS images which are 125downloaded. Each image must be enabled have input/output over the serial 126console, log in automatically at the serial console, detect if a second drive in 127QEMU is available, and if so mount it, run a script (it'll specifically be 128`run-qemu.sh` in this folder which is copied into the generated image talked 129about above), and then shut down. 130 131### QEMU Setup - FreeBSD 132 1331. [Download the latest stable amd64-bootonly release ISO](https://www.freebsd.org/where.html). 134 E.g. FreeBSD-11.1-RELEASE-amd64-bootonly.iso 1352. Create the disk image: `qemu-img create -f qcow2 FreeBSD-11.1-RELEASE-amd64.qcow2 2G` 1363. Boot the machine: `qemu-system-x86_64 -cdrom FreeBSD-11.1-RELEASE-amd64-bootonly.iso -drive if=virtio,file=FreeBSD-11.1-RELEASE-amd64.qcow2 -net nic,model=virtio -net user` 1374. Run the installer, and install FreeBSD: 138 1. Install 139 1. Continue with default keymap 140 1. Set Hostname: freebsd-ci 141 1. Distribution Select: 142 1. Uncheck lib32 143 1. Uncheck ports 144 1. Network Configuration: vtnet0 145 1. Configure IPv4? Yes 146 1. DHCP? Yes 147 1. Configure IPv6? No 148 1. Resolver Configuration: Ok 149 1. Mirror Selection: Main Site 150 1. Partitioning: Auto (UFS) 151 1. Partition: Entire Disk 152 1. Partition Scheme: MBR 153 1. App Partition: Ok 154 1. Partition Editor: Finish 155 1. Confirmation: Commit 156 1. Wait for sets to install 157 1. Set the root password to nothing (press enter twice) 158 1. Set time zone to UTC 159 1. Set Date: Skip 160 1. Set Time: Skip 161 1. System Configuration: 162 1. Disable sshd 163 1. Disable dumpdev 164 1. System Hardening 165 1. Disable Sendmail service 166 1. Add User Accounts: No 167 1. Final Configuration: Exit 168 1. Manual Configuration: Yes 169 1. `echo 'console="comconsole"' >> /boot/loader.conf` 170 1. `echo 'autoboot_delay="0"' >> /boot/loader.conf` 171 1. `echo 'ext2fs_load="YES"' >> /boot/loader.conf` 172 1. Look at `/etc/ttys`, see what getty argument is for `ttyu0` (E.g. `3wire`) 173 1. Edit `/etc/gettytab` (with `vi` for example), look for `ttyu0` argument, 174 prepend `:al=root` to the line beneath to have the machine auto-login as 175 root. E.g. 176 177 3wire:\ 178 :np:nc:sp#0: 179 becomes: 180 181 3wire:\ 182 :al=root:np:nc:sp#0: 183 184 1. Edit `/root/.login` and put this in it: 185 186 [ -e /dev/vtbd1 ] || exit 0 187 mount -t ext2fs /dev/vtbd1 /mnt 188 sh /mnt/run.sh /mnt 189 poweroff 190 191 1. Exit the post install shell: `exit` 192 1. Back in in the installer choose Reboot 193 1. If all went well the machine should reboot and show a login prompt. 194 If you switch to the serial console by choosing View > serial0 in 195 the qemu menu, you should be logged in as root. 196 1. Shutdown the machine: `shutdown -p now` 197 198Helpful links 199 200* https://en.wikibooks.org/wiki/QEMU/Images 201* https://blog.nekoconeko.nl/blog/2015/06/04/creating-an-openstack-freebsd-image.html 202* https://www.freebsd.org/doc/handbook/serialconsole-setup.html 203 204 205### QEMU setup - OpenBSD 206 2071. Download CD installer 2082. `qemu-img create -f qcow2 foo.qcow2 2G` 2093. `qemu -cdrom foo.iso -drive if=virtio,file=foo.qcow2 -net nic,model=virtio -net user` 2104. run installer 2115. `echo 'set tty com0' >> /etc/boot.conf` 2126. `echo 'boot' >> /etc/boot.conf` 2137. Modify /etc/ttys, change the `tty00` at the end from 'unknown off' to 214 'vt220 on secure' 2158. Modify same line in /etc/ttys to have `"/root/foo.sh"` as the shell 2169. Add this script to `/root/foo.sh` 217 218``` 219#!/bin/sh 220exec 1>/dev/tty00 221exec 2>&1 222 223if mount -t ext2fs /dev/sd1c /mnt; then 224 sh /mnt/run.sh /mnt 225 shutdown -ph now 226fi 227 228# limited shell... 229exec /bin/sh < /dev/tty00 230``` 231 23210. `chmod +x /root/foo.sh` 233 234Helpful links: 235 236* https://en.wikibooks.org/wiki/QEMU/Images 237* http://www.openbsd.org/faq/faq7.html#SerCon 238 239# Questions? 240 241Hopefully that's at least somewhat of an introduction to everything going on 242here, and feel free to ping @alexcrichton with questions! 243 244