diff --git a/.gitignore b/.gitignore index 02de39fba5..a1a054c502 100644 --- a/.gitignore +++ b/.gitignore @@ -205,6 +205,7 @@ testing/selftest/Makefile.in treeshr/testing/Makefile.in treeshr/TreeFindNodeWild.c wfevent/Makefile.in +wfevent/testing/Makefile.in m4/ax_git_revision.m4 # Generated Java binaries diff --git a/configure.ac b/configure.ac index 88f779cc8c..0b47b49052 100644 --- a/configure.ac +++ b/configure.ac @@ -1455,6 +1455,7 @@ AC_OUTPUT( treeshr/Makefile treeshr/testing/Makefile wfevent/Makefile + wfevent/testing/Makefile xmdsshr/Makefile xtreeshr/Makefile ) diff --git a/java/jscope/src/main/java/mds/jscope/jScopeMultiWave.java b/java/jscope/src/main/java/mds/jscope/jScopeMultiWave.java index 56ace9c283..6c148023f6 100644 --- a/java/jscope/src/main/java/mds/jscope/jScopeMultiWave.java +++ b/java/jscope/src/main/java/mds/jscope/jScopeMultiWave.java @@ -312,7 +312,7 @@ public void RemoveEvent() throws IOException public void RemoveEvent(String event) throws IOException { - ((MdsWaveInterface) wi).AddEvent(this, event); + ((MdsWaveInterface) wi).RemoveEvent(this, event); } @Override diff --git a/java/mdsobjects/src/test/java/MDSplus/MdsRemoteEventTest.java b/java/mdsobjects/src/test/java/MDSplus/MdsRemoteEventTest.java new file mode 100644 index 0000000000..7c50e6c7be --- /dev/null +++ b/java/mdsobjects/src/test/java/MDSplus/MdsRemoteEventTest.java @@ -0,0 +1,145 @@ +package MDSplus; + +import mds.connection.*; + +import java.io.File; +import java.net.DatagramSocket; +import java.net.SocketException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class MdsRemoteEventTest implements UpdateEventListener, ConnectionListener +{ + // See testing/ports.csv + static int port = 8019; + static Process mdsip; + + static java.lang.String event = "test_event"; + static boolean eventReceived = false; + static boolean connectionLost = false; + + @BeforeClass + public static void setUpBeforeClass() throws Exception + { + int test_port_offset = 0; + java.lang.String test_port_offset_env = System.getenv("TEST_PORT_OFFSET"); + if (test_port_offset_env != null) { + try { + test_port_offset = Integer.parseInt(test_port_offset_env); + } + catch (final NumberFormatException exc) + {} + } + + port += test_port_offset; + + try + { + new DatagramSocket(port).close(); + java.lang.String hostspath = System.getenv("MDSPLUS_DIR") + "/testing/mdsip.hosts"; + if (!new File(hostspath).exists()) + { + hostspath = "/etc/mdsip.hosts"; + if (!new File(hostspath).exists()) + { + System.exit(5); + } + } + final java.lang.String parts[] = + { "mdsip", "-s", "-p", Integer.toString(port), "-h", hostspath }; + System.out.println(java.lang.String.join(" ", parts)); + final ProcessBuilder pb = new ProcessBuilder(parts); + mdsip = pb.start(); + return; + } + catch (final SocketException exc) + {} + } + + @AfterClass + public static void tearDownAfterClass() throws Exception + { + mdsip.destroy(); + mdsip.waitFor(); + } + + @Before + public void setUp() throws Exception + {} + + @After + public void tearDown() throws Exception + {} + + @Test + public void testEvent() throws MDSplus.MdsException + { + try + { + System.out.println("connecting to localhost:" + port + " ... "); + MdsConnection c = new MdsConnection("localhost:" + port); + for (int count = 0; count < 3; ++count) + { + try + { + c.ConnectToMds(false); + System.out.println("connected!"); + + // Success, stop trying + break; + } + catch (final Exception exc) + { + exc.printStackTrace(); + + System.out.println("retry ... "); + Thread.sleep(1000); + + // Failure, keep trying + continue; + } + } + Assert.assertFalse("Cannot connect to mdsip server", c == null || !c.isConnected()); + // Set up connection listener + c.addConnectionListener(this); + // Set up event listener + c.MdsSetEvent((UpdateEventListener) this, event); + // Trigger Event + final MDSplus.Data dataMsg = new MDSplus.String("data message"); + eventReceived = false; + MDSplus.Event.setEvent(event, dataMsg); + Thread.sleep(2000); + // Check connection is still up + Assert.assertFalse("Connection to mdsip server has been lost", connectionLost); + // Check event received + Assert.assertTrue("Data Event not received", eventReceived); + } + catch (final Exception exc) + { + exc.printStackTrace(); + Assert.fail(exc.toString()); + } + } + + @Override + public void processUpdateEvent(UpdateEvent e) + { + System.out.println("Event "+e.getName()+" received"); + if (e.getName().equals(event)) { + eventReceived = true; + } + } + + @Override + public void processConnectionEvent(ConnectionEvent e) + { + System.out.println("Connection event: "+e.getInfo()); + if (e.getID() == ConnectionEvent.LOST_CONNECTION) { + connectionLost = true; + } + } +} diff --git a/java/mdsobjects/tests/Makefile.am b/java/mdsobjects/tests/Makefile.am index 47f56d0824..8fc7b4d0c9 100644 --- a/java/mdsobjects/tests/Makefile.am +++ b/java/mdsobjects/tests/Makefile.am @@ -24,3 +24,4 @@ TESTS = \ MDSplus.MdsTreeNodeTest\ MDSplus.MdsTreeTest\ MDSplus.MdsWindowTest +# MDSplus.MdsRemoteEventTest diff --git a/m4/m4_ax_mdsplus_testing.m4 b/m4/m4_ax_mdsplus_testing.m4 index cbee727002..e0a6071878 100644 --- a/m4/m4_ax_mdsplus_testing.m4 +++ b/m4/m4_ax_mdsplus_testing.m4 @@ -187,6 +187,7 @@ AC_DEFUN([TS_SELECT],[ [ TS_WINE_ENV([WINEPREFIX],[WINEARCH]) TS_WINE_LIBRARIESPATH([WINEPATH]) + TS_WINEPATH([WINEPATH],["\$(top_builddir)/wfevent" "\$(top_builddir)/setevent"]) AS_VAR_SET([PYTHONHOME],"TS_U2WPATH([/python27])") AS_VAR_APPEND([TESTS_ENVIRONMENT],["WINEARCH='${WINEARCH}' WINEPREFIX='${WINEPREFIX}' "]) AS_VAR_APPEND([TESTS_ENVIRONMENT],["WINEDEBUG=-all "]) @@ -196,19 +197,19 @@ AC_DEFUN([TS_SELECT],[ AS_VAR_APPEND([TESTS_ENVIRONMENT],["main_path='.;TS_U2WPATH([${srcdir}/trees])' "]) AS_VAR_APPEND([TESTS_ENVIRONMENT],["subtree_path='.;TS_U2WPATH([${srcdir}/trees/subtree])' "]) AS_VAR_IF([WINEARCH],[win64], - [# WINEARCH win64 - AS_VAR_APPEND([WINEPATH],["${PYTHONHOME}"]) - AS_VAR_APPEND([TESTS_ENVIRONMENT],["PYTHONHOME='${PYTHONHOME}' "]) - AS_VAR_APPEND([TESTS_ENVIRONMENT], - ["PYTHONPATH='%PYTHONHOME%\\Lib;%PYTHONHOME%\\Lib\\site-packages;TS_U2WPATH([${srcdir}/python])' "]) - AS_VAR_APPEND([TESTS_ENVIRONMENT],["PyLib='python27' "]) - AS_VAR_SET([PYTHON],["\$(abs_top_srcdir)/testing/winpython python"]) - AS_VAR_APPEND([PY_LOG_COMPILER], - ["\${PYTHON} -B \$(abs_top_srcdir)/testing/testing.py"])], - [# WINEARCH win32 - TS_LOG_SKIP([PY_LOG_COMPILER])]) - # any wine flavor - AS_VAR_APPEND([TESTS_ENVIRONMENT],"WINEPATH='${WINEPATH}' ") + [# WINEARCH win64 + AS_VAR_APPEND([WINEPATH],["${PYTHONHOME}"]) + AS_VAR_APPEND([TESTS_ENVIRONMENT],["PYTHONHOME='${PYTHONHOME}' "]) + AS_VAR_APPEND([TESTS_ENVIRONMENT], + ["PYTHONPATH='%PYTHONHOME%\\Lib;%PYTHONHOME%\\Lib\\site-packages;TS_U2WPATH([${srcdir}/python])' "]) + AS_VAR_APPEND([TESTS_ENVIRONMENT],["PyLib='python27' "]) + AS_VAR_SET([PYTHON],["\$(abs_top_srcdir)/testing/winpython python"]) + AS_VAR_APPEND([PY_LOG_COMPILER], + ["\${PYTHON} -B \$(abs_top_srcdir)/testing/testing.py"])], + [# WINEARCH win32 + TS_LOG_SKIP([PY_LOG_COMPILER])]) + # any wine flavor + AS_VAR_APPEND([TESTS_ENVIRONMENT],"WINEPATH='${WINEPATH}' ") AS_VAR_APPEND([LOG_COMPILER],"wine ") # WINE Valgrind tuning .. # see: http://wiki.winehq.org/WineAndValgrind @@ -233,7 +234,7 @@ AC_DEFUN([TS_SELECT],[ [ AS_VAR_SET([ENABLE_TESTS],[yes]) AS_ECHO("Set tests environment for linux->linux") - AS_VAR_APPEND([TESTS_ENVIRONMENT],"PATH=${MAKEBINDIR}:\$(abs_top_srcdir)/testing:\${PATH} ") + AS_VAR_APPEND([TESTS_ENVIRONMENT],"PATH=${MAKEBINDIR}:${MAKEBINDIR}/../setevent:${MAKEBINDIR}/../wfevent:\$(abs_top_srcdir)/testing:\${PATH} ") AS_VAR_APPEND([TESTS_ENVIRONMENT],"MDSPLUS_DIR=\$(abs_top_srcdir) ") AS_VAR_APPEND([TESTS_ENVIRONMENT],"MDS_PATH=\$(abs_top_srcdir)/tdi ") AS_VAR_APPEND([TESTS_ENVIRONMENT],"MDS_PYDEVICE_PATH='\$(abs_top_srcdir)/pydevices;\$(abs_top_srcdir)/python/MDSplus/tests/devices' ") diff --git a/mdsshr/MdsEvents.c b/mdsshr/MdsEvents.c index 9b97347957..e3d1a78db4 100644 --- a/mdsshr/MdsEvents.c +++ b/mdsshr/MdsEvents.c @@ -400,7 +400,7 @@ static void *handleRemoteAst(void *arg ) getServerDefinition("mds_event_server", receive_servers, &num_receive_servers); newRemoteId(eventInfo->eventid); for (idx = 0; idx < num_receive_servers; idx++) - { + { receive_thread_ids[idx] = searchOpenServer(receive_servers[idx]); if(receive_thread_ids[idx] < 0) { @@ -574,7 +574,7 @@ static int eventAstRemote(char const *eventnam, void (*astadr)(), void *astprm, if (STATUS_OK) { /* if external_thread running, it must be killed before sending messages - * over socket */ + * over socket */ if (external_thread_created) { KillHandler(); @@ -883,7 +883,7 @@ static int canEventRemote(const int eventid) { KillHandler(); for (i = 0; i < num_receive_servers; i++) - { + { if (receive_ids[i] < 0) receive_ids[i] = ConnectToMds_(receive_servers[i]); if(receive_ids[i] == INVALID_CONNECTION_ID) diff --git a/mdstcpip/mdsipshr/MakeDescrip.c b/mdstcpip/mdsipshr/MakeDescrip.c index 58c4b2532a..3ce0effcde 100644 --- a/mdstcpip/mdsipshr/MakeDescrip.c +++ b/mdstcpip/mdsipshr/MakeDescrip.c @@ -46,7 +46,7 @@ struct descrip *MakeDescripWithLength(struct descrip *in_descrip, char dtype, } //////////////////////////////////////////////////////////////////////////////// -// MakeSecrip //////////////////////////////////////////////////////////////// +// MakeDescrip /////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// struct descrip *MakeDescrip(struct descrip *in_descrip, char dtype, char ndims, diff --git a/mdstcpip/mdsipshr/MdsEventAst.c b/mdstcpip/mdsipshr/MdsEventAst.c index 4f1ee51e7f..f638ebd59f 100644 --- a/mdstcpip/mdsipshr/MdsEventAst.c +++ b/mdstcpip/mdsipshr/MdsEventAst.c @@ -25,6 +25,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../mdsip_connections.h" #include +#include //////////////////////////////////////////////////////////////////////////////// // MdsEventAst /////////////////////////////////////////////////////////////// @@ -40,6 +41,8 @@ int MdsEventAst(int id, char *eventnam, void (*astadr)(), void *astprm, MdsEventInfo info; int size = sizeof(info); int status; + memset(info.data,0,sizeof(info.data)); + info.eventid = 0; info.astadr = (void (*)(void *, int, char *))astadr; info.astprm = astprm; ansarg.ptr = 0; diff --git a/mdstcpip/mdsipshr/ProcessMessage.c b/mdstcpip/mdsipshr/ProcessMessage.c index 5421956fee..968cc7e6fb 100644 --- a/mdstcpip/mdsipshr/ProcessMessage.c +++ b/mdstcpip/mdsipshr/ProcessMessage.c @@ -611,7 +611,7 @@ static inline void _client_event_ast(MdsEventList *e, int data_len, char *data, (*m)->h.msglen = len; (*m)->h.dtype = DTYPE_EVENT_NOTIFY; if (data_len > 0) - memcpy(e->info->data, data, (data_len < 12) ? data_len : 12); + memcpy((*m)->bytes, data, (data_len < 12) ? data_len : 12); SendMdsMsgC(e->connection, *m, MSG_DONTWAIT); } diff --git a/testing/Makefile.am b/testing/Makefile.am index a79a604345..62c3688f80 100644 --- a/testing/Makefile.am +++ b/testing/Makefile.am @@ -60,7 +60,8 @@ C_TEST_DIRS =\ mdstcpip/testing\ tditest/testing\ mdsobjects/cpp/testing\ - actions/testing + actions/testing\ + wfevent/testing # testing/selftest TEST_DIRS ?=\ diff --git a/testing/ports.csv b/testing/ports.csv index e3a2b87b2c..0d1452a6e0 100644 --- a/testing/ports.csv +++ b/testing/ports.csv @@ -7,4 +7,6 @@ python/MDSplus/tests/connection-tcp, 8014 python/MDSplus/tests/connection-write, 8015 python/MDSplus/tests/dcl-dispatcher, 8016-8017 python/MDSplus/tests/dcl-timeout, 8018 +java/mdsobjects/test/MdsRemoteEventTest, 8019 +wfevent/testing/RemoteEventTest.sh, 8020 actions/testing/ServerShrTest.sh, 8021-8023 diff --git a/wfevent/testing/LocalEventTest.sh b/wfevent/testing/LocalEventTest.sh new file mode 100755 index 0000000000..d2c7079a6f --- /dev/null +++ b/wfevent/testing/LocalEventTest.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +status=0 + +srcdir=$(readlink -f $(dirname ${0})) + +event_name=test_event +timeout=20 +sleepdur=5 + +if [ "$OS" == "windows" ]; then + WFEVENT="wine wfevent" + SETEVENT="wine setevent" + OPTTIMEOUT="/t:$timeout" + OPTDATA="/d" + DIFF_Z="-Z" +else + WFEVENT="wfevent" + SETEVENT="setevent" + OPTTIMEOUT="--timeout=$timeout" + OPTDATA="--data" + DIFF_Z="" +fi + +### TEST 1: local event no data + +name=wfevent + +$WFEVENT $event_name $OPTTIMEOUT > $name.log 2> $name.err & +pid=$! +sleep $sleepdur +$SETEVENT $event_name + +# Make sure wfevent is terminated +if [ ! kill -0 $pid 2> /dev/null ]; then + sleep $timeout + if [ ! kill -0 $pid 2> /dev/null ]; then + kill -SIGKILL $pid + fi +fi + +# Check output of actlog against reference +if diff $DIFF_Z $name.log ${srcdir}/$name.ans; then + echo "PASS: $name" +else + echo "FAIL: $name" + status=1 +fi + +### TEST 2: local event with data + +name=wfeventData + +$WFEVENT $event_name $OPTDATA $OPTTIMEOUT > $name.log 2> $name.err & +pid=$! +sleep $sleepdur +$SETEVENT $event_name "hello" + +# Make sure wfevent is terminated +if [ ! kill -0 $pid 2> /dev/null ]; then + sleep $timeout + if [ ! kill -0 $pid 2> /dev/null ]; then + kill -SIGKILL $pid + fi +fi + +# Check output of actlog against reference +if diff $DIFF_Z $name.log ${srcdir}/$name.ans; then + echo "PASS: $name" +else + echo "FAIL: $name" + status=1 +fi + +# Return +exit $status diff --git a/wfevent/testing/Makefile.am b/wfevent/testing/Makefile.am new file mode 100644 index 0000000000..4fef5746c1 --- /dev/null +++ b/wfevent/testing/Makefile.am @@ -0,0 +1,30 @@ + +include @top_builddir@/Makefile.inc +include ../../testing/testing.am + + +## ////////////////////////////////////////////////////////////////////////// ## +## // TESTS //////////////////////////////////////////////////////////////// ## +## ////////////////////////////////////////////////////////////////////////// ## + +TEST_EXTENSIONS = .sh + +# Temporarily disable tests +#TESTS = \ +# LocalEventTest.sh\ +# RemoteEventTest.sh + +# Files produced by tests that must be purged +# +MOSTLYCLEANFILES = \ + ./*.log ./*.err + +## ////////////////////////////////////////////////////////////////////////// ## +## // TARGETS ////////////////////////////////////////////////////////////// ## +## ////////////////////////////////////////////////////////////////////////// ## + + +#clean-local: clean-local-tests + +check_PROGRAMS = +check_SCRIPTS = $(TESTS) diff --git a/wfevent/testing/RemoteEventTest.sh b/wfevent/testing/RemoteEventTest.sh new file mode 100755 index 0000000000..02b21e8b38 --- /dev/null +++ b/wfevent/testing/RemoteEventTest.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +status=0 + +srcdir=$(readlink -f $(dirname ${0})) + +event_name=test_event +timeout=20 +sleepdur=5 + +if [ "$OS" == "windows" ]; then + WFEVENT="wine wfevent" + SETEVENT="wine setevent" + MDSIP="wine mdsip" + OPTTIMEOUT="/t:$timeout" + OPTDATA="/d" + DIFF_Z="-Z" +else + WFEVENT="wfevent" + SETEVENT="setevent" + MDSIP="mdsip" + OPTTIMEOUT="--timeout=$timeout" + OPTDATA="--data" + DIFF_Z="" +fi + +# See testing/ports.csv +port=8020 +if [ ! -z $TEST_PORT_OFFET ]; then + port=$((port + TEST_PORT_OFFSET)) +fi + +# Start event server + +$MDSIP --multi --protocol=tcp --port=$port --hostfile=$MDSPLUS_DIR/testing/mdsip.hosts > mdsip.log 2> mdsip.err & +pidmdsip=$! + +sleep $sleepdur + +### TEST 1: remote event no data + +name=wfeventRemote + +mds_event_server=localhost:$port $WFEVENT $event_name $OPTTIMEOUT > $name.log 2> $name.err & +pid=$! +sleep $sleepdur +$SETEVENT $event_name + +# Make sure wfevent is terminated +if [ ! kill -0 $pid 2> /dev/null ]; then + sleep $timeout + if [ ! kill -0 $pid 2> /dev/null ]; then + kill -SIGKILL $pid + fi +fi + +# Check output of actlog against reference +if diff $DIFF_Z $name.log ${srcdir}/$name.ans; then + echo "PASS: $name" +else + echo "FAIL: $name" + status=1 +fi + +### TEST 2: remote event with data + +name=wfeventRemoteData + +mds_event_server=localhost:$port $WFEVENT $event_name $OPTDATA $OPTTIMEOUT > $name.log 2> $name.err & +pid=$! +sleep $sleepdur +$SETEVENT $event_name "hello1world2" # Data from remote event is always 12 byte long + +# Make sure wfevent is terminated +if [ ! kill -0 $pid 2> /dev/null ]; then + sleep $timeout + if [ ! kill -0 $pid 2> /dev/null ]; then + kill -SIGKILL $pid + fi +fi + +# Check output of actlog against reference +if diff $DIFF_Z $name.log ${srcdir}/$name.ans; then + echo "PASS: $name" +else + echo "FAIL: $name" + status=1 +fi + +# Cleanup +kill -SIGKILL $pidmdsip + +# Return +exit $status diff --git a/wfevent/testing/wfevent.ans b/wfevent/testing/wfevent.ans new file mode 100644 index 0000000000..ebc89328a5 --- /dev/null +++ b/wfevent/testing/wfevent.ans @@ -0,0 +1 @@ +Event test_event occurred. diff --git a/wfevent/testing/wfeventData.ans b/wfevent/testing/wfeventData.ans new file mode 100644 index 0000000000..12bc861fec --- /dev/null +++ b/wfevent/testing/wfeventData.ans @@ -0,0 +1 @@ +Event test_event occurred with data = \hello\ diff --git a/wfevent/testing/wfeventRemote.ans b/wfevent/testing/wfeventRemote.ans new file mode 100644 index 0000000000..ebc89328a5 --- /dev/null +++ b/wfevent/testing/wfeventRemote.ans @@ -0,0 +1 @@ +Event test_event occurred. diff --git a/wfevent/testing/wfeventRemoteData.ans b/wfevent/testing/wfeventRemoteData.ans new file mode 100644 index 0000000000..f33f70e8b9 --- /dev/null +++ b/wfevent/testing/wfeventRemoteData.ans @@ -0,0 +1 @@ +Event test_event occurred with data = \hello1world2\ diff --git a/wfevent/wfevent.c b/wfevent/wfevent.c index cbf8fd0b21..996dbc3d09 100644 --- a/wfevent/wfevent.c +++ b/wfevent/wfevent.c @@ -193,7 +193,7 @@ int main(int argc, char **argv) printf("Event %s occurred with data = \\%.*s\\\n", event, len, data); else { - printf("Event %s occured with data = [", event); + printf("Event %s occurred with data = [", event); for (i = 0; i < len - 1; i++) { printf("%0dB,", (int)data[i]); @@ -201,6 +201,10 @@ int main(int argc, char **argv) printf("%dB]\n", (int)data[i]); } } + else + { + printf("Event %s occurred.\n", event); + } return (0); } else if (timeout > 0)