diff options
author | Mihai Moldovan <ionic@ionic.de> | 2017-12-15 12:55:17 +0100 |
---|---|---|
committer | Mihai Moldovan <ionic@ionic.de> | 2017-12-15 12:55:17 +0100 |
commit | 1dad092caf01d733990648e6df64cbf964df5143 (patch) | |
tree | 39de0e643e76754a3e23ca9dd0350b8ba4f76250 /testscripts | |
parent | 6d70b9e3c47f27a166f4aacb522c5c1e49092dd9 (diff) | |
parent | 2b9025f797ee322e21077e100c2ee27c2e7fa0e0 (diff) | |
download | nx-libs-1dad092caf01d733990648e6df64cbf964df5143.tar.gz nx-libs-1dad092caf01d733990648e6df64cbf964df5143.tar.bz2 nx-libs-1dad092caf01d733990648e6df64cbf964df5143.zip |
Merge branch '3.6.x'
Diffstat (limited to 'testscripts')
-rwxr-xr-x | testscripts/run-nxproxy2nxagent-on-localhost | 144 | ||||
-rwxr-xr-x | testscripts/run-nxproxy2nxagent-over-network | 153 | ||||
-rwxr-xr-x | testscripts/run-nxproxy2nxagent-over-sockets | 149 | ||||
-rwxr-xr-x | testscripts/run-nxproxy2nxproxy | 144 | ||||
-rwxr-xr-x | testscripts/run-nxproxy2nxproxy-over-sockets | 153 | ||||
-rwxr-xr-x | testscripts/slave-agent | 311 | ||||
-rwxr-xr-x | testscripts/slave-client | 416 |
7 files changed, 1470 insertions, 0 deletions
diff --git a/testscripts/run-nxproxy2nxagent-on-localhost b/testscripts/run-nxproxy2nxagent-on-localhost new file mode 100755 index 000000000..c7533c711 --- /dev/null +++ b/testscripts/run-nxproxy2nxagent-on-localhost @@ -0,0 +1,144 @@ +#!/bin/bash + +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ +#/* Copyright (c) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +# +# Uncomment this to enable echo. +# +#set -x +# + +ulimit -c unlimited + +NXPROXYBIN=nxproxy +NXAGENTBIN=nxagent + + + +NX_PORT=9 + +NX_SYSTEM=${HOME}/.nx + +NX_ROOT=${HOME}/.nx + +# +# This should be randlomly generated. +# +#NX_COOKIE=`xauth list |grep "${HOSTNAME}/unix:\<${NX_PORT}\>" | grep MIT | cut -f 5 -d ' '` +NX_COOKIE=123efa980d2cba234ef6f73deac810ff + +# +# Create the directories for the NX session. +# + +rm -rf ${NX_ROOT}/C-${NX_PORT} || exit +mkdir -p ${NX_ROOT}/C-${NX_PORT} || exit + +rm -rf ${HOME}/.nx/S-${NX_PORT} || exit +mkdir -p ${HOME}/.nx/S-${NX_PORT} || exit + +# +# Set the path to libraries and NX executables. +# + +LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib" +export LD_LIBRARY_PATH + +PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/" +export PATH + +# +# Create the fake cookie for this display. +# + +echo -ne "Creating the X authorization cookie.\n" + +xauth add ${HOSTNAME}/unix:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} +xauth add ${HOSTNAME}:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} + +# +# Options are written in a file 'options' in the session +# directory. The agent will use the DISPLAY settings, so +# we pass in the DISPLAY the name of the options file. +# +# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0, +# accept=62.98.198.1,cookie=$NX_COOKIE, +# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# media=1:1098 +# + +NX_HOST=nx/nx,cache=8192k,link=modem,menu=1,keybd=1,samba=0,cups=0,limit=0,\ +accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/C-${NX_PORT}/options + +# +# Run the agent. if you don't have a font server running, +# remove the argument "-fp unix/:7100" +# + +NX_AGENT=:${NX_PORT} + +echo -ne "Running the X client side NX agent.\n" + +SAVED_DISPLAY=$DISPLAY + +DISPLAY=nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT} +export DISPLAY + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --num-callers=8 --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes \ +#ldd ${NXAGENTBIN} +${NXAGENTBIN} -name 'NX' -geometry 800x600+100+100 "$@" \ +${NX_AGENT} 2>>${NX_ROOT}/C-${NX_PORT}/session & + +# +# The X server side proxy will forward the connection +# to the original DISPLAY. +# + +DISPLAY=$SAVED_DISPLAY +export DISPLAY + +# +# These are the nxproxy options used to run a typical session. +# +# cookie=$NX_COOKIE,root=/home/pinzari/.nx,media=32824, +# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# connect=giulietta.nomachine.com:1098 +# + +#NX_HOST=nx/nx,keybd=1,samba=1,cups=1,connect=localhost,cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session +NX_HOST=nx/nx,keybd=1,samba=0,cups=0,connect=localhost,cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/S-${NX_PORT}/options + +echo -ne "Running the X server side NX proxy.\n" + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --num-callers=8 --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes \ +#ldd ${NXPROXYBIN} +${NXPROXYBIN} -S nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT} \ +2>>${HOME}/.nx/S-${NX_PORT}/session & + +echo -ne "Session running on display :$NX_PORT.\n" + diff --git a/testscripts/run-nxproxy2nxagent-over-network b/testscripts/run-nxproxy2nxagent-over-network new file mode 100755 index 000000000..35b67d41d --- /dev/null +++ b/testscripts/run-nxproxy2nxagent-over-network @@ -0,0 +1,153 @@ +#!/bin/bash + +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ +#/* Copyright (c) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +# +# Uncomment this to enable echo. +# +#set -x +# + +ulimit -c unlimited + +NXPROXYBIN=nxproxy +NXAGENTBIN=nxagent + +### +### Adapt to your needs: NXAGENT_HOST, NXPROXY_HOST +### +### This script launches nxagent and has to be executed on the NXAGENT_HOST. +### On the NXPROXY_HOST you will have to execute nxproxy by copy+pasting +### some command lines... +### +### (Instructions for copy+pasting are given when this script has been launched). +### +NXAGENT_HOST=127.0.0.1 # (e.g. 192.168.1.1, this scripts is launched on the NXAGENT_HOST machine) +NXPROXY_HOST=127.0.0.1 # (e.g. 192.168.1.2, you want to connect nxproxy -> nxagent from the NXPROXY_HOST machine) + +NX_PORT=9 + +NX_SYSTEM=${HOME}/.nx + +NX_ROOT=${HOME}/.nx + +# +# This should be randlomly generated. +# +#NX_COOKIE=`xauth list |grep "${HOSTNAME}/unix:\<${NX_PORT}\>" | grep MIT | cut -f 5 -d ' '` +NX_COOKIE=123efa980d2cba234ef6f73deac810ff + +# +# Create the directories for the NX session. +# + +rm -rf ${NX_ROOT}/C-${NX_PORT} || exit +mkdir -p ${NX_ROOT}/C-${NX_PORT} || exit + +rm -rf ${HOME}/.nx/S-${NX_PORT} || exit +mkdir -p ${HOME}/.nx/S-${NX_PORT} || exit + +# +# Set the path to libraries and NX executables. +# + +LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib" +export LD_LIBRARY_PATH + +PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/" +export PATH + +# +# Create the fake cookie for this display. +# + +echo -ne "Creating the X authorization cookie.\n" + +xauth add ${NXPROXY_HOST}/unix:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} +xauth add ${NXPROXY_HOST}:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} + +# +# Options are written in a file 'options' in the session +# directory. The agent will use the DISPLAY settings, so +# we pass in the DISPLAY the name of the options file. +# +# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0, +# accept=62.98.198.1,cookie=$NX_COOKIE, +# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# media=1:1098 +# + +NX_HOST=nx/nx,cache=8192k,link=modem,menu=1,keybd=1,samba=0,cups=0,limit=0,\ +accept=$NXPROXY_HOST,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/C-${NX_PORT}/options + +# +# Run the agent. if you don't have a font server running, +# remove the argument "-fp unix/:7100" +# + +NX_AGENT=:${NX_PORT} + +echo -ne "Running the X client side NX agent.\n" + +SAVED_DISPLAY=$DISPLAY + +DISPLAY=nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT} +export DISPLAY + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --num-callers=8 --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes \ +#ldd ${NXAGENTBIN} +${NXAGENTBIN} -name 'NX' -geometry 800x600+100+100 "$@" \ +${NX_AGENT} 2>>${NX_ROOT}/C-${NX_PORT}/session & + +# +# The X server side proxy will forward the connection +# to the original DISPLAY. +# + +DISPLAY=$SAVED_DISPLAY +export DISPLAY + +# +# These are the nxproxy options used to run a typical session. +# +# cookie=$NX_COOKIE,root=/home/pinzari/.nx,media=32824, +# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# connect=giulietta.nomachine.com:1098 +# + +echo +echo Now... COPY+PASTE the below lines to your local system +echo +echo "--------------8<---------" + +#NX_HOST=nx/nx,keybd=1,samba=1,cups=1,connect=$NXAGENT_HOST,cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session +NX_HOST=nx/nx,keybd=1,samba=0,cups=0,connect=tcp:$NXAGENT_HOST:4009,cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session +echo "NX_HOST=$NX_HOST" + +echo "echo \"${NX_HOST}:${NX_PORT}\" >${NX_ROOT}/S-${NX_PORT}/options" + +echo "${NXPROXYBIN} -S nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT} 2>>${HOME}/.nx/S-${NX_PORT}/session" +echo "-------------->8---------" +echo diff --git a/testscripts/run-nxproxy2nxagent-over-sockets b/testscripts/run-nxproxy2nxagent-over-sockets new file mode 100755 index 000000000..8e57db570 --- /dev/null +++ b/testscripts/run-nxproxy2nxagent-over-sockets @@ -0,0 +1,149 @@ +#!/bin/bash + +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ +#/* Copyright (c) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +# +# Uncomment this to enable echo. +# +#set -x +# + +ulimit -c unlimited + +NXPROXYBIN=nxproxy +NXAGENTBIN=nxagent + + +NX_PORT=7 + +NX_SYSTEM=${HOME}/.nx + +NX_ROOT=${HOME}/.nx + +# +# This should be randlomly generated. +# +#NX_COOKIE=`xauth list |grep "${HOSTNAME}/unix:\<${NX_PORT}\>" | grep MIT | cut -f 5 -d ' '` +NX_COOKIE=123efa980d2cba234ef6f73deac810ff + +# +# Create the directories for the NX session. +# + +rm -rf ${NX_ROOT}/C-${NX_PORT} || exit +mkdir -p ${NX_ROOT}/C-${NX_PORT} || exit + +rm -rf ${HOME}/.nx/S-${NX_PORT} || exit +mkdir -p ${HOME}/.nx/S-${NX_PORT} || exit + +# +# Set the path to libraries and NX executables. +# + +LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib" +export LD_LIBRARY_PATH + +PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/" +export PATH + +# +# Create the fake cookie for this display. +# + +echo -ne "Creating the X authorization cookie.\n" + +xauth add ${HOSTNAME}/unix:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} +xauth add ${HOSTNAME}:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} + +function urlencode() { + + echo "$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1")" + +} + +# +# Options are written in a file 'options' in the session +# directory. The agent will use the DISPLAY settings, so +# we pass in the DISPLAY the name of the options file. +# +# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0, +# accept=62.98.198.1,cookie=$NX_COOKIE, +# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# media=1:1098 +# + +NX_HOST=nx/nx,cache=8192k,link=modem,menu=1,keybd=1,samba=0,cups=0,limit=0,\ +listen=$(urlencode "unix:${NX_SYSTEM}/C-${NX_PORT}/proxy.socket"),cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/C-${NX_PORT}/options + +# +# Run the agent. if you don't have a font server running, +# remove the argument "-fp unix/:7100" +# + +NX_AGENT=:${NX_PORT} + +echo -ne "Running the X client side NX agent.\n" + +SAVED_DISPLAY=$DISPLAY + +DISPLAY=nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT} +export DISPLAY + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --num-callers=8 --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes \ +#ldd ${NXAGENTBIN} +${NXAGENTBIN} -name 'NX' -geometry 800x600+100+100 "$@" \ +${NX_AGENT} 2>>${NX_ROOT}/C-${NX_PORT}/session & + +# +# The X server side proxy will forward the connection +# to the original DISPLAY. +# + +DISPLAY=$SAVED_DISPLAY +export DISPLAY + +# +# These are the nxproxy options used to run a typical session. +# +# cookie=$NX_COOKIE,root=/home/pinzari/.nx,media=32824, +# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# connect=giulietta.nomachine.com:1098 +# + +#NX_HOST=nx/nx,keybd=1,samba=1,cups=1,connect=localhost,cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session +NX_HOST=nx/nx,keybd=1,samba=0,cups=0,connect=$(urlencode "unix:${NX_SYSTEM}/C-${NX_PORT}/proxy.socket"),cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/S-${NX_PORT}/options + +echo -ne "Running the X server side NX proxy.\n" + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --num-callers=8 --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes \ +#ldd ${NXPROXYBIN} +${NXPROXYBIN} -S nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT} \ +2>>${HOME}/.nx/S-${NX_PORT}/session & + +echo -ne "Session running on display :$NX_PORT.\n" + diff --git a/testscripts/run-nxproxy2nxproxy b/testscripts/run-nxproxy2nxproxy new file mode 100755 index 000000000..305d921c2 --- /dev/null +++ b/testscripts/run-nxproxy2nxproxy @@ -0,0 +1,144 @@ +#!/bin/bash + +set -e + +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ +#/* Copyright (c) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +# +# Uncomment this to enable echo. +# +# set -x +# + +ulimit -c unlimited + +NX_PORT=8 + +NX_SYSTEM=${HOME}/.nx + +NX_ROOT=${HOME}/.nx + +mkdir -p "${NX_ROOT}" + +# +# This should be randlomly generated. +# + +NX_COOKIE=`xauth -n list |grep "${HOSTNAME}/unix:${NX_PORT}" | grep MIT | cut -f 5 -d ' ' | head -n1` +if [ -z "$NX_COOKIE" ]; then + NX_COOKIE=`mcookie` +fi + +# +# Create the directories for the NX session. +# + +rm -rf ${NX_ROOT}/C-${NX_PORT} || exit +mkdir -p ${NX_ROOT}/C-${NX_PORT} || exit + +rm -rf ${HOME}/.nx/S-${NX_PORT} || exit +mkdir -p ${HOME}/.nx/S-${NX_PORT} || exit + +# +# Set the path to libraries and NX executables. +# + +LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib" +export LD_LIBRARY_PATH + +PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/" +export PATH + +# +# Create the fake cookie for this display. +# + +echo -ne "Creating the X authorization cookie.\n" + +xauth add ${HOSTNAME}/unix:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} +xauth add ${HOSTNAME}:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} + +# +# Options are written in a file 'options' in the session +# directory. The agent will use the DISPLAY settings, so +# we pass in the DISPLAY the name of the options file. +# +# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0, +# accept=62.98.198.1,cookie=$NX_COOKIE, +# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# media=1:1098 +# + +#NX_HOST=nx/nx,link=lan,pack=no-pack,keybd=1,samba=1,cups=1,limit=0,\ +#accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +#NX_HOST=nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\ +#accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +#NX_HOST=nx/nx,cache=8192k,link=modem,keybd=1,samba=1,cups=1,limit=0,\ +#connect=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +NX_HOST=nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\ +accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/C-${NX_PORT}/options + +# +# Run the local proxy impersonating the X display. +# + +echo -ne "Running the X client side NX proxy.\n" + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --tool=memcheck --track-fds=yes \ +nxproxy -C nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT} \ +2>>${HOME}/.nx/C-${NX_PORT}/session & + +# +# The X server side proxy will forward the connection +# to the original DISPLAY. +# + +# +# These are the nxproxy options used to run a typical session. +# +# cookie=$NX_COOKIE,root=/home/pinzari/.nx,media=32824, +# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# connect=giulietta.nomachine.com:1098 +# + +NX_HOST=nx/nx,keybd=1,samba=1,cups=1,connect=localhost,cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/S-${NX_PORT}/options + +echo -ne "Running the X server side NX proxy.\n" + +#cachegrind -v --dumps=100000000 \ +#cachegrind -v \ +#valgrind -v --leak-check=yes --leak-resolution=high --show-reachable=yes \ +# --show-reachable=yes --suppressions=nxproxy/nxproxy.supp \ +# --weird-hacks=lax-ioctls --num-callers=8 --logfile-fd=2 \ +nxproxy -S nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT} \ +2>>${HOME}/.nx/S-${NX_PORT}/session & + +echo -ne "Session running on display :$NX_PORT.\n" + diff --git a/testscripts/run-nxproxy2nxproxy-over-sockets b/testscripts/run-nxproxy2nxproxy-over-sockets new file mode 100755 index 000000000..0cc209377 --- /dev/null +++ b/testscripts/run-nxproxy2nxproxy-over-sockets @@ -0,0 +1,153 @@ +#!/bin/bash + +set -ex + +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ +#/* Copyright (c) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +# +# Uncomment this to enable echo. +# +# set -x +# + +ulimit -c unlimited + +NX_PORT=6 + +NX_SYSTEM=${HOME}/.nx + +NX_ROOT=${HOME}/.nx + +mkdir -p "${NX_ROOT}" + +# +# This should be randlomly generated. +# + +NX_COOKIE=`xauth -n list |grep "${HOSTNAME}/unix:${NX_PORT}" | grep MIT | cut -f 5 -d ' ' | head -n1` +if [ -z "$NX_COOKIE" ]; then + NX_COOKIE=`mcookie` +fi + +# +# Create the directories for the NX session. +# + +rm -rf ${NX_ROOT}/C-${NX_PORT} || exit +mkdir -p ${NX_ROOT}/C-${NX_PORT} || exit + +rm -rf ${HOME}/.nx/S-${NX_PORT} || exit +mkdir -p ${HOME}/.nx/S-${NX_PORT} || exit + +# +# Set the path to libraries and NX executables. +# + +LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib" +export LD_LIBRARY_PATH + +PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/" +export PATH + +# +# Create the fake cookie for this display. +# + +echo -ne "Creating the X authorization cookie.\n" + +xauth add ${HOSTNAME}/unix:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} +xauth add ${HOSTNAME}:${NX_PORT} MIT-MAGIC-COOKIE-1 ${NX_COOKIE} + +function urlencode() { + + echo "$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1")" + +} + +# +# Options are written in a file 'options' in the session +# directory. The agent will use the DISPLAY settings, so +# we pass in the DISPLAY the name of the options file. +# +# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0, +# accept=62.98.198.1,cookie=$NX_COOKIE, +# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# media=1:1098 +# + +#NX_HOST=nx/nx,link=lan,pack=no-pack,keybd=1,samba=1,cups=1,limit=0,\ +#accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +#NX_HOST=nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\ +#accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +#NX_HOST=nx/nx,cache=8192k,link=modem,keybd=1,samba=1,cups=1,limit=0,\ +#connect=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +#NX_HOST=nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\ +#accept=127.0.0.1,cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +NX_HOST=nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\ +listen=$(urlencode "unix:${NX_SYSTEM}/C-${NX_PORT}/proxy.socket"),cookie=$NX_COOKIE,errors=${NX_ROOT}/C-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/C-${NX_PORT}/options + +# +# Run the local proxy impersonating the X display. +# + +echo -ne "Running the X client side NX proxy.\n" + +#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ +#valgrind --tool=memcheck --track-fds=yes \ +nxproxy -C nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT} \ +2>>${HOME}/.nx/C-${NX_PORT}/session & + +# +# The X server side proxy will forward the connection +# to the original DISPLAY. +# + +# +# These are the nxproxy options used to run a typical session. +# +# cookie=$NX_COOKIE,root=/home/pinzari/.nx,media=32824, +# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, +# connect=giulietta.nomachine.com:1098 +# + +NX_HOST=nx/nx,keybd=1,samba=1,cups=1,connect=$(urlencode "unix:${NX_SYSTEM}/C-${NX_PORT}/proxy.socket"),cookie=$NX_COOKIE,errors=${NX_ROOT}/S-${NX_PORT}/session + +echo "${NX_HOST}:${NX_PORT}" >${NX_ROOT}/S-${NX_PORT}/options + +echo -ne "Running the X server side NX proxy.\n" + +#cachegrind -v --dumps=100000000 \ +#cachegrind -v \ +#valgrind -v --leak-check=yes --leak-resolution=high --show-reachable=yes \ +# --show-reachable=yes --suppressions=nxproxy/nxproxy.supp \ +# --weird-hacks=lax-ioctls --num-callers=8 --logfile-fd=2 \ +nxproxy -S nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT} \ +2>>${HOME}/.nx/S-${NX_PORT}/session & + +echo -ne "Session running on display :$NX_PORT.\n" + diff --git a/testscripts/slave-agent b/testscripts/slave-agent new file mode 100755 index 000000000..2f22c187a --- /dev/null +++ b/testscripts/slave-agent @@ -0,0 +1,311 @@ +#!/usr/bin/perl -w +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com) */ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +# This is a test script for the slave channel feature. While there are no +# particular requirements for the slave channel command, what makes the most +# sense is to use the feature to run some sort of multiplexer. +# +# This script contains functionality intended to test the channel's bandwidth, +# latency and integrity. +# +# Usage: +# Set NX_SLAVE_CMD to this script and enable the slave channel +# +# Run: +# nxproxy [...] slave=12000 +# nxagent -display nx/nx,options=nxagent.conf # slave=22000 in nxagent.conf +# +# Where 12000 and 22000 are example TCP ports the program will listen on. +# +# For ease of debugging and running both sides on a single machine, the script +# reacts to its own name and changes the prompt to "Proxy" if $0 contains +# "proxy", or "Agent" if it contains "agent". This has no other effect. +# +# + +use strict; +use POSIX ":sys_wait_h"; + +my $me = "?"; +my $EXIT; + +$| = 1; + +if ( $0 =~ /proxy/i ) { + $me = "Proxy"; +} elsif ( $0 =~ /agent/i ) { + $me = "Agent"; +} else { + $me = $0; +} + + +print "$me slave. "; +if ( scalar @ARGV ) { + print "Called with arguments: " . join(' ', @ARGV) . "\n\n"; +} else { + print "Called without arguments.\n\n"; +} + + +my %commands; +register('quit' , \&cmd_quit , "Exit."); +register('fork' , \&cmd_fork , "Test forking a child process."); +register('exec' , \&cmd_exec , "Test calling another process via exec."); +register('system' , \&cmd_system , "Test calling another process via system."); +register('echo' , \&cmd_echo , "Echo text after the command. Tests channel latency."); +register('blkecho' , \&cmd_blkecho, "Echo data by 1k blocks. Tests channel integrity."); +register('reexec' , \&cmd_reexec , "Reexecute slave handler."); +register('chargen' , \&cmd_chargen, "Output characters forever. Tests channel throughput."); +register('randgen' , \&cmd_randgen, "Output random characters forever. Tests channel throughput."); +register('discard' , \&cmd_discard, "Accept characters forever. Tests channel throughput."); +register('fastgen' , \&cmd_fastgen, "Output a single character forever. Tests channel throughput."); +register('env' , \&cmd_env , "Dump the environment."); +register('help' , \&cmd_help , "Shows this help."); +register('pwd' , \&cmd_pwd , "Print working directory."); +cmd_help(); + + + +#print "$me> "; +my $line; +while(!$EXIT) { + + print "$me> "; + + # Buffered IO screws things up + my $c=""; + $line = ""; + while($c ne "\n") { + my $ret = sysread(STDIN, $c, 1); + if (!defined $ret) { + die "Read failed: $!"; + } + + if (!$ret) { + last; + } + + $line .= $c; + } + + chomp $line; + $line =~ s/\r+$//; + $line =~ s/\n+$//; + + next unless ( $line ); + + my ($cmd, @args) = split(/\s+/, $line); + if ( exists $commands{$cmd} ) { + $commands{$cmd}->{handler}->( @args ); + } else { + print "Unknown command: '$cmd'\n"; + } + +} + +print "$me slave terminated.\n"; + +sub register { + my ($name, $handler, $desc) = @_; + $commands{$name} = { handler => $handler, desc => $desc }; +} + + +sub cmd_quit { + $EXIT = 1; +} + +sub cmd_echo { + my (@args) = @_; + print "You said: '" . join(' ', @args) . "'\n\n"; +} + +sub cmd_blkecho { + my $size = shift // 1024; + unless ($size =~ /^\d+/ ) { + print "The argument must be a number\n\n"; + return; + } + + my $buf; + while(1) { + my ($tmp, $ret); + $buf = ""; + + while(length($buf) < $size) { + $ret = sysread(STDIN, $tmp, $size - length($buf)); + if ( !defined $ret ) { + die "Error reading from socket: $!"; + } + + last if ( $ret == 0 ); + $buf .= $tmp; + } + + my $written =0; + while($written < $size) { + my $ret = syswrite(STDOUT, $buf, $size, $written); + if (!defined $ret) { + die "Error writing to socket: $!"; + } + + last if ( $ret == 0); + $written += $ret; + } + } +} + +sub cmd_reexec { + print "Will now re-execute: $0 " . join(' ', @ARGV) . "\n"; + exec($0, @ARGV); +} + +sub cmd_exec { + print "Will now exec: uname -a\n"; + exec("uname", "-a"); +} + +sub cmd_system { + print "Will now call: uptime\n"; + system("uptime"); + print "\n"; +} + +# Forks off a short lived process + +sub cmd_fork { + my $pid = fork(); + if ( $pid == 0 ) { + print "I am the child, with pid $$. Waiting 10 seconds.\n"; + sleep(10); + print "Child exiting with code 123\n"; + exit(123); + } else { + print "I am the parent, my child is $pid\n"; + my $dead = waitpid($pid, 0); + print "Reaped child $pid, return $dead\n"; + } + + print "\n"; +} + +sub cmd_help { + print "Commands:\n"; + for my $cmd ( sort keys %commands ) { + print "\t$cmd" . ( " " x (10 - length($cmd))) . ": " . $commands{$cmd}->{desc} . "\n"; + } + print "\n"; +} + +# Output a single character really fast. +# Used to test bandwidth and integrity +sub cmd_fastgen { + my $char = chr(shift // ord("x")); + my $buf = ($char x 72) . "\n"; + while( syswrite(STDOUT, $buf) ) { + 1; + } +} + +# Output RFC 864 chargen. +# Used to test bandwidth +sub cmd_chargen { + my $text = ""; + + for(my $i=33;$i<33+95;$i++) { + $text .= chr($i); + } + + + my $pos = 0; + my $strlen = 72; + while( 1 ) { + my $out = substr($text, $pos, $strlen); + + if ( $pos + $strlen > length($text) ) { + $out .= substr($text, 0, $pos + $strlen - length($text) + 1); + } + + $out .= "\n"; + + syswrite(STDOUT, $out) or return; + + if ( ++$pos >= length($text) ) { + $pos=0; + } + } + +} + +# Output random data +# Used to test channel integrity and bandwidth with incompressible content. +# Typically slower than chargen/fastgen. + +sub cmd_randgen { + if ( open(my $fh, '<', '/dev/urandom') ) { + my $buf; + while(1) { + sysread($fh, $buf, 1024); + syswrite(STDOUT, $buf) or return; + } + } else { + print "Failed to open /dev/urandom: $!. May not be available on this architecture.\n\n"; + } +} + +# Accept arbitrary data +# Used to test bandwidth + +sub cmd_discard { + my $buf = ""; + + while( sysread(STDIN, $buf, 1024) ) { + 1; + } + +} + +# Dump the environment + +sub cmd_env { + my $longest = 0; + + foreach my $var (keys %ENV) { + if ( $longest < length($var) ) { + $longest = length($var); + } + } + + foreach my $var (sort keys %ENV) { + print "$var" . (" " x ($longest - length($var))) . ": $ENV{$var}\n"; + } + + print "\n"; +} + +# Show the current directory + +sub cmd_pwd { + require Cwd; + import Cwd; + print "Current directory: " . getcwd() . "\n\n"; +} diff --git a/testscripts/slave-client b/testscripts/slave-client new file mode 100755 index 000000000..4ce75f45f --- /dev/null +++ b/testscripts/slave-client @@ -0,0 +1,416 @@ +#!/usr/bin/perl -w +#/**************************************************************************/ +#/* */ +#/* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com) */ +#/* */ +#/* NXSCRIPTS, NX protocol compression and NX extensions to this software */ +#/* are copyright of the aforementioned persons and companies. */ +#/* */ +#/* Redistribution and use of the present software is allowed according */ +#/* to terms specified in the file LICENSE.nxcomp which comes in the */ +#/* source distribution. */ +#/* */ +#/* All rights reserved. */ +#/* */ +#/* NOTE: This software has received contributions from various other */ +#/* contributors, only the core maintainers and supporters are listed as */ +#/* copyright holders. Please contact us, if you feel you should be listed */ +#/* as copyright holder, as well. */ +#/* */ +#/**************************************************************************/ + +use strict; +use Getopt::Long; +use IO::Socket; +use Time::HiRes qw(gettimeofday tv_interval sleep ); +use IO::Socket::INET; + +my ($opt_batch, $opt_count, $opt_host, $opt_port, $opt_debug, $opt_blocksize, $opt_dump, $opt_delay); +my ($cmd_echo, $cmd_pingbench, $cmd_rand_read_bench, $cmd_fast_read_bench, $cmd_fast_write_bench); +my ($cmd_rand_write_bench, $cmd_fast_echo_bench, $cmd_rand_echo_bench, $cmd_all_bench); +my ($cmd_char_write_bench, $cmd_char_read_bench); +my ($cmd_help); + + +$opt_host = "127.0.0.1"; +$opt_count = 10000; +$opt_blocksize = 1024; +$opt_delay = 0; + +Getopt::Long::Configure ("bundling"); + +GetOptions( + "d|dump" => \$opt_dump, + "c|count=i" => \$opt_count, + "H|host=s" => \$opt_host, + "P|port=i" => \$opt_port, + "D|debug" => \$opt_debug, + "e|delay=f" => \$opt_delay, + "b|blocksize=i" => \$opt_blocksize, + "E|echo=s" => \$cmd_echo, + "pingbench" => \$cmd_pingbench, + "randreadbench" => \$cmd_rand_read_bench, + "fastreadbench" => \$cmd_fast_read_bench, + "fastwritebench" => \$cmd_fast_write_bench, + "randwritebench" => \$cmd_rand_write_bench, + "fastechobench" => \$cmd_fast_echo_bench, + "randechobench" => \$cmd_rand_echo_bench, + "charwritebench" => \$cmd_char_write_bench, + "charreadbench" => \$cmd_char_read_bench, + "a|allbench" => \$cmd_all_bench, + "h|help" => \$cmd_help, +) or die "Getopt failed"; + + +if ($cmd_help) { + print <<HELP; +Usage: $0 --port <port> [options] <command> +NX Slave Channel demo, benchmark and tester. + +Options: + -b, --blocksize=INT Block size for testing. 1024 bytes by default. + -c, --count=NUM Number of blocks or pings to issue. + -D, --debug Output protocol data for debugging + -d, --dump Dump benchmark data in tab separated format, for + graphing. + -e, --delay=FLOAT Delay between blocks or pings. None by default. + -H, --host=HOST Host to connect to. 'localhost' by default. + -P, --port=PORT Port to connect to. Mandatory. + +Benchmarks: + -a, --allbench Run all the benchmarks + --fastechobench Benchmark sending a single repeated character, + and receiving it back. + --fastreadbench Benchmark reading a single repeated character. + --fastwritebench Benchmark writing a single repeated character. + --pingbench Benchmark ping time. + --randechobench Benchmark sending random data, and receiving it + back + --randreadbench Benchmark reading random, incompressible data. + --randwritebench Benchmark writing random, incompressible data. + +Other commands: + -E, --echo=STR Send STR to the slave channel handler, and print + the response. + -h, --help Show this text + +Example: + Test basic connectivity: + $0 --port 42000 --echo "hi" + + Connect to port 42000 and run all the benchmarks: + $0 --port 42000 -a + +HELP +exit(0); +} + +if (!$opt_port) { + print STDERR "Syntax: $0 --port <port> <command> [arguments]\nUse $0 --help for more information.\n\n"; + exit(1); +} + + +my $socket = IO::Socket::INET->new(PeerAddr => $opt_host, PeerPort => $opt_port, Proto => 'tcp'); +if (!$socket) { + die "Can't connect to $opt_host:$opt_port: $!"; +} + +my @greeting = read_until_prompt(); +my $sl = StatusLine->new(); +my $random_fh; + +if ( $cmd_all_bench ) { + $cmd_pingbench = 1; + $cmd_rand_read_bench = 1; + $cmd_fast_read_bench = 1; + $cmd_fast_write_bench = 1; + $cmd_rand_write_bench = 1; + $cmd_fast_echo_bench = 1; + $cmd_rand_echo_bench = 1; + $cmd_all_bench = 1; + +} + +if ( $cmd_echo ) { + send_cmd("echo $cmd_echo"); + print read_until_prompt() . "\n"; +} + +if ( $cmd_pingbench ) { + my $t0 = [gettimeofday()]; + for(my $i=0;$i<$opt_count;$i++) { + send_cmd("echo $i"); + read_until_prompt(); + + my $elapsed = tv_interval($t0, [gettimeofday()]); + if ( $opt_dump ) { + print "$elapsed\t$i\n"; + } else { + $sl->set("Pinged " . ($i+1) . " times, ${elapsed}s elapsed, " . $opt_count / $elapsed . "/s"); + } + + sleep($opt_delay) if ($opt_delay>0); + } + + $sl->show_last(); + print STDERR "\n\n"; +} + +if ( $cmd_rand_read_bench ) { + read_bench("Random read", "randgen"); +} + +if ( $cmd_fast_read_bench ) { + read_bench("Fast read", "fastgen"); +} + +if ( $cmd_fast_write_bench ) { + write_bench("Fast write", "discard", sub { "x" x $opt_blocksize }, 0); +} + +if ( $cmd_rand_write_bench ) { + write_bench("Random write", "discard", \&get_random_bytes, 0); +} + +if ( $cmd_fast_echo_bench ) { + write_bench("Fast echo", "blkecho $opt_blocksize", sub { "x" x $opt_blocksize }, 1); +} + + +if ( $cmd_rand_echo_bench ) { + write_bench("Random echo", "blkecho $opt_blocksize", \&get_random_bytes, 1); +} + +if ( $cmd_char_write_bench ) { + for(my $i=0;$i<=255;$i++) { + write_bench("Fast write $i", "discard", sub { chr($i) x $opt_blocksize }, 0); + } +} + +if ( $cmd_char_read_bench ) { + for(my $i=0;$i<=255;$i++) { + read_bench("Fast read $i", "fastgen $i"); + } +} + +sub get_random_bytes { + if (!$random_fh) { + open($random_fh, '<', "/dev/urandom") or die "Can't open /dev/urandom: $!"; + } + + my $buf=""; + while(length($buf) < $opt_blocksize) { + my $tmp; + sysread($random_fh, $tmp, $opt_blocksize - length($buf)); + $buf .= $tmp; + } + + return $buf; +} + +sub read_bench { + my ($desc, $command) = @_; + init(); + send_cmd($command); + + my $t0 = [gettimeofday()]; + my $bytes = 0; + + while($bytes < $opt_count * $opt_blocksize) { + my $junk = ""; + while(length($junk) < $opt_blocksize) { + $junk .= read_sock($opt_blocksize - length($junk)); + } + + $bytes += length($junk); + + my $elapsed = tv_interval($t0, [gettimeofday()]); + if ( $opt_dump ) { + print "$elapsed\t$bytes\n"; + } else { + $sl->set("$desc $bytes bytes, ${elapsed}s elapsed, " . sprintf("%0.3f", ($bytes / $elapsed) / (1024*1024)) . " MB/s"); + } + + sleep($opt_delay) if ($opt_delay>0); + + } + + $sl->show_last(); + print STDERR "\n\n"; + +} + +sub write_bench { + my ($desc, $command, $generator, $do_read) = @_; + init(); + send_cmd($command); + + my $t0 = [gettimeofday()]; + my $bytes = 0; + + while($bytes < $opt_count * $opt_blocksize) { + + my $junk = $generator->(); + $bytes += length($junk); + + write_sock($junk); + + if ( $do_read ) { + my $readbuf = ""; + while(length($readbuf) < $opt_blocksize) { + $readbuf .= read_sock($opt_blocksize-length($readbuf)); + } + + if ( $junk ne $readbuf ) { + die "Agent returned different data! Sent:\n$junk\nReceived:\n$readbuf\n"; + } + } + + my $elapsed = tv_interval($t0, [gettimeofday()]); + if ( $opt_dump ) { + print "$elapsed\t$bytes\n"; + } else { + $sl->set("$desc $bytes bytes, ${elapsed}s elapsed, " . sprintf("%0.3f", ($bytes / $elapsed) / (1024*1024)) . " MB/s"); + } + + sleep($opt_delay) if ($opt_delay>0); + } + + $sl->show_last(); + print STDERR "\n\n"; + +} + + + +sub read_until_prompt { + my $buf; + my $tmp; + my @lines; + my $ret = ""; + + while(1) { + $buf .= read_sock(1024); + + while ( $buf =~ /^(.*?)\n/m ) { + dbg("LINE: '$1'\n"); + push @lines, $1; + $ret .= "$1\n"; + $buf =~ s/^(.*?)\n//m; + } + + dbg("BUF: '$buf'\n"); + if ( $buf =~ /^(Agent|Proxy|\?)> / ) { + dbg("PROMPT: '$buf'\n"); + return wantarray ? @lines : $ret; + } + } +} + +sub init { + if ( $socket ) { + close $socket; + } + + $socket = IO::Socket::INET->new(PeerAddr => $opt_host, PeerPort => $opt_port, Proto => 'tcp'); + + if (!$socket) { + die "Can't connect to $opt_host:$opt_port: $!"; + } + + my @greeting = read_until_prompt(); +} + +sub read_sock { + my ($len) = @_; + my $buf; + my $ret = sysread($socket, $buf, $len); + if (!defined $ret) { + die "Error reading $len bytes from socket: $!"; + } + + if ( $ret == 0 ) { + die "Socket unexpectedly closed when trying to read $len bytes"; + } + + dbg("READ: '$buf', length $ret\n"); + return $buf; +} + +sub write_sock { + my ($data) = @_; + dbg("SEND: '$data'\n"); + + my $written = 0; + my $total = length($data); + + while($written < $total) { + my $ret = syswrite($socket, $data, $total, $written); + + if (!$ret) { + die "Error writing '$data' to socket: $!"; + } + if ( $ret == 0 ) { + die "Socket closed when writing '$data' to socket"; + } + + $written += $ret; + } + +} + + +sub send_cmd { + my ($cmd) = @_; + write_sock("$cmd\n"); +} + +sub dbg { + my ($str) = @_; + if ( $opt_debug ) { + $str =~ s/[^[:print:]\r\n\t]/./g; + print STDERR $str; + } +} + + +package StatusLine; +use Time::HiRes qw(gettimeofday tv_interval ); + +sub new { + my $class = shift; + + my $self = { + prev_len => 0 + }; + + bless $self, $class; + return $self; +} + +sub set { + my ($self, $str) = @_; + + my $now = [gettimeofday()]; + $self->{last_str} = $str; + + if ( !defined $self->{prev_time} || tv_interval($self->{prev_time}, $now) >= 0.1 ) { + print STDERR "\r" . (" " x $self->{prev_len}) . "\r$str"; + $self->{prev_len} = length($str); + $self->{prev_time} = $now; + } +} + +sub clear { + my ($self) = @_; + undef $self->{prev_time}; + $self->set(""); +} + +sub show_last { + my ($self) = @_; + undef $self->{prev_time}; + $self->set( $self->{last_str} ) if ( $self->{last_str} ); +} + |