@@ -275,6 +275,8 @@ AC_CONFIG_FILES([Makefile
tools/Makefile
tests/Makefile
tests/gpiosim/Makefile
+ tests/gpiosim-glib/Makefile
+ tests/harness/Makefile
bindings/cxx/libgpiodcxx.pc
bindings/Makefile
bindings/cxx/Makefile
@@ -1,25 +1,23 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2017-2022 Bartosz Golaszewski <brgl@bgdev.pl>
-SUBDIRS = gpiosim
+SUBDIRS = gpiosim gpiosim-glib harness
-AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/tests/gpiosim/
+AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/tests/gpiosim-glib/
+AM_CFLAGS += -I$(top_srcdir)/tests/harness/
AM_CFLAGS += -include $(top_builddir)/config.h
AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS) $(GIO_CFLAGS)
AM_CFLAGS += -DG_LOG_DOMAIN=\"gpiod-test\"
LDADD = $(top_builddir)/lib/libgpiod.la
LDADD += $(top_builddir)/tests/gpiosim/libgpiosim.la
+LDADD += $(top_builddir)/tests/gpiosim-glib/libgpiosim-glib.la
+LDADD += $(top_builddir)/tests/harness/libgpiod-test-harness.la
LDADD += $(GLIB_LIBS) $(GIO_LIBS)
noinst_PROGRAMS = gpiod-test
gpiod_test_SOURCES = \
- gpiod-test.c \
- gpiod-test.h \
- gpiod-test-helpers.c \
- gpiod-test-helpers.h \
- gpiod-test-sim.c \
- gpiod-test-sim.h \
+ helpers.h \
tests-chip.c \
tests-chip-info.c \
tests-edge-event.c \
deleted file mode 100644
@@ -1,41 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* SPDX-FileCopyrightText: 2017-2022 Bartosz Golaszewski <brgl@bgdev.pl> */
-
-/*
- * Testing framework for the core library.
- *
- * This file contains functions and definitions extending the GLib unit testing
- * framework with functionalities necessary to test the libgpiod core C API as
- * well as the kernel-to-user-space interface.
- */
-
-#include "gpiod-test-helpers.h"
-
-GVariant *
-gpiod_test_package_line_names(const GPIOSimLineName *names)
-{
- g_autoptr(GVariantBuilder) builder = NULL;
- const GPIOSimLineName *name;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(us)"));
-
- for (name = &names[0]; name->name; name++)
- g_variant_builder_add(builder, "(us)",
- name->offset, name->name);
-
- return g_variant_ref_sink(g_variant_new("a(us)", builder));
-}
-
-GVariant *gpiod_test_package_hogs(const GPIOSimHog *hogs)
-{
- g_autoptr(GVariantBuilder) builder = NULL;
- const GPIOSimHog *hog;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(usi)"));
-
- for (hog = &hogs[0]; hog->name; hog++)
- g_variant_builder_add(builder, "(usi)",
- hog->offset, hog->name, hog->direction);
-
- return g_variant_ref_sink(g_variant_new("a(usi)", builder));
-}
new file mode 100644
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
+
+noinst_LTLIBRARIES = libgpiosim-glib.la
+libgpiosim_glib_la_SOURCES = \
+ gpiosim-glib.c \
+ gpiosim-glib.h
+
+AM_CFLAGS = -I$(top_srcdir)/tests/gpiosim/
+AM_CFLAGS += -include $(top_builddir)/config.h
+AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS) $(GIO_CFLAGS)
+AM_CFLAGS += -DG_LOG_DOMAIN=\"gpiosim-glib\"
+libgpiosim_glib_la_LDFLAGS = -lgpiosim
similarity index 93%
rename from tests/gpiod-test-sim.c
rename to tests/gpiosim-glib/gpiosim-glib.c
@@ -6,7 +6,7 @@
#include <stdlib.h>
#include <unistd.h>
-#include "gpiod-test-sim.h"
+#include "gpiosim-glib.h"
G_DEFINE_QUARK(g-gpiosim-error, g_gpiosim_error);
@@ -462,3 +462,31 @@ void g_gpiosim_chip_set_pull(GPIOSimChip *chip, guint offset, GPIOSimPull pull)
g_critical("Unable to set the pull setting for simulated line: %s",
g_strerror(errno));
}
+
+GVariant *g_gpiosim_package_line_names(const GPIOSimLineName *names)
+{
+ g_autoptr(GVariantBuilder) builder = NULL;
+ const GPIOSimLineName *name;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(us)"));
+
+ for (name = &names[0]; name->name; name++)
+ g_variant_builder_add(builder, "(us)",
+ name->offset, name->name);
+
+ return g_variant_ref_sink(g_variant_new("a(us)", builder));
+}
+
+GVariant *g_gpiosim_package_hogs(const GPIOSimHog *hogs)
+{
+ g_autoptr(GVariantBuilder) builder = NULL;
+ const GPIOSimHog *hog;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(usi)"));
+
+ for (hog = &hogs[0]; hog->name; hog++)
+ g_variant_builder_add(builder, "(usi)",
+ hog->offset, hog->name, hog->direction);
+
+ return g_variant_ref_sink(g_variant_new("a(usi)", builder));
+}
similarity index 86%
rename from tests/gpiod-test-sim.h
rename to tests/gpiosim-glib/gpiosim-glib.h
@@ -74,6 +74,20 @@ void g_gpiosim_chip_set_pull(GPIOSimChip *self, guint offset, GPIOSimPull pull);
_val; \
})
+typedef struct {
+ guint offset;
+ const gchar *name;
+} GPIOSimLineName;
+
+typedef struct {
+ guint offset;
+ const gchar *name;
+ GPIOSimDirection direction;
+} GPIOSimHog;
+
+GVariant *g_gpiosim_package_line_names(const GPIOSimLineName *names);
+GVariant *g_gpiosim_package_hogs(const GPIOSimHog *hogs);
+
G_END_DECLS
#endif /* __GPIOD_TEST_SIM_H__ */
new file mode 100644
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
+
+noinst_LTLIBRARIES = libgpiod-test-harness.la
+libgpiod_test_harness_la_SOURCES = \
+ gpiod-test.c \
+ gpiod-test.h \
+ gpiod-test-common.h
+
+AM_CFLAGS = -include $(top_builddir)/config.h
+AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS)
+AM_CFLAGS += -DG_LOG_DOMAIN=\"gpiod-test\"
new file mode 100644
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl> */
+
+#ifndef __GPIOD_TEST_COMMON_H__
+#define __GPIOD_TEST_COMMON_H__
+
+#include <glib.h>
+
+#define gpiod_test_return_if_failed() \
+ do { \
+ if (g_test_failed()) \
+ return; \
+ } while (0)
+
+#define gpiod_test_join_thread_and_return_if_failed(_thread) \
+ do { \
+ if (g_test_failed()) { \
+ g_thread_join(_thread); \
+ return; \
+ } \
+ } while (0)
+
+#endif /* __GPIOD_TEST_COMMON_H__ */
similarity index 100%
rename from tests/gpiod-test.c
rename to tests/harness/gpiod-test.c
similarity index 100%
rename from tests/gpiod-test.h
rename to tests/harness/gpiod-test.h
similarity index 87%
rename from tests/gpiod-test-helpers.h
rename to tests/helpers.h
@@ -1,14 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl> */
+/* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <bartosz.golaszewski@linaro.org> */
#ifndef __GPIOD_TEST_HELPERS_H__
#define __GPIOD_TEST_HELPERS_H__
-#include <errno.h>
#include <glib.h>
#include <gpiod.h>
-
-#include "gpiod-test-sim.h"
+#include <gpiod-test-common.h>
/*
* These typedefs are needed to make g_autoptr work - it doesn't accept
@@ -49,20 +47,6 @@ typedef struct gpiod_edge_event_buffer struct_gpiod_edge_event_buffer;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_edge_event_buffer,
gpiod_edge_event_buffer_free);
-#define gpiod_test_return_if_failed() \
- do { \
- if (g_test_failed()) \
- return; \
- } while (0)
-
-#define gpiod_test_join_thread_and_return_if_failed(_thread) \
- do { \
- if (g_test_failed()) { \
- g_thread_join(_thread); \
- return; \
- } \
- } while (0)
-
#define gpiod_test_open_chip_or_fail(_path) \
({ \
struct gpiod_chip *_chip = gpiod_chip_open(_path); \
@@ -184,20 +168,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(struct_gpiod_edge_event_buffer,
} while (0)
#define gpiod_test_expect_errno(_expected) \
- g_assert_cmpint(_expected, ==, errno)
-
-typedef struct {
- guint offset;
- const gchar *name;
-} GPIOSimLineName;
-
-typedef struct {
- guint offset;
- const gchar *name;
- GPIOSimDirection direction;
-} GPIOSimHog;
-
-GVariant *gpiod_test_package_line_names(const GPIOSimLineName *names);
-GVariant *gpiod_test_package_hogs(const GPIOSimHog *hogs);
+ g_assert_cmpint((_expected), ==, errno)
#endif /* __GPIOD_TEST_HELPERS_H__ */
@@ -4,10 +4,11 @@
#include <errno.h>
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "chip-info"
@@ -4,10 +4,11 @@
#include <errno.h>
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "chip"
@@ -89,7 +90,7 @@ GPIOD_TEST_CASE(find_line_bad)
g_autoptr(GPIOSimChip) sim = NULL;
g_autoptr(struct_gpiod_chip) chip = NULL;
- g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
+ g_autoptr(GVariant) vnames = g_gpiosim_package_line_names(names);
sim = g_gpiosim_chip_new(
"num-lines", 8,
@@ -116,7 +117,7 @@ GPIOD_TEST_CASE(find_line_good)
g_autoptr(GPIOSimChip) sim = NULL;
g_autoptr(struct_gpiod_chip) chip = NULL;
- g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
+ g_autoptr(GVariant) vnames = g_gpiosim_package_line_names(names);
sim = g_gpiosim_chip_new(
"num-lines", 8,
@@ -142,7 +143,7 @@ GPIOD_TEST_CASE(find_line_duplicate)
g_autoptr(GPIOSimChip) sim = NULL;
g_autoptr(struct_gpiod_chip) chip = NULL;
- g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
+ g_autoptr(GVariant) vnames = g_gpiosim_package_line_names(names);
sim = g_gpiosim_chip_new(
"num-lines", 8,
@@ -165,7 +166,7 @@ GPIOD_TEST_CASE(find_line_non_standard_names)
{ }
};
- g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
+ g_autoptr(GVariant) vnames = g_gpiosim_package_line_names(names);
g_autoptr(GPIOSimChip) sim = g_gpiosim_chip_new("num-lines", 8,
"line-names", vnames,
NULL);
@@ -3,11 +3,12 @@
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
#include <poll.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "edge-event"
@@ -3,11 +3,12 @@
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
#include <poll.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "info-event"
@@ -4,10 +4,11 @@
#include <glib.h>
#include <gpiod.h>
#include <poll.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "kernel-uapi"
@@ -4,10 +4,11 @@
#include <errno.h>
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "line-config"
@@ -4,10 +4,11 @@
#include <errno.h>
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "line-info"
@@ -64,8 +65,8 @@ GPIOD_TEST_CASE(line_info_basic_properties)
g_autoptr(struct_gpiod_chip) chip = NULL;
g_autoptr(struct_gpiod_line_info) info4 = NULL;
g_autoptr(struct_gpiod_line_info) info6 = NULL;
- g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
- g_autoptr(GVariant) vhogs = gpiod_test_package_hogs(hogs);
+ g_autoptr(GVariant) vnames = g_gpiosim_package_line_names(names);
+ g_autoptr(GVariant) vhogs = g_gpiosim_package_hogs(hogs);
sim = g_gpiosim_chip_new(
"num-lines", 8,
@@ -3,10 +3,11 @@
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "line-request"
@@ -4,9 +4,10 @@
#include <errno.h>
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "line-settings"
@@ -4,11 +4,12 @@
#include <errno.h>
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
+#include <gpiosim-glib.h>
#include <unistd.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
-#include "gpiod-test-sim.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "misc"
@@ -3,9 +3,10 @@
#include <glib.h>
#include <gpiod.h>
+#include <gpiod-test.h>
+#include <gpiod-test-common.h>
-#include "gpiod-test.h"
-#include "gpiod-test-helpers.h"
+#include "helpers.h"
#define GPIOD_TEST_GROUP "request-config"