xfs/419: remove irrelevant swapfile test
[xfstests-dev.git] / common / locktest
1 ##/bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019 Intel Corp, All Rights Reserved
4
5 SERVER_LOG=$TEST_DIR/server.out
6 SERVER_PORT=$TEST_DIR/server.port
7 CLIENT_LOG=$TEST_DIR/client.out
8 TESTFILE=$TEST_DIR/lock_file
9 client_pid=""
10 server_pid=""
11
12 _cleanup()
13 {
14         kill $client_pid > /dev/null 2>&1
15         kill $server_pid > /dev/null 2>&1
16         rm -f $TESTFILE
17 }
18
19 _dump_logs_fail()
20 {
21         fail_str=$1
22
23         echo "     ***** Client log *****" >> $seqres.full
24         cat $CLIENT_LOG >> $seqres.full
25         echo "     ***** Server log *****" >> $seqres.full
26         cat $SERVER_LOG >> $seqres.full
27         echo "     ***** End file details *****" >> $seqres.full
28         ls -la $TESTFILE >> $seqres.full
29         _fail $fail_str
30         exit 1
31 }
32
33
34 _run_generic() {
35         mode=$1
36
37         # set up log files
38         rm -f $SERVER_LOG
39         touch $SERVER_LOG
40         rm -f $SERVER_PORT
41         touch $SERVER_PORT
42         rm -f $CLIENT_LOG
43         touch $CLIENT_LOG
44
45         touch $TESTFILE
46
47         # Start the server
48         $here/src/locktest $mode $TESTFILE 2> $SERVER_LOG 1> $SERVER_PORT &
49         server_pid=$!
50
51         timeout=30
52         while [ $timeout -gt 0 ]; do
53                 sleep 1
54
55                 PORT=$(cat $SERVER_PORT | grep "^server port: " | awk '{print $3}')
56                 if [ -n "$PORT" ]; then
57                         break
58                 fi
59
60                 # check the existence of server process
61                 if ! kill -s 0 $server_pid >/dev/null 2>&1; then
62                         _dump_logs_fail "Server died abnormally"
63                 fi
64
65                 let timeout=timeout-1
66         done
67
68         if [ -z "$PORT" ]; then
69                 _dump_logs_fail "Could not get server port"
70         fi
71
72         # Start the client
73
74         $here/src/locktest $mode -p $PORT -h localhost $TESTFILE 2> $CLIENT_LOG
75         client_result=$?
76         client_pid=$!
77         if [ $client_result -ne 0 ]; then
78                 _dump_logs_fail "Client reported failure ($client_result)"
79         fi
80         wait $server_pid
81         server_result=$?
82         if [ $server_result -ne 0 ]; then
83                 _dump_logs_fail "Server reported failure ($server_result)"
84         fi
85         echo success!
86         status=0
87 }
88
89 _run_locktest() {
90         _run_generic ""
91 }
92
93 _run_leasetest() {
94         _run_generic "-L"
95 }