This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
testmod_fstab.c
110 lines (83 loc) · 3.97 KB
/
testmod_fstab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#ifdef HAVE_KDBCONFIG_H
#include "kdbconfig.h"
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <tests_plugin.h>
void test_readfstab (const char * file)
{
Key * parentKey = keyNew ("user:/tests/fstab", KEY_VALUE, srcdir_file (file), KEY_END);
KeySet * conf = 0;
PLUGIN_OPEN ("fstab");
KeySet * ks = ksNew (0, KS_END);
printf ("Reading fstab using file: %s\n", file);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
// output_keyset(ks);
Key * key = ksLookupByName (ks, "user:/tests/fstab/\\//device", 0);
exit_if_fail (key, "rootfs device not found");
succeed_if (strcmp ("/dev/sda1", keyValue (key)) == 0, "device not correct");
key = ksLookupByName (ks, "user:/tests/fstab/\\/media\\/ext4/device", 0);
exit_if_fail (key, "media device not found");
succeed_if (strcmp ("/dev/sdg1", keyValue (key)) == 0, "device not correct");
exit_if_fail (key = ksLookupByName (ks, "user:/tests/fstab/\\/media\\/ext4/dumpfreq", 0), "rootfs device not found");
succeed_if (strcmp ("0", keyValue (key)) == 0, "dumpfreq not correct");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
void test_writefstab (const char * file)
{
KeySet * conf = 0;
PLUGIN_OPEN ("fstab");
printf ("Writing fstab using file: %s\n", file);
KeySet * ks = ksNew (
22, keyNew ("user:/tests/filesystems", KEY_VALUE, "filesystems", KEY_COMMENT, "", KEY_END),
keyNew ("user:/tests/filesystems/\\/", KEY_VALUE, "the root fs", KEY_COMMENT, "pseudo name", KEY_END),
keyNew ("user:/tests/filesystems/\\//device", KEY_VALUE, "/dev/sda6", KEY_COMMENT, "Device or Label", KEY_END),
keyNew ("user:/tests/filesystems/\\//dumpfreq", KEY_VALUE, "0", KEY_COMMENT, "Dump frequency in days", KEY_END),
keyNew ("user:/tests/filesystems/\\//mpoint", KEY_VALUE, "/", KEY_COMMENT, "Moint point", KEY_END),
keyNew ("user:/tests/filesystems/\\//options", KEY_VALUE, "defaults,errors=remount-ro", KEY_COMMENT,
"Fileuser/tests specific options. See mount(8)", KEY_END),
keyNew ("user:/tests/filesystems/\\//passno", KEY_VALUE, "1", KEY_COMMENT, "Pass number on parallel fsck", KEY_END),
keyNew ("user:/tests/filesystems/\\//type", KEY_VALUE, "jfs", KEY_COMMENT, "Fileuser/tests type. See fs(5)", KEY_END),
keyNew ("user:/tests/filesystems/swap00", KEY_VALUE, "non-swapfs", KEY_COMMENT, "pseudo name", KEY_END),
keyNew ("user:/tests/filesystems/swap00/device", KEY_VALUE, "/dev/sda10", KEY_COMMENT, "Device or Label", KEY_END),
keyNew ("user:/tests/filesystems/swap00/dumpfreq", KEY_VALUE, "0", KEY_COMMENT, "Dump frequency in days", KEY_END),
keyNew ("user:/tests/filesystems/swap00/mpoint", KEY_VALUE, "none", KEY_COMMENT, "Moint point", KEY_END),
keyNew ("user:/tests/filesystems/swap00/options", KEY_VALUE, "sw", KEY_COMMENT,
"Fileuser/tests specific options. See mount(8)", KEY_END),
keyNew ("user:/tests/filesystems/swap00/passno", KEY_VALUE, "0", KEY_COMMENT, "Pass number on parallel fsck", KEY_END),
keyNew ("user:/tests/filesystems/swap00/type", KEY_VALUE, "swap", KEY_COMMENT, "Fileuser/tests type. See fs(5)", KEY_END),
KS_END);
Key * parentKey = keyNew ("user:/tests/filesystems", KEY_VALUE, elektraFilename (), KEY_END);
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
succeed_if (output_error (parentKey), "error in kdbSet");
succeed_if (output_warnings (parentKey), "warnings in kdbSet");
succeed_if (compare_regex_to_line_files (srcdir_file (file), keyString (parentKey)), "files do not match as expected");
elektraUnlink (keyString (parentKey));
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
int main (int argc, char ** argv)
{
printf ("FSTAB TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_readfstab ("fstab/fstab");
test_writefstab ("fstab/fstab-write");
print_result ("testmod_fstab");
return nbError;
}