#!/bin/sh

if [ ! -d /sys/fs/cgroup/memory ]; then
  if [ ! "$AUTOPKGTEST_REBOOT_MARK" = "lxc-prepare" ]; then
    sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/ s/GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 cgroup_enable=memory swapaccount=1"/' /etc/default/grub
    update-grub2
    /tmp/autopkgtest-reboot lxc-prepare
  fi
fi

set -eu

# Build lxcfs itself (needed by the tests)
dpkg-source --before-build .
debian/rules build

# Taken from .travis.yml
(cd tests && make tests)
echo 1 > /sys/fs/cgroup/cpuset/cgroup.clone_children
./tests/main.sh
