aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/test/ei_connect_SUITE_data
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2009-12-15 10:33:33 +0000
committerErlang/OTP <[email protected]>2009-12-15 12:24:17 +0100
commitfe272a8454d2379c2ed5b0f9f04b493574316a8d (patch)
tree38e09b9529109886886241b03a20f589c3559d04 /lib/erl_interface/test/ei_connect_SUITE_data
parentde4639e46760493bad61ae48a5d894001216720e (diff)
downloadotp-fe272a8454d2379c2ed5b0f9f04b493574316a8d.tar.gz
otp-fe272a8454d2379c2ed5b0f9f04b493574316a8d.tar.bz2
otp-fe272a8454d2379c2ed5b0f9f04b493574316a8d.zip
Include the test suites for erl_interface
Diffstat (limited to 'lib/erl_interface/test/ei_connect_SUITE_data')
-rw-r--r--lib/erl_interface/test/ei_connect_SUITE_data/Makefile.first21
-rw-r--r--lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src46
-rw-r--r--lib/erl_interface/test/ei_connect_SUITE_data/ei_connect_test.c289
-rw-r--r--lib/erl_interface/test/ei_connect_SUITE_data/einode.c158
4 files changed, 514 insertions, 0 deletions
diff --git a/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.first b/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.first
new file mode 100644
index 0000000000..8bf22e366e
--- /dev/null
+++ b/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.first
@@ -0,0 +1,21 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 2001-2009. All Rights Reserved.
+#
+# The contents of this file are subject to the Erlang Public License,
+# Version 1.1, (the "License"); you may not use this file except in
+# compliance with the License. You should have received a copy of the
+# Erlang Public License along with this software. If not, it can be
+# retrieved online at http://www.erlang.org/.
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+# the License for the specific language governing rights and limitations
+# under the License.
+#
+# %CopyrightEnd%
+#
+
+ei_connect_test_decl.c: ei_connect_test.c
+ erl -noinput -pa ../all_SUITE_data -s init_tc run ei_connect_test -s erlang halt
diff --git a/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src b/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src
new file mode 100644
index 0000000000..a6525a9138
--- /dev/null
+++ b/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src
@@ -0,0 +1,46 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 2001-2009. All Rights Reserved.
+#
+# The contents of this file are subject to the Erlang Public License,
+# Version 1.1, (the "License"); you may not use this file except in
+# compliance with the License. You should have received a copy of the
+# Erlang Public License along with this software. If not, it can be
+# retrieved online at http://www.erlang.org/.
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+# the License for the specific language governing rights and limitations
+# under the License.
+#
+# %CopyrightEnd%
+#
+
+include @erl_interface_mk_include@@[email protected]
+
+CC0 = @CC@
+CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)"
+LD = @LD@
+LIBPATH = @erl_interface_libpath@
+LIBEI = $(LIBPATH)/@erl_interface_eilib@
+LIBFLAGS = ../all_SUITE_data/ei_runner@obj@ \
+ $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \
+ @erl_interface_threadlib@
+CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data
+EI_CONNECT_OBJS = ei_connect_test@obj@ ei_connect_test_decl@obj@
+EINODE_OBJS = einode@obj@
+
+all: ei_connect_test@exe@ einode@exe@
+
+clean:
+ $(RM) $(EI_CONNECT_OBJS) $(EINODE_OBJS)
+ $(RM) ei_connect_test@exe@ einode@exe@
+
+ei_connect_test@exe@: $(EI_CONNECT_OBJS) $(LIBEI)
+ $(LD) @CROSSLDFLAGS@ -o $@ $(EI_CONNECT_OBJS) $(LIBFLAGS)
+
+
+einode@exe@: $(EINODE_OBJS) $(LIBEI)
+ $(LD) @CROSSLDFLAGS@ -o $@ $(EINODE_OBJS) $(LIBFLAGS)
+
diff --git a/lib/erl_interface/test/ei_connect_SUITE_data/ei_connect_test.c b/lib/erl_interface/test/ei_connect_SUITE_data/ei_connect_test.c
new file mode 100644
index 0000000000..debd3e789b
--- /dev/null
+++ b/lib/erl_interface/test/ei_connect_SUITE_data/ei_connect_test.c
@@ -0,0 +1,289 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 2001-2009. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+/*
+ * Purpose: Tests the functions in ei_connect.c.
+ * Author: Bjorn Gustavsson (rewritten somewhat by Jakob Cederlund)
+ *
+ * See the ei_connect_SUITE.erl file for a "table of contents".
+ */
+
+#include <stdio.h>
+#include <string.h>
+#ifdef VXWORKS
+#include "reclaim.h"
+#endif
+
+#include "ei_runner.h"
+
+static void cmd_ei_connect_init(char* buf, int len);
+static void cmd_ei_connect(char* buf, int len);
+static void cmd_ei_send(char* buf, int len);
+static void cmd_ei_send_funs(char* buf, int len);
+static void cmd_ei_reg_send(char* buf, int len);
+static void cmd_ei_rpc(char* buf, int len);
+static void cmd_ei_set_get_tracelevel(char* buf, int len);
+
+static void send_errno_result(int value);
+
+ei_cnode ec;
+
+
+static struct {
+ char* name;
+ int num_args; /* Number of arguments. */
+ void (*func)(char* buf, int len);
+} commands[] = {
+ "ei_connect_init", 3, cmd_ei_connect_init,
+ "ei_connect", 1, cmd_ei_connect,
+ "ei_send", 3, cmd_ei_send,
+ "ei_send_funs", 3, cmd_ei_send_funs,
+ "ei_reg_send", 3, cmd_ei_reg_send,
+ "ei_rpc", 4, cmd_ei_rpc,
+ "ei_set_get_tracelevel", 1, cmd_ei_set_get_tracelevel,
+};
+
+
+/*
+ * Sends a list contaning all data types to the Erlang side.
+ */
+
+TESTCASE(interpret)
+{
+ ei_x_buff x;
+ int i;
+ ei_term term;
+
+ ei_x_new(&x);
+ for (;;) {
+ if (get_bin_term(&x, &term)) {
+ report(1);
+ return;
+ } else {
+ char* buf = x.buff, func[MAXATOMLEN];
+ int index = x.index, arity;
+ if (term.ei_type != ERL_SMALL_TUPLE_EXT || term.arity != 2)
+ fail("term should be a tuple of size 2");
+ if (ei_decode_atom(buf, &index, func) < 0)
+ fail("function name should be an atom");
+ if (ei_decode_tuple_header(buf, &index, &arity) != 0)
+ fail("function arguments should be a tuple");
+ for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) {
+ if (strcmp(func, commands[i].name) == 0) {
+ if (arity != commands[i].num_args)
+ fail("wrong number of arguments");
+ commands[i].func(buf + index, x.buffsz - index);
+ break;
+ }
+ }
+ if (i >= sizeof(commands)/sizeof(commands[0])) {
+ message("\"%d\" \n", func);
+ fail("bad command");
+ }
+ }
+ }
+}
+
+
+static void cmd_ei_connect_init(char* buf, int len)
+{
+ int index = 0, r = 0;
+ int type, size;
+ long l;
+ char b[100];
+ char cookie[MAXATOMLEN], * cp = cookie;
+ ei_x_buff res;
+ if (ei_decode_long(buf, &index, &l) < 0)
+ fail("expected int");
+ sprintf(b, "c%d", l);
+ /* FIXME don't use internal and maybe use skip?! */
+ ei_get_type_internal(buf, &index, &type, &size);
+ if (ei_decode_atom(buf, &index, cookie) < 0)
+ fail("expected atom (cookie)");
+ if (cookie[0] == '\0')
+ cp = NULL;
+ r = ei_connect_init(&ec, b, cp, 0);
+ ei_x_new_with_version(&res);
+ ei_x_encode_long(&res, r);
+ send_bin_term(&res);
+ ei_x_free(&res);
+}
+
+static void cmd_ei_connect(char* buf, int len)
+{
+ int index = 0;
+ char node[256];
+ int i;
+ if (ei_decode_atom(buf, &index, node) < 0)
+ fail("expected atom");
+ i=ei_connect(&ec, node);
+#ifdef VXWORKS
+ if(i >= 0) {
+ save_fd(i);
+ }
+#endif
+ send_errno_result(i);
+}
+
+static void cmd_ei_set_get_tracelevel(char* buf, int len)
+{
+ int index = 0;
+ long level = 0;
+ long ret = 0;
+ ei_x_buff x;
+
+ if (ei_decode_long(buf, &index, &level) < 0) {
+ fail("expected long");
+ }
+
+ ei_set_tracelevel((int)level);
+
+ ret = (long) ei_get_tracelevel();
+
+ ei_x_new_with_version(&x);
+ ei_x_encode_tuple_header(&x, 2);
+ ei_x_encode_atom(&x, "tracelevel");
+ ei_x_encode_long(&x, ret);
+ send_bin_term(&x);
+ ei_x_free(&x);
+}
+
+static void cmd_ei_send(char* buf, int len)
+{
+ int index = 0;
+ long fd;
+ erlang_pid pid;
+ ei_x_buff x;
+
+ if (ei_decode_long(buf, &index, &fd) < 0)
+ fail("expected long");
+ if (ei_decode_pid(buf, &index, &pid) < 0)
+ fail("expected pid (node)");
+ if (ei_x_new_with_version(&x) < 0)
+ fail("ei_x_new_with_version");
+ if (ei_x_append_buf(&x, &buf[index], len - index) < 0)
+ fail("append");
+ send_errno_result(ei_send(fd, &pid, x.buff, x.index));
+ ei_x_free(&x);
+}
+
+static void cmd_ei_send_funs(char* buf, int len)
+{
+ int index = 0, n;
+ long fd;
+ erlang_pid pid;
+ ei_x_buff x;
+ erlang_fun fun1, fun2;
+
+ if (ei_decode_long(buf, &index, &fd) < 0)
+ fail("expected long");
+ if (ei_decode_pid(buf, &index, &pid) < 0)
+ fail("expected pid (node)");
+ if (ei_decode_tuple_header(buf, &index, &n) < 0)
+ fail("expected tuple");
+ if (n != 2)
+ fail("expected tuple");
+ if (ei_decode_fun(buf, &index, &fun1) < 0)
+ fail("expected Fun1");
+ if (ei_decode_fun(buf, &index, &fun2) < 0)
+ fail("expected Fun2");
+ if (ei_x_new_with_version(&x) < 0)
+ fail("ei_x_new_with_version");
+ if (ei_x_encode_tuple_header(&x, 2) < 0)
+ fail("encode tuple header");
+ if (ei_x_encode_fun(&x, &fun1) < 0)
+ fail("encode fun1");
+ if (ei_x_encode_fun(&x, &fun2) < 0)
+ fail("encode fun2");
+ free_fun(&fun1);
+ free_fun(&fun2);
+ send_errno_result(ei_send(fd, &pid, x.buff, x.index));
+ ei_x_free(&x);
+}
+
+static void cmd_ei_reg_send(char* buf, int len)
+{
+ int index = 0;
+ long fd;
+ char reg_name[MAXATOMLEN];
+ erlang_pid pid;
+ ei_x_buff x;
+
+ if (ei_decode_long(buf, &index, &fd) < 0)
+ fail("expected long (fd)");
+ if (ei_decode_atom(buf, &index, reg_name) < 0)
+ fail("expected atom (reg name)");
+ if (ei_x_new_with_version(&x) < 0)
+ fail("ei_x_new_with_version");
+ if (ei_x_append_buf(&x, &buf[index], len - index) < 0)
+ fail("append");
+ send_errno_result(ei_reg_send(&ec, fd,
+ reg_name, x.buff, x.index));
+ ei_x_free(&x);
+}
+
+static void cmd_ei_rpc(char* buf, int len)
+{
+ int index = 0, n;
+ long fd;
+ erlang_pid pid;
+ ei_x_buff x, rpc_x;
+ int r;
+ char mod[MAXATOMLEN], func[MAXATOMLEN];
+
+#if 0 && defined(__WIN32__)
+ DebugBreak();
+#endif
+
+ if (ei_decode_long(buf, &index, &fd) < 0)
+ fail("expected long");
+ if (ei_decode_pid(buf, &index, &pid) < 0)
+ fail("expected pid (node)");
+ if (ei_decode_tuple_header(buf, &index, &n) < 0 && n < 2)
+ fail("expected tuple {module, function}");
+ if (ei_decode_atom(buf, &index, mod) < 0)
+ fail("expected atom (module)");
+ if (ei_decode_atom(buf, &index, func) < 0)
+ fail("expected atom (function)");
+ message("pid %s %d %d %d\n", pid.node, pid.num, pid.serial, pid.creation);
+ message("{%s, %s}\n", mod, func);
+ if (ei_x_new(&rpc_x) < 0)
+ fail("ei_x_new");
+ if (ei_rpc(&ec, fd, mod, func, &buf[index], len - index, &rpc_x) < 0)
+ fail("ei_rpc");
+ if (ei_x_new_with_version(&x) < 0)
+ fail("ei_x_new_with_version");
+ if (ei_x_append(&x, &rpc_x) < 0)
+ fail("append");
+ send_bin_term(&x);
+ /*send_errno_result(ei_send(&ec, fd, &pid, x.buff, x.index));*/
+ ei_x_free(&x);
+ ei_x_free(&rpc_x);
+}
+
+static void send_errno_result(int value)
+{
+ ei_x_buff x;
+ ei_x_new_with_version(&x);
+ ei_x_encode_tuple_header(&x, 2);
+ ei_x_encode_long(&x, value);
+ ei_x_encode_long(&x, erl_errno);
+ send_bin_term(&x);
+ ei_x_free(&x);
+}
diff --git a/lib/erl_interface/test/ei_connect_SUITE_data/einode.c b/lib/erl_interface/test/ei_connect_SUITE_data/einode.c
new file mode 100644
index 0000000000..bafe8bd5bd
--- /dev/null
+++ b/lib/erl_interface/test/ei_connect_SUITE_data/einode.c
@@ -0,0 +1,158 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 2001-2009. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ */
+
+/* to test multiple threads in ei */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef __WIN32__
+#include <winsock2.h>
+#include <windows.h>
+#include <process.h>
+#else
+#ifndef VXWORKS
+#include <pthread.h>
+#endif
+#include <sys/socket.h>
+#endif
+
+#include "ei.h"
+
+#ifdef VXWORKS
+#define MAIN cnode
+#else
+#define MAIN main
+#endif
+
+/*
+ A small einode.
+ To be called from the test case ei_accept_SUITE:multi_thread
+ usage: einode <cookie> <n> <destnode>
+
+ - start threads 0..n-1
+ - in each thread
+ - connect to destnode
+ - send a message ("ei0".."ei<n-1>") to mth0..mth<n-1> on destnode
+ - shutdown gracefully
+*/
+
+static const char* cookie, * desthost;
+
+#ifndef SD_SEND
+#ifdef SHUTWR
+#define SD_SEND SHUT_WR
+#else
+#define SD_SEND 1
+#endif
+#endif
+
+#ifndef __WIN32__
+#define closesocket(fd) close(fd)
+#endif
+
+#ifdef __WIN32__
+static DWORD WINAPI
+#else
+static void*
+#endif
+ einode_thread(void* num)
+{
+ int n = (int)num;
+ ei_cnode ec;
+ char myname[100], destname[100];
+ int r, fd;
+
+ sprintf(myname, "ei%d", n);
+ sprintf(destname, "mth%d", n);
+ printf("thread %d (%s %s) connecting\n", n, myname, destname);
+ r = ei_connect_init(&ec, myname, cookie, 0);
+ fd = ei_connect(&ec, (char*)desthost);
+ if (r == 0 && fd >= 0) {
+ ei_x_buff x;
+ ei_x_new_with_version(&x);
+ ei_x_encode_string(&x, myname);
+ ei_reg_send(&ec, fd, destname, x.buff, x.index);
+ ei_x_free(&x);
+ //SleepEx(100);
+ shutdown(fd, SD_SEND);
+ closesocket(fd);
+ } else {
+ printf("coudn't connect fd %d r %d\n", fd, r); // DebugBreak();
+ }
+ printf("done thread %d\n", n);
+ return 0;
+}
+
+MAIN(int argc, char *argv[])
+{
+ int i, n, no_threads;
+#ifndef VXWORKS
+#ifdef __WIN32__
+ HANDLE threads[100];
+#else
+ pthread_t threads[100];
+#endif
+#endif
+
+ if (argc < 3)
+ exit(1);
+
+ cookie = argv[1];
+ n = atoi(argv[2]);
+ if (n > 100)
+ exit(2);
+ desthost = argv[3];
+#ifndef VXWORKS
+ no_threads = argv[4] != NULL && strcmp(argv[4], "nothreads") == 0;
+#else
+ no_threads = 1;
+#endif
+ for (i = 0; i < n; ++i) {
+ if (!no_threads) {
+#ifndef VXWORKS
+#ifdef __WIN32__
+ unsigned tid;
+ threads[i] = (HANDLE)_beginthreadex(NULL, 0, einode_thread,
+ (void*)i, 0, &tid);
+#else
+ pthread_create(&threads[i], NULL, einode_thread, (void*)i);
+#endif
+#else
+ ;
+#endif
+ } else
+ einode_thread((void*)i);
+ }
+ if (!no_threads)
+#ifndef VXWORKS
+ for (i = 0; i < n; ++i) {
+#ifdef __WIN32__
+ if (WaitForSingleObject(threads[i], INFINITE) != WAIT_OBJECT_0)
+#else
+ if (pthread_join(threads[i], NULL) != 0)
+#endif
+ printf("bad wait thread %d\n", i);
+ }
+#else
+ ;
+#endif
+ printf("ok\n");
+ return 0;
+}