From e90315097198f6fb06236dbccccb46e29db9ecae Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 22 Jul 2019 15:22:17 +0200 Subject: [PATCH 1/5] Enable tests, fixing the existing ones to use the current API This also involved building a static library for the application for tests to link to. The main application executable also links to it. --- meson.build | 7 +++++- meson_options.txt | 9 +++++++- src/meson.build | 23 +++++++++++++++---- tests/eek-simple-test.c | 5 ++--- tests/eek-xml-test.c | 5 +++-- tests/meson.build | 49 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 tests/meson.build diff --git a/meson.build b/meson.build index ff12a382..1165b33f 100644 --- a/meson.build +++ b/meson.build @@ -4,7 +4,11 @@ project( version: '1.0.10', license: 'GPLv3', meson_version: '>=0.49.0', - default_options: [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ], + default_options: [ + 'warning_level=1', + 'buildtype=debugoptimized', + 'c_std=gnu11' + ] ) i18n = import('i18n') @@ -43,3 +47,4 @@ subdir('protocols') subdir('eek') subdir('src') subdir('po') +subdir('tests') diff --git a/meson_options.txt b/meson_options.txt index b74814dd..339e1ba3 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,8 @@ -option('depdatadir', type : 'string', value : '', description : 'System data path. Will be searched for definitions instead of datadir when provided') +option('depdatadir', + type : 'string', + value : '', + description : 'System data path. Will be searched for definitions instead of datadir when provided') + +option('tests', + type: 'boolean', value: true, + description: 'Whether to compile unit tests') diff --git a/src/meson.build b/src/meson.build index fefe5a80..271153b2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,13 +4,16 @@ dbus_src = gnome.gdbus_codegen( join_paths(meson.source_root() / 'data' / 'dbus', 'sm.puri.OSK0.xml') ) -config_h = configure_file(input: 'config.h.in', output: 'config.h',configuration: conf_data) +config_h = configure_file( + input: 'config.h.in', + output: 'config.h', + configuration: conf_data +) sources = [ config_h, 'imservice.c', 'server-context-service.c', - 'server-main.c', 'wayland.c', '../eek/eek.c', '../eek/eek-container.c', @@ -71,11 +74,24 @@ rslib = static_library( rust_crate_type: 'staticlib' ) -squeekboard = executable('squeekboard', +libsqueekboard = static_library('libsqueekboard', sources, link_with: rslib, include_directories: [include_directories('..'), include_directories('../eek')], dependencies: deps, + c_args: [ + '-DTHEMESDIR="' + pkgdatadir + '/themes"', + '-DKEYBOARDSDIR="' + pkgdatadir + '/keyboards"', + '-DEEKBOARD_COMPILATION=1', + '-DEEK_COMPILATION=1'], +) + +squeekboard = executable('squeekboard', + 'server-main.c', + wl_proto_sources, + link_with: libsqueekboard, + include_directories: [include_directories('..'), include_directories('../eek')], + dependencies: deps, install: true, c_args: [ '-DTHEMESDIR="' + pkgdatadir + '/themes"', @@ -83,4 +99,3 @@ squeekboard = executable('squeekboard', '-DEEKBOARD_COMPILATION=1', '-DEEK_COMPILATION=1'], ) - diff --git a/tests/eek-simple-test.c b/tests/eek-simple-test.c index b2597b7c..1a2e1f6a 100644 --- a/tests/eek-simple-test.c +++ b/tests/eek-simple-test.c @@ -30,16 +30,15 @@ test_create (void) section = eek_keyboard_create_section (keyboard); g_assert (EEK_IS_SECTION(section)); eek_section_add_row (section, 2, EEK_ORIENTATION_HORIZONTAL); - key0 = eek_section_create_key (section, 1, 0, 0); + key0 = eek_section_create_key (section, "key0", 1, 0, 0); g_assert (EEK_IS_KEY(key0)); - key1 = eek_section_create_key (section, 2, 1, 0); + key1 = eek_section_create_key (section, "key1", 2, 1, 0); g_assert (EEK_IS_KEY(key1)); } int main (int argc, char **argv) { - g_type_init (); g_test_init (&argc, &argv, NULL); g_test_add_func ("/eek-simple-test/create", test_create); return g_test_run (); diff --git a/tests/eek-xml-test.c b/tests/eek-xml-test.c index 0ed814e4..a130aa3f 100644 --- a/tests/eek-xml-test.c +++ b/tests/eek-xml-test.c @@ -36,7 +36,9 @@ test_output_parse (void) layout = eek_xml_layout_new ("us", &error); g_assert_no_error (error); - keyboard = eek_keyboard_new (layout, 640, 480); + /* We don't need the context service to parse an XML file, so we can pass + NULL when creating a keyboard. */ + keyboard = eek_keyboard_new (NULL, layout, 640, 480); g_object_unref (layout); g_object_unref (keyboard); } @@ -44,7 +46,6 @@ test_output_parse (void) int main (int argc, char **argv) { - g_type_init (); g_test_init (&argc, &argv, NULL); gtk_init (&argc, &argv); /* for gdk_x11_display_get_xdisplay() */ diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..9dfe7162 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,49 @@ +if get_option('tests') + +test_env = [ + 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()), + 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()), + 'G_DEBUG=gc-friendly,fatal-warnings', + 'GSETTINGS_BACKEND=memory', + 'MALLOC_CHECK_=2' +] + +test_cflags = [ + '-I@0@/../src'.format(meson.current_source_dir()), + '-I@0@/../src'.format(meson.current_build_dir()), + '-DEEK_COMPILATION', + '-DEEKBOARD_COMPILATION' +] + +test_link_args = [ + '-fPIC', +] + +tests = [ + 'eek-simple-test', + 'eek-xml-test' +] + +foreach name : tests + + test_sources = [name + '.c'] + + t = executable( + name, + test_sources, + squeekboard_resources, + link_with: libsqueekboard, + c_args : test_cflags, + link_args: test_link_args, + dependencies: deps, # from src/meson.build + include_directories: [ + include_directories('..'), + include_directories('../eek') + ] + ) + + test(name, t, env: test_env) + +endforeach + +endif From 2391947b3496899bd0bbdb245f6896faae89f1f6 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 22 Jul 2019 19:31:43 +0200 Subject: [PATCH 2/5] Update CI configuration to enable tests --- .gitlab-ci.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1eedd1d2..1cadc9d2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,16 +2,29 @@ image: debian:buster stages: - build + - test + +.tags: &tags + tags: + - librem5 before_script: - apt-get -y update - apt-get -y build-dep . build_meson: + <<: *tags stage: build - tags: - - librem5 script: - meson . _build/ -Ddepdatadir=/usr/share - ninja -C _build install +test: + <<: *tags + stage: test + dependencies: + - build_meson + script: + - export LC_ALL=C.UTF-8 + - ninja -C _build test + From 9b10f56ba6e79435351bac4e25b3b515dfe1f65b Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 22 Jul 2019 20:35:18 +0200 Subject: [PATCH 3/5] Keep the build directory as an artifact --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1cadc9d2..77832675 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,9 @@ before_script: build_meson: <<: *tags stage: build + artifacts: + paths: + - _build script: - meson . _build/ -Ddepdatadir=/usr/share - ninja -C _build install From aff71e0e3348e1e1f6c6ed63811186612c38878f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 23 Jul 2019 10:10:36 +0200 Subject: [PATCH 4/5] debian: Add test run dependencies We need xvfb to run the tests since this involves creating GTK widgets. --- debian/control | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index b4d16a57..ec86951a 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,10 @@ Build-Depends: libcroco3-dev, libwayland-dev (>= 1.16), rustc, - wayland-protocols (>= 1.14) + wayland-protocols (>= 1.14), +# for running the tests + xvfb, + xauth, Standards-Version: 4.1.3 Homepage: https://source.puri.sm/Librem5/squeekboard From 79dce7c4c3951277fdf7b11a5fbb85ffc18a9be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 23 Jul 2019 10:11:36 +0200 Subject: [PATCH 5/5] gitlab-ci: Run tests under xvfb We create widgets so need a display. --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 77832675..3dce6ad5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,4 @@ test: dependencies: - build_meson script: - - export LC_ALL=C.UTF-8 - - ninja -C _build test - + - xvfb-run -s -noreset ninja -C _build test