Skip to content

Instantly share code, notes, and snippets.

@wjt
Created November 3, 2017 11:26
Show Gist options
  • Save wjt/e938937829432572111d04a82c549336 to your computer and use it in GitHub Desktop.
Save wjt/e938937829432572111d04a82c549336 to your computer and use it in GitHub Desktop.
diff --git a/Makefile.am b/Makefile.am
index cd10f5b..d5b3636 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,10 +9,14 @@ SUBDIRS = \
po \
data \
eos-installer-data \
- tests
+ tests \
+ $(NULL)
EXTRA_DIST = \
autogen.sh \
+ buildutil/glib-tap.mk \
+ buildutil/glibtests.m4 \
+ buildutil/tap-test \
COPYING \
AUTHORS \
NEWS \
diff --git a/buildutil/glib-tap.mk b/buildutil/glib-tap.mk
index e98e5cc..a81e65e 100644
--- a/buildutil/glib-tap.mk
+++ b/buildutil/glib-tap.mk
@@ -8,7 +8,8 @@ AM_TESTS_ENVIRONMENT= \
MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
# Modified from upstream: added 'build-aux' subdirectory
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
-LOG_COMPILER = $(top_srcdir)/tap-test
+# Modified from upstream: added 'buildutil' subdirectory
+LOG_COMPILER = $(top_srcdir)/buildutil/tap-test
NULL =
diff --git a/buildutil/tap-test b/buildutil/tap-test
new file mode 100755
index 0000000..e35f2a4
--- /dev/null
+++ b/buildutil/tap-test
@@ -0,0 +1,39 @@
+#! /bin/bash
+#
+# Run a test in tap mode, ensuring we have a temporary directory. We
+# always use /var/tmp becuase we might want to use user xattrs, which
+# aren't available on tmpfs.
+#
+# The test binary is passed as $1
+
+srcd=$(cd $(dirname $1) && pwd)
+bn=$(basename $1)
+TEST_TMPDIR=${TEST_TMPDIR:-/var/tmp}
+tempdir=$(mktemp -d $TEST_TMPDIR/tap-test.XXXXXX)
+touch ${tempdir}/.testtmp
+function cleanup () {
+ if test -f ${tempdir}/.testtmp; then
+ rm "${tempdir}" -rf
+ fi
+}
+function skip_cleanup() {
+ echo "Skipping cleanup of ${tempdir}"
+}
+cd ${tempdir}
+timeout \
+ --kill-after=60 \
+ --signal=ABRT \
+ $(( 600 * ${TEST_TIMEOUT_FACTOR:-1} )) \
+ ${srcd}/${bn} -k --tap
+rc=$?
+case "${TEST_SKIP_CLEANUP:-}" in
+ no|"") cleanup ;;
+ err)
+ if test $rc != 0; then
+ skip_cleanup
+ else
+ cleanup
+ fi ;;
+ *) skip_cleanup ;;
+esac
+exit $rc
diff --git a/configure.ac b/configure.ac
index d5a8a7b..4e944ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,7 +57,7 @@ PKG_CHECK_MODULES(INITIAL_SETUP,
evince-document-3.0
webkit2gtk-4.0)
-PKG_CHECK_MODULES(LIBGLNX, gio-unix-2.0 >= $GLIB_REQUIRED_VERSION)
+PKG_CHECK_MODULES([LIBGLNX], [gio-unix-2.0 >= $GLIB_REQUIRED_VERSION])
PKG_CHECK_MODULES(COPY_WORKER, gio-2.0 gnome-keyring-1)
diff --git a/ext/Makefile.am b/ext/Makefile.am
index 5c7dbc3..eed5330 100644
--- a/ext/Makefile.am
+++ b/ext/Makefile.am
@@ -1,7 +1,4 @@
-EXTRA_DIST =
-TESTS =
-check_PROGRAMS =
-noinst_LTLIBRARIES =
+include $(top_srcdir)/buildutil/glib-tap.mk
libglnx_srcpath := $(srcdir)/libglnx
libglnx_cflags := $(LIBGLNX_CFLAGS) "-I$(libglnx_srcpath)"
@@ -12,6 +9,3 @@ libglnx/Makefile-libglnx.am.inc: libglnx/Makefile-libglnx.am
include libglnx/Makefile-libglnx.am.inc
EXTRA_DIST += libglnx/Makefile-libglnx.am
noinst_LTLIBRARIES += libglnx.la
-
-# Disable libglnx tests for now
-TESTS =
diff --git a/ext/libglnx b/ext/libglnx
index 4577dc8..016ea91 160000
--- a/ext/libglnx
+++ b/ext/libglnx
@@ -1 +1 @@
-Subproject commit 4577dc826a923d976ad1a98b4ed5ecc36eac6efe
+Subproject commit 016ea9168b1c372f9a09063245f9aab74434616f
diff --git a/gnome-image-installer/Makefile.am b/gnome-image-installer/Makefile.am
index 38a1b5a..138567a 100644
--- a/gnome-image-installer/Makefile.am
+++ b/gnome-image-installer/Makefile.am
@@ -36,7 +36,7 @@ gnome_image_installer_SOURCES = \
gnome-image-installer.c gnome-image-installer.h
gnome_image_installer_LDADD = \
- $(top_srcdir)/ext/libglnx.la \
+ $(top_builddir)/ext/libglnx.la \
util/libgiiutil.la \
$(gisdir)/libgisutil.la \
$(gisdir)/pages/language/libgislanguage.la \
diff --git a/gnome-image-installer/pages/install/gis-scribe.c b/gnome-image-installer/pages/install/gis-scribe.c
index ffdd66d..1453c78 100644
--- a/gnome-image-installer/pages/install/gis-scribe.c
+++ b/gnome-image-installer/pages/install/gis-scribe.c
@@ -32,6 +32,7 @@
#include "glnx-errors.h"
#define IMAGE_KEYRING "/usr/share/keyrings/eos-image-keyring.gpg"
+#define BUFFER_SIZE (1 * 1024 * 1024)
typedef struct _GisScribe {
GObject parent;
@@ -41,7 +42,6 @@ typedef struct _GisScribe {
GFile *signature;
gchar *keyring_path;
gchar *drive_path;
- gint drive_fd;
gboolean convert_to_mbr;
gboolean started;
@@ -61,17 +61,17 @@ typedef struct _GisScribe {
* either immutable, not touched by the worker thread, or not touched from
* the main thread while the worker thread is running.
*/
+ gint drive_fd;
guint64 bytes_written;
guint set_indeterminate_progress_id;
} GisScribe;
-G_DEFINE_QUARK(install-error, gis_install_error);
+G_DEFINE_QUARK (install-error, gis_install_error)
-G_DEFINE_TYPE (GisScribe, gis_scribe, G_TYPE_OBJECT);
+G_DEFINE_TYPE (GisScribe, gis_scribe, G_TYPE_OBJECT)
-enum {
- PROP_0,
- PROP_IMAGE,
+typedef enum {
+ PROP_IMAGE = 1,
PROP_IMAGE_SIZE,
PROP_SIGNATURE,
PROP_KEYRING_PATH,
@@ -81,7 +81,7 @@ enum {
PROP_STEP,
PROP_PROGRESS,
N_PROPERTIES
-};
+} GisScribePropertyId;
static GParamSpec *props[N_PROPERTIES] = { 0 };
@@ -93,7 +93,7 @@ gis_scribe_set_property (GObject *object,
{
GisScribe *self = GIS_SCRIBE (object);
- switch (property_id)
+ switch ((GisScribePropertyId) property_id)
{
case PROP_IMAGE:
g_clear_object (&self->image);
@@ -129,6 +129,9 @@ gis_scribe_set_property (GObject *object,
self->convert_to_mbr = g_value_get_boolean (value);
break;
+ case PROP_STEP:
+ case PROP_PROGRESS:
+ case N_PROPERTIES:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -143,7 +146,7 @@ gis_scribe_get_property (GObject *object,
{
GisScribe *self = GIS_SCRIBE (object);
- switch (property_id)
+ switch ((GisScribePropertyId) property_id)
{
case PROP_IMAGE:
g_value_set_object (value, self->image);
@@ -181,6 +184,7 @@ gis_scribe_get_property (GObject *object,
g_value_set_double (value, self->progress);
break;
+ case N_PROPERTIES:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -208,6 +212,7 @@ gis_scribe_dispose (GObject *object)
g_clear_object (&self->image);
g_clear_object (&self->signature);
+ g_clear_object (&self->decompressed);
G_OBJECT_CLASS (gis_scribe_parent_class)->dispose (object);
}
@@ -269,7 +274,7 @@ gis_scribe_class_init (GisScribeClass *klass)
/* Providing both the path and the fd seems redundant. However: in the app
* proper, we open the fd using udisks so we can write to it as an
- * unpriveleged user, but also need to be able to run a script on the device,
+ * unprivileged user, but also need to be able to run a script on the device,
* elevated with pkexec.
*
* Why not accept a UDisksBlock and perform this step internally? It's
@@ -388,9 +393,8 @@ gis_scribe_write_thread_copy (GisScribe *self,
GCancellable *cancellable,
GError **error)
{
- gssize buffer_size = 1 * 1024 * 1024;
- g_autofree gchar *buffer = g_malloc0 (buffer_size);
- g_autofree gchar *first_mib = g_malloc0 (buffer_size);
+ g_autofree gchar *buffer = g_malloc0 (BUFFER_SIZE);
+ g_autofree gchar *first_mib = g_malloc0 (BUFFER_SIZE);
gsize first_mib_bytes_read = 0;
gssize r = -1;
gsize w = 0;
@@ -398,15 +402,15 @@ gis_scribe_write_thread_copy (GisScribe *self,
/* Read the first 1 MiB; write zeros to the target drive. This ensures the
* system won't boot until the image is fully written.
*/
- if (!g_output_stream_write_all (output, first_mib, buffer_size,
+ if (!g_output_stream_write_all (output, first_mib, BUFFER_SIZE,
&w, cancellable, error)
- || !g_input_stream_read_all (self->decompressed, first_mib, buffer_size,
+ || !g_input_stream_read_all (self->decompressed, first_mib, BUFFER_SIZE,
&first_mib_bytes_read, cancellable, error))
return FALSE;
do
{
- r = g_input_stream_read (self->decompressed, buffer, buffer_size,
+ r = g_input_stream_read (self->decompressed, buffer, BUFFER_SIZE,
cancellable, error);
if (r < 0)
@@ -459,7 +463,7 @@ static gboolean
gis_scribe_convert_to_mbr (GisScribe *self,
GError **error)
{
- static const char *cmd = "/usr/sbin/eos-repartition-mbr";
+ const char *cmd = "/usr/sbin/eos-repartition-mbr";
g_autoptr(GSubprocessLauncher) launcher = NULL;
g_autoptr(GSubprocess) process = NULL;
@@ -780,7 +784,7 @@ gis_scribe_write_async (GisScribe *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GTask *task = g_task_new (self, cancellable, callback, user_data);
+ g_autoptr(GTask) task = g_task_new (self, cancellable, callback, user_data);
if (self->started)
{
@@ -789,7 +793,7 @@ gis_scribe_write_async (GisScribe *self,
else
{
self->started = TRUE;
- gis_scribe_begin_verify (self, task);
+ gis_scribe_begin_verify (self, g_steal_pointer (&task));
}
}
diff --git a/tap-test b/tap-test
deleted file mode 100644
index 481e333..0000000
--- a/tap-test
+++ /dev/null
@@ -1,5 +0,0 @@
-#! /bin/sh
-
-# run a GTest in tap mode. The test binary is passed as $1
-
-$1 -k --tap
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 39b3d8b..bdb2ec7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,6 +22,8 @@ test_data = \
w.truncated.gz.asc \
$(NULL)
+CLEANFILES += $(test_data)
+
# "OS image" consisting of the same byte repeated to 4 MiB
w.img:
$(AM_V_GEN) python3 -c 'print("w" * (2 ** 22), end="")' > $@
@@ -42,15 +44,19 @@ w.img:
test_scribe_SOURCES = test-scribe.c
test_scribe_CFLAGS = \
- $(INITIAL_SETUP_CFLAGS) \
- $(IMAGE_INSTALLER_CFLAGS) \
- -I $(top_srcdir)/ext/libglnx \
- -I"$(top_srcdir)/gnome-image-installer/pages/install" \
- $(WARN_CFLAGS)
+ $(INITIAL_SETUP_CFLAGS) \
+ $(IMAGE_INSTALLER_CFLAGS) \
+ -I $(top_srcdir)/ext/libglnx \
+ -I $(top_srcdir)/gnome-image-installer/pages/install \
+ $(WARN_CFLAGS) \
+ $(NULL)
test_scribe_LDADD = \
- $(INITIAL_SETUP_LIBS) \
- $(IMAGE_INSTALLER_LIBS) \
- $(top_builddir)/ext/libglnx.la \
- $(top_builddir)/gnome-image-installer/pages/install/libgisinstall.la \
- -llzma \
- $(WARN_LDFLAGS)
+ $(INITIAL_SETUP_LIBS) \
+ $(IMAGE_INSTALLER_LIBS) \
+ $(top_builddir)/ext/libglnx.la \
+ $(top_builddir)/gnome-image-installer/pages/install/libgisinstall.la \
+ -llzma \
+ $(NULL)
+test_scribe_LDFLAGS = \
+ $(WARN_LDFLAGS) \
+ $(NULL)
diff --git a/tests/sign-file b/tests/sign-file
index 4cb5cc9..ab2ab89 100755
--- a/tests/sign-file
+++ b/tests/sign-file
@@ -1,8 +1,24 @@
#!/usr/bin/env python3
+# vim: tw=79
+# Copyright © 2017 Endless Mobile, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
import argparse
import os
import subprocess
-import sys
import tempfile
@@ -34,7 +50,8 @@ def main():
with tempfile.TemporaryDirectory() as gnupghome:
cmd("gpg", "--batch", "--homedir", gnupghome, "--import", a.privkey)
- cmd("gpg", "--batch", "--homedir", gnupghome, "--detach-sign", "--armor", a.file)
+ cmd("gpg", "--batch", "--homedir", gnupghome, "--detach-sign",
+ "--armor", a.file)
cmd("gpgconf", "--homedir", gnupghome, "--kill", "gpg-agent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment