Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame^] | 1 | #!/bin/gawk |
| 2 | # |
| 3 | # Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com> |
| 4 | # Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 5 | # All rights reserved. |
| 6 | # |
| 7 | # Redistribution and use in source and binary forms, with or without |
| 8 | # modification, are permitted provided that the following conditions |
| 9 | # are met: |
| 10 | # 1. Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # 2. Redistributions in binary form must reproduce the above copyright |
| 13 | # notice, this list of conditions and the following disclaimer in the |
| 14 | # documentation and/or other materials provided with the distribution. |
| 15 | # 3. The name of the author may not be used to endorse or promote products |
| 16 | # derived from this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 29 | BEGIN { |
| 30 | lines = 8 |
| 31 | fail = 0 |
| 32 | |
Dmitry V. Levin | c9cc4cb | 2015-01-07 20:14:19 +0000 | [diff] [blame] | 33 | addrlen = length(addr) + 3 |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 34 | r_i = "[1-9][0-9]*" |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 35 | r_socket = "^socket\\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\\) += 0<UNIX:\\[(" r_i ")\\]>$" |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 36 | } |
| 37 | |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 38 | NR == 1 { |
| 39 | if (match($0, r_socket, a)) { |
| 40 | inode_listen = a[2] |
| 41 | r_bind = "^bind\\(0<UNIX:\\[" inode_listen "\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), sun_path=\"" addr "\"\\}, " addrlen "\\) += 0$" |
Dmitry V. Levin | c9cc4cb | 2015-01-07 20:14:19 +0000 | [diff] [blame] | 42 | r_listen = "^listen\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>, 5\\) += 0$" |
Dmitry V. Levin | ed7ada2 | 2015-01-13 00:06:09 +0000 | [diff] [blame] | 43 | r_getsockname = "^getsockname\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), sun_path=\"" addr "\"\\}, \\[" addrlen "\\]\\) += 0$" |
| 44 | r_accept = "^accept\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), NULL\\}, \\[2\\]\\) += 1<UNIX:\\[(" r_i ")->(" r_i "),\"" addr "\"\\]>" |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 45 | next |
| 46 | } |
| 47 | } |
| 48 | |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 49 | NR == 2 {if (r_bind != "" && match($0, r_bind)) next} |
| 50 | |
Dmitry V. Levin | f0ed167 | 2014-12-25 00:32:23 +0000 | [diff] [blame] | 51 | NR == 3 {if (r_listen != "" && match($0, r_listen)) next} |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 52 | |
Dmitry V. Levin | f0ed167 | 2014-12-25 00:32:23 +0000 | [diff] [blame] | 53 | NR == 4 {if (r_getsockname != "" && match($0, r_getsockname)) next} |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 54 | |
| 55 | NR == 5 { |
Dmitry V. Levin | f0ed167 | 2014-12-25 00:32:23 +0000 | [diff] [blame] | 56 | if (r_accept != "" && match($0, r_accept, a)) { |
| 57 | inode_accepted = a[2] |
| 58 | inode_peer = a[3] |
Dmitry V. Levin | c9cc4cb | 2015-01-07 20:14:19 +0000 | [diff] [blame] | 59 | r_close_listen = "^close\\(0<UNIX:\\[" inode_listen ",\"" addr "\"\\]>\\) += 0$" |
| 60 | r_close_accepted = "^close\\(1<UNIX:\\[" inode_accepted ",\"" addr "\"\\]>\\) += 0$" |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 61 | next |
| 62 | } |
| 63 | } |
| 64 | |
Dmitry V. Levin | f0ed167 | 2014-12-25 00:32:23 +0000 | [diff] [blame] | 65 | NR == 6 {if (r_close_listen != "" && match($0, r_close_listen)) next} |
| 66 | NR == 7 {if (r_close_accepted != "" && match($0, r_close_accepted)) next} |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 67 | |
Dmitry V. Levin | f0ed167 | 2014-12-25 00:32:23 +0000 | [diff] [blame] | 68 | NR == lines && $0 == "+++ exited with 0 +++" {next} |
Masatake YAMATO | 6077ad8 | 2014-12-24 20:59:32 +0900 | [diff] [blame] | 69 | |
| 70 | { |
| 71 | print "Line " NR " does not match: " $0 |
| 72 | fail=1 |
| 73 | } |
| 74 | |
| 75 | END { |
| 76 | if (NR != lines) { |
| 77 | print "Expected " lines " lines, found " NR " line(s)." |
| 78 | print "" |
| 79 | exit 1 |
| 80 | } |
| 81 | if (fail) { |
| 82 | print "" |
| 83 | exit 1 |
| 84 | } |
| 85 | } |