Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make autotools tests read files?

my autotools project has a couple of unit-tests. one of these tests (filereader) needs to read a file (data/test1.bin)

Here's my filesystem layout: - libfoo/tests/filereader.c - libfoo/tests/data/test1.bin

and my libfoo/tests/Makefile.am:

AUTOMAKE_OPTIONS = foreign
AM_CPPFLAGS = -I$(top_srcdir)/foo
LDADD = $(top_builddir)/src/libfoo.la

EXTRA_DIST = data/file1.bin

TESTS = filereader
check_PROGRAMS= filereader
filereader_SOURCES = filereader.c

this works great, as long as i do in-tree builds. However, when running the test-suite out-of-tree (e.g. make distcheck), the filereader test cannot find the input file anymore.

This is obviously because only the source tree contains the input file, but not the build tree.

i wonder what is the canonical way to fix this problem?

  • compile the directory of the test-file into the unittest (AM_CPPFLAGS+=-DSRCDIR=$(srcdir))
  • pass the qualified input file as a cmdline argument to the test? (e.g. $(builddir)/filereader $(srcdir)/data/file1.bin)
  • copy the input file from the source tree to the build tree? (cp $(srcdir)/data/file1.bin $(builddir)/data/file1.bin? how would a proper make-rule look like??)
like image 706
umläute Avatar asked Oct 30 '22 04:10

umläute


1 Answers

Canonically, the solution would be to define the path to your file into the unittest, so the first option you laid out. The second one is also possible but it requires using an in-between driver script.

I would suggest avoiding the third one, but if you do want to go down that route, use $(LN_S) rather than cp; this way you reduce the I/O load of the test.

like image 113
Diego Elio Pettenò Avatar answered Nov 08 '22 14:11

Diego Elio Pettenò