1#!/usr/bin/env expect
2#
3# Variables used by this script:
4# - TEST_TIMEOUT: timeout between each *_MSG match
5# - TEST_TIMEOUT_OVERRIDE: when set, overrides TEST_TIMEOUT
6# - TEST_LOG: save console log to this file
7# - TEST_CMD: commands that prints test system console output to stdout - in
8#   qemu tests that's usually qemu itself (with -serial stdio), in hardware
9#   tests that's a command to read serial console
10# - UBOOT_CMD (optional): command to enter at u-boot prompt
11# - BOOT_MSG (optional): initial Xen message to wait for (aka sign-of-life)
12# - SUSPEND_MSG (optional): message signaling system is going to sleep, it's
13#   trigger for WAKEUP_CMD (see below)
14# - WAKEUP_CMD (optional): command to execute to wakeup the system 30s after
15#   seeing SUSPEND_MSG
16# - LOG_MSG (optional): final console message to wait for
17# - PASSED: message to look for to consider test a success; if LOG_MSG is set,
18#   both LOG_MSG and PASSED must appear (in any order) for test to succeed
19
20if {[info exists env(TEST_TIMEOUT_OVERRIDE)]} {
21    set timeout $env(TEST_TIMEOUT_OVERRIDE)
22} elseif {[info exists env(TEST_TIMEOUT)]} {
23    set timeout $env(TEST_TIMEOUT)
24} else {
25    set timeout 1500
26}
27
28log_file -a $env(TEST_LOG)
29
30match_max 10000
31
32eval spawn $env(TEST_CMD)
33
34expect_after {
35    -re "(.*)\r" {
36        exp_continue -continue_timer
37    }
38    timeout {send_error "ERROR-Timeout!\n"; exit 1}
39    eof {send_error "ERROR-EOF!\n"; exit 1}
40}
41
42if {[info exists env(UBOOT_CMD)]} {
43    expect "=>"
44
45    send "$env(UBOOT_CMD)\r"
46}
47
48if {[info exists env(BOOT_MSG)]} {
49    expect -re "$env(BOOT_MSG)"
50}
51
52if {[info exists env(WAKEUP_CMD)]} {
53    expect -re "$env(SUSPEND_MSG)"
54
55    # keep it suspended a bit, then wakeup
56    sleep 30
57
58    system "$env(WAKEUP_CMD)"
59}
60
61if {[info exists env(LOG_MSG)]} {
62    expect {
63        -notransfer -re "$env(PASSED)" {
64            expect -re "$env(LOG_MSG)"
65            exit 0
66        }
67        -notransfer -re "$env(LOG_MSG)" {
68            expect -re "$env(PASSED)"
69            exit 0
70        }
71    }
72}
73
74expect {
75    -re "$env(PASSED)" {
76        exit 0
77    }
78}
79
80expect eof
81
82