Commit 0fc7cc4b authored by Michael Büsch's avatar Michael Büsch

Add awlsim-client and rename awlsim-cli to awlsim-test

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent cbfcb885
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# AWL simulator - Client interface
#
# Copyright 2013-2016 Michael Buesch <m@bues.ch>
#
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *
import sys
import getopt
from awlsim.common import *
from awlsim.coreclient import *
class TextInterfaceAwlSimClient(AwlSimClient):
pass
def usage():
print("awlsim-client version %s" % VERSION_STRING)
print("")
print("Usage: awlsim-client [OPTIONS] <ACTIONS>")
print("")
print("Options:")
print(" -c|--connect HOST:PORT Connect to the server at HOST:PORT")
print(" Defaults to %s:%d" %\
(AwlSimServer.DEFAULT_HOST, AwlSimServer.DEFAULT_PORT))
print(" -t|--timeout 5.0 Set the connection timeout (default 5 s)")
print(" -L|--loglevel LVL Set the client log level:")
print(" 0: Log nothing")
print(" 1: Log errors")
print(" 2: Log errors and warnings (default)")
print(" 3: Log errors, warnings and info messages")
print(" 4: Verbose logging")
print(" 5: Extremely verbose logging")
print("")
print("Actions to be performed on the server:")
print(" -r|--runstate RUN/STOP Set the run state of the CPU.")
def main():
opt_connect = (AwlSimServer.DEFAULT_HOST, AwlSimServer.DEFAULT_PORT)
opt_timeout = 5.0
opt_loglevel = Logging.LOG_WARNING
actions = []
try:
(opts, args) = getopt.getopt(sys.argv[1:],
"hc:t:L:r:",
[ "help", "connect=", "timeout=", "loglevel=",
"runstate=", ])
except getopt.GetoptError as e:
printError(str(e))
usage()
return 1
for (o, v) in opts:
if o in ("-h", "--help"):
usage()
return 0
if o in ("-c", "--connect"):
try:
idx = v.rfind(":")
if idx <= 0:
raise ValueError
opt_listen = (v[:idx], int(v[idx+1:]))
except ValueError:
printError("-c|--connect: Invalid host/port")
sys.exit(1)
if o in ("-t", "--timeout"):
try:
opt_timeout = float(v)
except ValueError:
printError("-t|--timeout: Invalid timeout value")
sys.exit(1)
if o in ("-L", "--loglevel"):
try:
opt_loglevel = int(v)
except ValueError:
printError("-L|--loglevel: Invalid log level")
sys.exit(1)
if o in ("-r", "--runstate"):
if v.upper().strip() in ("RUN", "1", "START"):
actions.append(("runstate", True))
elif v.upper().strip() in ("STOP", "0"):
actions.append(("runstate", False))
else:
printError("-r|--runstate: Invalid run state")
sys.exit(1)
if args:
usage()
return 1
if not actions:
usage()
return 1
exitCode = 0
client = None
try:
Logging.setLoglevel(opt_loglevel)
client = TextInterfaceAwlSimClient()
client.connectToServer(host = opt_connect[0],
port = opt_connect[1],
timeout = opt_timeout)
for action, actionValue in actions:
if action == "runstate":
client.setRunState(actionValue)
else:
assert(0)
except AwlSimError as e:
printError(e.getReport())
return 1
finally:
if client:
client.shutdown()
return exitCode
if __name__ == "__main__":
sys.exit(main())
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# AWL simulator - Commandline interface
# AWL simulator - Commandline testing interface
#
# Copyright 2012-2014 Michael Buesch <m@bues.ch>
# Copyright 2012-2016 Michael Buesch <m@bues.ch>
#
# 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
......@@ -33,14 +33,14 @@ from awlsim.core import *
from awlsim.coreclient import *
class TextInterfaceAwlSimClient(AwlSimClient):
class TestAwlSimClient(AwlSimClient):
def handle_CPUDUMP(self, dumpText):
emitCpuDump(dumpText)
def usage():
print("awlsim version %s" % VERSION_STRING)
print("")
print("Usage: awlsim-cli [OPTIONS] <AWL-source or awlsim-project file>")
print("Usage: awlsim-test [OPTIONS] <AWL-source or awlsim-project file>")
print("")
print("Options:")
print(" -C|--cycle-limit SEC Cycle time limit, in seconds (default 5.0)")
......@@ -254,7 +254,7 @@ def runWithServerBackend(inputFile):
project = Project.fromProjectOrRawAwlFile(inputFile)
# Connect to the server
client = TextInterfaceAwlSimClient()
client = TestAwlSimClient()
if opt_spawnBackend:
host, port = AwlSimServer.DEFAULT_HOST, AwlSimServer.DEFAULT_PORT
if opt_connect:
......
......@@ -59,10 +59,11 @@ isMicroPython = hasattr(sys, "implementation") and\
# isWinStandalone is True, if this is a Windows standalone package (py2exe)
isWinStandalone = osIsWindows and\
(sys.executable.endswith("awlsim-gui.exe") or\
sys.executable.endswith("awlsim-cli.exe") or\
sys.executable.endswith("awlsim-client.exe") or\
sys.executable.endswith("awlsim-server.exe") or\
sys.executable.endswith("awlsim-server-module.exe") or\
sys.executable.endswith("awlsim-symtab.exe"))
sys.executable.endswith("awlsim-symtab.exe") or\
sys.executable.endswith("awlsim-test.exe"))
# isPy3Compat is True, if the interpreter is Python 3 compatible.
isPy3Compat = sys.version_info[0] == 3
......
......@@ -5,7 +5,7 @@ basedir="$(dirname "$0")"
set -e
if ! [ -x "$basedir/awlsim-cli" -a -x "$basedir/setup.py" ]; then
if ! [ -x "$basedir/awlsim-test" -a -x "$basedir/setup.py" ]; then
echo "basedir sanity check failed"
exit 1
fi
......
......@@ -285,10 +285,11 @@ try:
except ValueError:
pass
freezeExecutables = [ ("awlsim-cli", None),
("awlsim-gui", None),
freezeExecutables = [ ("awlsim-gui", None),
("awlsim-client", None),
("awlsim-server", None),
("awlsim-symtab", None),
("awlsim-test", None),
("awlsim/coreserver/server.py", "awlsim-server-module"), ]
if py2exe:
extraKeywords["console"] = [ s for s, e in freezeExecutables ]
......@@ -333,10 +334,11 @@ setup( name = "awlsim",
"awlsimhw_dummy",
"awlsimhw_linuxcnc",
"awlsimhw_pyprofibus", ],
scripts = [ "awlsim-cli",
"awlsim-gui",
scripts = [ "awlsim-gui",
"awlsim-client",
"awlsim-server",
"awlsim-symtab",
"awlsim-test",
"awlsim-linuxcnc-hal",
"awlsim-win.bat", ] + extraScripts,
cmdclass = cmdclass,
......
# awlsim-cli tests
# command line interface tests
sh_test()
{
......@@ -7,23 +7,25 @@ sh_test()
cd "$rootdir" || die "Failed to change to rootdir '$rootdir'"
"$interpreter" ./awlsim-cli -h >/dev/null ||\
test_failed "Call to awlsim-cli -h failed"
"$interpreter" ./awlsim-cli --help >/dev/null ||\
test_failed "Call to awlsim-cli -h failed"
"$interpreter" ./awlsim-cli -I dummy >/dev/null ||\
test_failed "Call to awlsim-cli -I dummy failed"
"$interpreter" ./awlsim-cli --hardware-info dummy >/dev/null ||\
test_failed "Call to awlsim-cli --hardware-info dummy failed"
"$interpreter" ./awlsim-cli --list-sfc >/dev/null ||\
test_failed "Call to awlsim-cli --list-sfc failed"
"$interpreter" ./awlsim-cli --list-sfc-verbose >/dev/null ||\
test_failed "Call to awlsim-cli --list-sfc-verbose failed"
"$interpreter" ./awlsim-cli --list-sfb >/dev/null ||\
test_failed "Call to awlsim-cli --list-sfb failed"
"$interpreter" ./awlsim-cli --list-sfb-verbose >/dev/null ||\
test_failed "Call to awlsim-cli --list-sfb-verbose failed"
# check awlsim-test executable
"$interpreter" ./awlsim-test -h >/dev/null ||\
test_failed "Call to awlsim-test -h failed"
"$interpreter" ./awlsim-test --help >/dev/null ||\
test_failed "Call to awlsim-test -h failed"
"$interpreter" ./awlsim-test -I dummy >/dev/null ||\
test_failed "Call to awlsim-test -I dummy failed"
"$interpreter" ./awlsim-test --hardware-info dummy >/dev/null ||\
test_failed "Call to awlsim-test --hardware-info dummy failed"
"$interpreter" ./awlsim-test --list-sfc >/dev/null ||\
test_failed "Call to awlsim-test --list-sfc failed"
"$interpreter" ./awlsim-test --list-sfc-verbose >/dev/null ||\
test_failed "Call to awlsim-test --list-sfc-verbose failed"
"$interpreter" ./awlsim-test --list-sfb >/dev/null ||\
test_failed "Call to awlsim-test --list-sfb failed"
"$interpreter" ./awlsim-test --list-sfb-verbose >/dev/null ||\
test_failed "Call to awlsim-test --list-sfb-verbose failed"
}
# awlsim-cli with coreserver tests
# awlsim-test with coreserver tests
sh_test()
{
......
......@@ -92,7 +92,7 @@ cleanup_test_environment()
export AWLSIMCYTHON=
}
# $1=interpreter $2=awl_file ($3ff additional options to awlsim-cli)
# $1=interpreter $2=awl_file ($3ff additional options to awlsim-test)
run_awl_test()
{
local interpreter="$1"
......@@ -104,7 +104,7 @@ run_awl_test()
local ok=1
command time -o "$test_time_file" -f '%E' \
"$interpreter" "$rootdir/awlsim-cli" --loglevel 2 --extended-insns \
"$interpreter" "$rootdir/awlsim-test" --loglevel 2 --extended-insns \
--hardware debug:inputAddressBase=7:outputAddressBase=8:dummyParam=True \
--cycle-time 60 \
"$@" \
......@@ -146,7 +146,7 @@ run_sh_test()
echo "[OK]"
}
# $1=interpreter $2=testfile(.awl/.sh) ($3ff additional options to awlsim-cli or testfile)
# $1=interpreter $2=testfile(.awl/.sh) ($3ff additional options to awlsim-test or testfile)
run_test()
{
local interpreter="$1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment