#!/bin/bash

### NOTE: Run as root

### 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 "hung_task_timeout_secs [secs] is now ..."
cat /proc/sys/kernel/hung_task_timeout_secs

echo "$PM_TEST_TYPE" > /sys/power/pm_test
echo "pm-test type [string] is now ..."
cat /sys/power/pm_test

echo "pm_test/$PM_TEST_TYPE: Running ..."
while [ $COUNTER -lt $LOOPS ]; do
    echo [ Running ... $COUNTER ]
    echo mem > /sys/power/state && sleep 1
    echo [ Done ...... $COUNTER ]
    let COUNTER=COUNTER+1
done
echo "pm_test/$PM_TEST_TYPE: END."
