From 355eceba7ef60805123fad0bdcc69996891537be Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 18 Feb 2009 16:10:45 +0100 Subject: [PATCH] tests: add fsck:ismounted reg.test Signed-off-by: Karel Zak --- lib/ismounted.c | 11 +++++---- tests/commands.sh.in | 2 ++ tests/expected/fsck/ismounted | 1 + tests/ts/fsck/ismounted | 45 +++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/expected/fsck/ismounted create mode 100755 tests/ts/fsck/ismounted diff --git a/lib/ismounted.c b/lib/ismounted.c index 79a1df6a..0481c77e 100644 --- a/lib/ismounted.c +++ b/lib/ismounted.c @@ -190,11 +190,14 @@ int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "Usage: %s device\n", argv[0]); - exit(1); + return EXIT_FAILURE; } - if (is_mounted(argv[1])) - printf("\t%s is mounted.\n", argv[1]); - exit(0); + if (is_mounted(argv[1])) { + printf("mounted\n"); + return EXIT_SUCCESS; + } + printf("not mounted\n"); + return EXIT_FAILURE; } #endif /* DEBUG */ diff --git a/tests/commands.sh.in b/tests/commands.sh.in index 9c8104a0..55feda7f 100644 --- a/tests/commands.sh.in +++ b/tests/commands.sh.in @@ -9,6 +9,8 @@ TS_HELPER_PATHS="$TS_TOPDIR/helpers/test_pathnames" TS_HELPER_BYTESWAP="$TS_TOPDIR/helpers/test_byteswap" TS_HELPER_MD5="$TS_TOPDIR/helpers/test_md5" +TS_HELPER_ISMOUNTED="$TOPDIR/lib/test_ismounted" + # external commands TS_ECMD_BLKID="@BLKID@" TS_ECMD_VOLID="@VOLID@" diff --git a/tests/expected/fsck/ismounted b/tests/expected/fsck/ismounted new file mode 100644 index 00000000..bc3bd431 --- /dev/null +++ b/tests/expected/fsck/ismounted @@ -0,0 +1 @@ +mounted diff --git a/tests/ts/fsck/ismounted b/tests/ts/fsck/ismounted new file mode 100755 index 00000000..3279ddfd --- /dev/null +++ b/tests/ts/fsck/ismounted @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Copyright (C) 2009 Karel Zak +# +# This file is part of util-linux-ng. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="$(dirname $0)/../.." +TS_DESC="is mounted" + +. $TS_TOPDIR/functions.sh +ts_init "$*" +ts_skip_nonroot + +set -o pipefail + +> $TS_OUTPUT + +DEVICE=$(ts_device_init) +[ "$?" == 0 ] || ts_die "Cannot init device" + +mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE + +ts_device_has "TYPE" "ext3" $DEVICE || ts_die "Cannot found ext3 on $DEVICE" $DEVICE + +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT + +$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1 + +# test by ismounted.c +$TS_HELPER_ISMOUNTED $DEVICE >> $TS_OUTPUT 2>&1 + +$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE + +ts_device_deinit $DEVICE +ts_finalize -- 2.39.5