#!/bin/sh

if ! whence date
then
	mt_message "sleep test really wants date, but continuing anyway"
fi

if ! whence sed
then
	mt_ignored "this sleep test needs sed, ignoring this test"
	exit
fi

if [ ! -f /proc/acpi/alarm -o ! -f /proc/acpi/sleep ] 
then
	mt_ignored "kernel not configured for sleep/wakeup"
	exit
fi

if [ "`sed -ne 's/^model.*Transmeta.*TM5.*/XXX/p' /proc/cpuinfo`" != "XXX" ]
then
	mt_ignored "only runs on Transmeta(tm) Crusoe(tm) Processor TM5x00"
	exit
fi

if echo "+0-0-0 0:1:0" > /proc/acpi/alarm
then
	mt_success "RTC Wakeup alarm set to 1 minute"
else
	mt_failed "RTC driver not configured"
fi

START=`date +%s`

if echo 1 > /proc/acpi/sleep
then
	END=`date +%s`
	mt_success "Slept for $(($END - $START)) seconds"
else
	mt_failed "Could not enter sleep state"
fi
