summaryrefslogtreecommitdiffstats
path: root/debian/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:23:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:23:58 +0000
commit6dce38a7d3f755cfa88207007c0cb199c4c8a2e3 (patch)
treea9bba51153f8bdaad3be20eefae2cfe0072ca4f7 /debian/tests
parentAdding upstream version 0.0~2023.04.11. (diff)
downloadpci.ids-6dce38a7d3f755cfa88207007c0cb199c4c8a2e3.tar.xz
pci.ids-6dce38a7d3f755cfa88207007c0cb199c4c8a2e3.zip
Adding debian version 0.0~2023.04.11-1.debian/0.0_2023.04.11-1debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/tests')
-rw-r--r--debian/tests/control1
-rwxr-xr-xdebian/tests/test-db-format83
2 files changed, 84 insertions, 0 deletions
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..2ee676f
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1 @@
+Tests: test-db-format
diff --git a/debian/tests/test-db-format b/debian/tests/test-db-format
new file mode 100755
index 0000000..70b89e0
--- /dev/null
+++ b/debian/tests/test-db-format
@@ -0,0 +1,83 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my ($SELF) = $0 =~ m{(?:.*/)?([^/]*)};
+my $DEBUG = defined $ENV{PCI_IDS_DEBUG};
+my $PCIIDS = $ARGV[0] // '/usr/share/misc/pci.ids';
+
+sub error
+{
+ my (@args) = @_;
+
+ die "$SELF: @args: FAIL\n";
+}
+
+sub debug
+{
+ my (@args) = @_;
+
+ print "@args\n" if $DEBUG;
+}
+
+sub check
+{
+ my $fh = shift;
+
+ my ($vendor, $device);
+ my ($class, $subclass);
+
+ while (<$fh>) {
+ next if m/^#/;
+ next if m/^\s*$/;
+
+ s/#.*$//;
+
+ if (m/^([0-9a-fA-F]{4}) (.*)$/) {
+ debug("Vendor ($1) ($2)");
+ $vendor = $1;
+ $device = undef;
+ $class = undef;
+ $subclass = undef;
+ } elsif (m/^\t([0-9a-fA-F]{4}) (.*)$/) {
+ if (not defined $vendor) {
+ error("Device defined not within a Vendor at line $.");
+ }
+ debug("Device ($1) ($2)");
+ $device = $1;
+ } elsif (m/^\t\t([0-9a-fA-F]{4}) ([0-9a-fA-F]{4}) (.*)$/) {
+ if (not defined $device) {
+ error("SubDevice defined not within a Device at line $.");
+ }
+ debug("SubVendor SubDevice ($1 $2) ($2)");
+ } elsif (m/^C ([0-9a-fA-F]{2}) (.*)$/) {
+ debug("Class ($1) ($2)");
+ $vendor = undef;
+ $device = undef;
+ $class = $1;
+ $subclass = undef;
+ } elsif (m/^\t([0-9a-fA-F]{2}) (.*)$/) {
+ if (not defined $class) {
+ error("SubClass defined not within a Class at line $.");
+ }
+ debug("SubClass ($1) ($2)");
+ $subclass = $1;
+ } elsif (m/^\t\t([0-9a-fA-F]{2}) (.*)$/) {
+ if (not defined $subclass) {
+ error("Programming Interface defined not within a SubClass at line $.");
+ }
+ debug("ProgIface ($1) ($2)");
+ } else {
+ error("Unknown entry in file at line $.");
+ }
+ }
+}
+
+open my $fh, '<', $PCIIDS or error("cannot open $PCIIDS database: $!");
+check($fh);
+close $fh;
+
+print "$SELF: format of $PCIIDS is ok: PASS\n";
+
+exit 0;