summaryrefslogtreecommitdiff
path: root/testsuite/config/unix.exp
blob: 5331b0df3a91ecf821ab36370520c40680e3403e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

regexp "(.*\/)testsuite" $objdir objdir topdir

# These are the same as include/c.h
set usage_help "\\s*-h, --help\\s+display this help and exit\\s+"
set usage_version "\\s*-V, --version\\s+output version information and exit\\s+"
set usage_man "\\s*For more details see \\S+\\."

proc procps_v_version { tool } {
  global topdir
  set toolpath ${topdir}${tool}
  set tmp [ exec $toolpath -V ]
  regexp "from procps-ng (\[0-9.\]*)" $tmp tmp version
  clone_output "$toolpath version $version\n"
}

proc free_version {} { procps_v_version free } 
proc kill_version {} { procps_v_version kill } 
proc pgrep_version {} { procps_v_version pgrep } 
proc pkill_version {} { procps_v_version pkill } 
proc pmap_version {} { procps_v_version pmap } 
proc pwdx_version {} { procps_v_version pwdx } 
proc sysctl_version {} { procps_v_version sysctl } 
proc uptime_version {} { procps_v_version uptime } 
proc vmstat_version {} { procps_v_version vmstat } 
proc w_version {} { procps_v_version w } 

#
#
# common utilities
proc expect_continue { testname reg } {
    expect {
        -re "$reg" { }
        eof { fail "$testname" }
        timeout { fail "$testname" }
    }
}

proc expect_pass { testname reg } {
    expect {
        -re "$reg" { pass "$testname" }
        default { fail "$testname" }
    }
}

proc expect_blank { testname } {
    expect {
        -re "\\w" { fail "$testname" }
        eof { pass "$testname" }
        timeout { pass "$testname" }
    }
}

proc expect_table { test match_header match_items match_footer } {
    expect {
        -re "$match_header" {
            expect {
                -re "$match_items" {
                    expect {
                        -re "$match_footer" { pass "$test" }
                        default { fail "$test (footer)" }
                    }
                }
                default { fail "$test (items)" }
            }
        }
        default { fail "$test (header)" }
    }
}
            
proc expect_table_dsc { test match_header match_item } {
    expect {
        -re $match_header {}
        default {
            fail "$test (header)"
            return
        }
    }

    set do_loop 1
    set last_value 999999
    set found_item 0
    while { $do_loop ==1 } {
    expect {
        -re $match_item {
            set current_value $expect_out(1,string)
            if { $current_value > $last_value } {
                fail "$test (sorting $current_value > $last_value)"
                return
            } else {
                set found_item 1
                set last_value $current_value
            }
        }
        default {
            if { $found_item == 0 } {
                fail "$test (items)"
            } else {
                pass $test
            }
            return
        }
    }
    }
    #expect {
    #    -re $match_footer { pass $test }
    #    default { fail "$test (footer)" }
    #}
}

proc make_testproc { } {
    # Time to run the whole job
    set sleep_time 300

    global testproc_path testproc_comm testproc1_pid testproc2_pid

    set testproc_path [ exec mktemp -u ]
    exec ln -s "/bin/sleep" $testproc_path
    set testproc_comm [ exec basename $testproc_path ]

    spawn readlink $testproc_path
    expect {
        -re "^/bin/sleep\\s*$" { }
        timeout { perror "test proc does not link to sleep 1" }
        eof { perror "test proc does not link to sleep 1" }
    }

    set testproc1_pid [ exec $testproc_path $sleep_time & ]
    set testproc2_pid [ exec $testproc_path $sleep_time & ]
}