Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ AC_OUTPUT(
treeshr/Makefile
treeshr/testing/Makefile
wfevent/Makefile
wfevent/testing/Makefile
xmdsshr/Makefile
xtreeshr/Makefile
)
Expand Down
2 changes: 1 addition & 1 deletion java/jscope/src/main/java/mds/jscope/jScopeMultiWave.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
145 changes: 145 additions & 0 deletions java/mdsobjects/src/test/java/MDSplus/MdsRemoteEventTest.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions java/mdsobjects/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ TESTS = \
MDSplus.MdsTreeNodeTest\
MDSplus.MdsTreeTest\
MDSplus.MdsWindowTest
# MDSplus.MdsRemoteEventTest
29 changes: 15 additions & 14 deletions m4/m4_ax_mdsplus_testing.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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 "])
Expand 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
Expand All @@ -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' ")
Expand Down
6 changes: 3 additions & 3 deletions mdsshr/MdsEvents.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mdstcpip/mdsipshr/MakeDescrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions mdstcpip/mdsipshr/MdsEventAst.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "../mdsip_connections.h"
#include <stdlib.h>
#include <string.h>

////////////////////////////////////////////////////////////////////////////////
// MdsEventAst ///////////////////////////////////////////////////////////////
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mdstcpip/mdsipshr/ProcessMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion testing/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ C_TEST_DIRS =\
mdstcpip/testing\
tditest/testing\
mdsobjects/cpp/testing\
actions/testing
actions/testing\
wfevent/testing
# testing/selftest

TEST_DIRS ?=\
Expand Down
2 changes: 2 additions & 0 deletions testing/ports.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 76 additions & 0 deletions wfevent/testing/LocalEventTest.sh
Original file line number Diff line number Diff line change
@@ -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
Loading