#!/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

echo 1 > /sys/fs/cgroup/cpuset/cgroup.clone_children
chmod ugo+x tests/test_confinement.sh
dpkg-source --before-build .
debian/rules build
make tests
./tests/main.sh
