diff mbox

[i-g-t,v5] tests: install test programs to libexec

Message ID 1427806397.21482.1.camel@jlahtine-mobl1 (mailing list archive)
State New, archived
Headers show

Commit Message

Joonas Lahtinen March 31, 2015, 12:53 p.m. UTC
Install the test programs by default so that they can be packaged.

Tested with the testdisplay test so that it still runs after the
modifications as it depends on a data file to be present. Need to
pass -r option to enable QR code display on success (PNG data file).

Packaging is useful when building a complete software stack for a
DUT from scratch. This should bring us closer to achieving a
built-from-scratch testing workflow.

Package maintainers can always decide to ignore the installed files.

v2:
- Install more tests including scripts and their data

v3:
- Add clarification to commit message about why we do this.
  (Chris Wilson & Thomas Wood)
- Change libexec into pkglibexec to comply to standard
  (Thomas Wood)
- Do not install $(common_files). (Thomas Wood)
- Make it really obvious the installed files are tests by using
  tests directory name to avoid any confusion with packagers.

v4:
- Fixed commit message.

v5:
- Add file locator helper to retain backwards compatibility.
  (Thomas Wood)
- Test with testdisplay -r option that draws the .png file.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Wood <thomas.wood@intel.com>
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 lib/igt_core.c         | 16 ++++++++++++++++
 lib/igt_core.h         | 13 +++++++++++++
 tests/Makefile.am      | 22 +++++++++++++++++++---
 tests/Makefile.sources | 16 ++++++++++++++--
 tests/testdisplay.c    | 21 +++++++++++++++++++--
 5 files changed, 81 insertions(+), 7 deletions(-)

Comments

Thomas Wood April 2, 2015, 4:43 p.m. UTC | #1
On 31 March 2015 at 13:53, Joonas Lahtinen
<joonas.lahtinen@linux.intel.com> wrote:
> Install the test programs by default so that they can be packaged.
>
> Tested with the testdisplay test so that it still runs after the
> modifications as it depends on a data file to be present. Need to
> pass -r option to enable QR code display on success (PNG data file).
>
> Packaging is useful when building a complete software stack for a
> DUT from scratch. This should bring us closer to achieving a
> built-from-scratch testing workflow.
>
> Package maintainers can always decide to ignore the installed files.
>
> v2:
> - Install more tests including scripts and their data
>
> v3:
> - Add clarification to commit message about why we do this.
>   (Chris Wilson & Thomas Wood)
> - Change libexec into pkglibexec to comply to standard
>   (Thomas Wood)
> - Do not install $(common_files). (Thomas Wood)
> - Make it really obvious the installed files are tests by using
>   tests directory name to avoid any confusion with packagers.
>
> v4:
> - Fixed commit message.
>
> v5:
> - Add file locator helper to retain backwards compatibility.
>   (Thomas Wood)
> - Test with testdisplay -r option that draws the .png file.


Thanks, patch merged.


>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Thomas Wood <thomas.wood@intel.com>
> Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> ---
>  lib/igt_core.c         | 16 ++++++++++++++++
>  lib/igt_core.h         | 13 +++++++++++++
>  tests/Makefile.am      | 22 +++++++++++++++++++---
>  tests/Makefile.sources | 16 ++++++++++++++--
>  tests/testdisplay.c    | 21 +++++++++++++++++++--
>  5 files changed, 81 insertions(+), 7 deletions(-)
>
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 783a219..8d60930 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -54,6 +54,7 @@
>  #include <errno.h>
>  #include <time.h>
>  #include <ctype.h>
> +#include <limits.h>
>
>  #include "drmtest.h"
>  #include "intel_chipset.h"
> @@ -1735,3 +1736,18 @@ void igt_set_timeout(unsigned int seconds)
>
>         alarm(seconds);
>  }
> +
> +FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
> +                      const char* filename)
> +{
> +       char path[PATH_MAX];
> +       FILE *fp;
> +
> +       snprintf(path, sizeof(path), "%s/%s", igt_datadir, filename);
> +       fp = fopen(path, "r");
> +       if (!fp) {
> +               snprintf(path, sizeof(path), "%s/%s", igt_srcdir, filename);
> +               fp = fopen(path, "r");
> +       }
> +       return fp;
> +}
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 33f8940..4e56be8 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -33,6 +33,7 @@
>  #include <setjmp.h>
>  #include <stdbool.h>
>  #include <stdlib.h>
> +#include <stdio.h>
>  #include <string.h>
>  #include <sys/types.h>
>  #include <stdarg.h>
> @@ -650,4 +651,16 @@ extern enum igt_log_level igt_log_level;
>
>  void igt_set_timeout(unsigned int seconds);
>
> +FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
> +                      const char* filename);
> +/**
> + * igt_fopen_data:
> + * @filename: filename to open.
> + *
> + * Open a datafile for test, first try from installation directory
> + * then from build directory.
> + */
> +#define igt_fopen_data(filename) \
> +       __igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename)
> +
>  #endif /* IGT_CORE_H */
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index f45c6c9..69c7c4e 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -27,8 +27,23 @@ multi-tests.txt: Makefile.sources
>         @echo ${multi_kernel_tests} >> $@
>         @echo END TESTLIST >> $@
>
> -EXTRA_PROGRAMS = $(TESTS_progs) $(TESTS_progs_M) $(HANG)
> -EXTRA_DIST = $(TESTS_scripts) $(TESTS_scripts_M) $(scripts) $(IMAGES) $(common_files)
> +igt_tests_bin_PROGRAMS += \
> +       $(TESTS_progs) \
> +       $(TESTS_progs_M) \
> +       $(NULL)
> +
> +igt_tests_bin_SCRIPTS += \
> +       $(TESTS_scripts) \
> +       $(TESTS_scripts_M) \
> +       $(scripts) \
> +       $(NULL)
> +
> +igt_tests_data_DATA += \
> +       $(IMAGES) \
> +       $(NULL)
> +
> +EXTRA_PROGRAMS = $(HANG)
> +EXTRA_DIST = $(common_files)
>
>  CLEANFILES = $(EXTRA_PROGRAMS) single-tests.txt multi-tests.txt
>
> @@ -36,7 +51,8 @@ AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) $(DEBUG_CFLAGS)\
>         -I$(srcdir)/.. \
>         -I$(srcdir)/../lib \
>         -include "$(srcdir)/../lib/check-ndebug.h" \
> -       -DIGT_DATADIR=\""$(abs_srcdir)"\" \
> +       -DIGT_SRCDIR=\""$(abs_srcdir)"\" \
> +       -DIGT_DATADIR=\""$(igt_tests_datadir)"\" \
>         $(LIBUNWIND_CFLAGS) \
>         $(NULL)
>
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 93e05e4..3e3aa57 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -1,10 +1,22 @@
> +igt_tests_bindir = $(pkglibexecdir)/tests
> +igt_tests_datadir = $(pkgdatadir)/tests
> +
>  noinst_PROGRAMS = \
> +       $(HANG) \
> +       $(TESTS_testsuite) \
> +       $(NULL)
> +
> +igt_tests_bin_PROGRAMS = \
>         gem_alive \
>         gem_stress \
>         $(TESTS_progs) \
>         $(TESTS_progs_M) \
> -       $(HANG) \
> -       $(TESTS_testsuite) \
> +       $(NULL)
> +
> +igt_tests_bin_SCRIPTS = \
> +       $(NULL)
> +
> +igt_tests_data_DATA = \
>         $(NULL)
>
>  NOUVEAU_TESTS_M = \
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index f864940..92ea08c 100644
> --- a/tests/testdisplay.c
> +++ b/tests/testdisplay.c
> @@ -68,6 +68,7 @@
>  #include "drmtest.h"
>  #include "testdisplay.h"
>  #include "igt_kms.h"
> +#include "igt_core.h"
>
>  #include <stdlib.h>
>  #include <signal.h>
> @@ -238,12 +239,21 @@ paint_color_key(struct igt_fb *fb_info)
>         munmap(fb_ptr, fb_info->size);
>  }
>
> +static cairo_status_t
> +stdio_read_func(void* closure, unsigned char* data, unsigned int size)
> +{
> +       if (fread (data, 1, size, (FILE*)closure) != size)
> +               return CAIRO_STATUS_READ_ERROR;
> +       return CAIRO_STATUS_SUCCESS;
> +}
> +
>  static void paint_image(cairo_t *cr, const char *file)
>  {
>         int img_x, img_y, img_w, img_h, img_w_o, img_h_o;
>         double img_w_scale, img_h_scale;
>
>         cairo_surface_t *image;
> +       FILE* fp;
>
>         img_y = height * (0.10 );
>         img_h = height * 0.08 * 4;
> @@ -251,7 +261,14 @@ static void paint_image(cairo_t *cr, const char *file)
>
>         img_x = (width / 2) - (img_w / 2);
>
> -       image = cairo_image_surface_create_from_png(file);
> +       fp = igt_fopen_data(file);
> +       if (!fp) {
> +                igt_warn("data file \'%s\' missing: %s\n",
> +                        file, strerror(errno));
> +                return;
> +       }
> +       image = cairo_image_surface_create_from_png_stream(&stdio_read_func,
> +                                                          (void*)fp);
>
>         img_w_o = cairo_image_surface_get_width(image);
>         img_h_o = cairo_image_surface_get_height(image);
> @@ -318,7 +335,7 @@ static void paint_output_info(struct connector *c, struct igt_fb *fb)
>         }
>
>         if (qr_code)
> -               paint_image(cr, IGT_DATADIR"/pass.png");
> +               paint_image(cr, "pass.png");
>
>         igt_assert(!cairo_status(cr));
>
> --
> 1.9.3
diff mbox

Patch

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 783a219..8d60930 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -54,6 +54,7 @@ 
 #include <errno.h>
 #include <time.h>
 #include <ctype.h>
+#include <limits.h>
 
 #include "drmtest.h"
 #include "intel_chipset.h"
@@ -1735,3 +1736,18 @@  void igt_set_timeout(unsigned int seconds)
 
 	alarm(seconds);
 }
+
+FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
+		       const char* filename)
+{
+	char path[PATH_MAX];
+	FILE *fp;
+
+	snprintf(path, sizeof(path), "%s/%s", igt_datadir, filename);
+	fp = fopen(path, "r");
+	if (!fp) {
+		snprintf(path, sizeof(path), "%s/%s", igt_srcdir, filename);
+		fp = fopen(path, "r");
+	}
+	return fp;
+}
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 33f8940..4e56be8 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -33,6 +33,7 @@ 
 #include <setjmp.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 #include <stdarg.h>
@@ -650,4 +651,16 @@  extern enum igt_log_level igt_log_level;
 
 void igt_set_timeout(unsigned int seconds);
 
+FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
+		       const char* filename);
+/**
+ * igt_fopen_data:
+ * @filename: filename to open.
+ *
+ * Open a datafile for test, first try from installation directory
+ * then from build directory.
+ */
+#define igt_fopen_data(filename) \
+	__igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename)
+
 #endif /* IGT_CORE_H */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f45c6c9..69c7c4e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,8 +27,23 @@  multi-tests.txt: Makefile.sources
 	@echo ${multi_kernel_tests} >> $@
 	@echo END TESTLIST >> $@
 
-EXTRA_PROGRAMS = $(TESTS_progs) $(TESTS_progs_M) $(HANG)
-EXTRA_DIST = $(TESTS_scripts) $(TESTS_scripts_M) $(scripts) $(IMAGES) $(common_files)
+igt_tests_bin_PROGRAMS += \
+	$(TESTS_progs) \
+	$(TESTS_progs_M) \
+	$(NULL)
+
+igt_tests_bin_SCRIPTS += \
+	$(TESTS_scripts) \
+	$(TESTS_scripts_M) \
+	$(scripts) \
+	$(NULL)
+
+igt_tests_data_DATA += \
+	$(IMAGES) \
+	$(NULL)
+
+EXTRA_PROGRAMS = $(HANG)
+EXTRA_DIST = $(common_files)
 
 CLEANFILES = $(EXTRA_PROGRAMS) single-tests.txt multi-tests.txt
 
@@ -36,7 +51,8 @@  AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) $(DEBUG_CFLAGS)\
 	-I$(srcdir)/.. \
 	-I$(srcdir)/../lib \
 	-include "$(srcdir)/../lib/check-ndebug.h" \
-	-DIGT_DATADIR=\""$(abs_srcdir)"\" \
+	-DIGT_SRCDIR=\""$(abs_srcdir)"\" \
+	-DIGT_DATADIR=\""$(igt_tests_datadir)"\" \
 	$(LIBUNWIND_CFLAGS) \
 	$(NULL)
 
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 93e05e4..3e3aa57 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -1,10 +1,22 @@ 
+igt_tests_bindir = $(pkglibexecdir)/tests
+igt_tests_datadir = $(pkgdatadir)/tests
+
 noinst_PROGRAMS = \
+	$(HANG) \
+	$(TESTS_testsuite) \
+	$(NULL)
+
+igt_tests_bin_PROGRAMS = \
 	gem_alive \
 	gem_stress \
 	$(TESTS_progs) \
 	$(TESTS_progs_M) \
-	$(HANG) \
-	$(TESTS_testsuite) \
+	$(NULL)
+
+igt_tests_bin_SCRIPTS = \
+	$(NULL)
+
+igt_tests_data_DATA = \
 	$(NULL)
 
 NOUVEAU_TESTS_M = \
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index f864940..92ea08c 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -68,6 +68,7 @@ 
 #include "drmtest.h"
 #include "testdisplay.h"
 #include "igt_kms.h"
+#include "igt_core.h"
 
 #include <stdlib.h>
 #include <signal.h>
@@ -238,12 +239,21 @@  paint_color_key(struct igt_fb *fb_info)
 	munmap(fb_ptr, fb_info->size);
 }
 
+static cairo_status_t
+stdio_read_func(void* closure, unsigned char* data, unsigned int size)
+{
+	if (fread (data, 1, size, (FILE*)closure) != size)
+		return CAIRO_STATUS_READ_ERROR;
+	return CAIRO_STATUS_SUCCESS;
+}
+
 static void paint_image(cairo_t *cr, const char *file)
 {
 	int img_x, img_y, img_w, img_h, img_w_o, img_h_o;
 	double img_w_scale, img_h_scale;
 
 	cairo_surface_t *image;
+	FILE* fp;
 
 	img_y = height * (0.10 );
 	img_h = height * 0.08 * 4;
@@ -251,7 +261,14 @@  static void paint_image(cairo_t *cr, const char *file)
 
 	img_x = (width / 2) - (img_w / 2);
 
-	image = cairo_image_surface_create_from_png(file);
+	fp = igt_fopen_data(file);
+	if (!fp) {
+                igt_warn("data file \'%s\' missing: %s\n",
+		         file, strerror(errno));
+                return;
+	}
+	image = cairo_image_surface_create_from_png_stream(&stdio_read_func,
+							   (void*)fp);
 
 	img_w_o = cairo_image_surface_get_width(image);
 	img_h_o = cairo_image_surface_get_height(image);
@@ -318,7 +335,7 @@  static void paint_output_info(struct connector *c, struct igt_fb *fb)
 	}
 
 	if (qr_code)
-		paint_image(cr, IGT_DATADIR"/pass.png");
+		paint_image(cr, "pass.png");
 
 	igt_assert(!cairo_status(cr));