From: Jan Kiszka <[email protected]>

Unfortunately, the current test setup requires to keep a number of
functions public in order to attach to them during unit tests. Move
their prototypes into a separate header that does not expose them
widely.

No functional changes, just cleanups.

Signed-off-by: Jan Kiszka <[email protected]>
---

I'm looking forward to patches the integrate the tests into the build.
Otherwise, they will bit-rot.

 Makefile.am                    |  1 +
 tools/bg_utils.c               |  5 +++--
 tools/ebgpart.c                | 31 ++++++++++++++++---------------
 tools/ebgpart.h                |  2 +-
 tools/test-interface.h         | 24 ++++++++++++++++++++++++
 tools/tests/test_environment.c |  4 +---
 tools/tests/test_partitions.c  |  3 +--
 7 files changed, 47 insertions(+), 23 deletions(-)
 create mode 100644 tools/test-interface.h

diff --git a/Makefile.am b/Makefile.am
index 7745bb1..6038f30 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir) 
-include config.h
 
 AM_CFLAGS = \
        -Wno-unused-parameter \
+       -Wmissing-prototypes \
        -fshort-wchar \
        -DHAVE_ENDIAN_H \
        -D_GNU_SOURCE
diff --git a/tools/bg_utils.c b/tools/bg_utils.c
index 026abb9..496e2c8 100644
--- a/tools/bg_utils.c
+++ b/tools/bg_utils.c
@@ -11,6 +11,7 @@
  */
 
 #include "bg_utils.h"
+#include "test-interface.h"
 
 const char *tmp_mnt_dir = "/tmp/mnt-XXXXXX";
 
@@ -89,7 +90,7 @@ static char *get_mountpoint(char *devpath)
        return NULL;
 }
 
-bool mount_partition(CONFIG_PART *cfgpart)
+static bool mount_partition(CONFIG_PART *cfgpart)
 {
        char tmpdir_template[256];
        char *mountpoint;
@@ -121,7 +122,7 @@ bool mount_partition(CONFIG_PART *cfgpart)
        return true;
 }
 
-void unmount_partition(CONFIG_PART *cfgpart)
+static void unmount_partition(CONFIG_PART *cfgpart)
 {
        if (!cfgpart) {
                return;
diff --git a/tools/ebgpart.c b/tools/ebgpart.c
index 878cc5e..d0997bd 100644
--- a/tools/ebgpart.c
+++ b/tools/ebgpart.c
@@ -28,7 +28,7 @@ void ebgpart_beverbose(bool v)
        verbosity = v;
 }
 
-void add_block_dev(PedDevice *dev)
+static void add_block_dev(PedDevice *dev)
 {
        if (!first_device) {
                first_device = dev;
@@ -41,7 +41,7 @@ void add_block_dev(PedDevice *dev)
        d->next = dev;
 }
 
-char *GUID_to_str(uint8_t *g)
+static char *GUID_to_str(uint8_t *g)
 {
        snprintf(buffer, 37, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%"
                             "02X%02X%02X%02X%02X",
@@ -50,7 +50,7 @@ char *GUID_to_str(uint8_t *g)
        return buffer;
 }
 
-char *type_to_name(char t)
+static char *type_to_name(char t)
 {
        switch (t) {
        case MBR_TYPE_FAT12:
@@ -69,8 +69,8 @@ char *type_to_name(char t)
        return "not supported";
 }
 
-bool check_GPT_FAT_entry(int fd, struct EFIpartitionentry *e,
-                        PedFileSystemType *pfst, uint32_t i)
+static bool check_GPT_FAT_entry(int fd, struct EFIpartitionentry *e,
+                               PedFileSystemType *pfst, uint32_t i)
 {
        if (strcmp(GPT_PARTITION_GUID_FAT_NTFS, GUID_to_str(e->type_GUID)) !=
                0 &&
@@ -131,7 +131,8 @@ bool check_GPT_FAT_entry(int fd, struct EFIpartitionentry 
*e,
        return true;
 }
 
-void read_GPT_entries(int fd, uint64_t table_LBA, uint32_t num, PedDevice *dev)
+static void read_GPT_entries(int fd, uint64_t table_LBA, uint32_t num,
+                            PedDevice *dev)
 {
        off64_t offset;
        struct EFIpartitionentry e;
@@ -185,9 +186,9 @@ void read_GPT_entries(int fd, uint64_t table_LBA, uint32_t 
num, PedDevice *dev)
        }
 }
 
-void scanLogicalVolumes(int fd, off64_t extended_start_LBA,
-                       struct Masterbootrecord *ebr, int i,
-                       PedPartition *partition, int lognum)
+static void scanLogicalVolumes(int fd, off64_t extended_start_LBA,
+                              struct Masterbootrecord *ebr, int i,
+                              PedPartition *partition, int lognum)
 {
        struct Masterbootrecord next_ebr;
        PedFileSystemType *pfst;
@@ -246,7 +247,7 @@ scl_out_of_mem:
        if (partition->next) free(partition->next);
 }
 
-bool check_partition_table(PedDevice *dev)
+static bool check_partition_table(PedDevice *dev)
 {
        int fd;
        struct Masterbootrecord mbr;
@@ -346,8 +347,8 @@ bool check_partition_table(PedDevice *dev)
        return true;
 }
 
-int scan_devdir(unsigned int fmajor, unsigned int fminor, char *fullname,
-                unsigned int maxlen)
+static int scan_devdir(unsigned int fmajor, unsigned int fminor, char 
*fullname,
+                      unsigned int maxlen)
 {
        int result = -1;
 
@@ -398,7 +399,7 @@ static int get_major_minor(char *filename, unsigned int 
*major, unsigned int *mi
        return 0;
 }
 
-void ped_device_probe_all()
+void ped_device_probe_all(void)
 {
        struct dirent *sysblockfile;
        char fullname[DEV_FILENAME_LEN];
@@ -457,7 +458,7 @@ void ped_device_probe_all()
        closedir(sysblockdir);
 }
 
-void ped_partition_destroy(PedPartition *p)
+static void ped_partition_destroy(PedPartition *p)
 {
        if (!p) return;
        if (!p->fs_type) goto fs_type_Null;
@@ -467,7 +468,7 @@ fs_type_Null:
        free(p);
 }
 
-void ped_device_destroy(PedDevice *d)
+static void ped_device_destroy(PedDevice *d)
 {
        if (!d) return;
        if (d->model) free(d->model);
diff --git a/tools/ebgpart.h b/tools/ebgpart.h
index 918602e..097bf8f 100644
--- a/tools/ebgpart.h
+++ b/tools/ebgpart.h
@@ -131,7 +131,7 @@ typedef struct _PedDisk {
        PedPartition *part_list;
 } PedDisk;
 
-void ped_device_probe_all();
+void ped_device_probe_all(void);
 PedDevice *ped_device_get_next(const PedDevice *dev);
 PedDisk *ped_disk_new(const PedDevice *dev);
 PedPartition *ped_disk_next_partition(const PedDisk *pd,
diff --git a/tools/test-interface.h b/tools/test-interface.h
new file mode 100644
index 0000000..d0bf6d4
--- /dev/null
+++ b/tools/test-interface.h
@@ -0,0 +1,24 @@
+/*
+ * EFI Boot Guard
+ *
+ * Copyright (c) Siemens AG, 2017
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef __TEST_INTERFACE_H__
+#define __TEST_INTERFACE_H__
+
+#include "bg_utils.h"
+
+bool read_env(CONFIG_PART *part, BG_ENVDATA *env);
+bool write_env(CONFIG_PART *part, BG_ENVDATA *env);
+
+bool probe_config_file(CONFIG_PART *cfgpart);
+bool probe_config_partitions(CONFIG_PART *cfgparts);
+
+#endif // __TEST_INTERFACE_H__
diff --git a/tools/tests/test_environment.c b/tools/tests/test_environment.c
index 7fa4061..fe9d50e 100644
--- a/tools/tests/test_environment.c
+++ b/tools/tests/test_environment.c
@@ -18,6 +18,7 @@
 #include <cmocka.h>
 #include <string.h>
 #include "bg_utils.h"
+#include "test-interface.h"
 
 /* Mock functions from libparted */
 
@@ -59,9 +60,6 @@ size_t fwrite(const void *ptr, size_t size, size_t count, 
FILE *stream)
        return mock_type(size_t);
 }
 
-extern bool read_env(CONFIG_PART *part, BG_ENVDATA *env);
-extern bool write_env(CONFIG_PART *part, BG_ENVDATA *env);
-
 static void test_configfile_read(void **state)
 {
        CONFIG_PART part;
diff --git a/tools/tests/test_partitions.c b/tools/tests/test_partitions.c
index bb2bff3..6781b79 100644
--- a/tools/tests/test_partitions.c
+++ b/tools/tests/test_partitions.c
@@ -17,6 +17,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 #include "bg_utils.h"
+#include "test-interface.h"
 
 static PedDevice ped_devices[32] = {0};
 static int num_simulated_devices = 2;
@@ -30,8 +31,6 @@ static const char *const fsname = "fat16";
 static char *fakemodel = "Mocked Disk Drive";
 static char *fakedevice = "/dev/nobrain";
 
-extern bool probe_config_partitions(CONFIG_PART *cfgparts);
-
 /* Mock functions from libparted */
 void ped_device_probe_all()
 {
-- 
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/4bbae446-9cb4-df45-d809-a27b751427d5%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to