Debian Codegraph @

tests/kafs/basic-t

raw
1 #!/bin/sh
2 #
3 # Test suite for the kafs library.
4 #
5 # The canonical version of this file is maintained in the rra-c-util package,
6 # which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
7 #
8 # Written by Russ Allbery <[email protected]>
9 # Copyright 2016 Russ Allbery <[email protected]>
10 # Copyright 2009
11 # The Board of Trustees of the Leland Stanford Junior University
12 #
13 # Permission is hereby granted, free of charge, to any person obtaining a
14 # copy of this software and associated documentation files (the "Software"),
15 # to deal in the Software without restriction, including without limitation
16 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 # and/or sell copies of the Software, and to permit persons to whom the
18 # Software is furnished to do so, subject to the following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included in
21 # all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 # DEALINGS IN THE SOFTWARE.
30 #
31 # SPDX-License-Identifier: MIT
32
33 . "$C_TAP_SOURCE/tap/libtap.sh"
34 cd "$C_TAP_BUILD/kafs"
35
36 # Check whether we already have a token.
37 if tokens | grep -i 'tokens for ' >/dev/null ; then
38 tokens=true
39 else
40 tokens=false
41 fi
42
43 # Run the helper program and save its output and error.
44 ./basic > basic-output 2> basic-errors
45 status=$?
46
47 # If it exited with status 2, AFS is apparently not running and we should skip
48 # all of the tests.
49 if [ "$status" -eq 2 ] ; then
50 rm -f basic-output basic-errors
51 skip_all 'AFS not available'
52 fi
53 plan 5
54
55 # If we don't currently have a token, we can't check that it disappears after
56 # k_setpag. Otherwise, check the first tokens output and be sure that no
57 # tokens are seen.
58 if sed -n '/^=== tokens .setpag./,/^===/p' basic-output \
59 | grep -i 'tokens for ' > /dev/null ; then
60 ok 'k_setpag hides existing tokens' false
61 else
62 if [ "$tokens" = true ] ; then
63 ok 'k_setpag hides existing tokens' true
64 else
65 skip 'no existing tokens'
66 fi
67 fi
68
69 # If aklog or tokens failed, we can't run the rest of the tests.
70 if [ "$status" -eq 3 ] ; then
71 skip_block 3 'aklog or tokens failed'
72 else
73 if sed -n '/^=== tokens .aklog./,/^===/p' basic-output \
74 | grep -i 'tokens for ' > /dev/null ; then
75 ok 'token present after aklog' true
76 else
77 ok 'token present after aklog' false
78 fi
79
80 # Check for no token after k_unlog.
81 if sed -n '/^=== tokens .unlog./,/^===/p' basic-output \
82 | grep -i 'tokens for ' > /dev/null ; then
83 ok 'token absent after unlog' false
84 else
85 ok 'token absent after unlog' true
86 fi
87
88 # Be sure that everything succeeded; otherwise print out the errors file.
89 if [ "$status" -ne 0 ] ; then
90 sed 's/^/# /' basic-errors
91 fi
92 ok 'all kafs calls succeeded' [ "$status" -eq 0 ]
93 fi
94
95 # Ensure that none of this affected our starting token.
96 if [ "$tokens" = true ] ; then
97 if tokens | grep -i 'tokens for ' >/dev/null ; then
98 ok 'still have initial token' true
99 else
100 ok 'still have initial token' false
101 fi
102 else
103 skip 'no existing tokens'
104 fi
105
106 # Clean up.
107 rm -f basic-output basic-errors