Welcome to mirror list, hosted at ThFree Co, Russian Federation.

daemon-test.sh « test - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c35fc1f48808e655d201a4bc245ca82b115c79d (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
#!/bin/bash
# -- vw daemon test
#
NAME='vw-daemon-test'

export PATH="vowpalwabbit:../vowpalwabbit:${PATH}"
# The VW under test
VW=`which vw`

MODEL=$NAME.model
TRAINSET=$NAME.train
PREDREF=$NAME.predref
PREDOUT=$NAME.predict
PORT=54248

# -- make sure we can find vw first
if [ -x "$VW" ]; then
    : cool found vw at: $VW
else
    echo "$NAME: can not find 'vw' in $PATH - sorry"
    exit 1
fi

# -- and netcat
NETCAT=`which netcat`
if [ -x "$NETCAT" ]; then
    : cool found netcat at: $NETCAT
else
    echo "$NAME: can not find 'netcat' in $PATH - sorry"
    exit 1
fi

# -- and pkill
PKILL=`which pkill`
if [ -x "$PKILL" ]; then
    : cool found pkill at: $PKILL
else
    echo "$NAME: can not find 'pkill' in $PATH - sorry"
    exit 1
fi

#
# fractional seconds sleep
#
mysleep() {
    case "$1" in
        *[0-9]*) Seconds="$1" ;;
        *) Seconds=0.2 ;;
    esac
    perl -e "select(undef,undef,undef,$Seconds)"
}

# A command and pattern that will unlikely to match anything but our own test
DaemonCmd="$VW -t -i $MODEL --daemon --num_children 1 --quiet --port $PORT"

stop_daemon() {
    # make sure we are not running, may ignore 'error' that we're not
    # echo stopping daemon
    $PKILL -9 -f "$DaemonCmd" 2>&1 | grep -q 'no process found'
    # relinquish CPU by forcing some conext switches to be safe
    # (to let existing vw daemon procs die)
    mysleep 0.05
}

start_daemon() {
    # echo starting daemon
    $DaemonCmd </dev/null >/dev/null &
    # give it time to be ready
    wait; wait; wait
}

cleanup() {
    /bin/rm -f $MODEL $TRAINSET $PREDREF $PREDOUT
    stop_daemon
}

# -- main
cleanup

# prepare training set
cat > $TRAINSET <<EOF
0.55 1 '1| a
0.99 1 '2| b c
EOF

# prepare expected predict output
cat > $PREDREF <<EOF
0.553585 1
0.733882 2
EOF

# Train
$VW -b 10 --quiet -d $TRAINSET -f $MODEL

start_daemon

# Test on train-set
# OpenBSD netcat quits immediately after stdin EOF
# nc.traditional does not, so let's use -q 1.
#$NETCAT -q 1 localhost $PORT < $TRAINSET > $PREDOUT
#wait
# However, GNU netcat does not know -q, so let's do a work-around
touch $PREDOUT
$NETCAT localhost $PORT < $TRAINSET > $PREDOUT &
# Wait until we recieve a prediction from the vw daemon then kill netcat
until [ `wc -l < $PREDOUT` -eq 2 ]; do :; done
$PKILL -9 $NETCAT

# We should ignore small (< $Epsilon) floating-point differences (fuzzy compare)
diff <(cut -c-5 $PREDREF) <(cut -c-5 $PREDOUT)
case $? in
    0)  echo "$NAME: OK"
        cleanup
        exit 0
        ;;
    1)  echo "$NAME FAILED: see $PREDREF vs $PREDOUT"
        stop_daemon
        exit 1
        ;;
    *)  echo "$NAME: diff failed - something is fishy"
        stop_daemon
        exit 2
        ;;
esac