]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/lsfd/mkfds-inotify
tests: (lsfd::mkfds-inotify) consider environments not having / as a mount point
[thirdparty/util-linux.git] / tests / ts / lsfd / mkfds-inotify
CommitLineData
6b58fb5f
MY
1#!/bin/bash
2#
3# Copyright (C) 2023 Masatake YAMATO <yamato@redhat.com>
4#
5# This file is part of util-linux.
6#
7# This file is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This file is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17TS_TOPDIR="${0%/*}/../.."
18TS_DESC="inotify"
19
20. "$TS_TOPDIR"/functions.sh
21ts_init "$*"
22
23ts_check_test_command "$TS_CMD_LSFD"
cc937cf3 24ts_check_test_command "$TS_CMD_FINDMNT"
6b58fb5f
MY
25ts_check_prog "stat"
26ts_check_prog "sed"
27
28ts_cd "$TS_OUTDIR"
29
30PID=
31FD=3
121b3703
MY
32dir=/proc
33file=/proc/cmdline
34PROC="$(stat -c %i $dir)"@"$($TS_CMD_FINDMNT --raw --noheadings -oMAJ:MIN --target $dir)"
35CMDLINE="$(stat -c %i $file)"@"$($TS_CMD_FINDMNT --raw --noheadings -oMAJ:MIN --target $file)"
6b58fb5f 36{
121b3703 37 coproc MKFDS { "$TS_HELPER_MKFDS" inotify $FD dir=$dir file=$file ; }
6b58fb5f
MY
38 if read -u ${MKFDS[0]} PID; then
39 EXPR='(PID == '"${PID}"') and (FD == '"$FD"')'
40 INODES_RAW=$(${TS_CMD_LSFD} --raw -n -o INOTIFY.INODES.RAW -Q "${EXPR}")
41 echo "INOTIFY.INODES.RAW": $?
121b3703
MY
42 if [[ "$INODES_RAW" == "${CMDLINE}"'\x0a'"${PROC}" ]]; then
43 echo "INOTIFY.INODES.RAW" == CMDLINE'\x0a'PROC
6b58fb5f
MY
44 else
45 echo "INOTIFY.INODES.RAW": "$INODES_RAW"
121b3703
MY
46 echo "CMDLINE": "$CMDLINE"
47 echo "PROC": "$PROC"
6b58fb5f 48 fi
42497e7d
MY
49 INODES_RAW_JSON=$(${TS_CMD_LSFD} -J --raw -n -o INOTIFY.INODES.RAW -Q "${EXPR}")
50 echo "INOTIFY.INODES.RAW (JSON)": $?
51 EXPECTED_JSON=$(cat<<EOF
52{
53 "lsfd": [
54 {
55 "inotify.inodes.raw": [
121b3703 56 "$CMDLINE", "$PROC"
42497e7d
MY
57 ]
58 }
59 ]
60}
61EOF
62 )
63 if [[ "$INODES_RAW_JSON" == "${EXPECTED_JSON}" ]]; then
64 echo "INOTIFY.INODES.RAW" == EXPECTED_JSON
65 else
66 echo "INOTIFY.INODES.RAW": "$INODES_RAW_JSON"
67 fi
68
0fec4965 69 echo DONE >&"${MKFDS[1]}"
6b58fb5f
MY
70 fi
71 wait "${MKFDS_PID}"
72} > "$TS_OUTPUT" 2>&1
73
74ts_finalize