summaryrefslogtreecommitdiff
path: root/tests/virtualfb.sh
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-02-03 02:13:37 (GMT)
committerMarius Kintel <marius@kintel.net>2013-02-03 02:13:37 (GMT)
commitd2d22503eb0e9b5cfe3846562aa84af18a044907 (patch)
tree536dc65cf43152e3934ac123086afa9d9d648483 /tests/virtualfb.sh
parente5448f5e69f6d59256ba1816acf2647e808e10db (diff)
parent44cddd0b3cf69b1e10811f0000c0ddef02c15d58 (diff)
Merge pull request #271 from openscad/cmake_workaround
Cmake workaround
Diffstat (limited to 'tests/virtualfb.sh')
-rwxr-xr-xtests/virtualfb.sh75
1 files changed, 58 insertions, 17 deletions
diff --git a/tests/virtualfb.sh b/tests/virtualfb.sh
index e745765..5abd804 100755
--- a/tests/virtualfb.sh
+++ b/tests/virtualfb.sh
@@ -1,23 +1,64 @@
#!/bin/sh
-if [ "`command -v Xvfb`" ]; then
- VFB_BINARY=Xvfb
-fi
+# Toggle the Virtual Framebuffer
+# If started, stop. If stopped, start.
-if [ "`command -v Xvnc`" ]; then
- VFB_BINARY=Xvnc
-fi
+start()
+{
+ if [ "`command -v Xvfb`" ]; then
+ VFB_BINARY=Xvfb
+ fi
+
+ if [ "`command -v Xvnc`" ]; then
+ VFB_BINARY=Xvnc
+ fi
+
+ if [ ! $VFB_BINARY ]; then
+ echo "$0 Failed, cannot find Xvfb or Xvnc"
+ exit 1
+ fi
+
+ VFB_DISPLAY=`echo | awk 'BEGIN{srand();} {printf ":%.0f", rand()*1000+100};'`
+ $VFB_BINARY $VFB_DISPLAY -screen 0 800x600x24 &> ./virtualfb.log &
+ VFB_PID=$!
+
+ echo $VFB_DISPLAY > ./virtualfb.DISPLAY
+ echo $VFB_PID > ./virtualfb.PID
+
+ echo "Started virtual fb, PID=$VFB_PID , DISPLAY=$VFB_DISPLAY"
+ sleep 1
+}
+
+stop()
+{
+ VFB_PID=`cat ./virtualfb.PID`
+ VFB_DISPLAY=`cat ./virtualfb.DISPLAY`
+
+ echo "Stopping virtual fb, PID was $VFB_PID, DISPLAY was $VFB_DISPLAY"
+ kill $VFB_PID
+ LOCKFILE=`echo "/tmp/.X"$VFB_DISPLAY"-lock"`
+ if [ -e $LOCKFILE ]; then
+ rm $LOCKFILE
+ fi
+ rm ./virtualfb.PID
+ rm ./virtualfb.DISPLAY
+}
+
+isrunning()
+{
+ isrunning_result=
+ if [ -e ./virtualfb.PID ]; then
+ VFB_PID=`cat ./virtualfb.PID`
+ if [ "`ps cax | awk ' { print $1 } ' | grep ^$VFB_PID\$`" ]; then
+ isrunning_result=1
+ fi
+ fi
+}
-if [ ! $VFB_BINARY ]; then
- echo "$0 Failed, cannot find Xvfb or Xvnc"
- exit 1
+isrunning
+if [ $isrunning_result ]; then
+ stop
+else
+ start
fi
-DISPLAY=`echo | awk 'BEGIN{srand();} {printf ":%.0f", rand()*1000+100};'`
-#DISPLAY=:98
-$VFB_BINARY $DISPLAY -screen 0 800x600x24 &> virtualfb.log &
-echo PID=$! " "
-echo DISPLAY=$DISPLAY
-# trap "kill -KILL $xpid ||:" EXIT
-export DISPLAY
-sleep 3
contact: Jan Huwald // Impressum