From 27a5daae33616e662a36ed514c31618d51ad66e3 Mon Sep 17 00:00:00 2001 From: Niclas Eklund Date: Thu, 2 Sep 2010 16:15:32 +0200 Subject: Add test suite for ic --- .../erl_client_c_server_SUITE_data/Makefile.src | 150 +++++ .../test/erl_client_c_server_SUITE_data/c_server.c | 299 ++++++++++ .../erl_client_c_server_SUITE_data/callbacks.c | 610 +++++++++++++++++++++ .../erl_client_c_server_SUITE_data/erl_c_test.idl | 174 ++++++ .../erl_client_c_server_SUITE_data/erl_client.erl | 331 +++++++++++ 5 files changed, 1564 insertions(+) create mode 100644 lib/ic/test/erl_client_c_server_SUITE_data/Makefile.src create mode 100644 lib/ic/test/erl_client_c_server_SUITE_data/c_server.c create mode 100644 lib/ic/test/erl_client_c_server_SUITE_data/callbacks.c create mode 100644 lib/ic/test/erl_client_c_server_SUITE_data/erl_c_test.idl create mode 100644 lib/ic/test/erl_client_c_server_SUITE_data/erl_client.erl (limited to 'lib/ic/test/erl_client_c_server_SUITE_data') diff --git a/lib/ic/test/erl_client_c_server_SUITE_data/Makefile.src b/lib/ic/test/erl_client_c_server_SUITE_data/Makefile.src new file mode 100644 index 0000000000..cd34d2b247 --- /dev/null +++ b/lib/ic/test/erl_client_c_server_SUITE_data/Makefile.src @@ -0,0 +1,150 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2002-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% +# +# +# Makefile.src for erl_client_c_server test +# Note: This file *must* work for both Unix and Windows +# +# We use both `rm' (Unix) and `del' (Windows) for removing files, but +# with a `-' in front so that the error in not finding `rm' (`del') on +# Windows (Unix) is ignored. +# +# VxWorks? XXX +# + +.SUFFIXES: +.SUFFIXES: .c .h .erl .idl @obj@ .@EMULATOR@ + + +# Variables from ts: +# + +ERL_INCLUDE = @erl_include@ + +IC_INCLUDE_PATH = @ic_include_path@ +IC_LIB = @ic_libpath@@DS@@ic_lib@ + +ERL_INTERFACE_INCLUDE = @erl_interface_include@ +ERL_INTERFACE_LIB = @erl_interface_libpath@@DS@@erl_interface_lib@ +ERL_INTERFACE_EILIB = @erl_interface_libpath@@DS@@erl_interface_eilib@ +ERL_INTERFACE_THREADLIB = @erl_interface_threadlib@ +ERL_INTERFACE_SOCK_LIBS = @erl_interface_sock_libs@ + +CC = @CC@ +## XXX Should set warning flag with a DEBUG_FLAG +CFLAGS = @CFLAGS@ @DEFS@ -I$(ERL_INCLUDE) \ + -I$(IC_INCLUDE_PATH) -I$(ERL_INTERFACE_INCLUDE) + +LD = @LD@ +LDFLAGS = @CROSSLDFLAGS@ +LIBS = $(IC_LIB) $(ERL_INTERFACE_LIB) $(ERL_INTERFACE_EILIB) \ + $(ERL_INTERFACE_THREADLIB) @LIBS@ $(ERL_INTERFACE_SOCK_LIBS) +ERLC = erlc + +# Generated C header files +GEN_H_FILES = \ + m__s.h \ + m_i__s.h \ + oe_erl_c_test__s.h + +# Generated C files +GEN_C_FILES = \ + m__s.c \ + m_i__s.c \ + oe_code_m_a.c \ + oe_code_m_arr1.c \ + oe_code_m_arr2.c \ + oe_code_m_arr3.c \ + oe_code_m_aseq.c \ + oe_code_m_b.c \ + oe_code_m_bseq.c \ + oe_code_m_dd.c \ + oe_code_m_dyn.c \ + oe_code_m_dyn_sl.c \ + oe_code_m_es.c \ + oe_code_m_et.c \ + oe_code_m_etseq.c \ + oe_code_m_fruit.c \ + oe_code_m_lseq.c \ + oe_code_m_s.c \ + oe_code_m_s_sl.c \ + oe_code_m_sarr3.c \ + oe_code_m_simple.c \ + oe_code_m_ssarr3.c \ + oe_code_m_sseq.c \ + oe_code_m_ssstr3.c \ + oe_code_m_sstr3.c \ + oe_code_m_str1.c \ + oe_code_m_str3.c \ + oe_code_m_strRec.c \ + oe_code_m_strRec_str5.c \ + oe_code_m_strRec_str7.c \ + oe_erl_c_test__s.c + +GEN_HRL_FILES = \ + m.hrl \ + m_i.hrl \ + oe_erl_c_test.hrl + +GEN_ERL_FILES = \ + m.erl \ + m_arr2.erl \ + m_arr3.erl \ + m_i.erl \ + m_str3.erl \ + oe_erl_c_test.erl + +C_FILES = $(GEN_C_FILES) c_server.c callbacks.c + +OBJS = $(C_FILES:.c=@obj@) + +PGMS = c_server@exe@ + +ERL_FILES = $(GEN_ERL_FILES) erl_client.erl + +EBINS = $(ERL_FILES:.erl=.@EMULATOR@) + + +all: $(PGMS) $(EBINS) + +clean: + -rm -f $(OBJS) $(GEN_C_FILES) $(GEN_H_FILES) $(PGMS) \ + $(EBINS) $(GEN_ERL_FILES) $(GEN_HRL_FILES) + -del /F /Q $(OBJS) $(GEN_C_FILES) $(GEN_H_FILES) $(PGMS) \ + $(EBINS) $(GEN_ERL_FILES) $(GEN_HRL_FILES) + +$(PGMS): $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +$(GEN_C_FILES) $(GEN_H_FILES): erl_c_test.idl + $(ERLC) -I $(IC_INCLUDE_PATH) "+{be,c_server}" \ + "+{scoped_op_calls,true}" erl_c_test.idl + +# If we have scoped operation calls for C, we must have that for +# Erlang as well, if we use the m_i.erl file for calling the server. + +$(GEN_ERL_FILES) $(GEN_HRL_FILES): erl_c_test.idl + $(ERLC) -I $(IC_INCLUDE_PATH) "+{be,erl_genserv}" \ + "+{scoped_op_calls,true}" "+{timeout,true}" erl_c_test.idl + +.c@obj@: + $(CC) -c -o $*@obj@ $(CFLAGS) $< + +.erl.@EMULATOR@: + $(ERLC) -W -I $(IC_INCLUDE_PATH) $< + diff --git a/lib/ic/test/erl_client_c_server_SUITE_data/c_server.c b/lib/ic/test/erl_client_c_server_SUITE_data/c_server.c new file mode 100644 index 0000000000..acdeff80fe --- /dev/null +++ b/lib/ic/test/erl_client_c_server_SUITE_data/c_server.c @@ -0,0 +1,299 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2002-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% + * + */ +/* C-server for test of IC. + * + * The C-node implemented here connects to its peer node, waits for + * one message, evaluates the message, returns an result message, and + * terminates. + * + * TODO: + * + * 1. XXX #includes for VxWorks, Windows + */ + +#include +#include + +#ifndef __WIN32__ +# include +#endif + +#include + +#ifdef __WIN32__ +# include +# include +#elif defined VXWORKS +# include +# include +#else +# include +#endif + +#include + +#ifdef __WIN32__ +# include +# include +#else +# include +# include +# include +# include +# include +#endif + +#include "ic.h" +#include "ei.h" +#include "erl_interface.h" +#include "eicode.h" +#include "m_i__s.h" +#include "m__s.h" + +#ifdef __WIN32__ +typedef struct { + long tv_sec; + long tv_usec; +} MyTimeval; +#else +typedef struct timeval MyTimeval; +#endif +static void my_gettimeofday(MyTimeval *tv); +static void showtime(MyTimeval *start, MyTimeval *stop); +static void usage(void); +static void done(int r); + +#define HOSTNAMESZ 256 +#define NODENAMESZ 512 +#define INBUFSZ 10 +#define OUTBUFSZ 0 +#define MAXTRIES 5 + +static char *progname; + +/* main */ +#ifdef VXWORKS +int c_server(int argc, char **argv) +#else +int main(int argc, char **argv) +#endif +{ + struct hostent *hp; + MyTimeval start, stop; + int i, fd, ires, tries; + CORBA_Environment *env; + char *this_node_name = NULL; + char *peer_node = NULL; + char *cookie = NULL; + char host[HOSTNAMESZ + 1]; + char this_node[NODENAMESZ + 1]; + erlang_msg msg; + int status, loop; + +#ifdef __WIN32__ + WORD wVersionRequested; + WSADATA wsaData; + + wVersionRequested = MAKEWORD(2, 0); + + if (WSAStartup(wVersionRequested, &wsaData) != 0) { + fprintf(stderr, "Could not load winsock2 v2.0 compatible DLL"); + exit(1); + } +#endif + + progname = argv[0]; + host[HOSTNAMESZ] = '\0'; + if (gethostname(host, HOSTNAMESZ) < 0) { + fprintf(stderr, "Can't find own hostname\n"); + done(1); + } + if ((hp = gethostbyname(host)) == 0) { + fprintf(stderr, "Can't get ip address for host %s\n", host); + done(1); + } + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-help") == 0) { + usage(); + done(0); + } else if (strcmp(argv[i], "-this-node-name") == 0) { + i++; + this_node_name = argv[i]; + } else if (strcmp(argv[i], "-peer-node") == 0) { + i++; + peer_node = argv[i]; + } else if (strcmp(argv[i], "-cookie") == 0) { + i++; + cookie = argv[i]; + } else { + fprintf(stderr, "Error : invalid argument \"%s\"\n", argv[i]); + usage(); + done(1); + } + } + + if (this_node_name == NULL || peer_node == NULL || cookie == NULL) { + fprintf(stderr, "Error: missing option\n"); + usage(); + done(1); + } + + /* Behead hostname at first dot */ + for (i=0; host[i] != '\0'; i++) { + if (host[i] == '.') { host[i] = '\0'; break; } + } + sprintf(this_node, "%s@%s", this_node_name, host); + + fprintf(stderr, "c_server: this node: \"%s\"\n", this_node); + fprintf(stderr, "c_server: peer node: \"%s\"\n", peer_node); + + /* initialize erl_interface */ + erl_init(NULL, 0); + + for (tries = 0; tries < MAXTRIES; tries++) { + /* connect to peer node */ + ires = erl_connect_xinit(host, this_node_name, this_node, + (struct in_addr *)*hp->h_addr_list, + cookie, 0); + fprintf(stderr, "c_server: erl_connect_xinit(): %d\n", ires); + + fd = erl_connect(peer_node); + fprintf(stderr, "c_server: erl_connect(): %d\n", fd); + if (fd >= 0) + break; + fprintf(stderr, "c_server: cannot connect, retrying\n"); + } + if (fd < 0) { + fprintf(stderr, "c_server: cannot connect, exiting\n"); + done(1); + } + env = CORBA_Environment_alloc(INBUFSZ, OUTBUFSZ); + env->_fd = fd; + + status = 1; + loop = 1; + my_gettimeofday(&start); + while (status >= 0 && loop > 0) { + status = ei_receive_encoded(env->_fd, &env->_inbuf, &env->_inbufsz, + &msg, &env->_iin); + switch(status) { + case ERL_SEND: + case ERL_REG_SEND: + /* get result */ + m_i__switch(NULL, env); + switch(env->_major) { + case CORBA_NO_EXCEPTION: + break; + case CORBA_SYSTEM_EXCEPTION: + fprintf(stderr, "Request failure, reason : %s\n", + (char *) CORBA_exception_value(env)); + CORBA_exception_free(env); + break; + default: /* Should not happen */ + CORBA_exception_free(env); + break; + } + /* send back result data */ + if (env->_iout > 0) + ei_send_encoded(env->_fd, &env->_caller, env->_outbuf, + env->_iout); + loop = 0; + break; + case ERL_TICK: + break; + default: + if (status < 0) { + fprintf(stderr, "Status negative: %d\n", status); + loop = 0; + } + break; + } + } + my_gettimeofday(&stop); + showtime(&start, &stop); + + erl_close_connection(fd); + + CORBA_free(env->_inbuf); + CORBA_free(env->_outbuf); + CORBA_free(env); + if (status < 0) + done(-status); + else + done(0); +} + +static void usage() +{ + fprintf(stderr, "Usage: %s [-help] -this-node-name " + "-peer-node -cookie \n", progname); + fprintf(stderr, "Example:\n %s -this-node-name kalle " + "-peer-node olle@home -cookie oa678er\n", progname); +} + +static void done(int r) +{ +#ifdef __WIN32__ + WSACleanup(); +#endif + exit(r); +} + +static void showtime(MyTimeval *start, MyTimeval *stop) +{ + MyTimeval elapsed; + + elapsed.tv_sec = stop->tv_sec - start->tv_sec; + elapsed.tv_usec = stop->tv_usec - start->tv_usec; + while (elapsed.tv_usec < 0) { + elapsed.tv_sec -= 1; + elapsed.tv_usec += 1000000; + } + fprintf(stderr,"%ld.%06ld seconds\n",elapsed.tv_sec, elapsed.tv_usec); +} + + + +static void my_gettimeofday(MyTimeval *tv) +#ifdef __WIN32__ +#define EPOCH_JULIAN_DIFF 11644473600i64 +{ + SYSTEMTIME t; + FILETIME ft; + LONGLONG lft; + + GetSystemTime(&t); + SystemTimeToFileTime(&t, &ft); + memcpy(&lft, &ft, sizeof(lft)); + tv->tv_usec = (long) ((lft / 10i64) % 1000000i64); + tv->tv_sec = (long) ((lft / 10000000i64) - EPOCH_JULIAN_DIFF); +} +#elif defined VXWORKS +{ + int rate = sysClkRateGet(); /* Ticks per second */ + unsigned long ctick = tickGet(); + tv->tv_sec = ctick / rate; /* secs since reboot */ + tv->tv_usec = ((ctick - (tv->tv_sec * rate))*1000000)/rate; +} +#else +{ + gettimeofday(tv, NULL); +} +#endif diff --git a/lib/ic/test/erl_client_c_server_SUITE_data/callbacks.c b/lib/ic/test/erl_client_c_server_SUITE_data/callbacks.c new file mode 100644 index 0000000000..d6b28b619d --- /dev/null +++ b/lib/ic/test/erl_client_c_server_SUITE_data/callbacks.c @@ -0,0 +1,610 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2002-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 +#include +#ifndef __WIN32__ +# include +#endif +#include +#include +#include +#include +#include +#include "m_i__s.h" + + + +/* OK */ + +void my_void_test(CORBA_Object oe_obj, + CORBA_Environment *oe_env) +{ + /* printf("void test !\n"); */ +} + +m_i_void_test__rs* m_i_void_test__cb(CORBA_Object oe_obj, + CORBA_Environment *oe_env) +{ + return (m_i_void_test__rs*) (my_void_test); +} + + + +/* OK */ + +void my_long_test(CORBA_Object oe_obj, + long* a, + long* b, + long* c, + CORBA_Environment *oe_env) +{ + /* printf("long test !\n"); */ +} + + +m_i_long_test__rs* m_i_long_test__cb(CORBA_Object oe_obj, + long* a, + long* b, + long* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_long_test__rs*) (my_long_test); +} + +/* OK */ + +void my_longlong_test(CORBA_Object oe_obj, + CORBA_long_long* a, + CORBA_long_long* b, + CORBA_long_long* c, + CORBA_Environment *oe_env) +{ + /* printf("long test !\n"); */ +} + +m_i_longlong_test__rs* m_i_longlong_test__cb(CORBA_Object oe_obj, + CORBA_long_long* a, + CORBA_long_long* b, + CORBA_long_long* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_longlong_test__rs*) (my_longlong_test); +} + +/* OK */ +void my_ulong_test(CORBA_Object oe_obj, + unsigned long* a, + unsigned long* b, + unsigned long* c, + CORBA_Environment *oe_env) +{ + /* printf("ulong test !\n"); */ +} + +m_i_ulong_test__rs* m_i_ulong_test__cb(CORBA_Object oe_obj, + unsigned long* a, + unsigned long* b, + unsigned long* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_ulong_test__rs*) (my_ulong_test); +} + +/* OK */ +void my_ulonglong_test(CORBA_Object oe_obj, + CORBA_unsigned_long_long* a, + CORBA_unsigned_long_long* b, + CORBA_unsigned_long_long* c, + CORBA_Environment *oe_env) +{ + /* printf("ulong test !\n"); */ +} + +m_i_ulonglong_test__rs* m_i_ulonglong_test__cb(CORBA_Object oe_obj, + CORBA_unsigned_long_long* a, + CORBA_unsigned_long_long* b, + CORBA_unsigned_long_long* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_ulonglong_test__rs*) (my_ulonglong_test); +} + +m_i_ushort_test__rs* m_i_ushort_test__cb(CORBA_Object oe_obj, + unsigned short* a, + unsigned short* b, + unsigned short* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_ushort_test__rs*) NULL; +} + + +/* OK */ +void my_double_test(CORBA_Object oe_obj, + double* a, + double* b, + double* c, + CORBA_Environment *oe_env) +{ + /* printf("double test !\n"); */ +} + +m_i_double_test__rs* m_i_double_test__cb(CORBA_Object oe_obj, + double* a, + double* b, + double* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_double_test__rs*) (my_double_test); +} + +/* OK */ +m_i_char_test__rs* m_i_char_test__cb(CORBA_Object oe_obj, + char* a, + char* b, + char* c, + CORBA_Environment *oe_env) +{ + m_i_char_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + + +/* OK */ +m_i_wchar_test__rs* m_i_wchar_test__cb(CORBA_Object oe_obj, + CORBA_wchar* a, + CORBA_wchar* b, + CORBA_wchar* c, + CORBA_Environment *oe_env) +{ + m_i_wchar_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +/* OK */ +m_i_octet_test__rs* m_i_octet_test__cb(CORBA_Object oe_obj, + char* a, + char* b, + char* c, + CORBA_Environment *oe_env) +{ + m_i_octet_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +/* OK */ +m_i_bool_test__rs* m_i_bool_test__cb(CORBA_Object oe_obj, + CORBA_boolean* a, + CORBA_boolean* b, + CORBA_boolean* c, + CORBA_Environment *oe_env) +{ + m_i_bool_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +/* OK */ +void my_struct_test(CORBA_Object oe_obj, + m_b* a, + m_b* b, + m_b* c, + CORBA_Environment *oe_env) +{ + /* printf("struct test !\n"); */ +} + +m_i_struct_test__rs* m_i_struct_test__cb(CORBA_Object oe_obj, + m_b* a, + m_b* b, + m_b* c, + CORBA_Environment *oe_env) +{ + *a = *b; + *c = *b; + return (m_i_struct_test__rs*) (my_struct_test); +} + +/* OK */ +m_i_struct2_test__rs* m_i_struct2_test__cb(CORBA_Object oe_obj, + m_es* a, + m_es* b, + m_es* c, + CORBA_Environment *oe_env) +{ + m_i_struct2_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +/* OK */ +/* XXX Commented out +m_i_struct3_test__rs* m_i_struct3_test__cb(CORBA_Object oe_obj, + m_simple* a, + m_simple* b, + m_simple* c, + CORBA_Environment *oe_env) +{ + m_i_struct3_test__rs* rs = NULL; + *a = *b; + *c = *b; + return rs; +} +*/ + +/* OK */ +m_i_seq1_test__rs* m_i_seq1_test__cb(CORBA_Object oe_obj, + m_bseq** a, + m_bseq* b, + m_bseq** c, + CORBA_Environment *oe_env) +{ + m_i_seq1_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + + +/* OK */ +m_i_seq2_test__rs* m_i_seq2_test__cb(CORBA_Object oe_obj, + m_aseq** a, + m_aseq* b, + m_aseq** c, + CORBA_Environment *oe_env) +{ + m_i_seq2_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_seq3_test__rs* m_i_seq3_test__cb(CORBA_Object oe_obj, + m_lseq** a, + m_lseq* b, + m_lseq** c, + CORBA_Environment *oe_env) +{ + m_i_seq3_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_seq4_test__rs* m_i_seq4_test__cb(CORBA_Object oe_obj, + m_ssstr3** a, + m_ssstr3* b, + m_ssstr3** c, + CORBA_Environment *oe_env) +{ + m_i_seq4_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_seq5_test__rs* m_i_seq5_test__cb(CORBA_Object oe_obj, + m_ssarr3** a, + m_ssarr3* b, + m_ssarr3** c, + CORBA_Environment *oe_env) +{ + m_i_seq5_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_array1_test__rs* m_i_array1_test__cb(CORBA_Object oe_obj, + m_arr1 a, + m_arr1 b, + m_arr1 c, + CORBA_Environment *oe_env) +{ + int i; + m_i_array1_test__rs* rs = NULL; + + for (i = 0; i < 500; i++) { + a[i] = b[i]; + c[i] = b[i]; + } + return rs; +} + +/* OK */ +m_i_array2_test__rs* m_i_array2_test__cb(CORBA_Object oe_obj, + m_dd a, + m_dd b, + m_dd c, + CORBA_Environment *oe_env) +{ + int i,j; + m_i_array2_test__rs* rs = NULL; + + for (i = 0; i < 2; i++) + for (j = 0; j < 3; j++) { + a[i][j] = b[i][j]; + c[i][j] = b[i][j]; + } + return rs; +} + + +/* OK */ +m_i_enum_test__rs* m_i_enum_test__cb(CORBA_Object oe_obj, + m_fruit* a, + m_fruit* b, + m_fruit* c, + CORBA_Environment *oe_env) +{ + m_i_enum_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +/* OK */ +m_i_string1_test__rs* m_i_string1_test__cb(CORBA_Object oe_obj, + char ** a, + char * b, + char ** c, + CORBA_Environment *oe_env) +{ + m_i_string1_test__rs* rs = NULL; + + /*printf("\nString in ------> %s\n\n",b);*/ + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_string2_test__rs* m_i_string2_test__cb(CORBA_Object oe_obj, + m_sseq** a, + m_sseq* b, + m_sseq** c, + CORBA_Environment *oe_env) +{ + m_i_string2_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_string3_test__rs* m_i_string3_test__cb(CORBA_Object oe_obj, + char ** a, + char * b, + char ** c, + CORBA_Environment *oe_env) +{ + m_i_string3_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +m_i_string4_test__rs* m_i_string4_test__cb(CORBA_Object oe_obj, + m_strRec** a, + m_strRec* b, + m_strRec** c, + CORBA_Environment *oe_env) +{ + *a = b; + *c = b; + + return (m_i_string4_test__rs*) NULL; +} + +/* OK */ +m_i_wstring1_test__rs* m_i_wstring1_test__cb(CORBA_Object oe_obj, + CORBA_wchar ** a, + CORBA_wchar * b, + CORBA_wchar ** c, + CORBA_Environment *oe_env) +{ + int tmp; + m_i_wstring1_test__rs* rs = NULL; + + /*printf("\nString in ------> %s\n\n",b);*/ + + for(tmp = 0; tmp < 5; tmp++) + fprintf(stderr,"\np[%d] = %ld\n", tmp, b[tmp]); + *a = b; + *c = b; + return rs; +} + + +/* OK */ +m_i_pid_test__rs* m_i_pid_test__cb(CORBA_Object oe_obj, + erlang_pid* a, + erlang_pid* b, + erlang_pid* c, + CORBA_Environment *oe_env) +{ + m_i_pid_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +/* OK */ +m_i_port_test__rs* m_i_port_test__cb(CORBA_Object oe_obj, + erlang_port* a, + erlang_port* b, + erlang_port* c, + CORBA_Environment *oe_env) +{ + m_i_port_test__rs* rs = NULL; + + strcpy((*a).node,(*b).node); + (*a).id = (*b).id; + (*a).creation = 0; + + strcpy((*c).node,(*b).node); + (*c).id = (*b).id; + (*c).creation = 0; + return rs; +} + +/* OK */ +m_i_ref_test__rs* m_i_ref_test__cb(CORBA_Object oe_obj, + erlang_ref* a, + erlang_ref* b, + erlang_ref* c, + CORBA_Environment *oe_env) +{ + + m_i_ref_test__rs* rs = NULL; + + strcpy((*a).node,(*b).node); + /*(*a).id = (*b).id;*/ + (*a).len = (*b).len; + (*a).n[0] = (*b).n[0]; + (*a).n[1] = (*b).n[1]; + (*a).n[2] = (*b).n[2]; + (*a).creation = 0; + + strcpy((*c).node,(*b).node); + /*(*c).id = (*b).id;*/ + (*c).len = (*b).len; + (*c).n[0] = (*b).n[0]; + (*c).n[1] = (*b).n[1]; + (*c).n[2] = (*b).n[2]; + (*c).creation = 0; + return rs; +} + +/* OK */ +m_i_term_test__rs* m_i_term_test__cb(CORBA_Object oe_obj, + ETERM** a, + ETERM** b, + ETERM** c, + CORBA_Environment *oe_env) +{ + m_i_term_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + +m_i_typedef_test__rs* m_i_typedef_test__cb(CORBA_Object oe_obj, + long* a, + ETERM** b, + erlang_port* c, + ETERM** d , + erlang_port* e, + CORBA_Environment *oe_env) +{ + m_i_typedef_test__rs* rs = NULL; + + *d = *b; + strcpy((*e).node,(*c).node); + (*e).id = (*c).id; + (*e).creation = 0; + *a = 4711; + return rs; +} + +/* OK */ +m_i_inline_sequence_test__rs* m_i_inline_sequence_test__cb( + CORBA_Object oe_obj, + m_s** a, + m_s* b, + m_s** c, + CORBA_Environment *oe_env) +{ + m_i_inline_sequence_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + +/* OK */ +m_i_term_sequence_test__rs* m_i_term_sequence_test__cb( + CORBA_Object oe_obj, + m_etseq** a, + m_etseq* b, + m_etseq** c, + CORBA_Environment *oe_env) +{ + m_i_term_sequence_test__rs* rs = NULL; + + *a = b; + *c = b; + return rs; +} + + +/* OK */ +m_i_term_struct_test__rs* m_i_term_struct_test__cb(CORBA_Object oe_obj, + m_et* a, + m_et* b, + m_et* c, + CORBA_Environment *oe_env) +{ + m_i_term_struct_test__rs* rs = NULL; + + *a = *b; + *c = *b; + return rs; +} + diff --git a/lib/ic/test/erl_client_c_server_SUITE_data/erl_c_test.idl b/lib/ic/test/erl_client_c_server_SUITE_data/erl_c_test.idl new file mode 100644 index 0000000000..963bc69017 --- /dev/null +++ b/lib/ic/test/erl_client_c_server_SUITE_data/erl_c_test.idl @@ -0,0 +1,174 @@ + + +// %CopyrightBegin% +// +// Copyright Ericsson AB 2002-2010. 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 "erlang.idl" + + +const short TestConst = 1; + +module m { + + const short TestConst = 2; + + struct b { + long l; + char c; + }; + + struct simple { + long l; + b b_t; + }; + + enum fruit {orange, banana, apple, peach, pear}; + + typedef sequence lseq; + + typedef sequence bseq; + + struct a { + long l; + bseq y; + double d; + }; + + typedef sequence aseq; + + typedef sequence sseq; + typedef string str; + typedef long myLong; + + typedef long arr1[500], dd[2][3]; + + typedef erlang::term apa; + typedef erlang::port banan; + + typedef sequence etseq; + + struct s { + long l; + sequence sl; + }; + + struct es { + fruit f; + myLong l; + }; + + struct et { + erlang::term e; + long l; + }; + + + typedef sequence str1; + typedef string<12> str2; + typedef char str3[3]; + + typedef sequence sstr3; // sequence of string + typedef sequence ssstr3; // sequence of sequences of strings + + typedef long arr3[3]; // array of long + typedef sequence sarr3; // sequence of array + typedef sequence ssarr3; // sequence of sequnces of arrays of strings + + struct strRec{ + boolean bb; + string str4; + long str7[3][2]; + sequence str5; + string<12> str6; + str3 str8; + str2 str9; + str1 str10; + }; + + + struct dyn { + long l; + sequence sl; + }; + typedef dyn arr2[1][2]; + + + interface i { + + const short TestConst = 3; + + //arr2 suck(in arr2 x, out arr2 y ); + + ///////////////////////////////// attribute long l; + + // simple types + void void_test(); + long long_test(in long a, out long a1); + long long longlong_test(in long long a, out long long a1); + unsigned short ushort_test(in unsigned short a, out unsigned short a1); + unsigned long ulong_test(in unsigned long a, out unsigned long a1); + unsigned long long ulonglong_test(in unsigned long long a, out unsigned long long a1); + double double_test(in double a, out double a1); + char char_test(in char a, out char a1); + wchar wchar_test(in wchar a, out wchar a1); + octet octet_test(in octet a, out octet a1); + boolean bool_test(in boolean a, out boolean a1); + + // Seq. and struct tests + b struct_test(in b a, out b a1); + es struct2_test(in es a, out es a1); + //simple struct3_test(in simple x, out simple y); + bseq seq1_test(in bseq a, out bseq a1); + aseq seq2_test(in aseq a, out aseq a1); + lseq seq3_test(in lseq a, out lseq a1); + ssstr3 seq4_test(in ssstr3 a, out ssstr3 a1); + ssarr3 seq5_test(in ssarr3 a, out ssarr3 a1); + + // Array tests + arr1 array1_test(in arr1 a, out arr1 a1); + dd array2_test(in dd a, out dd a1); + + // enum test + fruit enum_test(in fruit a, out fruit a1); + + // string tests + string string1_test(in string a, out string a1); + wstring wstring1_test(in wstring a, out wstring a1); + sseq string2_test(in sseq a, out sseq a1); + str string3_test(in str a, out str a1); + strRec string4_test(in strRec a, out strRec a1); + + // Special erlang types + erlang::pid pid_test(in erlang::pid a, out erlang::pid a1); + erlang::port port_test(in erlang::port a, out erlang::port a1); + erlang::ref ref_test(in erlang::ref a, out erlang::ref a1); + erlang::term term_test(in erlang::term a, out erlang::term a1); + + // typedef test + long typedef_test(in apa a, in banan b, out apa a1, out banan b1); + + // inlined seq. test + s inline_sequence_test(in s a, out s a1); + + // term seq. test + etseq term_sequence_test(in etseq a, out etseq a1); + // term struct test + et term_struct_test(in et a, out et a1); + + }; + +}; diff --git a/lib/ic/test/erl_client_c_server_SUITE_data/erl_client.erl b/lib/ic/test/erl_client_c_server_SUITE_data/erl_client.erl new file mode 100644 index 0000000000..79ec28a921 --- /dev/null +++ b/lib/ic/test/erl_client_c_server_SUITE_data/erl_client.erl @@ -0,0 +1,331 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2002-2010. 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% +%% +%% +-module(erl_client). + +-export([void_test/2, long_test/2, longlong_test/2, ushort_test/2, + ulong_test/2, ulonglong_test/2, double_test/2, char_test/2, + wchar_test/2, octet_test/2, bool_test/2, struct_test/2, + struct2_test/2, seq1_test/2, seq2_test/2, seq3_test/2, + seq4_test/2, seq5_test/2, array1_test/2, array2_test/2, + enum_test/2, string1_test/2, wstring1_test/2, string2_test/2, + string3_test/2, string4_test/2, pid_test/2, port_test/2, + ref_test/2, term_test/2, typedef_test/2, + inline_sequence_test/2, term_sequence_test/2, + term_struct_test/2 + +]). + +-include("m.hrl"). +-include("m_i.hrl"). +-include("oe_erl_c_test.hrl"). + +%%b +void_test(Node, Timeout) -> + Ret = m_i:void_test({olsson, Node}, Timeout), + Ret == void. % XXX Not documented +%%e + +%%b +long_test(Node, Timeout) -> + In = max_long(), + {Ret, Out} = m_i:long_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +longlong_test(Node, Timeout) -> + In = 65537, + {Ret, Out} = m_i:longlong_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +ushort_test(Node, Timeout) -> + In = max_ushort(), + {Ret, Out} = m_i:ushort_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +ulong_test(Node, Timeout) -> + In = max_ulong(), + {Ret, Out} = m_i:ulong_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +ulonglong_test(Node, Timeout) -> + In = 65537, + {Ret, Out} = m_i:ulonglong_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +double_test(Node, Timeout) -> + In = 37768.93, + {Ret, Out} = m_i:double_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +char_test(Node, Timeout) -> + In = 80, + {Ret, Out} = m_i:char_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +wchar_test(Node, Timeout) -> + In = 4097, + {Ret, Out} = m_i:wchar_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +octet_test(Node, Timeout) -> + In = 255, + {Ret, Out} = m_i:octet_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +bool_test(Node, Timeout) -> + In = false, + {Ret, Out} = m_i:bool_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +struct_test(Node, Timeout) -> + In = #m_b{l = max_long(), c = $a}, + {Ret, Out} = m_i:struct_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +struct2_test(Node, Timeout) -> + In = #m_es{ f = banana, l = max_long()}, + {Ret, Out} = m_i:struct2_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +seq1_test(Node, Timeout) -> + B1 = #m_b{l = max_long(), c = $a}, + B2 = #m_b{l = min_long(), c = $b}, + In = [B1, B2], + {Ret, Out} = m_i:seq1_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +seq2_test(Node, Timeout) -> + B = #m_b{l = max_long(), c = $a}, + A = #m_a{l = min_long(), y = [B, B], d = 4711.31}, + In = [A, A, A], + {Ret, Out} = m_i:seq2_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +seq3_test(Node, Timeout) -> + In = [max_long(), min_long(), max_long()], + {Ret, Out} = m_i:seq3_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +seq4_test(Node, Timeout) -> + In = [["hello", "all"], ["Erlang", "users", "!"]], + {Ret, Out} = m_i:seq4_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +seq5_test(Node, Timeout) -> + Arr3 = mk_array(3, max_long()), + In = [[Arr3, Arr3], [Arr3, Arr3, Arr3]], + {Ret, Out} = m_i:seq5_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +array1_test(Node, Timeout) -> + In = mk_array(500, min_long()), + {Ret, Out} = m_i:array1_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +array2_test(Node, Timeout) -> + In = mk_array(2, mk_array(3, min_long())), + {Ret, Out} = m_i:array2_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +enum_test(Node, Timeout) -> + In = banana, + {Ret, Out} = m_i:enum_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +string1_test(Node, Timeout) -> + In = "Developing Erlang applications is fun!", + {Ret, Out} = m_i:string1_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +wstring1_test(Node, Timeout) -> + In = [1047| "eveloping Erlang applications is fun!"], + {Ret, Out} = m_i:wstring1_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +string2_test(Node, Timeout) -> + In = ["Developing Erlang applications ", "is fun!"], + {Ret, Out} = m_i:string2_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +string3_test(Node, Timeout) -> + In = "Developing Erlang applications is fun!", + {Ret, Out} = m_i:string3_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +string4_test(Node, Timeout) -> + + In = #m_strRec{ + bb = true, + str4 = "Developing Erlang applications " + "is fun!", + str7 = mk_array(3, mk_array(2, max_long())), + str5 = [$a, $b, $c, $d, $e, $f], + str6 = "123456789012", + str8 = {$x, $y, $x}, + str9 = "123456789012", + str10 = [$a, $b, $c, $d, $e, $f] + }, + {Ret, Out} = m_i:string4_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +pid_test(Node, Timeout) -> + In = self(), + {Ret, Out} = m_i:pid_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +port_test(Node, Timeout) -> + In = get(port_test_port), + {Ret, Out} = m_i:port_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +ref_test(Node, Timeout) -> + In = make_ref(), + {Ret, Out} = m_i:ref_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +term_test(Node, Timeout) -> + In = {[a, b], 17, kalle}, + {Ret, Out} = m_i:term_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +typedef_test(Node, Timeout) -> + In1 = {nisse, [1, 2], olsson}, + In2 = get(port_test_port), + {Ret, Out1, Out2} = m_i:typedef_test({olsson, Node}, Timeout, In1, In2), + %% XXX Should check that Ret is an integer. + (Out1 == In1) and (Out2 == In2). +%%e + +%%b +inline_sequence_test(Node, Timeout) -> + In = #m_s{l = min_long(), sl = [max_long(), min_long()]}, + {Ret, Out} = m_i:inline_sequence_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +term_sequence_test(Node, Timeout) -> + In = lists:duplicate(17, {nisse, [1, 2], {kalle, olsson}}), + {Ret, Out} = m_i:term_sequence_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + +%%b +term_struct_test(Node, Timeout) -> + In = #m_et{e = {nisse, ["abcde"], {kalle, olsson}}, l = 4711}, + {Ret, Out} = m_i:term_struct_test({olsson, Node}, Timeout, In), + (Ret == In) and (Out == In). +%%e + + +%% Locals + +mk_array(Es) -> + list_to_tuple(Es). + +mk_array(N, E) -> + mk_array(lists:duplicate(N, E)). + +%% max_short() -> +%% power_of_two(15) - 1. +max_long() -> + power_of_two(31) - 1. +max_longlong() -> + power_of_two(63) - 1. +max_ushort() -> + power_of_two(16) - 1. +max_ulong() -> + power_of_two(32) - 1. +max_ulonglong() -> + power_of_two(64) - 1. + +%% min_short() -> +%% -power_of_two(15). +min_long() -> + -power_of_two(31). +%% min_longlong() -> +%% -power_of_two(63). +%% min_ushort() -> +%% 0. +%% min_ulong() -> +%% 0. +%% min_ulonglong() -> +%% 0. + +power_of_two(N) -> + round(math:pow(2, N)). + -- cgit v1.2.3