#!/system/bin/sh
# Drives the skin zone through its first throttling levels with kernel thermal emulation, to
# exercise netlink -> severity -> trip point -> framework callback. Stops at 50.5 C (SEVERE);
# never goes near CRITICAL (60 C) or the 90 C shutdown level. thermal-engine also sees the
# emulated value, so the CPUs may throttle for the ~30 s this runs. Emulation is always cleared.
Z=
for z in /sys/class/thermal/thermal_zone*; do
    [ "$(cat $z/type)" = sys-therm-2 ] && Z=$z
done
[ -n "$Z" ] || { echo "No sys-therm-2 zone"; exit 1; }
[ -w "$Z/emul_temp" ] || { echo "No emul_temp on $Z (CONFIG_THERMAL_EMULATION off?)"; exit 1; }
trap 'echo 0 > $Z/emul_temp; echo "emulation cleared, skin $(cat $Z/temp)"' EXIT

for t in 47000 48500 49500 50500 47000 45000; do
    echo $t > $Z/emul_temp
    sleep 5
    status=$(dumpsys thermalservice | grep -m1 "mName=skin" | grep -o "mStatus=[0-9]*")
    echo "emul $t: $status trip1 $(cat $Z/trip_point_1_temp) hyst1 $(cat $Z/trip_point_1_hyst)"
done
