Source: pciutils
Version: 1:3.6.4-1
Severity: wishlist
Tags: patch

While backporting the solution for #721270 into a Debian derivative, I
added the attached autopkgtest to verify that the -dev package works
correctly.

I've found that tests like this are a useful way to automate checks that
development files are packaged correctly: even though they don't have
significant coverage of the actual library code, they can detect common
mistakes like missing header files, wrong search paths, and missing
dependencies on other -dev packages referenced by the pkg-config file.

    smcv
>From 1468841c3285ce7c42673e1639a52129ce372254 Mon Sep 17 00:00:00 2001
From: Simon McVittie <s...@collabora.com>
Date: Tue, 12 May 2020 14:20:26 +0100
Subject: [PATCH] Add a superficial compile/link/execute autopkgtest for
 libpci-dev

Signed-off-by: Simon McVittie <s...@collabora.com>
---
 debian/tests/control    |  3 +++
 debian/tests/libpci-dev | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 debian/tests/control
 create mode 100755 debian/tests/libpci-dev

diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..1f2d981
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: libpci-dev
+Restrictions: allow-stderr, superficial
+Depends: build-essential, libpci-dev, pkg-config
diff --git a/debian/tests/libpci-dev b/debian/tests/libpci-dev
new file mode 100755
index 0000000..60b343b
--- /dev/null
+++ b/debian/tests/libpci-dev
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright 2020 Collabora Ltd.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -eux
+
+if [ -n "${AUTOPKGTEST_ARTIFACTS-}" ]; then
+	WORKDIR="$AUTOPKGTEST_ARTIFACTS"
+else
+	WORKDIR="$(mktemp -d)"
+	trap 'cd /; rm -fr "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM
+fi
+
+if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
+    CROSS_COMPILE="$DEB_HOST_GNU_TYPE-"
+else
+    CROSS_COMPILE=
+fi
+
+cd "$WORKDIR"
+
+cat <<EOF > sample.c
+#include <pci/pci.h>
+
+int main(void)
+{
+  struct pci_access *a;
+  a = pci_alloc();
+  pci_init(a);
+  pci_cleanup(a);
+  return 0;
+}
+EOF
+
+# Deliberately word-splitting pkg-config's output:
+# shellcheck disable=SC2046
+"${CROSS_COMPILE}gcc" -osample sample.c $("${CROSS_COMPILE}pkg-config" --cflags --libs libpci)
+./sample
-- 
2.26.2

Reply via email to