LCOV - code coverage report
Current view: top level - src/plugins/fstab - testmod_fstab.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 42 42 100.0 %
Date: 2019-09-12 12:28:41 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.13