#!/bin/bash

# HELP
# [1] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/power/basic-pm-debugging.txt
# [2] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/power/freezing-of-tasks.txt

# PREREQ: Kernel DEBUG options
# CONFIG_PM_DEBUG=y
# CONFIG_EXT4_DEBUG=y
# CONFIG_JBD2_DEBUG=y

export LANG=C
export LC_ALL=C

# Default value of hung_task_timeout_secs is 120 [secs]
SECS="0"

# Possible types: none core processors platform devices freezer
PM_TEST_TYPE="freezer"

# Counter and loops
COUNTER="0"
LOOPS="10"

echo "$SECS" > /proc/sys/kernel/hung_task_timeout_secs

echo "$PM_TEST_TYPE" > /sys/power/pm_test

while [ $COUNTER -lt $LOOPS ]; do
    echo [ pm_test/freezer: Run $COUNTER ]
    echo mem > /sys/power/state && sleep 1
    echo [ pm_test/freezer: OK $COUNTER ]
    let COUNTER=COUNTER+1
done
