Moved usb ids check into a shell script
authorMichal Minář <miminar@redhat.com>
Tue, 19 Jan 2016 08:24:58 +0000 (09:24 +0100)
committerMichal Minář <miminar@redhat.com>
Tue, 19 Jan 2016 08:31:29 +0000 (09:31 +0100)
Added test for unix line endings.

Converting oui.txt and iab.txt automatically to unix line endings.

Signed-off-by: Michal Minář <miminar@redhat.com>
Makefile
check-usb-ids.sh [new file with mode: 0755]

index 0f3280238bac2c898ec61adca99fc6aa31a75ef2..3d385aed0515e239eb794272964fdf7cc414d891 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ CVSROOT = $(shell cat CVS/Root 2>/dev/null || :)
 
 CVSTAG = $(NAME)-r$(subst .,-,$(VERSION))
 
-FILES = pci.ids usb.ids oui.txt iab.txt pnp.ids
+IDFILES = pci.ids usb.ids oui.txt iab.txt pnp.ids
 
 .PHONY: all install tag force-tag check commit create-archive archive srpm-x \
     clean clog new-pci-ids new-usb-ids new-oui new-iab new-pnp-ids
@@ -54,18 +54,16 @@ changelog:
 check:
        @[ -x /sbin/lspci ] && /sbin/lspci -i pci.ids > /dev/null || { echo "FAILURE: /sbin/lspci -i pci.ids"; exit 1; } && echo "OK: /sbin/lspci -i pci.ids"
        @./check-pci-ids.py || { echo "FAILURE: ./check-pci-ids.py"; exit 1; } && echo "OK: ./check-pci-ids.py"
-       @if [[ -e /run/docker.sock ]]; then \
-           tmpdir=`mktemp -d`; \
-           echo "Listing usb devices:"; \
-           docker run -t --privileged --rm=true \
-               -v `pwd`/usb.ids:/usr/share/hwdata/usb.ids:ro \
-               -v "$$tmpdir:/mnt/out" \
-               miminar/hwdata-check /bin/bash -c 'lsusb 2>/mnt/out/err.out'; \
-           if [[ `cat $$tmpdir/err.out | wc -l` -gt 0 ]]; then \
-               echo "ERRORS:"; nl $$tmpdir/err.out; rm -rf $$tmpdir; exit 1; \
+       @./check-usb-ids.sh
+       @for file in $(IDFILES); do \
+           text=`LANG=C file $$file`; \
+           expected="$$file: UTF-8 Unicode text"; \
+           if [[ "$$text" != "$$expected" ]]; then \
+               printf "Expected: %s\n Got instead: %s\n" "$$expected" "$$text" >&2; \
+               exit 1; \
            fi; \
-           rm -rf $$tmpdir; \
-       fi
+           echo "OK: $$text"; \
+       done
        @echo -n "CHECK date of pci.ids: "; grep "Date:" pci.ids | cut -d ' ' -f 5
        @echo -n "CHECK date of usb.ids: "; grep "Date:" usb.ids | cut -d ' ' -f 6
 
@@ -109,9 +107,11 @@ new-pci-ids:
 
 new-oui:
        @curl -O http://standards-oui.ieee.org/oui.txt
+       @dos2unix oui.txt
 
 new-iab:
        @curl -O http://standards.ieee.org/develop/regauth/iab/iab.txt
+       @dos2unix iab.txt
 
 new-pnp-ids: pnp.ids
 
diff --git a/check-usb-ids.sh b/check-usb-ids.sh
new file mode 100755 (executable)
index 0000000..b9f81d3
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+set -euo pipefail
+IFS=$'\n\t'
+
+if [[ "${NO_DOCKER:-0}" == 1 ]]; then
+    echo "SKIP: usb ids because of disabled docker test"
+    exit 0
+fi
+
+if ! [[ -e /run/docker.sock ]]; then
+    echo "Skipping check of usb ids because of missing docker socket."
+    exit 0
+fi
+
+tmpdir=`mktemp -d`
+echo "Listing usb devices:"
+sudo docker run -t --privileged --rm=true \
+    -v `pwd`/usb.ids:/usr/share/hwdata/usb.ids:ro \
+    -v "$tmpdir:/mnt/out" \
+    miminar/hwdata-check \
+    /bin/bash -c 'lsusb 2>/mnt/out/err.out' || :
+if [[ `cat $tmpdir/err.out | wc -l` -gt 0 ]]; then
+    echo "ERRORS:"
+    nl $tmpdir/err.out
+    rm -rf $tmpdir
+    exit 1
+fi
+rm -rf $tmpdir