Add detection for LXC + tests
authorMarc Fournier <marc.fournier@camptocamp.com>
Tue, 16 Apr 2013 20:20:30 +0000 (22:20 +0200)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 31 Oct 2016 10:14:35 +0000 (06:14 -0400)
(cherry picked from commit b4a8cdb672ec73e57219932c1d7d0093963b5642)

Makefile.am
tests/lxc/proc/1/environ [new file with mode: 0644]
tests/lxc/proc/cpuinfo [new file with mode: 0644]
tests/lxc/proc/self/status [new file with mode: 0644]
tests/lxc/sbin/dmidecode [new file with mode: 0755]
tests/lxc/sbin/uname [new file with mode: 0755]
tests/lxc/sbin/virt-what-cpuid-helper [new file with mode: 0755]
tests/test-lxc.sh [new file with mode: 0755]
virt-what.in

index 4ddbb64..a381a2b 100644 (file)
@@ -45,6 +45,7 @@ TESTS = \
        tests/test-kvm.sh \
        tests/test-kvm-explicit-cpu.sh \
        tests/test-linux-vserver.sh \
+       tests/test-lxc.sh \
        tests/test-lx86.sh \
        tests/test-parallels-desktop.sh \
        tests/test-qemu.sh \
@@ -93,6 +94,13 @@ EXTRA_DIST = \
        tests/linux-vserver/sbin/id \
        tests/linux-vserver/sbin/uname \
        tests/linux-vserver/sbin/virt-what-cpuid-helper \
+       tests/lxc/proc/1/environ \
+       tests/lxc/proc/cpuinfo \
+       tests/lxc/proc/self/status \
+       tests/lxc/sbin/dmidecode \
+       tests/lxc/sbin/id \
+       tests/lxc/sbin/uname \
+       tests/lxc/sbin/virt-what-cpuid-helper \
        tests/lx86/proc/cpuinfo \
        tests/lx86/proc/self/status \
        tests/lx86/sbin/dmidecode \
diff --git a/tests/lxc/proc/1/environ b/tests/lxc/proc/1/environ
new file mode 100644 (file)
index 0000000..cba6db0
Binary files /dev/null and b/tests/lxc/proc/1/environ differ
diff --git a/tests/lxc/proc/cpuinfo b/tests/lxc/proc/cpuinfo
new file mode 100644 (file)
index 0000000..1b12948
--- /dev/null
@@ -0,0 +1,26 @@
+processor      : 0
+vendor_id      : GenuineIntel
+cpu family     : 15
+model          : 4
+model name     : Intel(R) Xeon(TM) CPU 3.80GHz
+stepping       : 3
+microcode      : 0x5
+cpu MHz                : 3790.823
+cache size     : 2048 KB
+physical id    : 0
+siblings       : 2
+core id                : 0
+cpu cores      : 1
+apicid         : 0
+initial apicid : 0
+fpu            : yes
+fpu_exception  : yes
+cpuid level    : 5
+wp             : yes
+flags          : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc pebs bts nopl pni dtes64 monitor ds_cpl est tm2 cid cx16 xtpr
+bogomips       : 7581.64
+clflush size   : 64
+cache_alignment        : 128
+address sizes  : 36 bits physical, 48 bits virtual
+power management:
+
diff --git a/tests/lxc/proc/self/status b/tests/lxc/proc/self/status
new file mode 100644 (file)
index 0000000..6a4f213
--- /dev/null
@@ -0,0 +1,39 @@
+Name:  cat
+State: R (running)
+Tgid:  7424
+Pid:   7424
+PPid:  7216
+TracerPid:     0
+Uid:   0       0       0       0
+Gid:   0       0       0       0
+FDSize:        256
+Groups:        0 
+VmPeak:            4112 kB
+VmSize:            4112 kB
+VmLck:        0 kB
+VmPin:        0 kB
+VmHWM:      320 kB
+VmRSS:      320 kB
+VmData:             180 kB
+VmStk:      136 kB
+VmExe:       48 kB
+VmLib:     1664 kB
+VmPTE:       32 kB
+VmSwap:               0 kB
+Threads:       1
+SigQ:  4/63942
+SigPnd:        0000000000000000
+ShdPnd:        0000000000000000
+SigBlk:        0000000000000000
+SigIgn:        0000000000000000
+SigCgt:        0000000000000000
+CapInh:        0000000000000000
+CapPrm:        fffffffcff9effff
+CapEff:        fffffffcff9effff
+CapBnd:        fffffffcff9effff
+Cpus_allowed:  0f
+Cpus_allowed_list:     0-3
+Mems_allowed:  00000000,00000001
+Mems_allowed_list:     0
+voluntary_ctxt_switches:       1
+nonvoluntary_ctxt_switches:    1
diff --git a/tests/lxc/sbin/dmidecode b/tests/lxc/sbin/dmidecode
new file mode 100755 (executable)
index 0000000..d9992ad
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh -
+cat <<'EOF'
+# dmidecode 2.11
+/dev/mem: Operation not permitted
+EOF
+exit 1
diff --git a/tests/lxc/sbin/uname b/tests/lxc/sbin/uname
new file mode 100755 (executable)
index 0000000..ab0ec89
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh -
+echo x86_64
diff --git a/tests/lxc/sbin/virt-what-cpuid-helper b/tests/lxc/sbin/virt-what-cpuid-helper
new file mode 100755 (executable)
index 0000000..ad82504
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh -
+echo @
diff --git a/tests/test-lxc.sh b/tests/test-lxc.sh
new file mode 100755 (executable)
index 0000000..47a5f2b
--- /dev/null
@@ -0,0 +1,34 @@
+# Test for lxc
+# Copyright (C) 2008-2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+root=tests/lxc
+
+output="$(./virt-what --test-root=$root 2>&1)"
+expected="lxc"
+
+if [ "$output" != "$expected" ]; then
+    echo "$0: test failed because output did not match expected"
+    echo "Expected output was:"
+    echo "----------------------------------------"
+    echo "$expected"
+    echo "----------------------------------------"
+    echo "But the actual output of the program was:"
+    echo "----------------------------------------"
+    echo "$output"
+    echo "----------------------------------------"
+    exit 1
+fi
index 297956d..7cc4853 100644 (file)
@@ -135,6 +135,15 @@ if [ -d $root/proc/vz -a ! -d $root/proc/bc ]; then
     echo openvz
 fi
 
+# Check for LXC containers
+# http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface
+# Added by Marc Fournier
+
+if [ -e $root/proc/1/environ ] &&
+    cat $root/proc/1/environ | tr '\000' '\n' | grep -Eiq '^container='; then
+    echo lxc
+fi
+
 # Check for Linux-VServer
 if cat $root/proc/self/status | grep -q "VxID: [0-9]*"; then
     echo linux_vserver