#!/bin/sh
## cgroup2 not supported in tests
if [ ! -d /sys/fs/cgroup/cpuset ]; then
    echo "CGroup2 isn't currently supported for LXCFS tests"
    exit 0
fi

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 obj-*/
echo 1 > /sys/fs/cgroup/cpuset/cgroup.clone_children
./tests/main.sh
