From: Andreas Reichel <[email protected]>

* Use --weaken to generally weaken library functions for tests,
  so that arbitrary functions can be overwritten. This avoids unneeded
  complexity in the tests' Makefile

* gcc newer than 4.8 inlines functions that break the test,
  because objcopy --weaken does not affect inline functions.

* Reinsert mock for mount_partition that was accidentally removed

Note: This is a quick fix for the tests. Either redesign of the object
files or a different test layout is considered to use cmocka in a more
standard way.

Signed-off-by: Andreas Reichel <[email protected]>
---
 tools/bg_utils.c              |  4 +++-
 tools/test-interface.h        |  1 +
 tools/tests/Makefile.am       | 29 ++++++++---------------------
 tools/tests/test_partitions.c |  5 +++++
 4 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/tools/bg_utils.c b/tools/bg_utils.c
index 496e2c8..528e43b 100644
--- a/tools/bg_utils.c
+++ b/tools/bg_utils.c
@@ -90,7 +90,8 @@ static char *get_mountpoint(char *devpath)
        return NULL;
 }
 
-static bool mount_partition(CONFIG_PART *cfgpart)
+__attribute__((noinline))
+bool mount_partition(CONFIG_PART *cfgpart)
 {
        char tmpdir_template[256];
        char *mountpoint;
@@ -160,6 +161,7 @@ static FILE *open_config_file(CONFIG_PART *cfgpart, char 
*mode)
        return config;
 }
 
+__attribute__((noinline))
 bool probe_config_file(CONFIG_PART *cfgpart)
 {
        bool do_unmount = false;
diff --git a/tools/test-interface.h b/tools/test-interface.h
index d0bf6d4..6b27943 100644
--- a/tools/test-interface.h
+++ b/tools/test-interface.h
@@ -20,5 +20,6 @@ bool write_env(CONFIG_PART *part, BG_ENVDATA *env);
 
 bool probe_config_file(CONFIG_PART *cfgpart);
 bool probe_config_partitions(CONFIG_PART *cfgparts);
+bool mount_partition(CONFIG_PART *cfgpart);
 
 #endif // __TEST_INTERFACE_H__
diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am
index c99ba60..dd4a249 100644
--- a/tools/tests/Makefile.am
+++ b/tools/tests/Makefile.am
@@ -27,36 +27,23 @@ AM_CFLAGS = \
 
 CLEANFILES =
 
-test_partitions_LDADD = \
-       libebgenv-test_partitions.a \
-       -lcmocka
+libebgenv-test.a: $(top_builddir)/libebgenv.a
+       $(AM_V_GEN) $(OBJCOPY) --weaken $< $@
 
-libebgenv-test_partitions.a: $(top_builddir)/libebgenv.a
-       $(AM_V_GEN) $(OBJCOPY) -W probe_config_file -W ped_device_probe_all \
-         -W ped_device_get_next -W ped_disk_next_partition $< $@
+CLEANFILES += libebgenv-test.a
 
-CLEANFILES += libebgenv-test_partitions.a
+test_partitions_LDADD = \
+       libebgenv-test.a \
+       -lcmocka
 
 test_environment_LDADD = \
-       libebgenv-test_environment.a \
+       libebgenv-test.a \
        -lcmocka
 
-libebgenv-test_environment.a: $(top_builddir)/libebgenv.a
-       $(AM_V_GEN) $(OBJCOPY) -W oldenvs -W configparts -W fopen -W fopen64 \
-         -W fclose -W fread -W fwrite -W feof $< $@
-
-CLEANFILES += libebgenv-test_environment.a
-
 test_api_LDADD = \
-       libebgenv-test_api.a \
+       libebgenv-test.a \
        -lcmocka
 
-libebgenv-test_api.a: $(top_builddir)/libebgenv.a
-       $(AM_V_GEN) $(OBJCOPY) -W bgenv_init -W bgenv_write -W bgenv_close \
-         -W bgenv_get_latest -W bgenv_get_by_index -W bgenv_get_oldest $< $@
-
-CLEANFILES += libebgenv-test_api.a
-
 check_PROGRAMS = test_partitions test_environment test_api
 
 TESTS = $(check_PROGRAMS)
diff --git a/tools/tests/test_partitions.c b/tools/tests/test_partitions.c
index 6781b79..6765e32 100644
--- a/tools/tests/test_partitions.c
+++ b/tools/tests/test_partitions.c
@@ -84,6 +84,11 @@ PedPartition *ped_disk_next_partition(const PedDisk *disk,
        return NULL;
 }
 
+bool mount_partition(CONFIG_PART *cfgpart)
+{
+       return true;
+}
+
 bool probe_config_file(CONFIG_PART *cfgpart)
 {
        return mock_type(bool);
-- 
2.14.1

-- 
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/20170926091921.9134-1-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to