Skip to content

Commit cc63f6f

Browse files
Merge pull request #1338 from jan-cerny/extend_fsdev_test
Extend unit test for is_local_fs from fsdev.h
2 parents 009bca9 + 4f8fcd1 commit cc63f6f

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/dev/mapper/fedora-root / ext4 rw,seclabel,relatime 0 0
2+
tmpfs /tmp tmpfs rw,seclabel,nosuid,nodev 0 0
3+
/etc/mount.map /nfs/test autofs rw,relatime,fd=17,pgrp=11111,timeout=5,minproto=5,maxproto=5,direct,pipe_ino=1246883 0 0
4+
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
5+
/dev/mapper/fedora-home /home ext4 rw,seclabel,relatime 0 0
6+
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
7+
//192.168.0.5/storage /media/movies cifs guest,uid=myuser,iocharset=utf8,file_mode=0777,dir_mode=0777,noperm 0 0

tests/API/probes/test_fsdev_is_local_fs.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,46 @@
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+
/*
44+
* fake mtab contains only 4 local filesystems:
45+
* /, /tmp, /home and /proc
46+
*/
47+
FILE *f = setmntent(DATADIR "fake_mtab", "r");
48+
if (f == NULL) {
49+
fprintf(stderr, "fake_mtab could not be open\n");
50+
return 0;
51+
}
52+
struct mntent *ment;
53+
unsigned int locals = 0;
54+
while ((ment = getmntent(f)) != NULL) {
55+
if (is_local_fs(ment)) {
56+
locals++;
57+
}
58+
}
59+
endmntent(f);
60+
return (locals == 4);
61+
}
62+
63+
int main(int argc, char *argv[])
64+
{
65+
if (!test_single_call()) {
66+
fprintf(stderr, "test_single_call has failed\n");
67+
return 1;
68+
}
69+
if (!test_multiple_calls()) {
70+
fprintf(stderr, "test_multiple_calls has failed\n");
3871
return 1;
3972
}
4073
return 0;
41-
}
74+
}

0 commit comments

Comments
 (0)