PDLPorters / devops

2 stars 0 forks source link

Test on different architectures #34

Open zmughal opened 2 years ago

zmughal commented 2 years ago

See https://github.com/PDLPorters/pdl/issues/369.

mohawk2 commented 2 years ago

My script (put together from the history of the files, rather than a fully-tested script per se):

#!/bin/sh

# works with QEMU emulator version 6.2.0
# usage: $0 arch (install|run)

disk=disk.qcow2
disksize=20G

if [ "$1" = arm64 ]; then
  debian_iso=debian-11.2.0-arm64-netinst.iso
  firmware=QEMU_EFI.fd
  INSTMEDIA="-drive file=$debian_iso,id=cdrom,if=none,media=cdrom \
      -device virtio-scsi-device \
      -device scsi-cd,drive=cdrom"
  BASECMD="qemu-system-aarch64 -smp cpus=6 -M virt -cpu max -m 2G -nographic \
      -bios $firmware \
      -drive file=$disk,if=virtio"
  if [ "$2" = "install" ]; then
    curl -O "https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/$debian_iso"
    curl -OL "http://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/$firmware"
    qemu-img create -f qcow2 $disk $disksize
    $BASECMD \
        $INSTMEDIA
  elif [ "$2" = "run" ]; then
    # from https://unix.stackexchange.com/questions/52996/how-to-boot-efi-kernel-using-qemu-kvm
    cat <<'EOF'
at UEFI prompt:
  fs0:
   cd EFI\debian
   grubaa64.efi
EOF
    $BASECMD \
        $INSTMEDIA
  else
    echo >&2 "Unknown instruction '$2'"; exit 1;
  fi

elif [ "$1" = armhf ]; then
  # modified from https://willhaley.com/blog/debian-arm-qemu/
  bootprefix=http://ftp.us.debian.org/debian/dists/stable/main/installer-armhf/current/images/cdrom
  prefix=https://cdimage.debian.org/debian-cd/current/armhf/iso-dvd
  debian_iso=debian-11.2.0-armhf-DVD-1.iso
  INSTMEDIA="-drive file=$debian_iso,id=cdrom,if=none,media=cdrom \
      -device virtio-scsi-device \
      -device scsi-cd,drive=cdrom"
  BASECMD="qemu-system-arm -m 4G -machine type=virt -cpu cortex-a7 -smp 4 \
    -drive file=$disk,id=hd,if=none,media=disk \
      -device virtio-scsi-device \
      -device scsi-hd,drive=hd \
    -netdev user,id=net0,hostfwd=tcp::5555-:22 \
      -device virtio-net-device,netdev=net0 \
    -nographic"
  if [ "$2" = "install" ]; then
    init=initrd.gz
    kernel=vmlinuz
    curl -OL "$bootprefix/$init"
    curl -OL "$bootprefix/$kernel"
    curl -OL "$prefix/$debian_iso"
    qemu-img create -f qcow2 $disk $disksize
    $BASECMD \
      -append "console=ttyAMA0" \
      $INSTMEDIA \
      -initrd "$init" \
      -kernel "$kernel"
  elif [ "$2" = "run" ]; then
    init=initrd.img-from-guest
    kernel=vmlinuz-from-guest
    $BASECMD \
      -append "console=ttyAMA0 root=/dev/sda2" \
      $INSTMEDIA \
      -initrd "$init" \
      -kernel "$kernel"
  else
    echo >&2 "Unknown instruction '$2'"; exit 1;
  fi

elif [ "$1" = s390x ]; then
  # modified from https://wiki.qemu.org/Documentation/Platforms/S390X
  bootprefix=https://ftp.debian.org/debian/dists/stable/main/installer-s390x/current/images/generic/
  init=initrd.debian
  kernel=kernel.debian
  prefix=https://cdimage.debian.org/debian-cd/current/s390x/iso-cd
  debian_iso=debian-11.2.0-s390x-netinst.iso
  INSTMEDIA="-cdrom $debian_iso"
  BASECMD="qemu-system-s390x -m 4G -machine s390-ccw-virtio -cpu max,zpci=on -serial mon:stdio -smp 8 \
    -drive file=$disk,if=none,id=drive-virtio-disk0 \
       -device virtio-blk-ccw,devno=fe.0.0001,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \
    -nic user,model=virtio,hostfwd=tcp::2222-:22 \
    -nographic"
  if [ "$2" = "install" ]; then
    curl -OL "$bootprefix/$init"
    curl -OL "$bootprefix/$kernel"
    curl -OL "$prefix/$debian_iso"
    qemu-img create -f qcow2 $disk $disksize
    $BASECMD \
      -initrd "$init" \
      -kernel "$kernel" \
      $INSTMEDIA
  elif [ "$2" = "run" ]; then
    $BASECMD
  else
    echo >&2 "Unknown instruction '$2'"; exit 1;
  fi

else
  echo >&2 "Unknown arch '$1'"; exit 1;
fi

The commands to clone PDL, and get a sufficient (and parallel) build:

sudo apt-get install git build-essential gfortran libtest-warn-perl libtest-exception-perl libdevel-checklib-perl libpod-parser-perl libfile-which-perl libfile-map-perl libtest-deep-perl libextutils-f77-perl libinline-c-perl libterm-readkey-perl libextutils-depends-perl libastro-fits-header-perl
git clone https://github.com/PDLPorters/pdl.git
export MAKEFLAGS=--jobs=8 HARNESS_OPTIONS=j8

The Vagrantfile I used to debug on i386, which ran much quicker and was painless to set up:

Vagrant.configure("2") do |config|
  config.vm.box = "bento/debian-11.2-i386"
  config.vm.provider "virtualbox" do |v|
    v.memory = 4096
    v.cpus = 8
  end
end