[PATCH bugfix] tests: test_partitions: Fix function overloading

4 views
Skip to first unread message

Andreas J. Reichel

unread,
Sep 26, 2017, 5:20:20 AM9/26/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

* 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 <andreas.r...@siemens.com>
---
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

Jan Kiszka

unread,
Sep 26, 2017, 6:56:01 AM9/26/17
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
On 2017-09-26 11:19, [ext] Andreas J. Reichel wrote:
> From: Andreas Reichel <andreas.r...@siemens.com>
>
> * 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.

OK, will merge - instead of fixing my patches in next and improving some
documentation aspects of this one. I'm counting on a rework of the unit
test afterwards!

Thanks,
Jan

Andreas Reichel

unread,
Sep 26, 2017, 7:58:29 AM9/26/17
to Jan Kiszka, efibootg...@googlegroups.com
On Tue, Sep 26, 2017 at 12:55:59PM +0200, Jan Kiszka wrote:
> On 2017-09-26 11:19, [ext] Andreas J. Reichel wrote:
> > From: Andreas Reichel <andreas.r...@siemens.com>
> >
> > * 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.
>
> OK, will merge - instead of fixing my patches in next and improving some
> documentation aspects of this one. I'm counting on a rework of the unit
> test afterwards!
>
Promised! Thanks,

Andreas
--
Andreas Reichel
Dipl.-Phys. (Univ.)
Software Consultant

Andreas...@tngtech.com, +49-174-3180074
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterfoehring
Geschaeftsfuehrer: Henrik Klagges, Dr. Robert Dahlke, Gerhard Mueller
Sitz: Unterfoehring * Amtsgericht Muenchen * HRB 135082

Reply all
Reply to author
Forward
0 new messages