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
29BEGIN {
30  lines = 6
31  fail = 0
32  addrlen = length(addr) + 3
33
34  r_i = "[1-9][0-9]*"
35  r_socket = "^socket\\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\\) += 1<UNIX:\\[(" r_i ")\\]>$"
36  r_close_listen = "^close\\(0<UNIX:\\[" r_i ",\"" addr "\"\\]>\\) += 0$"
37}
38
39NR == 1 {
40  if (match($0, r_socket, a)) {
41    inode = a[2]
42    r_connect = "^connect\\(1<UNIX:\\[" inode "\\]>, \\{sa_family=AF_(LOCAL|UNIX|FILE), sun_path=\"" addr "\"\\}, " addrlen "\\) += 0$"
43    next
44  }
45}
46
47NR == 2 {if (match($0, r_close_listen)) next}
48
49NR == 3 {
50  if (r_connect != "" && match($0, r_connect)) {
51    r_close_connected = "^close\\(1<UNIX:\\[(" r_i ")->" r_i "\\]>\\) += 0$"
52    next
53  }
54}
55
56NR == 4 && /^--- SIGUSR1 / {next}
57
58NR == 5 {
59  if (inode != "" && r_close_connected != "" && match($0, r_close_connected, a) && a[1] == inode) {
60    next
61  }
62}
63
64NR == lines && $0 == "+++ exited with 0 +++" {next}
65
66{
67  print "Line " NR " does not match: " $0
68  fail=1
69}
70
71END {
72  if (NR != lines) {
73    print "Expected " lines " lines, found " NR " line(s)."
74    print ""
75    exit 1
76  }
77  if (fail) {
78    print ""
79    exit 1
80  }
81}
82