#!/bin/sh

modulename=taskmonitor
if modprobe $modulename target="-1" 2> /dev/null; then
	echo "Should throw an error with an invalid pid"
	exit 1
fi

if ! modprobe $modulename target="$$"; then
	echo "Could not load module $modulename.ko!"
	exit 1
fi

cd /linux-6.5.7/tools/mm || return
if ! gcc -o slabinfo slabinfo.c; then
	echo "can't compile slabinfo!"
	echo "please contact lkp@os.rwth-aachen.de"
	exit 1
fi

sleep 3
if ! out=$(./slabinfo task_sample) || [ -z "$out" ]; then
	echo "failed to find the slabs task_sample"
	exit 1
fi

if ! rmmod $modulename; then
	echo "Fail while unloading module"
	exit 1
fi

echo scan > /sys/kernel/debug/kmemleak
sleep 60
cat /sys/kernel/debug/kmemleak
