Skip to content

Commit 673f338

Browse files
committed
Extend unit test for is_local_fs from fsdev.h
The test uses a fake `mtab` file which contains 1 entry for a local filesystem, 1 entry for a direct autofs map and 1 entry for a NFS system mounted using autofs. By parsing the `mtab` file only 1 local filesystem should be found. It will help us to test #1329
1 parent 6363562 commit 673f338

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

tests/API/probes/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AM_CPPFLAGS = \
2+
-DDATADIR=\"$(srcdir)/\" \
23
-I$(top_srcdir)/src \
34
-I$(top_srcdir)/src/CCE/public \
45
-I$(top_srcdir)/src/CPE/public \
@@ -35,6 +36,7 @@ test_fsdev_is_local_fs_SOURCES = test_fsdev_is_local_fs.c
3536

3637
EXTRA_DIST += \
3738
all.sh \
39+
fake_mtab \
3840
fts.sh \
3941
gentree.sh \
4042
test_api_probes_smoke.c \

tests/API/probes/fake_mtab

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/dev/mapper/fedora-root / ext4 rw,seclabel,relatime 0 0
2+
/etc/mount.map /nfs/test autofs rw,relatime,fd=17,pgrp=11111,timeout=5,minproto=5,maxproto=5,direct,pipe_ino=1246883 0 0
3+
192.168.122.231:/test /nfs/test nfs4 rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.231 0 0

tests/API/probes/test_fsdev_is_local_fs.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,43 @@
2929
#include <mntent.h>
3030
#include "fsdev.h"
3131

32-
int main(int argc, char *argv[])
32+
static int test_single_call()
3333
{
3434
struct mntent ment;
3535
ment.mnt_type = "autofs";
3636
int ret = is_local_fs(&ment);
37-
if (ret != 0) {
37+
/* autofs entry is never considered local */
38+
return (ret == 0);
39+
}
40+
41+
static int test_multiple_calls()
42+
{
43+
/* fake mtab contains only 1 local filesystem */
44+
FILE *f = setmntent(DATADIR "fake_mtab", "r");
45+
if (f == NULL) {
46+
fprintf(stderr, "fake_mtab could not be open\n");
47+
return 0;
48+
}
49+
struct mntent *ment;
50+
unsigned int locals = 0;
51+
while ((ment = getmntent(f)) != NULL) {
52+
if (is_local_fs(ment)) {
53+
locals++;
54+
}
55+
}
56+
endmntent(f);
57+
return (locals == 1);
58+
}
59+
60+
int main(int argc, char *argv[])
61+
{
62+
if (!test_single_call()) {
63+
fprintf(stderr, "test_single_call has failed\n");
64+
return 1;
65+
}
66+
if (!test_multiple_calls()) {
67+
fprintf(stderr, "test_multiple_calls has failed\n");
3868
return 1;
3969
}
4070
return 0;
41-
}
71+
}

0 commit comments

Comments
 (0)