From 5dcc399cd21f607f13eb092a3abfc8b8daa59d4c Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Fri, 13 Jan 2023 10:44:28 +0200
Subject: [PATCH] Add a test for special device node installation

This is a bit theoretical as it does not work for regular users or in
containers which are the typical scenarios for running the test-suite.
---
 tests/atlocal.in          |  6 ++++++
 tests/data/SPECS/dev.spec | 14 ++++++++++++++
 tests/rpmi.at             | 17 +++++++++++++++++
 3 files changed, 37 insertions(+)
 create mode 100644 tests/data/SPECS/dev.spec

diff --git a/tests/atlocal.in b/tests/atlocal.in
index 70383bb46..a037de728 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -64,6 +64,12 @@ if grep -q '#define WITH_CAP 1' "${abs_top_builddir}/config.h"; then
 else
     CAP_DISABLED=true;
 fi
+if mknod foodev c 123 123; then
+   MKNOD_DISABLED=false
+   rm -f foodev
+else
+   MKNOD_DISABLED=true
+fi
 
 function setup_env()
 {
diff --git a/tests/data/SPECS/dev.spec b/tests/data/SPECS/dev.spec
new file mode 100644
index 000000000..d784fe114
--- /dev/null
+++ b/tests/data/SPECS/dev.spec
@@ -0,0 +1,14 @@
+Name: dev
+Version: 1.0
+Release: 1
+Group: Testing
+License: GPL
+Summary: Testing dev behavior
+BuildArch: noarch
+
+%description
+%{summary}
+
+%files
+%dev(c 11 22) /test-char
+%dev(b 33 44) /test-block
diff --git a/tests/rpmi.at b/tests/rpmi.at
index a2389de..f439e46 100644
--- a/tests/rpmi.at
+++ b/tests/rpmi.at
@@ -888,3 +888,20 @@ runroot rpm -Vv --nouser --nogroup fifo
 ],
 [])
 AT_CLEANUP
+
+AT_SETUP([rpm -U dev])
+AT_KEYWORDS([install])
+AT_SKIP_IF([$MKNOD_DISABLED])
+AT_CHECK([
+RPMDB_INIT
+
+runroot rpmbuild -bb --quiet /data/SPECS/dev.spec
+runroot rpm -U --ignoreos /build/RPMS/noarch/dev-1.0-1.noarch.rpm
+runroot rpm -Vv --nouser --nogroup dev
+],
+[0],
+[.........    /test-block
+.........    /test-char
+],
+[])
+AT_CLEANUP
-- 
2.27.0

