diff options
Diffstat (limited to 'lib/erl_interface/test')
51 files changed, 1147 insertions, 5509 deletions
diff --git a/lib/erl_interface/test/Makefile b/lib/erl_interface/test/Makefile index f8f2ef0156..3e3213d3e1 100644 --- a/lib/erl_interface/test/Makefile +++ b/lib/erl_interface/test/Makefile @@ -34,12 +34,7 @@ MODULES= \ ei_print_SUITE \ ei_tmo_SUITE \ erl_call_SUITE \ - erl_connect_SUITE \ - erl_global_SUITE \ - erl_eterm_SUITE \ - erl_ext_SUITE \ - erl_format_SUITE \ - erl_match_SUITE \ + ei_global_SUITE \ port_call_SUITE \ runner diff --git a/lib/erl_interface/test/all_SUITE_data/Makefile.src b/lib/erl_interface/test/all_SUITE_data/Makefile.src index 4f27b097c8..0d242663ea 100644 --- a/lib/erl_interface/test/all_SUITE_data/Makefile.src +++ b/lib/erl_interface/test/all_SUITE_data/Makefile.src @@ -23,7 +23,7 @@ CC0 = @CC@ CC = .@DS@gccifier@exe@ -CC"$(CC0)" CFLAGS0 = @CFLAGS@ -I@erl_interface_include@ CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -EI_COMMON_OBJS = runner@obj@ ei_runner@obj@ +EI_COMMON_OBJS = runner@obj@ ei_runner@obj@ my_ussi@obj@ ALL_OBJS = gccifier@exe@ $(EI_COMMON_OBJS) CP=cp diff --git a/lib/erl_interface/test/all_SUITE_data/init_tc.erl b/lib/erl_interface/test/all_SUITE_data/init_tc.erl index d9ad291f3d..da3d8053a0 100644 --- a/lib/erl_interface/test/all_SUITE_data/init_tc.erl +++ b/lib/erl_interface/test/all_SUITE_data/init_tc.erl @@ -77,11 +77,7 @@ generate_c(Cases, File, TcName) -> lists:foreach(fun(Case) -> io:format(File, " ~s,~n", [Case]) end, Cases), io:format(File, "~s", [["};\n\n", - "#ifdef VXWORKS\n", - "int ", TcName, "(int argc, char* argv[])\n", - "#else\n", "int main(int argc, char* argv[])\n", - "#endif\n", "{\n", " run_tests(argv[0], test_cases, ", "sizeof(test_cases)/sizeof(test_cases[0]));\n", diff --git a/lib/erl_interface/test/all_SUITE_data/my_ussi.c b/lib/erl_interface/test/all_SUITE_data/my_ussi.c new file mode 100644 index 0000000000..5f8c79b7cf --- /dev/null +++ b/lib/erl_interface/test/all_SUITE_data/my_ussi.c @@ -0,0 +1,198 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2019. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * %CopyrightEnd% + */ + +/* + * User Supplied Socket Implementation (ussi) + * for test purpose. + */ +#include <stdlib.h> +#include <string.h> +#include "ei.h" + +struct my_ctx +{ + void* ctx; +}; + +/* + * To minimize effort but still test a different context format + * we cheat and wrap the existing TCP default callbacks. + */ +extern ei_socket_callbacks ei_default_socket_callbacks; + +static int my_socket(void **ctx, void *setup_ctx) +{ + struct my_ctx *myctx = malloc(sizeof(struct my_ctx)); + int ret; + ret = ei_default_socket_callbacks.socket(&myctx->ctx, NULL); + *ctx = myctx; + return ret; +} + +static int my_close(void *ctx) +{ + struct my_ctx *myctx = ctx; + int ret = ei_default_socket_callbacks.close(myctx->ctx); + free(myctx); + return ret; +} + +static int my_get_fd(void *ctx, int *fd) +{ + struct my_ctx *myctx = ctx; + return ei_default_socket_callbacks.get_fd(myctx->ctx, fd); +} + +static int my_hs_packet_header_size(void *ctx, int *sz) +{ + struct my_ctx *myctx = ctx; + return ei_default_socket_callbacks.handshake_packet_header_size(myctx->ctx, sz); +} + +static int my_connect_handshake_complete(void *ctx) +{ + struct my_ctx *myctx = ctx; + return ei_default_socket_callbacks.connect_handshake_complete(myctx->ctx); +} + +static int my_accept_handshake_complete(void *ctx) +{ + struct my_ctx *myctx = ctx; + return ei_default_socket_callbacks.accept_handshake_complete(myctx->ctx); +} + +static int my_listen(void *ctx, void *addr, int *len, int backlog) +{ + struct my_ctx *myctx = ctx; + return ei_default_socket_callbacks.listen(myctx->ctx, addr, len, backlog); +} + +static int my_accept(void **ctx, void *addr, int *len, unsigned tmo) +{ + struct my_ctx *listen_ctx = *ctx; + struct my_ctx *conn_ctx = malloc(sizeof(struct my_ctx)); + int ret; + *conn_ctx = *listen_ctx; + ret = ei_default_socket_callbacks.accept(&conn_ctx->ctx, addr, len, tmo); + if (ret == 0) + *ctx = conn_ctx; + else + free(conn_ctx); + return ret; +} + +static int my_connect(void *ctx, void *addr, int len, unsigned tmo) +{ + struct my_ctx *myctx = ctx; + return ei_default_socket_callbacks.connect(myctx->ctx, addr, len, tmo); +} + +static void* memdup(const void* mem, int nbytes) +{ + void *p = malloc(nbytes); + memcpy(p, mem, nbytes); + return p; +} + +static void scramble(void* bytes, int nbytes) +{ +/* Would be nice to really test that only our callbacks are used + and the default ones are not. + Need corresponding Erlang distribution impl to work. + + unsigned char *p = bytes; + int i; + for (i=0; i < nbytes; ++i) + p[i] = ~p[i]; +*/ +} + +/* our own iovec struct to avoid config dependency HAVE_WRITEV */ +struct my_iovec { + void *iov_base; /* Starting address */ + size_t iov_len; /* Number of bytes to transfer */ +}; + +static int my_writev(void *ctx, const void *viov, int iovcnt, ssize_t *len, unsigned tmo) +{ + struct my_ctx *myctx = ctx; + struct my_iovec *iov; + int i, ret; + + /* create mutable copy of both iovec and data */ + iov = memdup(viov, sizeof(struct my_iovec) * iovcnt); + for (i=0; i < iovcnt; ++i) { + iov[i].iov_base = memdup(iov[i].iov_base, iov[i].iov_len); + scramble(iov[i].iov_base, iov[i].iov_len); + } + + ret = ei_default_socket_callbacks.writev(myctx->ctx, viov, iovcnt, len, tmo); + + for (i=0; i < iovcnt; ++i) + free(iov[i].iov_base); + free(iov); + return ret; +} + +static int my_write(void *ctx, const char* buf, ssize_t *len, unsigned tmo) +{ + struct my_ctx *myctx = ctx; + unsigned char* copy = memdup(buf, *len); + int i, ret; + + scramble(copy, *len); + ret = ei_default_socket_callbacks.write(myctx->ctx, copy, len, tmo); + free(copy); + return ret; +} + +static int my_read(void *ctx, char* buf, ssize_t *len, unsigned tmo) +{ + struct my_ctx *myctx = ctx; + int ret, i; + + ret = ei_default_socket_callbacks.read(myctx->ctx, buf, len, tmo); + if (ret == 0) + scramble(buf, *len); + return ret; +} + +ei_socket_callbacks my_ussi = { + 0, /* flags */ + my_socket, + my_close, + my_listen, + my_accept, + my_connect, + my_writev, + my_write, + my_read, + my_hs_packet_header_size, + my_connect_handshake_complete, + my_accept_handshake_complete, + my_get_fd +}; + +void my_ussi_init(void) +{ + my_ussi.flags = ei_default_socket_callbacks.flags; + if (!ei_default_socket_callbacks.writev) + my_ussi.writev = NULL; +} diff --git a/lib/erl_interface/test/all_SUITE_data/my_ussi.h b/lib/erl_interface/test/all_SUITE_data/my_ussi.h new file mode 100644 index 0000000000..0db07c990e --- /dev/null +++ b/lib/erl_interface/test/all_SUITE_data/my_ussi.h @@ -0,0 +1,28 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2019. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * %CopyrightEnd% + */ + +/* + * User Supplied Socket Implementation (ussi) + * for test purpose. + */ + +extern ei_socket_callbacks my_ussi; + +extern void my_ussi_init(void); diff --git a/lib/erl_interface/test/all_SUITE_data/runner.c b/lib/erl_interface/test/all_SUITE_data/runner.c deleted file mode 100644 index 42e8bb03e5..0000000000 --- a/lib/erl_interface/test/all_SUITE_data/runner.c +++ /dev/null @@ -1,459 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#ifndef __WIN32__ -#include <unistd.h> -#endif -#include <stdarg.h> - -#include "runner.h" - -#ifndef __WIN32__ -#define _O_BINARY 0 -#define _setmode(fd, mode) -#endif - -#define HEADER_SIZE 4 - -static char* progname; /* Name of this program (from argv[0]). */ -static int fd_from_erl; /* File descriptor from Erlang. */ -static int fd_to_erl; /* File descriptor to Erlang. */ - -static int packet_loop(); -static void ensure_buf_big_enough(); -static int readn(); -static void reply(char* buf, unsigned size); -static void dump(); - -void -run_tests(char* argv0, TestCase test_cases[], unsigned number) -{ - int i; - int n; - char* packet; - - progname = argv0; - _setmode(0, _O_BINARY); - _setmode(1, _O_BINARY); - fd_from_erl = 0; - fd_to_erl = 1; - - packet = read_packet(&n); - - /* - * Dispatch to the appropriate test function. - */ - - i = packet[0] * 256 + packet[1]; - if (i >= number) { - fprintf(stderr, "%s: bad test case number %d", - progname, i); - free(packet); - exit(1); - } else { - (*test_cases[i])(); - free(packet); - } -} - - -/*********************************************************************** - * - * R e a d i n g p a c k e t s - * - ************************************************************************/ - -/* - * Reads an Erlang term. - * - * Returns: A pointer to a term (an ETERM structure) if there was - * at term available, or a NULL pointer if there was an 'eot' (end-of-test) - * packet. Aborts if anything else received. - */ - -ETERM* -get_term(void) -{ - char* encoded; - ETERM* term; - int n; - - encoded = read_packet(&n); - - switch (encoded[0]) { - case 'e': - free(encoded); - return NULL; - case 't': - term = erl_decode(encoded+1); - free(encoded); - if (term == NULL) { - fail("Failed to decode term"); - exit(0); - } - return term; - default: - fprintf(stderr, "Garbage received: "); - dump(encoded, n, 16); - putc('\n', stderr); - fail("C program received garbage"); - free(encoded); - exit(1); - } -} - - -/* - * Reads a packet from Erlang. The packet must be a standard {packet, 2} - * packet. This function aborts if any error is detected (including EOF). - * - * Returns: The number of bytes in the packet. - */ - -char *read_packet(int *len) -{ - - unsigned char* io_buf = NULL; /* Buffer for file i/o. */ - int i; - unsigned char header[HEADER_SIZE]; - unsigned packet_length; /* Length of current packet. */ - int bytes_read; - - /* - * Read the packet header. - */ - - bytes_read = readn(fd_from_erl, header, HEADER_SIZE); - - if (bytes_read == 0) { - fprintf(stderr, "%s: Unexpected end of file\n", progname); - exit(1); - } - if (bytes_read != HEADER_SIZE) { - fprintf(stderr, "%s: Failed to read packet header\n", progname); - exit(1); - } - - /* - * Get the length of this packet. - */ - - packet_length = 0; - - for (i = 0; i < HEADER_SIZE; i++) - packet_length = (packet_length << 8) | header[i]; - - if (len) *len=packet_length; /* report length only if caller requested it */ - - if ((io_buf = (char *) malloc(packet_length)) == NULL) { - fprintf(stderr, "%s: insufficient memory for i/o buffer of size %d\n", - progname, packet_length); - exit(1); - } - - /* - * Read the packet itself. - */ - - bytes_read = readn(fd_from_erl, io_buf, packet_length); - if (bytes_read != packet_length) { - fprintf(stderr, "%s: couldn't read packet of length %d\r\n", - progname, packet_length); - free(io_buf); - exit(1); - } - - return io_buf; -} - - -/*********************************************************************** - * S e n d i n g r e p l i e s - * - * The functions below send various types of replies back to Erlang. - * Each reply start with a letter indicating the type of reply. - * - * Reply Translated to on Erlang side - * ----- ---------------------------- - * [$b|Bytes] {bytes, Bytes} - * [$e] eot - * [$f] ct:fail() - * [$f|Reason] ct:fail(Reason) - * [$t|EncodedTerm] {term, Term} - * [$N] 'NULL' - * [$m|Message] io:format("~s", [Message]) (otherwise ignored) - * - ***********************************************************************/ - -/* - * This function reports the outcome of a test fail. It is useful if - * you implement a test case entirely in C code. - * - * If the ok argument is zero, a [$f] reply will be sent to the - * Erlang side (causing ct:fail() to be called); otherwise, - * the atom 'eot' will be sent to Erlang. - * - * If you need to provide more details on a failure, use the fail() function. - */ - -void -do_report(file, line, ok) - char* file; - int line; - int ok; /* Zero if failed; non-zero otherwise. */ -{ - char reason; - unsigned long ab; - unsigned long fb; - - reason = ok ? 'e' : 'f'; - - if (!ok) { - do_fail(file, line, "Generic failure"); - } else { - /* release all unallocated blocks */ - erl_eterm_release(); - /* check mem usage stats */ - erl_eterm_statistics(&ab, &fb); - if ((ab == 0) && (fb == 0) ) { - reply(&reason, 1); - } - else { - char sbuf[128]; - - sprintf(sbuf, "still %lu terms allocated," - " %lu on freelist at end of test", ab, fb); - do_fail(file, line, sbuf); - } - } -} - - -/* - * This function causes a call to ct:fail(Reason) on the - * Erlang side. - */ - -void -do_fail(char* file, int line, char* reason) -{ - char sbuf[2048]; - - sbuf[0] = 'f'; - sprintf(sbuf+1, "%s, line %d: %s", file, line, reason); - reply(sbuf, 1+strlen(sbuf+1)); -} - -/* - * This function sends a message to the Erlang side. - * The message will be written to the test servers log file, - * but will otherwise be completly ignored. - */ - -void -message(char* format, ...) -{ - va_list ap; - char sbuf[1024]; - - sbuf[0] = 'm'; - va_start(ap, format); - vsprintf(sbuf+1, format, ap); - va_end(ap); - - reply(sbuf, 1+strlen(sbuf+1)); -} - -/* - * This function sends the given term to the Erlang side, - * where it will be received as {term, Term}. - * - * If the given pointer is NULL (indicating an invalid term), - * the result on the Erlang side will be the atom 'NULL'. - * - * After sending the term, this function frees the term by - * calling erl_free_term(). - */ - -void -send_term(term) - ETERM* term; /* Term to be sent to Erlang side. */ -{ - char encoded[64*1024]; - int n; - - if (term == NULL) { - encoded[0] = 'N'; - n = 1; - } else { - encoded[0] = 't'; - n = 1 + erl_encode(term, encoded+1); - erl_free_term(term); - } - reply(encoded, n); -} - -#if 0 - -/* Seriously broken!!! */ - -void -send_bin_term(x_ei_buff* x) -{ - x_ei_buff x2; - x_ei_new(&x2); - x2.buff[x2.index++] = 't'; - x_ei_append(&x2, x); - reply(x2.buff, x2.index); - free(x2.buff); -} -#endif - -/* - * This function sends a raw buffer of data to the - * Erlang side, where it will be received as {bytes, Bytes}. - */ - -void -send_buffer(buf, size) - char* buf; /* Buffer with bytes to send to Erlang. */ - int size; /* Size of data to send to Erlang. */ -{ - char* send_buf; - - send_buf = (char *) malloc(size+1); - send_buf[0] = 'b'; - memcpy(send_buf+1, buf, size); - reply(send_buf, size+1); - free(send_buf); -} - -/*********************************************************************** - * - * P r i v a t e h e l p e r s - * - ***********************************************************************/ - -/* - * Sends a packet back to Erlang. - */ - -static void -reply(reply_buf, size) - char* reply_buf; /* Buffer with reply. */ - unsigned size; /* Size of reply. */ -{ - int n; /* Temporary to hold size. */ - int i; /* Loop counter. */ - char* buf; - - - buf = (char *) malloc(size+HEADER_SIZE); - memcpy(buf+HEADER_SIZE, reply_buf, size); - - /* - * Fill the header starting with the least significant byte. - */ - - n = size; - for (i = HEADER_SIZE-1; i >= 0; i--) { - buf[i] = (char) n; /* Store least significant byte. */ - n = n >> 8; - } - - size += HEADER_SIZE; -/* - fprintf(stderr, "\r\nReply size: %u\r\n", - (unsigned)buf[0] << 8 + (unsigned)buf[1]); - - for (i = 0; i < size; i++) { - fprintf(stderr,"%u %c\r\n",buf[i],buf[i]); - } - - fprintf(stderr, "\r\n"); -*/ - write(fd_to_erl, buf, size); - free(buf); -} - - -/* - * Reads len number of bytes. - */ - -static int -readn(fd, buf, len) - int fd; /* File descriptor to read from. */ - unsigned char *buf; /* Store in this buffer. */ - int len; /* Number of bytes to read. */ -{ - int n; /* Byte count in last read call. */ - int sofar = 0; /* Bytes read so far. */ - - do { - if ((n = read(fd, buf+sofar, len-sofar)) <= 0) - /* error or EOF in read */ - return(n); - sofar += n; - } while (sofar < len); - return sofar; -} - -void -dump(buf, sz, max) - unsigned char* buf; - int sz; - int max; -{ - int i, imax; - char comma[5] = ","; - - if (!sz) - return; - if (sz > max) - imax = max; - else - imax = sz; - - for (i=0; i<imax; i++) { - if (i == imax-1) { - if (sz > max) - strcpy(comma, ",..."); - else - comma[0] = 0; - } - if (isdigit(buf[i])) - fprintf(stderr, "%u%s", (int)(buf[i]), comma); - else { - if (isalpha(buf[i])) { - fprintf(stderr, "%c%s", buf[i], comma); - } - else - fprintf(stderr, "%u%s", (int)(buf[i]), comma); - } - } -} - diff --git a/lib/erl_interface/test/all_SUITE_data/runner.h b/lib/erl_interface/test/all_SUITE_data/runner.h deleted file mode 100644 index 493602869f..0000000000 --- a/lib/erl_interface/test/all_SUITE_data/runner.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -#include "erl_interface.h" - -typedef void (*TestCase)(void); - -#define TESTCASE(name) void name(void) -#define ASIZE(a) (sizeof(a)/sizeof(a[0])) - -void run_tests(char* argv0, TestCase cases[], unsigned number); - -/* - * Reading. - */ - -ETERM* get_term(void); -char *read_packet(int *len); - -/* - * Sending replies. - */ - -#define fail(reason) do_fail(__FILE__, __LINE__, reason) -#define report(ok) do_report(__FILE__, __LINE__, ok) - -void do_report(char* file, int line, int ok); -void do_fail(char* file, int line, char* reason); -void send_term(ETERM* term); -void send_buffer(char* buf, int size); -void message(char* format, ...); - -void send_bin_term(ei_x_buff* x); - diff --git a/lib/erl_interface/test/ei_accept_SUITE.erl b/lib/erl_interface/test/ei_accept_SUITE.erl index f40c67375b..c49b8a358a 100644 --- a/lib/erl_interface/test/ei_accept_SUITE.erl +++ b/lib/erl_interface/test/ei_accept_SUITE.erl @@ -43,12 +43,15 @@ init_per_testcase(Case, Config) -> runner:init_per_testcase(?MODULE, Case, Config). ei_accept(Config) when is_list(Config) -> - ei_accept_do(Config, 0), % default - ei_accept_do(Config, 21). % ei_set_compat_rel + [ei_accept_do(Config, CR, SI) + || CR <- [0,21], + SI <- [default, ussi]], + ok. -ei_accept_do(Config, CompatRel) -> +ei_accept_do(Config, CompatRel, SockImpl) -> + io:format("CompatRel=~p, SockImpl=~p\n", [CompatRel, SockImpl]), P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, CompatRel), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, CompatRel, SockImpl), Myname = hd(tl(string:tokens(atom_to_list(node()), "@"))), io:format("Myname ~p ~n", [Myname]), @@ -72,7 +75,8 @@ ei_accept_do(Config, CompatRel) -> {ok, ListenFd} = ei_publish(P, Port), {any, EINode} ! TermToSend, - {ok, Fd, _Node} = ei_accept(P, ListenFd), + {ok, Fd, Node} = ei_accept(P, ListenFd), + Node = node(), Got1 = ei_receive(P, Fd), %% Send again, now without auto-connect @@ -88,9 +92,13 @@ ei_accept_do(Config, CompatRel) -> ei_threaded_accept(Config) when is_list(Config) -> Einode = filename:join(proplists:get_value(data_dir, Config), "eiaccnode"), + ei_threaded_accept_do(Einode, default), + ei_threaded_accept_do(Einode, ussi), + ok. + +ei_threaded_accept_do(Einode, SockImpl) -> N = 3, - Host = atom_to_list(node()), - start_einode(Einode, N, Host), + start_einode(Einode, N, SockImpl), io:format("started eiaccnode"), TestServerPid = self(), [spawn_link(fun() -> send_rec_einode(I, TestServerPid) end) || I <- lists:seq(0, N-1)], @@ -101,7 +109,7 @@ ei_threaded_accept(Config) when is_list(Config) -> %% Test erlang:monitor toward erl_interface "processes" monitor_ei_process(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, 0, default), Myname = hd(tl(string:tokens(atom_to_list(node()), "@"))), io:format("Myname ~p ~n", [Myname]), @@ -125,10 +133,19 @@ monitor_ei_process(Config) when is_list(Config) -> runner:finish(P), - [{'DOWN', MRef1, process, {any, EINode}, noconnection}, - {'DOWN', MRef2, process, {any, EINode}, noconnection} - ] = lists:sort(flush(2, 1000)), - + ok =receive + {'DOWN', MRef1, process, {any, EINode}, noconnection} -> + ok + after 1000 -> + timeout + end, + ok = receive + {'DOWN', MRef2, process, {any, EINode}, noconnection} -> + ok + after 1000 -> + timeout + end, + [] = flush(0, 1000), ok. waitfornode(String,0) -> @@ -164,9 +181,10 @@ send_rec_einode(N, TestServerPid) -> ct:fail(EINode) end. -start_einode(Einode, N, Host) -> +start_einode(Einode, N, SockImpl) -> Einodecmd = Einode ++ " " ++ atom_to_list(erlang:get_cookie()) - ++ " " ++ integer_to_list(N) ++ " " ++ Host, + ++ " " ++ integer_to_list(N) + ++ " " ++ atom_to_list(SockImpl), io:format("Einodecmd ~p ~n", [Einodecmd]), open_port({spawn, Einodecmd}, []), ok. @@ -174,8 +192,8 @@ start_einode(Einode, N, Host) -> %%% Interface functions for ei (erl_interface) functions. -ei_connect_init(P, Num, Cookie, Creation, Compat) -> - send_command(P, ei_connect_init, [Num,Cookie,Creation,Compat]), +ei_connect_init(P, Num, Cookie, Creation, Compat, SockImpl) -> + send_command(P, ei_connect_init, [Num,Cookie,Creation,Compat,SockImpl]), case get_term(P) of {term,Int} when is_integer(Int) -> Int end. diff --git a/lib/erl_interface/test/ei_accept_SUITE_data/Makefile.src b/lib/erl_interface/test/ei_accept_SUITE_data/Makefile.src index 10ef437f8b..7fd0a123b4 100644 --- a/lib/erl_interface/test/ei_accept_SUITE_data/Makefile.src +++ b/lib/erl_interface/test/ei_accept_SUITE_data/Makefile.src @@ -25,6 +25,7 @@ CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" LD = @LD@ LIBEI = @erl_interface_eilib@ LIBFLAGS = ../all_SUITE_data/ei_runner@obj@ \ + ../all_SUITE_data/my_ussi@obj@ \ $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ @erl_interface_threadlib@ CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data diff --git a/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c b/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c index 09b0b5440b..64cb2dc447 100644 --- a/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c +++ b/lib/erl_interface/test/ei_accept_SUITE_data/ei_accept_test.c @@ -27,9 +27,6 @@ #include <stdio.h> #include <string.h> -#ifdef VXWORKS -#include "reclaim.h" -#endif #ifdef __WIN32__ #include <winsock2.h> @@ -41,6 +38,7 @@ #endif #include "ei_runner.h" +#include "my_ussi.h" static void cmd_ei_connect_init(char* buf, int len); static void cmd_ei_publish(char* buf, int len); @@ -58,7 +56,7 @@ static struct { int num_args; /* Number of arguments. */ void (*func)(char* buf, int len); } commands[] = { - "ei_connect_init", 4, cmd_ei_connect_init, + "ei_connect_init", 5, cmd_ei_connect_init, "ei_publish", 1, cmd_ei_publish, "ei_accept", 1, cmd_ei_accept, "ei_receive", 1, cmd_ei_receive, @@ -110,10 +108,11 @@ static void cmd_ei_connect_init(char* buf, int len) unsigned long compat; char node_name[100]; char cookie[MAXATOMLEN], * cp = cookie; + char socket_impl[10]; ei_x_buff res; if (ei_decode_long(buf, &index, &num) < 0) fail("expected int"); - sprintf(node_name, "c%d", num); + sprintf(node_name, "c%ld", num); if (ei_decode_atom(buf, &index, cookie) < 0) fail("expected atom (cookie)"); if (cookie[0] == '\0') @@ -124,7 +123,18 @@ static void cmd_ei_connect_init(char* buf, int len) fail("expected uint"); if (compat) ei_set_compat_rel(compat); - r = ei_connect_init(&ec, node_name, cp, creation); + if (ei_decode_atom_as(buf, &index, socket_impl, sizeof(socket_impl), + ERLANG_ASCII, NULL, NULL) < 0) + fail("expected atom (socket_impl)"); + if (strcmp(socket_impl,"default") == 0) + r = ei_connect_init(&ec, node_name, cp, creation); + else if (strcmp(socket_impl,"ussi") == 0) + r = ei_connect_init_ussi(&ec, node_name, cp, creation, + &my_ussi, sizeof(my_ussi), NULL); + else + fail1("unknown socket_impl atom '%s'", socket_impl); + + ei_x_new_with_version(&res); ei_x_encode_long(&res, r); send_bin_term(&res); @@ -152,9 +162,6 @@ static void cmd_ei_publish(char* buf, int len) if ((i = ei_publish(&ec, lport)) == -1) fail("ei_publish"); -#ifdef VXWORKS - save_fd(i); -#endif /* send listen-fd, result and errno */ ei_x_new_with_version(&x); ei_x_encode_tuple_header(&x, 3); @@ -179,9 +186,6 @@ static void cmd_ei_accept(char* buf, int len) fail("expected int (listen fd)"); r = ei_accept(&ec, listen, &conn); -#ifdef VXWORKS - save_fd(r); -#endif /* send result, errno and nodename */ ei_x_new_with_version(&x); ei_x_encode_tuple_header(&x, 3); diff --git a/lib/erl_interface/test/ei_accept_SUITE_data/eiaccnode.c b/lib/erl_interface/test/ei_accept_SUITE_data/eiaccnode.c index 90c7a2259f..4ce55cacef 100644 --- a/lib/erl_interface/test/ei_accept_SUITE_data/eiaccnode.c +++ b/lib/erl_interface/test/ei_accept_SUITE_data/eiaccnode.c @@ -22,35 +22,28 @@ #include <stdlib.h> #include <stdio.h> +#include <string.h> #ifdef __WIN32__ #include <winsock2.h> #include <windows.h> #include <process.h> #else -#ifndef VXWORKS #include <pthread.h> -#endif #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #endif #include "ei.h" +#include "my_ussi.h" -#ifdef VXWORKS -#include <vxWorks.h> -#include <sockLib.h> -#include <inetLib.h> -#define MAIN cnode -#else #define MAIN main -#endif /* A small einode. To be called from the test case ei_accept_SUITE:multi_thread - usage: eiaccnode <cookie> <n> + usage: eiaccnode <cookie> <n> <default|ussi> - start threads 0..n-1 - in each thread @@ -61,7 +54,8 @@ - shutdown gracefully */ -static const char* cookie, * desthost; +static const char* cookie; +static int use_ussi; #ifndef SD_SEND #ifdef SHUTWR @@ -78,7 +72,7 @@ static void* #endif einode_thread(void* num) { - int n = (int)num; + int n = (int)(long)num; int port; ei_cnode ec; char myname[100], destname[100], filename[100]; @@ -88,10 +82,15 @@ static void* FILE* file; sprintf(filename, "eiacc%d_trace.txt", n); - file = fopen(filename, "w"); + file = fopen(filename, "a"); sprintf(myname, "eiacc%d", n); fflush(file); - r = ei_connect_init(&ec, myname, cookie, 0); + fprintf(file, "---- use_ussi = %d ----\n", use_ussi); fflush(file); + if (use_ussi) + r = ei_connect_init_ussi(&ec, myname, cookie, 0, + &my_ussi, sizeof(my_ussi), NULL); + else + r = ei_connect_init(&ec, myname, cookie, 0); port = 0; listen = ei_listen(&ec, &port, 5); if (listen <= 0) { @@ -151,54 +150,52 @@ static void* return 0; } +int 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) + if (argc < 4) exit(1); cookie = argv[1]; n = atoi(argv[2]); if (n > 100) exit(2); - desthost = argv[3]; - if (argc == 3) + + if (strcmp(argv[3], "default") == 0) + use_ussi = 0; + else if (strcmp(argv[3], "ussi") == 0) + use_ussi = 1; + else + printf("bad argv[3] '%s'", argv[3]); + + if (argc == 4) no_threads = 0; else no_threads = argv[4] != NULL && strcmp(argv[4], "nothreads") == 0; -#ifdef VXWORKS - no_threads = 1; -#endif ei_init(); 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 + (void*)(size_t)i, 0, &tid); #else - ; + pthread_create(&threads[i], NULL, einode_thread, (void*)(size_t)i); #endif } else - einode_thread((void*)i); + einode_thread((void*)(size_t)i); } if (!no_threads) -#ifndef VXWORKS for (i = 0; i < n; ++i) { #ifdef __WIN32__ if (WaitForSingleObject(threads[i], INFINITE) != WAIT_OBJECT_0) @@ -207,9 +204,6 @@ MAIN(int argc, char *argv[]) #endif printf("bad wait thread %d\n", i); } -#else - ; -#endif printf("ok\n"); return 0; } diff --git a/lib/erl_interface/test/ei_connect_SUITE.erl b/lib/erl_interface/test/ei_connect_SUITE.erl index 6184ce801b..2ec1237e8e 100644 --- a/lib/erl_interface/test/ei_connect_SUITE.erl +++ b/lib/erl_interface/test/ei_connect_SUITE.erl @@ -24,7 +24,7 @@ -include_lib("common_test/include/ct.hrl"). -include("ei_connect_SUITE_data/ei_connect_test_cases.hrl"). --export([all/0, suite/0, +-export([all/0, suite/0, groups/0, init_per_testcase/2, ei_send/1, ei_reg_send/1, @@ -33,7 +33,8 @@ rpc_test/1, ei_send_funs/1, ei_threaded_send/1, - ei_set_get_tracelevel/1]). + ei_set_get_tracelevel/1, + ei_connect_host_port_test/1]). -import(runner, [get_term/1,send_term/2]). @@ -42,15 +43,30 @@ suite() -> {timetrap, {seconds, 30}}]. all() -> - [ei_send, ei_reg_send, ei_rpc, ei_format_pid, ei_send_funs, - ei_threaded_send, ei_set_get_tracelevel]. + [ei_threaded_send, + ei_connect_host_port_test, + {group, default}, + {group, ussi}]. + +groups() -> + Members = [ei_send, + ei_format_pid, + ei_send_funs, + ei_set_get_tracelevel, + ei_reg_send, + ei_rpc], + [{default, [], Members}, + {ussi, [], Members}]. + +get_group(Config) -> + proplists:get_value(name, proplists:get_value(tc_group_properties,Config)). init_per_testcase(Case, Config) -> runner:init_per_testcase(?MODULE, Case, Config). ei_send(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, get_group(Config)), {ok,Fd} = ei_connect(P, node()), ok = ei_send(P, Fd, self(), AMsg={a,message}), @@ -63,7 +79,7 @@ ei_send(Config) when is_list(Config) -> ei_format_pid(Config) when is_list(Config) -> S = self(), P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, get_group(Config)), {ok,Fd} = ei_connect(P, node()), ok = ei_format_pid(P, Fd, S), @@ -75,7 +91,7 @@ ei_format_pid(Config) when is_list(Config) -> ei_send_funs(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, get_group(Config)), {ok,Fd} = ei_connect(P, node()), Fun1 = fun ei_send/1, @@ -94,7 +110,7 @@ ei_send_funs(Config) when is_list(Config) -> ei_reg_send(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, get_group(Config)), {ok,Fd} = ei_connect(P, node()), ARegName = a_strange_registred_name, @@ -143,7 +159,7 @@ start_einode(Einode, N, Host) -> ei_rpc(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, get_group(Config)), {ok,Fd} = ei_connect(P, node()), S= "Hej du glade!", SRev = lists:reverse(S), @@ -157,7 +173,7 @@ ei_rpc(Config) when is_list(Config) -> ei_set_get_tracelevel(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), 5 = ei_set_get_tracelevel(P, 5), - 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, get_group(Config)), {ok,Fd} = ei_connect(P, node()), S= "Hej du glade!", SRev = lists:reverse(S), @@ -171,10 +187,31 @@ ei_set_get_tracelevel(Config) when is_list(Config) -> ok. +ei_connect_host_port_test(Config) when is_list(Config) -> + P = runner:start(Config, ?interpret), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, default), + [NodeName, Hostname] = string:lexemes(atom_to_list(node()), "@"), + {ok, NamePortList} = net_adm:names(), + {value, {_, Port}} + = lists:search(fun({N, _}) -> + string:equal(N, NodeName) + end, + NamePortList), + {ok,Fd} = ei_connect_host_port(P, + erlang:list_to_atom(Hostname), + Port), + ok = ei_send(P, Fd, self(), AMsg={a,message}), + receive AMsg -> ok end, + + runner:send_eot(P), + runner:recv_eot(P), + ok. + + %%% Interface functions for ei (erl_interface) functions. -ei_connect_init(P, Num, Cookie, Creation) -> - send_command(P, ei_connect_init, [Num,Cookie,Creation]), +ei_connect_init(P, Num, Cookie, Creation, SockImpl) -> + send_command(P, ei_connect_init, [Num,Cookie,Creation,SockImpl]), case get_term(P) of {term,Int} when is_integer(Int) -> Int end. @@ -186,6 +223,13 @@ ei_connect(P, Node) -> {term,{-1,Errno}} -> {error,Errno} end. +ei_connect_host_port(P, Hostname, Port) -> + send_command(P, ei_connect_host_port, [Hostname, Port]), + case get_term(P) of + {term,{Fd,_}} when Fd >= 0 -> {ok,Fd}; + {term,{-1,Errno}} -> {error,Errno} + end. + ei_set_get_tracelevel(P, Tracelevel) -> send_command(P, ei_set_get_tracelevel, [Tracelevel]), case get_term(P) of diff --git a/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src b/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src index c2d8261dd8..bbea076ebd 100644 --- a/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src +++ b/lib/erl_interface/test/ei_connect_SUITE_data/Makefile.src @@ -23,10 +23,9 @@ include @erl_interface_mk_include@ CC0 = @CC@ CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" LD = @LD@ -LIBERL = @erl_interface_lib@ LIBEI = @erl_interface_eilib@ LIBFLAGS = ../all_SUITE_data/ei_runner@obj@ \ - $(LIBERL) $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ + $(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@ @@ -39,7 +38,8 @@ clean: $(RM) ei_connect_test@exe@ einode@exe@ ei_connect_test@exe@: $(EI_CONNECT_OBJS) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(EI_CONNECT_OBJS) $(LIBFLAGS) + $(LD) @CROSSLDFLAGS@ -o $@ $(EI_CONNECT_OBJS) \ + ../all_SUITE_data/my_ussi@obj@ $(LIBFLAGS) einode@exe@: $(EINODE_OBJS) $(LIBEI) 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 index 385bcdd422..54e78253a0 100644 --- 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 @@ -27,14 +27,13 @@ #include <stdio.h> #include <string.h> -#ifdef VXWORKS -#include "reclaim.h" -#endif #include "ei_runner.h" +#include "my_ussi.h" static void cmd_ei_connect_init(char* buf, int len); static void cmd_ei_connect(char* buf, int len); +static void cmd_ei_connect_host_port(char* buf, int len); static void cmd_ei_send(char* buf, int len); static void cmd_ei_format_pid(char* buf, int len); static void cmd_ei_send_funs(char* buf, int len); @@ -52,8 +51,9 @@ static struct { int num_args; /* Number of arguments. */ void (*func)(char* buf, int len); } commands[] = { - "ei_connect_init", 3, cmd_ei_connect_init, + "ei_connect_init", 4, cmd_ei_connect_init, "ei_connect", 1, cmd_ei_connect, + "ei_connect_host_port", 2, cmd_ei_connect_host_port, "ei_send", 3, cmd_ei_send, "ei_send_funs", 3, cmd_ei_send_funs, "ei_reg_send", 3, cmd_ei_reg_send, @@ -107,9 +107,11 @@ TESTCASE(interpret) static void cmd_ei_connect_init(char* buf, int len) { int index = 0, r = 0; - long l; + long l, creation; char b[100]; char cookie[MAXATOMLEN], * cp = cookie; + char socket_impl[10]; + int use_ussi; ei_x_buff res; if (ei_decode_long(buf, &index, &l) < 0) fail("expected int"); @@ -118,7 +120,23 @@ static void cmd_ei_connect_init(char* buf, int len) fail("expected atom (cookie)"); if (cookie[0] == '\0') cp = NULL; - r = ei_connect_init(&ec, b, cp, 0); + if (ei_decode_long(buf, &index, &creation) < 0) + fail("expected int (creation)"); + if (ei_decode_atom_as(buf, &index, socket_impl, + sizeof(socket_impl), ERLANG_ASCII, NULL, NULL) < 0) + fail("expected atom (socket_impl)"); + if (strcmp(socket_impl, "default") == 0) + use_ussi = 0; + else if (strcmp(socket_impl, "ussi") == 0) + use_ussi = 1; + else + fail1("expected atom 'default' or 'ussi', got '%s'", socket_impl); + + if (use_ussi) + r = ei_connect_init_ussi(&ec, b, cp, (short)creation, + &my_ussi, sizeof(my_ussi), NULL); + else + r = ei_connect_init(&ec, b, cp, (short)creation); ei_x_new_with_version(&res); ei_x_encode_long(&res, r); send_bin_term(&res); @@ -133,11 +151,20 @@ static void cmd_ei_connect(char* buf, int len) 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_connect_host_port(char* buf, int len) +{ + int index = 0; + char hostname[256]; + int i; + long port; + if (ei_decode_atom(buf, &index, hostname) < 0) + fail("expected atom"); + if (ei_decode_long(buf, &index, &port) < 0) + fail("expected int"); + i = ei_connect_host_port(&ec, hostname, (int)port); send_errno_result(i); } @@ -225,7 +252,7 @@ static void cmd_ei_send_funs(char* buf, int len) fail("expected Fun1"); if (ei_decode_fun(buf, &index, &fun2) < 0) fail("expected Fun2"); - if (ei_decode_bitstring(buf, &index, &bitstring, &bitoffs, &bits) < 0) + if (ei_decode_bitstring(buf, &index, (const char**)&bitstring, &bitoffs, &bits) < 0) fail("expected bitstring"); if (ei_x_new_with_version(&x) < 0) fail("ei_x_new_with_version"); diff --git a/lib/erl_interface/test/ei_connect_SUITE_data/einode.c b/lib/erl_interface/test/ei_connect_SUITE_data/einode.c index bb71575740..083ca1d372 100644 --- a/lib/erl_interface/test/ei_connect_SUITE_data/einode.c +++ b/lib/erl_interface/test/ei_connect_SUITE_data/einode.c @@ -28,20 +28,13 @@ #include <windows.h> #include <process.h> #else -#ifndef VXWORKS #include <pthread.h> -#endif #include <sys/socket.h> #endif #include "ei.h" -#include "erl_interface.h" -#ifdef VXWORKS -#define MAIN cnode -#else #define MAIN main -#endif /* A small einode. @@ -105,32 +98,25 @@ static void* 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); - erl_init(NULL, 0); + ei_init(); 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, @@ -138,14 +124,10 @@ MAIN(int argc, char *argv[]) #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) @@ -154,9 +136,6 @@ MAIN(int argc, char *argv[]) #endif printf("bad wait thread %d\n", i); } -#else - ; -#endif printf("ok\n"); return 0; } diff --git a/lib/erl_interface/test/ei_decode_SUITE.erl b/lib/erl_interface/test/ei_decode_SUITE.erl index e005ec89c7..35feeea42c 100644 --- a/lib/erl_interface/test/ei_decode_SUITE.erl +++ b/lib/erl_interface/test/ei_decode_SUITE.erl @@ -77,29 +77,19 @@ test_ei_decode_ulong(Config) when is_list(Config) -> %% ######################################################################## %% test_ei_decode_longlong(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skip,"Skipped on VxWorks"}; - _ -> - P = runner:start(Config, ?test_ei_decode_longlong), - send_integers2(P), - runner:recv_eot(P), - ok - end. + P = runner:start(Config, ?test_ei_decode_longlong), + send_integers2(P), + runner:recv_eot(P), + ok. %% ######################################################################## %% test_ei_decode_ulonglong(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skip,"Skipped on VxWorks"}; - _ -> - P = runner:start(Config, ?test_ei_decode_ulonglong), - send_integers2(P), - runner:recv_eot(P), - ok - end. + P = runner:start(Config, ?test_ei_decode_ulonglong), + send_integers2(P), + runner:recv_eot(P), + ok. %% ######################################################################## %% @@ -128,13 +118,8 @@ test_ei_decode_nonoptimal(Config) when is_list(Config) -> send_non_optimal_pos(P), % decode_char send_non_optimal(P), % decode_long send_non_optimal_pos(P), % decode_ulong - case os:type() of - vxworks -> - ok; - _ -> - send_non_optimal(P), % decode_longlong - send_non_optimal_pos(P) % decode_ulonglong - end, + send_non_optimal(P), % decode_longlong + send_non_optimal_pos(P), % decode_ulonglong runner:recv_eot(P), ok. diff --git a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c index 46d6b8f2af..b27c3c589c 100644 --- a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c +++ b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c @@ -20,10 +20,6 @@ #include <string.h> -#ifdef VXWORKS -#include "reclaim.h" -#endif - #include "ei_runner.h" /* @@ -31,15 +27,9 @@ * Author: Kent */ -#ifdef VXWORKS -#define MESSAGE_BACK(SIZE) \ - message("err = %d, size2 = %d, expected size = %d", \ - err, size1, SIZE); -#else #define MESSAGE_BACK(SIZE) \ message("err = %d, size2 = %d, expected size = %d, long long val = %lld", \ err, size1, SIZE, (EI_LONGLONG)p); -#endif #define ERLANG_ANY (ERLANG_ASCII|ERLANG_LATIN1|ERLANG_UTF8) @@ -483,7 +473,6 @@ TESTCASE(test_ei_decode_longlong) { ei_init(); -#ifndef VXWORKS EI_DECODE_2 (decode_longlong, 2, EI_LONGLONG, 0); EI_DECODE_2 (decode_longlong, 2, EI_LONGLONG, 255); EI_DECODE_2 (decode_longlong, 5, EI_LONGLONG, 256); @@ -509,7 +498,6 @@ TESTCASE(test_ei_decode_longlong) EI_DECODE_2_FAIL(decode_longlong, 11, EI_LONGLONG, ll(0xffffffffffffffff)); EI_DECODE_2_FAIL(decode_longlong, 1, EI_LONGLONG, 0); /* Illegal type */ -#endif report(1); } @@ -519,7 +507,6 @@ TESTCASE(test_ei_decode_ulonglong) { ei_init(); -#ifndef VXWORKS EI_DECODE_2 (decode_ulonglong, 2, EI_ULONGLONG, 0); EI_DECODE_2 (decode_ulonglong, 2, EI_ULONGLONG, 255); EI_DECODE_2 (decode_ulonglong, 5, EI_ULONGLONG, 256); @@ -545,7 +532,6 @@ TESTCASE(test_ei_decode_ulonglong) EI_DECODE_2 (decode_ulonglong,11, EI_ULONGLONG, ll(0xffffffffffffffff)); EI_DECODE_2_FAIL(decode_ulonglong, 1, EI_ULONGLONG, 0); /* Illegal type */ -#endif report(1); } @@ -637,8 +623,6 @@ TESTCASE(test_ei_decode_nonoptimal) /* ---------------------------------------------------------------- */ -#ifndef VXWORKS - EI_DECODE_2(decode_longlong, 2, EI_LONGLONG, 42); EI_DECODE_2(decode_longlong, 5, EI_LONGLONG, 42); EI_DECODE_2(decode_longlong, 4, EI_LONGLONG, 42); @@ -681,8 +665,6 @@ TESTCASE(test_ei_decode_nonoptimal) /* EI_DECODE_2(decode_ulonglong, EI_ULONGLONG, -42); */ /* EI_DECODE_2(decode_ulonglong, EI_ULONGLONG, -42); */ -#endif /* !VXWORKS */ - /* ---------------------------------------------------------------- */ report(1); diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c index 512f9ed0c7..5594bec757 100644 --- a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c +++ b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c @@ -18,10 +18,6 @@ * %CopyrightEnd% */ -#ifdef VXWORKS -#include "reclaim.h" -#endif - #include "ei_runner.h" /* diff --git a/lib/erl_interface/test/ei_encode_SUITE.erl b/lib/erl_interface/test/ei_encode_SUITE.erl index 0267a5126f..10fcd6b871 100644 --- a/lib/erl_interface/test/ei_encode_SUITE.erl +++ b/lib/erl_interface/test/ei_encode_SUITE.erl @@ -101,59 +101,49 @@ test_ei_encode_ulong(Config) when is_list(Config) -> %% ######################################################################## %% test_ei_encode_longlong(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skip,"Skipped on VxWorks"}; - _ -> - P = runner:start(Config, ?test_ei_encode_longlong), - - {<<97,0>> ,0} = get_buf_and_term(P), - {<<97,255>> ,255} = get_buf_and_term(P), - {<<98,256:32/big-signed-integer>>,256} = get_buf_and_term(P), - {<<98,-1:32/big-signed-integer>> ,-1} = get_buf_and_term(P), - - {<<98, 16#07ffffff:32/big-signed-integer>>, 16#07ffffff} = get_buf_and_term(P), - {<<98,-16#08000000:32/big-signed-integer>>,-16#08000000} = get_buf_and_term(P), - {<<110,4,0, 0,0,0,8>> , 16#08000000} = get_buf_and_term(P), - {<<110,4,1, 1,0,0,8>> ,-16#08000001} = get_buf_and_term(P), - - {<<110,4,0, 255,255,255,127>> , 16#7fffffff} = get_buf_and_term(P), - {<<110,4,1, 0,0,0,128>> ,-16#80000000} = get_buf_and_term(P), - {<<110,6,0, 255,255,255,255,255,127>> , 16#7fffffffffff} = get_buf_and_term(P), - {<<110,6,1, 0,0,0,0,0,128>> ,-16#800000000000} = get_buf_and_term(P), - {<<110,8,0, 255,255,255,255,255,255,255,127>>,16#7fffffffffffffff} = get_buf_and_term(P), - {<<110,8,1, 0,0,0,0,0,0,0,128>> ,-16#8000000000000000} = get_buf_and_term(P), - - runner:recv_eot(P), - ok - end. + P = runner:start(Config, ?test_ei_encode_longlong), + + {<<97,0>> ,0} = get_buf_and_term(P), + {<<97,255>> ,255} = get_buf_and_term(P), + {<<98,256:32/big-signed-integer>>,256} = get_buf_and_term(P), + {<<98,-1:32/big-signed-integer>> ,-1} = get_buf_and_term(P), + + {<<98, 16#07ffffff:32/big-signed-integer>>, 16#07ffffff} = get_buf_and_term(P), + {<<98,-16#08000000:32/big-signed-integer>>,-16#08000000} = get_buf_and_term(P), + {<<110,4,0, 0,0,0,8>> , 16#08000000} = get_buf_and_term(P), + {<<110,4,1, 1,0,0,8>> ,-16#08000001} = get_buf_and_term(P), + + {<<110,4,0, 255,255,255,127>> , 16#7fffffff} = get_buf_and_term(P), + {<<110,4,1, 0,0,0,128>> ,-16#80000000} = get_buf_and_term(P), + {<<110,6,0, 255,255,255,255,255,127>> , 16#7fffffffffff} = get_buf_and_term(P), + {<<110,6,1, 0,0,0,0,0,128>> ,-16#800000000000} = get_buf_and_term(P), + {<<110,8,0, 255,255,255,255,255,255,255,127>>,16#7fffffffffffffff} = get_buf_and_term(P), + {<<110,8,1, 0,0,0,0,0,0,0,128>> ,-16#8000000000000000} = get_buf_and_term(P), + + runner:recv_eot(P), + ok. %% ######################################################################## %% test_ei_encode_ulonglong(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skip,"Skipped on VxWorks"}; - _ -> - P = runner:start(Config, ?test_ei_encode_ulonglong), - - {<<97,0>> ,0} = get_buf_and_term(P), - {<<97,255>> ,255} = get_buf_and_term(P), - {<<98,256:32/big-unsigned-integer>>,256} = get_buf_and_term(P), - - {<<98, 16#07ffffff:32/big-signed-integer>>,16#07ffffff} = get_buf_and_term(P), - {<<110,4,0, 0,0,0,8>> ,16#08000000} = get_buf_and_term(P), - - {<<110,4,0, 255,255,255,127>> ,16#7fffffff} = get_buf_and_term(P), - {<<110,4,0, 0,0,0,128>> ,16#80000000} = get_buf_and_term(P), - {<<110,4,0, 255,255,255,255>> ,16#ffffffff} = get_buf_and_term(P), - {<<110,6,0, 255,255,255,255,255,255>>,16#ffffffffffff} = get_buf_and_term(P), - {<<110,8,0, 255,255,255,255,255,255,255,255>>,16#ffffffffffffffff} = get_buf_and_term(P), + P = runner:start(Config, ?test_ei_encode_ulonglong), - runner:recv_eot(P), - ok - end. + {<<97,0>> ,0} = get_buf_and_term(P), + {<<97,255>> ,255} = get_buf_and_term(P), + {<<98,256:32/big-unsigned-integer>>,256} = get_buf_and_term(P), + + {<<98, 16#07ffffff:32/big-signed-integer>>,16#07ffffff} = get_buf_and_term(P), + {<<110,4,0, 0,0,0,8>> ,16#08000000} = get_buf_and_term(P), + + {<<110,4,0, 255,255,255,127>> ,16#7fffffff} = get_buf_and_term(P), + {<<110,4,0, 0,0,0,128>> ,16#80000000} = get_buf_and_term(P), + {<<110,4,0, 255,255,255,255>> ,16#ffffffff} = get_buf_and_term(P), + {<<110,6,0, 255,255,255,255,255,255>>,16#ffffffffffff} = get_buf_and_term(P), + {<<110,8,0, 255,255,255,255,255,255,255,255>>,16#ffffffffffffffff} = get_buf_and_term(P), + + runner:recv_eot(P), + ok. %% ######################################################################## %% diff --git a/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c b/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c index 6f63cc5d7e..6f1276e016 100644 --- a/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c +++ b/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c @@ -18,10 +18,6 @@ * %CopyrightEnd% */ -#ifdef VXWORKS -#include "reclaim.h" -#endif - #include "ei_runner.h" /* @@ -460,8 +456,6 @@ TESTCASE(test_ei_encode_longlong) { ei_init(); -#ifndef VXWORKS - EI_ENCODE_1(encode_longlong, 0); EI_ENCODE_1(encode_longlong, 255); @@ -490,8 +484,6 @@ TESTCASE(test_ei_encode_longlong) EI_ENCODE_1(encode_longlong, -ll(0x8000000000000000)); -#endif /* !VXWORKS */ - report(1); } @@ -501,8 +493,6 @@ TESTCASE(test_ei_encode_ulonglong) { ei_init(); -#ifndef VXWORKS - EI_ENCODE_1(encode_ulonglong, 0); EI_ENCODE_1(encode_ulonglong, 255); @@ -523,8 +513,6 @@ TESTCASE(test_ei_encode_ulonglong) EI_ENCODE_1(encode_ulonglong, ll(0xffffffffffffffff)); -#endif /* !VXWORKS */ - report(1); } diff --git a/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c b/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c index 1c0443c0f4..19d2cc1510 100644 --- a/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c +++ b/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c @@ -18,10 +18,6 @@ * %CopyrightEnd% */ -#ifdef VXWORKS -#include "reclaim.h" -#endif - #include "ei_runner.h" #include <string.h> diff --git a/lib/erl_interface/test/erl_global_SUITE.erl b/lib/erl_interface/test/ei_global_SUITE.erl index 6d3a75c8d7..da80ab24cd 100644 --- a/lib/erl_interface/test/erl_global_SUITE.erl +++ b/lib/erl_interface/test/ei_global_SUITE.erl @@ -19,22 +19,27 @@ %% %% --module(erl_global_SUITE). +-module(ei_global_SUITE). -include_lib("common_test/include/ct.hrl"). --include("erl_global_SUITE_data/erl_global_test_cases.hrl"). +-include("ei_global_SUITE_data/ei_global_test_cases.hrl"). -export([all/0,suite/0, init_per_testcase/2, - erl_global_registration/1, - erl_global_whereis/1, erl_global_names/1]). + ei_global_registration/1, + ei_global_whereis/1, + ei_global_names/1 + ]). -import(runner, [get_term/1,send_term/2]). -define(GLOBAL_NAME, global_register_node_test). all() -> - [erl_global_registration, erl_global_whereis, erl_global_names]. + [ei_global_registration, ei_global_whereis, ei_global_names]. + +get_group(Config) -> + proplists:get_value(name, proplists:get_value(tc_group_properties,Config)). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -43,82 +48,76 @@ suite() -> init_per_testcase(Case, Config) -> runner:init_per_testcase(?MODULE, Case, Config). -erl_global_registration(Config) when is_list(Config) -> +ei_global_registration(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - {ok, Fd} = erl_connect(P, node(), 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, ussi), + {ok,Fd} = ei_connect(P, node()), - ok = erl_global_register(P, Fd, ?GLOBAL_NAME), - ok = erl_global_unregister(P, Fd, ?GLOBAL_NAME), + ok = ei_global_register(P, Fd, ?GLOBAL_NAME), + ok = ei_global_unregister(P, Fd, ?GLOBAL_NAME), - 0 = erl_close_connection(P,Fd), runner:send_eot(P), runner:recv_eot(P), ok. -erl_global_whereis(Config) when is_list(Config) -> +ei_global_whereis(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - {ok, Fd} = erl_connect(P, node(), 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, ussi), + {ok,Fd} = ei_connect(P, node()), Self = self(), yes = global:register_name(?GLOBAL_NAME, Self), - Self = erl_global_whereis(P, Fd, ?GLOBAL_NAME), + Self = ei_global_whereis(P, Fd, ?GLOBAL_NAME), global:unregister_name(?GLOBAL_NAME), - 0 = erl_close_connection(P, Fd), runner:send_eot(P), runner:recv_eot(P), ok. -erl_global_names(Config) when is_list(Config) -> +ei_global_names(Config) when is_list(Config) -> P = runner:start(Config, ?interpret), - {ok, Fd} = erl_connect(P, node(), 42, erlang:get_cookie(), 0), + 0 = ei_connect_init(P, 42, erlang:get_cookie(), 0, ussi), + {ok,Fd} = ei_connect(P, node()), Self = self(), global:register_name(?GLOBAL_NAME, Self), - {Names1, _N1} = erl_global_names(P, Fd), + {Names1, _N1} = ei_global_names(P, Fd), true = lists:member(atom_to_list(?GLOBAL_NAME), Names1), global:unregister_name(?GLOBAL_NAME), - {Names2, _N2} = erl_global_names(P, Fd), + {Names2, _N2} = ei_global_names(P, Fd), false = lists:member(atom_to_list(?GLOBAL_NAME), Names2), - 0 = erl_close_connection(P, Fd), runner:send_eot(P), runner:recv_eot(P), ok. -%%% Interface functions for erl_interface functions. - -erl_connect(P, Node, Num, Cookie, Creation) -> - send_command(P, erl_connect, [Num, Node, Cookie, Creation]), - case get_term(P) of - {term,{Fd,_}} when Fd >= 0 -> {ok,Fd}; - {term,{-1,Errno}} -> {error,Errno} - end. +%% %%% Interface functions for erl_interface functions. -erl_close_connection(P, FD) -> - send_command(P, erl_close_connection, [FD]), - case get_term(P) of - {term,Int} when is_integer(Int) -> Int - end. +%% erl_connect(P, Node, Num, Cookie, Creation) -> +%% send_command(P, erl_connect, [Num, Node, Cookie, Creation]), +%% case get_term(P) of +%% {term,{Fd,_}} when Fd >= 0 -> {ok,Fd}; +%% {term,{-1,Errno}} -> {error,Errno} +%% end. -erl_global_register(P, Fd, Name) -> - send_command(P, erl_global_register, [Fd,Name]), +ei_global_register(P, Fd, Name) -> + send_command(P, ei_global_register, [Fd,Name]), get_send_result(P). -erl_global_whereis(P, Fd, Name) -> - send_command(P, erl_global_whereis, [Fd,Name]), +ei_global_whereis(P, Fd, Name) -> + send_command(P, ei_global_whereis, [Fd,Name]), case get_term(P) of {term, What} -> What end. -erl_global_names(P, Fd) -> - send_command(P, erl_global_names, [Fd]), +ei_global_names(P, Fd) -> + send_command(P, ei_global_names, [Fd]), case get_term(P) of {term, What} -> What end. -erl_global_unregister(P, Fd, Name) -> - send_command(P, erl_global_unregister, [Fd,Name]), +ei_global_unregister(P, Fd, Name) -> + send_command(P, ei_global_unregister, [Fd,Name]), get_send_result(P). get_send_result(P) -> @@ -132,3 +131,17 @@ get_send_result(P) -> send_command(P, Name, Args) -> runner:send_term(P, {Name,list_to_tuple(Args)}). + + +ei_connect_init(P, Num, Cookie, Creation, SockImpl) -> + send_command(P, ei_connect_init, [Num,Cookie,Creation,SockImpl]), + case get_term(P) of + {term,Int} when is_integer(Int) -> Int + end. + +ei_connect(P, Node) -> + send_command(P, ei_connect, [Node]), + case get_term(P) of + {term,{Fd,_}} when Fd >= 0 -> {ok,Fd}; + {term,{-1,Errno}} -> {error,Errno} + end. diff --git a/lib/erl_interface/test/erl_global_SUITE_data/Makefile.first b/lib/erl_interface/test/ei_global_SUITE_data/Makefile.first index b2c62be1f2..5ec0c06af8 100644 --- a/lib/erl_interface/test/erl_global_SUITE_data/Makefile.first +++ b/lib/erl_interface/test/ei_global_SUITE_data/Makefile.first @@ -18,5 +18,5 @@ # %CopyrightEnd% # -erl_global_test_decl.c: erl_global_test.c - erl -noinput -pa ../all_SUITE_data -s init_tc run erl_global_test -s erlang halt +erl_global_test_decl.c: ei_global_test.c + erl -noinput -pa ../all_SUITE_data -s init_tc run ei_global_test -s erlang halt diff --git a/lib/erl_interface/test/erl_global_SUITE_data/Makefile.src b/lib/erl_interface/test/ei_global_SUITE_data/Makefile.src index 1c1530d1b6..43c9095ab4 100644 --- a/lib/erl_interface/test/erl_global_SUITE_data/Makefile.src +++ b/lib/erl_interface/test/ei_global_SUITE_data/Makefile.src @@ -25,17 +25,18 @@ CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" LD = @LD@ LIBERL = @erl_interface_lib@ LIBEI = @erl_interface_eilib@ -LIBFLAGS = ../all_SUITE_data/runner@obj@ \ - $(LIBERL) $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ +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 -OBJS = erl_global_test@obj@ erl_global_test_decl@obj@ +EI_GLOBAL_OBJS = ei_global_test@obj@ ei_global_test_decl@obj@ -all: erl_global_test@exe@ - -erl_global_test@exe@: $(OBJS) $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(OBJS) $(LIBFLAGS) +all: ei_global_test@exe@ clean: - $(RM) $(OBJS) - $(RM) erl_global_test@exe@ + $(RM) $(EI_GLOBAL_OBJS) + $(RM) ei_global_test@exe@ + +ei_global_test@exe@: $(EI_GLOBAL_OBJS) $(LIBEI) + $(LD) @CROSSLDFLAGS@ -o $@ $(EI_GLOBAL_OBJS) \ + ../all_SUITE_data/my_ussi@obj@ $(LIBFLAGS) diff --git a/lib/erl_interface/test/ei_global_SUITE_data/ei_global_test.c b/lib/erl_interface/test/ei_global_SUITE_data/ei_global_test.c new file mode 100644 index 0000000000..4c018667fe --- /dev/null +++ b/lib/erl_interface/test/ei_global_SUITE_data/ei_global_test.c @@ -0,0 +1,239 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2000-2016. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * %CopyrightEnd% + */ + +/* + * Purpose: Tests the functions in erl_global.c. + * + * See the ei_global_SUITE.erl file for a "table of contents". + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "ei_runner.h" +#include "my_ussi.h" +#include "ei_connect.h" + +static void cmd_ei_connect_init(char* buf, int len); +static void cmd_ei_connect(char* buf, int len); +static void cmd_ei_global_register(char* buf, int len); +static void cmd_ei_global_whereis(char* buf, int len); +static void cmd_ei_global_names(char* buf, int len); +static void cmd_ei_global_unregister(char* buf, int len); +static void cmd_ei_close_connection(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", 4, cmd_ei_connect_init, + "ei_connect", 1, cmd_ei_connect, + "ei_global_register", 2, cmd_ei_global_register, + "ei_global_whereis", 2, cmd_ei_global_whereis, + "ei_global_names", 1, cmd_ei_global_names, + "ei_global_unregister", 2, cmd_ei_global_unregister +}; + + +/* + * Sends a list contaning all data types to the Erlang side. + */ + +TESTCASE(interpret) +{ + ei_x_buff x; + int i; + ei_term term; + + ei_init(); + + ei_x_new(&x); + while (get_bin_term(&x, &term) == 0) { + 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"); + } + } + report(1); + ei_x_free(&x); + return; +} + +static void cmd_ei_connect_init(char* buf, int len) +{ + int index = 0, r = 0; + long l, creation; + char b[100]; + char cookie[MAXATOMLEN], * cp = cookie; + char socket_impl[10]; + int use_ussi; + ei_x_buff res; + if (ei_decode_long(buf, &index, &l) < 0) + fail("expected int"); + sprintf(b, "c%ld", l); + if (ei_decode_atom(buf, &index, cookie) < 0) + fail("expected atom (cookie)"); + if (cookie[0] == '\0') + cp = NULL; + if (ei_decode_long(buf, &index, &creation) < 0) + fail("expected int (creation)"); + if (ei_decode_atom_as(buf, &index, socket_impl, + sizeof(socket_impl), ERLANG_ASCII, NULL, NULL) < 0) + fail("expected atom (socket_impl)"); + if (strcmp(socket_impl, "default") == 0) + use_ussi = 0; + else if (strcmp(socket_impl, "ussi") == 0) + use_ussi = 1; + else + fail1("expected atom 'default' or 'ussi', got '%s'", socket_impl); + + if (use_ussi) + r = ei_connect_init_ussi(&ec, b, cp, (short)creation, + &my_ussi, sizeof(my_ussi), NULL); + else + r = ei_connect_init(&ec, b, cp, (short)creation); + 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); + send_errno_result(i); +} + +static void +cmd_ei_global_register(char* buf, int len) +{ + int index = 0; + long fd; + char name[256]; + if (ei_decode_long(buf, &index, &fd) < 0) + fail("expected long"); + if (ei_decode_atom(buf, &index, name) < 0) + fail("expected atom"); + send_errno_result(ei_global_register((int)fd, name, ei_self(&ec))); +} + +static void +cmd_ei_global_whereis(char* buf, int len) +{ + int index = 0; + long fd; + char name[512]; + char node_name[512]; + erlang_pid pid; + if (ei_decode_long(buf, &index, &fd) < 0) + fail("expected long"); + if (ei_decode_atom(buf, &index, name) < 0) + fail("expected atom"); + + if (ei_global_whereis(&ec, fd, name, &pid, node_name) < 0) + fail("ei_global_whereis error code"); + + { + ei_x_buff x; + ei_x_new_with_version(&x); + ei_x_encode_pid(&x, &pid); + send_bin_term(&x); + ei_x_free(&x); + } +} + +static void +cmd_ei_global_names(char* buf, int len) +{ + int index = 0; + long fd; + char** names = NULL; + int count = 0, i; + if (ei_decode_long(buf, &index, &fd) < 0) + fail("expected long"); + + names = ei_global_names(&ec, (int)fd, &count); + + { + ei_x_buff x; + ei_x_new_with_version(&x); + ei_x_encode_tuple_header(&x, 2); + ei_x_encode_list_header(&x, count); + for(i=0; i<count; i++) { + ei_x_encode_string(&x, names[i]); + } + ei_x_encode_empty_list(&x); + ei_x_encode_long(&x, count); + send_bin_term(&x); + ei_x_free(&x); + } +} + +static void +cmd_ei_global_unregister(char* buf, int len) +{ + int index = 0; + long fd; + char name[256]; + if (ei_decode_long(buf, &index, &fd) < 0) + fail("expected long"); + if (ei_decode_atom(buf, &index, name) < 0) + fail("expected atom"); + + send_errno_result(ei_global_unregister(&ec, (int)fd, name)); +} + +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_print_SUITE_data/ei_print_test.c b/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c index 27d4153250..2d332c8b0c 100644 --- a/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c +++ b/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c @@ -37,13 +37,9 @@ send_printed_buf(ei_x_buff* x) FILE* f; int n, index = 0, ver; -#ifdef VXWORKS - tmp = "."; -#else if (tmp == NULL) { tmp = "/tmp"; } -#endif strcpy(fn, tmp); strcat(fn, "/ei_print_test.txt"); f = fopen(fn, "w+"); diff --git a/lib/erl_interface/test/ei_tmo_SUITE.erl b/lib/erl_interface/test/ei_tmo_SUITE.erl index 5b9de80128..8d8776949c 100644 --- a/lib/erl_interface/test/ei_tmo_SUITE.erl +++ b/lib/erl_interface/test/ei_tmo_SUITE.erl @@ -25,10 +25,12 @@ -include_lib("kernel/include/inet.hrl"). -include("ei_tmo_SUITE_data/ei_tmo_test_cases.hrl"). --export([all/0, suite/0, +-export([all/0, groups/0, suite/0, init_per_testcase/2, end_per_testcase/2, - framework_check/1, ei_accept_tmo/1, ei_connect_tmo/1, ei_send_tmo/1, - ei_connect_tmo/0, + framework_check/1, ei_accept_tmo/1, ei_connect_tmo/1, + ei_send_tmo/1, + ei_send_failure_tmo/1, + ei_connect_unreachable_tmo/0, ei_connect_unreachable_tmo/1, ei_recv_tmo/1]). suite() -> @@ -36,19 +38,25 @@ suite() -> {timetrap, {minutes, 1}}]. all() -> - [framework_check, ei_accept_tmo, ei_connect_tmo, - ei_send_tmo, ei_recv_tmo]. + [framework_check, + ei_connect_unreachable_tmo, + ei_send_failure_tmo, + {group, default}, + {group, ussi}]. + +groups() -> + Members = [ei_recv_tmo, + ei_accept_tmo, + ei_connect_tmo, + ei_send_tmo], + [{default, [], Members}, + {ussi, [], Members}]. + +get_group(Config) -> + proplists:get_value(name, proplists:get_value(tc_group_properties,Config)). init_per_testcase(Case, Config) -> - Config1 = runner:init_per_testcase(?MODULE, Case, Config), - - % test if platform is vxworks_simso - {_,Host} = split(node()), - Bool = case atom_to_list(Host) of - [$v,$x,$s,$i,$m | _] -> true; - _ -> false - end, - [{vxsim,Bool} | Config1]. + runner:init_per_testcase(?MODULE, Case, Config). end_per_testcase(_Case, _Config) -> ok. @@ -76,7 +84,8 @@ do_one_recv(Config,CNode) -> P1 = runner:start(Config, ?recv_tmo), runner:send_term(P1,{CNode, erlang:get_cookie(), - node()}), + node(), + get_group(Config)}), {term, X} = runner:get_term(P1, 10000), true = is_integer(X), CNode1 = join(CNode,Host), @@ -89,24 +98,22 @@ do_one_recv_failure(Config,CNode) -> P1 = runner:start(Config, ?recv_tmo), runner:send_term(P1,{CNode, erlang:get_cookie(), - node()}), + node(), + get_group(Config)}), {term, X} = runner:get_term(P1, 10000), true = is_integer(X), {term, {Ret,ETimedout,ETimedout}} = runner:get_term(P1, 10000), true = (Ret < 0), runner:recv_eot(P1). +-define(EI_DIST_LOW, 5). +-define(EI_DIST_HIGH, 6). %% Check send with timeouts. ei_send_tmo(Config) when is_list(Config) -> - %dbg:tracer(), - %dbg:p(self()), - VxSim = proplists:get_value(vxsim, Config), register(ei_send_tmo_1,self()), do_one_send(Config,self(),c_node_send_tmo_1), do_one_send(Config,ei_send_tmo_1,c_node_send_tmo_2), - do_one_send_failure(Config,self(),cccc1,c_nod_send_tmo_3,VxSim), - do_one_send_failure(Config,ei_send_tmo_1,cccc2,c_nod_send_tmo_4,VxSim), ok. @@ -115,7 +122,8 @@ do_one_send(Config,From,CNode) -> P1 = runner:start(Config, ?send_tmo), runner:send_term(P1,{CNode, erlang:get_cookie(), - node()}), + node(), + get_group(Config)}), {term, X} = runner:get_term(P1, 10000), true = is_integer(X), CNode1 = join(CNode,Host), @@ -130,7 +138,17 @@ do_one_send(Config,From,CNode) -> {term, 0} = runner:get_term(P1, 10000), runner:recv_eot(P1). -do_one_send_failure(Config,From,FakeName,CName,VxSim) -> +ei_send_failure_tmo(Config) when is_list(Config) -> + register(ei_send_tmo_1,self()), + [begin + io:format("Test dist version ~p\n", [Ver]), + do_one_send_failure(Config,self(),cccc1,c_nod_send_tmo_3, Ver), + do_one_send_failure(Config,ei_send_tmo_1,cccc2,c_nod_send_tmo_4, Ver) + end + || Ver <- lists:seq(?EI_DIST_LOW, ?EI_DIST_HIGH)], + ok. + +do_one_send_failure(Config,From,FakeName,CName, OurVer) -> {_,Host} = split(node()), OurName = join(FakeName,Host), Node = join(CName,Host), @@ -140,22 +158,23 @@ do_one_send_failure(Config,From,FakeName,CName,VxSim) -> Else -> exit(Else) end, - EpmdSocket = register(OurName, LSocket, 1, 5), + EpmdSocket = epmd_register(OurName, LSocket, OurVer), P3 = runner:start(Config, ?send_tmo), Cookie = kaksmula_som_ingen_bryr_sig_om, runner:send_term(P3,{CName, Cookie, - OurName}), + OurName, + default}), SocketB = case gen_tcp:accept(LSocket) of {ok, Socket1} -> Socket1; Else2 -> exit(Else2) end, - {hidden,Node,5} = recv_name(SocketB), % See 1) + {hidden,Node} = recv_name(SocketB, OurVer), % See 1) send_status(SocketB, ok), MyChallengeB = gen_challenge(), - send_challenge(SocketB, OurName, MyChallengeB, 5), + send_challenge(SocketB, OurName, MyChallengeB, OurVer), HisChallengeB = recv_challenge_reply(SocketB, MyChallengeB, Cookie), @@ -178,53 +197,43 @@ do_one_send_failure(Config,From,FakeName,CName,VxSim) -> %% must be large enough so there's time for the select() to time out and %% the test program to return the error tuple (below). - Res0 = if VxSim == false -> - {term,{Res,ETO,Iters,ETO}} = runner:get_term(P3, 20000), - Res; - true -> % relax the test for vxsim - case runner:get_term(P3, 20000) of - {term,{Res,ETO,Iters,ETO}} -> - Res; - {term,{Res,_,Iters,_ETO}} -> % EIO? - Res - end - end, + {term,{Res,ETO,Iters,ETO}} = runner:get_term(P3, 20000), runner:recv_eot(P3), - true = ((Res0 < 0) and (Iters > 0)), + true = ((Res < 0) and (Iters > 0)), gen_tcp:close(SocketB), gen_tcp:close(EpmdSocket), ok. %% Check accept with timeouts. -ei_connect_tmo() -> [{require, test_host_not_reachable}]. +ei_connect_unreachable_tmo() -> [{require, test_host_not_reachable}]. -ei_connect_tmo(Config) when is_list(Config) -> - %dbg:tracer(), - %dbg:p(self()), - VxSim = proplists:get_value(vxsim, Config), +ei_connect_unreachable_tmo(Config) when is_list(Config) -> DummyNode = make_and_check_dummy(), P = runner:start(Config, ?connect_tmo), runner:send_term(P,{c_nod_connect_tmo_1, kaksmula_som_ingen_bryr_sig_om, - DummyNode}), - ETimedout = - if VxSim == false -> - {term,{-3,ETO,ETO}} = runner:get_term(P, 10000), - ETO; - true -> % relax the test for vxsim - case runner:get_term(P, 10000) of - {term,{-3,ETO,ETO}} -> - ETO; - {term,{-1,_,ETO}} -> % EHOSTUNREACH = ok - ETO - end - end, + DummyNode, + default}), + {term,{-3,ETimedout,ETimedout}} = runner:get_term(P, 10000), runner:recv_eot(P), + ok. + +ei_connect_tmo(Config) when is_list(Config) -> + [begin + io:format("Test dist version ~p published as ~p\n", [OurVer,OurEpmdVer]), + do_ei_connect_tmo(Config, OurVer, OurEpmdVer) + end + || OurVer <- lists:seq(?EI_DIST_LOW, ?EI_DIST_HIGH), + OurEpmdVer <- lists:seq(?EI_DIST_LOW, ?EI_DIST_HIGH), + OurVer >= OurEpmdVer]. + +do_ei_connect_tmo(Config, OurVer, OurEpmdVer) -> P2 = runner:start(Config, ?connect_tmo), runner:send_term(P2,{c_nod_connect_tmo_2, erlang:get_cookie(), - node()}), + node(), + get_group(Config)}), {term, X} = runner:get_term(P2, 10000), runner:recv_eot(P2), true = is_integer(X), @@ -238,22 +247,24 @@ ei_connect_tmo(Config) when is_list(Config) -> Else -> exit(Else) end, - EpmdSocket = register(OurName, LSocket, 1, 5), + EpmdSocket = epmd_register(OurName, LSocket, OurEpmdVer), P3 = runner:start(Config, ?connect_tmo), Cookie = kaksmula_som_ingen_bryr_sig_om, runner:send_term(P3,{c_nod_connect_tmo_3, Cookie, - OurName}), + OurName, + get_group(Config)}), SocketB = case gen_tcp:accept(LSocket) of {ok, Socket1} -> Socket1; Else2 -> exit(Else2) end, - {hidden,Node,5} = recv_name(SocketB), % See 1) + {hidden,Node} = recv_name(SocketB, OurEpmdVer), % See 1) send_status(SocketB, ok), MyChallengeB = gen_challenge(), - send_challenge(SocketB, OurName, MyChallengeB, 5), + send_challenge(SocketB, OurName, MyChallengeB, OurVer), + recv_complement(SocketB, OurVer, OurEpmdVer), _HisChallengeB = recv_challenge_reply(SocketB, MyChallengeB, Cookie), @@ -266,16 +277,27 @@ ei_connect_tmo(Config) when is_list(Config) -> %% Check accept with timeouts. ei_accept_tmo(Config) when is_list(Config) -> - %%dbg:tracer(), - %%dbg:p(self()), + [begin + io:format("Test our dist ver=~p and assumed ver=~p\n", + [OurVer, AssumedVer]), + do_ei_accept_tmo(Config, OurVer, AssumedVer) + end + || OurVer <- lists:seq(?EI_DIST_LOW, ?EI_DIST_HIGH), + AssumedVer <- lists:seq(?EI_DIST_LOW, ?EI_DIST_HIGH), + OurVer >= AssumedVer], + ok. + +do_ei_accept_tmo(Config, OurVer, AssumedVer) -> P = runner:start(Config, ?accept_tmo), runner:send_term(P,{c_nod_som_ingen_kontaktar_1, - kaksmula_som_ingen_bryr_sig_om}), + kaksmula_som_ingen_bryr_sig_om, + get_group(Config)}), {term,{-1,ETimedout,ETimedout}} = runner:get_term(P, 10000), runner:recv_eot(P), P2 = runner:start(Config, ?accept_tmo), runner:send_term(P2,{c_nod_som_vi_kontaktar_1, - erlang:get_cookie()}), + erlang:get_cookie(), + get_group(Config)}), receive after 1000 -> ok end, CNode1 = make_node(c_nod_som_vi_kontaktar_1), {ignored,CNode1} ! tjenare, @@ -284,19 +306,20 @@ ei_accept_tmo(Config) when is_list(Config) -> true = is_integer(X), P3 = runner:start(Config, ?accept_tmo), runner:send_term(P3,{c_nod_som_vi_kontaktar_2, - erlang:get_cookie()}), + erlang:get_cookie(), + get_group(Config)}), receive after 1000 -> ok end, CNode2 = make_node(c_nod_som_vi_kontaktar_2), {NA,NB} = split(CNode2), {_,Host} = split(node()), OurName = join(ccc,Host), - {port,PortNo,_} = erl_epmd:port_please(NA,NB), + {port,PortNo,?EI_DIST_HIGH} = erl_epmd:port_please(NA,NB), {ok, SocketA} = gen_tcp:connect(atom_to_list(NB),PortNo, [{active,false}, {packet,2}]), - send_name(SocketA,OurName,5), + send_name(SocketA,OurName,OurVer,AssumedVer), ok = recv_status(SocketA), - {hidden,_Node,5,HisChallengeA} = recv_challenge(SocketA), % See 1) + {hidden,_Node,HisChallengeA} = recv_challenge(SocketA,OurVer), % See 1) _OurChallengeA = gen_challenge(), _OurDigestA = gen_digest(HisChallengeA, erlang:get_cookie()), %% Dont do the last two steps of the connection setup... @@ -342,6 +365,7 @@ make_and_check_dummy() -> -define(DFLAG_EXTENDED_PIDS_PORTS,16#100). -define(DFLAG_NEW_FLOATS,16#800). -define(DFLAG_DIST_MONITOR,8). +-define(DFLAG_HANDSHAKE_23,16#1000000). %% From R9 and forward extended references is compulsory %% From 14 and forward new float is compulsory @@ -405,31 +429,61 @@ recv_status(Socket) -> exit(Bad) end. -send_challenge(Socket, Node, Challenge, Version) -> - send_challenge(Socket, Node, Challenge, Version, ?COMPULSORY_DFLAGS). -send_challenge(Socket, Node, Challenge, Version, Flags) -> - {ok, {{_Ip1,_Ip2,_Ip3,_Ip4}, _}} = inet:sockname(Socket), - ?to_port(Socket, [$n,?int16(Version),?int32(Flags), - ?int32(Challenge), atom_to_list(Node)]). - -recv_challenge(Socket) -> +send_challenge(Socket, Node, Challenge, OurVer) -> + send_challenge(Socket, Node, Challenge, OurVer, ?COMPULSORY_DFLAGS). + +send_challenge(Socket, Node, Challenge, OurVer, Flags) -> + if OurVer =:= 5 -> + ?to_port(Socket, [$n, ?int16(OurVer), ?int32(Flags), + ?int32(Challenge), atom_to_list(Node)]); + OurVer >= 6 -> + NodeName = atom_to_binary(Node, latin1), + NameLen = byte_size(NodeName), + Creation = erts_internal:get_creation(), + ?to_port(Socket, [$N, + <<(Flags bor ?DFLAG_HANDSHAKE_23):64, + Challenge:32, + Creation:32, + NameLen:16>>, + NodeName]) + end. + +recv_challenge(Socket, OurVer) -> case gen_tcp:recv(Socket, 0) of {ok,[$n,V1,V0,Fl1,Fl2,Fl3,Fl4,CA3,CA2,CA1,CA0 | Ns]} -> + 5 = OurVer, Flags = ?u32(Fl1,Fl2,Fl3,Fl4), - Type = case Flags band ?DFLAG_PUBLISHED of - 0 -> - hidden; - _ -> - normal - end, + Type = flags_to_type(Flags), Node =list_to_atom(Ns), - Version = ?u16(V1,V0), + OurVer = ?u16(V1,V0), % echoed back + Challenge = ?u32(CA3,CA2,CA1,CA0), + {Type,Node,Challenge}; + + {ok,[$N, F7,F6,F5,F4,F3,F2,F1,F0, CA3,CA2,CA1,CA0, + _Cr3,_Cr2,_Cr1,_Cr0, NL1,NL0 | Rest]} -> + true = (OurVer >= 6), + <<Flags:64>> = <<F7,F6,F5,F4,F3,F2,F1,F0>>, + Type = flags_to_type(Flags), + NameLen = ?u16(NL1,NL0), + {NodeName,_} = lists:split(NameLen, Rest), + Node = list_to_atom(NodeName), Challenge = ?u32(CA3,CA2,CA1,CA0), - {Type,Node,Version,Challenge}; + %%Creation = ?u32(Cr3,Cr2,Cr1,Cr0), + %%true = (Creation =/= 0), + {Type,Node,Challenge}; + _ -> ?shutdown(no_node) end. +flags_to_type(Flags) -> + case Flags band ?DFLAG_PUBLISHED of + 0 -> + hidden; + _ -> + normal + end. + %send_challenge_reply(Socket, Challenge, Digest) -> % ?to_port(Socket, [$r,?int32(Challenge),Digest]). @@ -443,8 +497,8 @@ recv_challenge_reply(Socket, ChallengeA, Cookie) -> true -> ?shutdown(bad_challenge_reply) end; - _ -> - ?shutdown(no_node) + Other -> + ?shutdown({recv_challenge_reply,Other}) end. send_challenge_ack(Socket, Digest) -> @@ -463,37 +517,53 @@ send_challenge_ack(Socket, Digest) -> % ?shutdown(bad_challenge_ack) % end. -send_name(Socket, MyNode0, Version) -> - send_name(Socket, MyNode0, Version, ?COMPULSORY_DFLAGS). -send_name(Socket, MyNode0, Version, Flags) -> - MyNode = atom_to_list(MyNode0), - ?to_port(Socket, [$n,?int16(Version),?int32(Flags)] ++ - MyNode). +send_name(Socket, MyNode, OurVer, AssumedVer) -> + Flags = ?COMPULSORY_DFLAGS bor (case OurVer of + 5 -> 0; + 6 -> ?DFLAG_HANDSHAKE_23 + end), + send_name(Socket, MyNode, OurVer, AssumedVer, Flags). + +send_name(Socket, MyNode, OurVer, AssumedVer, Flags) -> + NodeName = atom_to_binary(MyNode, latin1), + if AssumedVer =:= 5 -> + ?to_port(Socket, [$n,?int16(OurVer),?int32(Flags),NodeName]); + AssumedVer >= 6 -> + Creation = erts_internal:get_creation(), + ?to_port(Socket, [$N, + <<Flags:64, + Creation:32, + (byte_size(NodeName)):16>>, + NodeName]) + end. -%% -%% recv_name is common for both old and new handshake. -%% -recv_name(Socket) -> +recv_name(Socket, OurEpmdVer) -> case gen_tcp:recv(Socket, 0) of - {ok,Data} -> - get_name(Data); + {ok,[$n, V1,V0, F3,F2,F1,F0 | OtherNode]} -> + 5 = OurEpmdVer, + 5 = ?u16(V1,V0), + Type = flags_to_type(?u32(F3,F2,F1,F0)), + {Type, list_to_atom(OtherNode)}; + {ok,[$N, F7,F6,F5,F4,F3,F2,F1,F0, _Cr3,_Cr2,_Cr1,_Cr0, NL1, NL0 | Rest]} -> + true = (OurEpmdVer >= 6), + {OtherNode, _Residue} = lists:split(?u16(NL1,NL0), Rest), + <<Flags:64>> = <<F7,F6,F5,F4,F3,F2,F1,F0>>, + Type = flags_to_type(Flags), + {Type, list_to_atom(OtherNode)}; Res -> ?shutdown({no_node,Res}) end. -get_name([$m,VersionA,VersionB,_Ip1,_Ip2,_Ip3,_Ip4|OtherNode]) -> - {normal, list_to_atom(OtherNode), ?u16(VersionA,VersionB)}; -get_name([$h,VersionA,VersionB,_Ip1,_Ip2,_Ip3,_Ip4|OtherNode]) -> - {hidden, list_to_atom(OtherNode), ?u16(VersionA,VersionB)}; -get_name([$n,VersionA, VersionB, Flag1, Flag2, Flag3, Flag4 | OtherNode]) -> - Type = case ?u32(Flag1, Flag2, Flag3, Flag4) band ?DFLAG_PUBLISHED of - 0 -> hidden; - _ -> normal - end, - {Type, list_to_atom(OtherNode), - ?u16(VersionA,VersionB)}; -get_name(Data) -> - ?shutdown(Data). +recv_complement(Socket, OurVer, 5) when OurVer > 5 -> + case gen_tcp:recv(Socket, 0) of + {ok,[$c, _F7,_F6,_F5,_F4, _Cr3,_Cr2,_Cr1,_Cr0]} -> + ok; + Res -> + ?shutdown({no_node,Res}) + end; +recv_complement(_, _OurVer, _OurEpmdVer) -> + ok. + %% %% tell_name is for old handshake @@ -538,13 +608,10 @@ wait_for_reg_reply(Socket, SoFar) -> receive {tcp, Socket, Data0} -> case SoFar ++ Data0 of - [$y, Result, A, B] -> - case Result of - 0 -> - {alive, Socket, ?u16(A, B)}; - _ -> - {error, duplicate_name} - end; + [$y, 0, Cr1,Cr0] -> + {alive, Socket, ?u16(Cr1,Cr0)}; + [$v, 0, Cr3,Cr2,Cr1,Cr0] -> + {alive, Socket, ?u32(Cr3,Cr2,Cr1,Cr0)}; Data when length(Data) < 4 -> wait_for_reg_reply(Socket, Data); Garbage -> @@ -558,9 +625,9 @@ wait_for_reg_reply(Socket, SoFar) -> end. -register(NodeName, ListenSocket, VLow, VHigh) -> +epmd_register(NodeName, ListenSocket, OurVer) -> {ok,{_,TcpPort}} = inet:sockname(ListenSocket), - case do_register_node(NodeName, TcpPort, VLow, VHigh) of + case do_register_node(NodeName, TcpPort, ?EI_DIST_LOW, OurVer) of {alive, Socket, _Creation} -> Socket; Other -> diff --git a/lib/erl_interface/test/ei_tmo_SUITE_data/Makefile.src b/lib/erl_interface/test/ei_tmo_SUITE_data/Makefile.src index b4ee361939..378e276524 100644 --- a/lib/erl_interface/test/ei_tmo_SUITE_data/Makefile.src +++ b/lib/erl_interface/test/ei_tmo_SUITE_data/Makefile.src @@ -25,7 +25,8 @@ CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" LD = @LD@ LIBEI = @erl_interface_eilib@ LIBFLAGS = ../all_SUITE_data/ei_runner@obj@ \ - $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ + ../all_SUITE_data/my_ussi@obj@ \ + $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ @erl_interface_threadlib@ CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data EI_TMO_OBJS = ei_tmo_test@obj@ ei_tmo_test_decl@obj@ diff --git a/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c b/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c index 693e405f75..3c20e94c02 100644 --- a/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c +++ b/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c @@ -21,9 +21,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef VXWORKS -#include "reclaim.h" -#endif #ifdef __WIN32__ #include <winsock2.h> @@ -35,6 +32,7 @@ #endif #include "ei_runner.h" +#include "my_ussi.h" #ifndef __WIN32__ #define closesocket(X) close(X) @@ -67,7 +65,7 @@ static void debugf_open(int number) { char filename[1024]; sprintf(filename,"ei_tmo_test%d.debug",number); -#if !defined(VXWORKS) && !defined(__WIN32__) +#if !defined(__WIN32__) close(2); #endif debugfile = fopen(filename,"a"); @@ -86,6 +84,7 @@ static void debugf_close(void) #define DEBUGF(X) /* noop */ #endif + TESTCASE(framework_check) { char *ptr = NULL; @@ -128,19 +127,26 @@ TESTCASE(framework_check) report(1); } -int decode_request(char **nodename_p, char **cookie_p, char **peername_p) +int decode_request(char **nodename_p, char **cookie_p, char **peername_p, + int *use_ussi_p) { char *nodename = NULL; char *cookie = NULL; char *peername = NULL; + char socket_impl[10]; char *ptr = NULL; ei_x_buff x; int len; int version; int type; int size; - int expected_size = (peername_p == NULL) ? 2 : 3; + int expected_size = 2; int ret = -1; + + if (peername_p) + ++expected_size; + if (use_ussi_p) + ++expected_size; ptr = read_packet(&len); ei_x_new(&x); @@ -180,7 +186,6 @@ int decode_request(char **nodename_p, char **cookie_p, char **peername_p) } nodename = malloc(size+1); ei_decode_atom(x.buff,&len,nodename); - nodename[size] = '\0'; /* needed????? */ if (ei_get_type(x.buff,&len,&type,&size) != 0) { DEBUGF(("Failure at line %d\n",__LINE__)); goto cleanup; @@ -191,8 +196,7 @@ int decode_request(char **nodename_p, char **cookie_p, char **peername_p) } cookie = malloc(size + 1); ei_decode_atom(x.buff,&len,cookie); - cookie[size] = '\0'; /* needed????? */ - if (expected_size > 2) { + if (peername_p) { if (ei_get_type(x.buff,&len,&type,&size) != 0) { DEBUGF(("Failure at line %d\n",__LINE__)); goto cleanup; @@ -212,6 +216,22 @@ int decode_request(char **nodename_p, char **cookie_p, char **peername_p) DEBUGF(("nodename = %s, cookie = %s\n", nodename, cookie)); } + + if (use_ussi_p) { + if (ei_decode_atom_as(x.buff,&len,socket_impl,sizeof(socket_impl), + ERLANG_ASCII, NULL, NULL)) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + if (strcmp(socket_impl,"default") == 0) + *use_ussi_p = 0; + else if (strcmp(socket_impl,"ussi") == 0) + *use_ussi_p = 1; + else { + DEBUGF(("Unkown socket_impl '%s' at %d\n",socket_impl,__LINE__)); + goto cleanup; + } + } *nodename_p = nodename; nodename = NULL; *cookie_p = cookie; @@ -339,6 +359,7 @@ TESTCASE(recv_tmo) char *nodename = NULL; char *cookie = NULL; char *peername = NULL; + int use_ussi; int com_sock = -1; ei_cnode nodeinfo; @@ -346,12 +367,22 @@ TESTCASE(recv_tmo) OPEN_DEBUGFILE(5); - if (decode_request(&nodename,&cookie,&peername) != 0) { + if (decode_request(&nodename,&cookie,&peername,&use_ussi) != 0) { goto cleanup; } - if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; + if (use_ussi) { + my_ussi_init(); + if (ei_connect_init_ussi(&nodeinfo, nodename, cookie, 0, + &my_ussi, sizeof(my_ussi), NULL) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + } + else { + if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } } if ((com_sock = ei_connect_tmo(&nodeinfo, peername, 5000)) < 0) { @@ -451,18 +482,29 @@ TESTCASE(send_tmo) char *cookie = NULL; char *peername = NULL; int com_sock = -1; + int use_ussi; ei_cnode nodeinfo; ei_init(); OPEN_DEBUGFILE(4); - if (decode_request(&nodename,&cookie,&peername) != 0) { + if (decode_request(&nodename,&cookie,&peername,&use_ussi) != 0) { goto cleanup; } - if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; + if (use_ussi) { + my_ussi_init(); + if (ei_connect_init_ussi(&nodeinfo, nodename, cookie, 0, + &my_ussi, sizeof(my_ussi), NULL) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + } + else { + if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } } if ((com_sock = ei_connect_tmo(&nodeinfo, peername, 5000)) < 0) { @@ -593,18 +635,29 @@ TESTCASE(connect_tmo) char *cookie = NULL; char *peername = NULL; int com_sock = -1; + int use_ussi; ei_cnode nodeinfo; ei_init(); OPEN_DEBUGFILE(3); - if (decode_request(&nodename,&cookie,&peername) != 0) { + if (decode_request(&nodename,&cookie,&peername,&use_ussi) != 0) { goto cleanup; } - if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; + if (use_ussi) { + my_ussi_init(); + if (ei_connect_init_ussi(&nodeinfo, nodename, cookie, 0, + &my_ussi, sizeof(my_ussi), NULL) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + } + else { + if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } } if ((com_sock = ei_connect_tmo(&nodeinfo, peername, 5000)) < 0) { @@ -679,10 +732,12 @@ TESTCASE(accept_tmo) int listen_sock = -1; int epmd_sock = -1; int com_sock = -1; + int use_ussi; struct sockaddr_in sin; int sin_siz = sizeof(sin); ErlConnect peer; ei_cnode nodeinfo; + int port_no; ei_init(); @@ -690,38 +745,55 @@ TESTCASE(accept_tmo) putenv("EI_TRACELEVEL=10"); - if (decode_request(&nodename,&cookie,NULL) != 0) { - goto cleanup; - } - if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); + if (decode_request(&nodename,&cookie,NULL,&use_ussi) != 0) { goto cleanup; } + if (use_ussi) { + my_ussi_init(); + if (ei_connect_init_ussi(&nodeinfo, nodename, cookie, 0, + &my_ussi, sizeof(my_ussi), NULL) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + port_no = 0; + listen_sock = ei_listen(&nodeinfo, &port_no, 5); + if (listen_sock == ERL_ERROR) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + } + else { + if (ei_connect_init(&nodeinfo, nodename, cookie, 0) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } - if ((listen_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; - } - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - - if (bind(listen_sock,(struct sockaddr *) &sin, sizeof(sin)) != 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; - } - if (getsockname(listen_sock, - (struct sockaddr *) &sin, &sin_siz) != 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; - } - if (listen(listen_sock, 5) != 0) { - DEBUGF(("Failure at line %d\n",__LINE__)); - goto cleanup; - } - - if ((epmd_sock = ei_publish(&nodeinfo, ntohs(sin.sin_port))) < 0) { - DEBUGF(("Failure at line %d[%d,%d]\n",__LINE__,sin.sin_port,erl_errno)); + if ((listen_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + + if (bind(listen_sock,(struct sockaddr *) &sin, sizeof(sin)) != 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + if (getsockname(listen_sock, + (struct sockaddr *) &sin, &sin_siz) != 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + if (listen(listen_sock, 5) != 0) { + DEBUGF(("Failure at line %d\n",__LINE__)); + goto cleanup; + } + port_no = ntohs(sin.sin_port); + } + + if ((epmd_sock = ei_publish(&nodeinfo, port_no)) < 0) { + DEBUGF(("Failure at line %d[%d,%d]\n",__LINE__,port_no,erl_errno)); goto cleanup; } diff --git a/lib/erl_interface/test/erl_call_SUITE.erl b/lib/erl_interface/test/erl_call_SUITE.erl index 9e2b2e4251..0d95a1361b 100644 --- a/lib/erl_interface/test/erl_call_SUITE.erl +++ b/lib/erl_interface/test/erl_call_SUITE.erl @@ -23,42 +23,88 @@ -include_lib("common_test/include/ct.hrl"). --export([all/0, smoke/1]). +-export([all/0, smoke/1, test_connect_to_host_port/1]). -all() -> - [smoke]. +all() -> + [smoke, + test_connect_to_host_port]. smoke(Config) when is_list(Config) -> - ErlCall = find_erl_call(), - NameSwitch = case net_kernel:longnames() of - true -> - "-name"; - false -> - "-sname" - end, Name = atom_to_list(?MODULE) ++ "-" ++ integer_to_list(erlang:system_time(microsecond)), - ArgsList = ["-s", "-a", "erlang node", NameSwitch, Name], - io:format("erl_call: \"~ts\"\n~nargs list: ~p~n", [ErlCall, ArgsList]), - CmdRes = get_smoke_port_res(open_port({spawn_executable, ErlCall}, - [{args, ArgsList}, eof]), []), - io:format("CmdRes: ~p~n", [CmdRes]), + RetNodeName = start_node_and_get_node_name(Name), + + halt_node(Name), [_, Hostname] = string:lexemes(atom_to_list(node()), "@"), NodeName = list_to_atom(Name ++ "@" ++ Hostname), - io:format("NodeName: ~p~n~n", [NodeName]), + NodeName = list_to_atom(RetNodeName), + ok. - pong = net_adm:ping(NodeName), - rpc:cast(NodeName, erlang, halt, []), - NodeName = list_to_atom(string:trim(CmdRes, both, "'")), + +test_connect_to_host_port(Config) when is_list(Config) -> + Name = atom_to_list(?MODULE) + ++ "-" + ++ integer_to_list(erlang:system_time(microsecond)), + Port = start_node_and_get_port(Name), + AddressCaller = + fun(Address) -> + get_erl_call_result(["-address", + Address, + "-a", + "erlang length [[1,2,3,4,5,6,7,8,9]]"]) + end, + "9" = AddressCaller(erlang:integer_to_list(Port)), + "9" = AddressCaller(":" ++ erlang:integer_to_list(Port)), + [_, Hostname] = string:lexemes(atom_to_list(node()), "@"), + "9" = AddressCaller(Hostname ++ ":" ++ erlang:integer_to_list(Port)), + FailedRes = AddressCaller("80"), + case string:find(FailedRes, "80") of + nomatch -> ct:fail("Incorrect error message"); + _ -> ok + end, + halt_node(Name), ok. % % Utility functions... % + +halt_node(Name) -> + [_, Hostname] = string:lexemes(atom_to_list(node()), "@"), + NodeName = list_to_atom(Name ++ "@" ++ Hostname), + io:format("NodeName: ~p~n~n", [NodeName]), + + pong = net_adm:ping(NodeName), + rpc:cast(NodeName, erlang, halt, []). + +start_node_and_get_node_name(Name) -> + NameSwitch = case net_kernel:longnames() of + true -> + "-name"; + false -> + "-sname" + end, + string:trim(get_erl_call_result(["-s", + NameSwitch, + Name, "-a", + "erlang node"]), + both, + "'"). + +start_node_and_get_port(Name) -> + start_node_and_get_node_name(Name), + {ok, NamePortList} = net_adm:names(), + {value, {_, Port}} + = lists:search(fun({N, _}) -> + string:equal(N, Name) + end, + NamePortList), + Port. + find_erl_call() -> ErlCallName = case os:type() of {win32, _} -> "erl_call.exe"; @@ -86,10 +132,19 @@ find_erl_call() -> ErlCall end. -get_smoke_port_res(Port, Acc) when is_port(Port) -> + +get_erl_call_result(ArgsList) -> + ErlCall = find_erl_call(), + io:format("erl_call: \"~ts\"\n~nargs list: ~p~n", [ErlCall, ArgsList]), + CmdRes = get_port_res(open_port({spawn_executable, ErlCall}, + [{args, ArgsList}, eof, stderr_to_stdout]), []), + io:format("CmdRes: ~p~n", [CmdRes]), + CmdRes. + +get_port_res(Port, Acc) when is_port(Port) -> receive {Port, {data, Data}} -> - get_smoke_port_res(Port, [Acc|Data]); + get_port_res(Port, [Acc|Data]); {Port, eof} -> lists:flatten(Acc) end. diff --git a/lib/erl_interface/test/erl_connect_SUITE.erl b/lib/erl_interface/test/erl_connect_SUITE.erl deleted file mode 100644 index 782691b8fb..0000000000 --- a/lib/erl_interface/test/erl_connect_SUITE.erl +++ /dev/null @@ -1,131 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2000-2018. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%% -%% %CopyrightEnd% -%% - -%% --module(erl_connect_SUITE). - --include_lib("common_test/include/ct.hrl"). --include("erl_connect_SUITE_data/erl_connect_test_cases.hrl"). - --export([all/0, suite/0, - init_per_testcase/2, - erl_send/1, erl_reg_send/1, - erl_send_cookie_file/1]). - --import(runner, [get_term/1,send_term/2]). - -suite() -> - [{ct_hooks,[ts_install_cth]}, - {timetrap, {seconds, 30}}]. - -all() -> - [erl_send, erl_reg_send, erl_send_cookie_file]. - - -init_per_testcase(Case, Config) -> - runner:init_per_testcase(?MODULE, Case, Config). - -erl_send(Config) when is_list(Config) -> - P = runner:start(Config, ?interpret), - 1 = erl_connect_init(P, 42, erlang:get_cookie(), 0), - {ok,Fd} = erl_connect(P, node()), - - ok = erl_send(P, Fd, self(), AMsg={a,message}), - receive AMsg -> ok end, - - 0 = erl_close_connection(P,Fd), - runner:send_eot(P), - runner:recv_eot(P), - ok. - -erl_send_cookie_file(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skip,"Skipped on VxWorks"}; - _ -> - P = runner:start(Config, ?interpret), - 1 = erl_connect_init(P, 42, '', 0), - {ok,Fd} = erl_connect(P, node()), - - ok = erl_send(P, Fd, self(), AMsg={a,message}), - receive AMsg -> ok end, - - 0 = erl_close_connection(P,Fd), - runner:send_eot(P), - runner:recv_eot(P), - ok - end. - -erl_reg_send(Config) when is_list(Config) -> - P = runner:start(Config, ?interpret), - 1 = erl_connect_init(P, 42, erlang:get_cookie(), 0), - {ok,Fd} = erl_connect(P, node()), - - ARegName = a_strange_registred_name, - register(ARegName, self()), - ok = erl_reg_send(P, Fd, ARegName, AMsg={another,[strange],message}), - receive AMsg -> ok end, - - 0 = erl_close_connection(P,Fd), - runner:send_eot(P), - runner:recv_eot(P), - ok. - - -%%% Interface functions for erl_interface functions. - -erl_connect_init(P, Num, Cookie, Creation) -> - send_command(P, erl_connect_init, [Num,Cookie,Creation]), - case get_term(P) of - {term,Int} when is_integer(Int) -> Int - end. - -erl_connect(P, Node) -> - send_command(P, erl_connect, [Node]), - case get_term(P) of - {term,{Fd,_}} when Fd >= 0 -> {ok,Fd}; - {term,{-1,Errno}} -> {error,Errno} - end. - -erl_close_connection(P, FD) -> - send_command(P, erl_close_connection, [FD]), - case get_term(P) of - {term,Int} when is_integer(Int) -> Int - end. - -erl_send(P, Fd, To, Msg) -> - send_command(P, erl_send, [Fd,To,Msg]), - get_send_result(P). - -erl_reg_send(P, Fd, To, Msg) -> - send_command(P, erl_reg_send, [Fd,To,Msg]), - get_send_result(P). - -get_send_result(P) -> - case get_term(P) of - {term,{1,_}} -> ok; - {term,{-1,Errno}} -> {error,Errno}; - {term,{Res,Errno}}-> - io:format("Return value: ~p\nerl_errno: ~p", [Res,Errno]), - ct:fail(bad_return_value) - end. - -send_command(P, Name, Args) -> - runner:send_term(P, {Name,list_to_tuple(Args)}). diff --git a/lib/erl_interface/test/erl_connect_SUITE_data/Makefile.first b/lib/erl_interface/test/erl_connect_SUITE_data/Makefile.first deleted file mode 100644 index 21a7aac0b0..0000000000 --- a/lib/erl_interface/test/erl_connect_SUITE_data/Makefile.first +++ /dev/null @@ -1,22 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2001-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -erl_connect_test_decl.c: erl_connect_test.c - erl -noinput -pa ../all_SUITE_data -s init_tc run erl_connect_test -s erlang halt diff --git a/lib/erl_interface/test/erl_connect_SUITE_data/Makefile.src b/lib/erl_interface/test/erl_connect_SUITE_data/Makefile.src deleted file mode 100644 index ff4c382c97..0000000000 --- a/lib/erl_interface/test/erl_connect_SUITE_data/Makefile.src +++ /dev/null @@ -1,41 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2000-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -include @erl_interface_mk_include@ - -CC0 = @CC@ -CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" -LD = @LD@ -LIBERL = @erl_interface_lib@ -LIBEI = @erl_interface_eilib@ -LIBFLAGS = ../all_SUITE_data/runner@obj@ \ - $(LIBERL) $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ - @erl_interface_threadlib@ -CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data -OBJS = erl_connect_test@obj@ erl_connect_test_decl@obj@ - -all: erl_connect_test@exe@ - -erl_connect_test@exe@: $(OBJS) $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(OBJS) $(LIBFLAGS) - -clean: - $(RM) $(OBJS) - $(RM) erl_connect_test@exe@ diff --git a/lib/erl_interface/test/erl_connect_SUITE_data/erl_connect_test.c b/lib/erl_interface/test/erl_connect_SUITE_data/erl_connect_test.c deleted file mode 100644 index 0adaa79a33..0000000000 --- a/lib/erl_interface/test/erl_connect_SUITE_data/erl_connect_test.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 2000-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -/* - * Purpose: Tests the functions in erl_connect.c. - * Author: Bjorn Gustavsson - * - * See the erl_connect_SUITE.erl file for a "table of contents". - */ - -#include <stdio.h> -#include <string.h> - -#include "runner.h" - -static void cmd_erl_connect_init(ETERM* args); -static void cmd_erl_connect(ETERM* args); -static void cmd_erl_send(ETERM* args); -static void cmd_erl_reg_send(ETERM* args); -static void cmd_erl_close_connection(ETERM *args); - -static void send_errno_result(int value); - -static struct { - char* name; - int num_args; /* Number of arguments. */ - void (*func)(ETERM* args); -} commands[] = { - "erl_connect_init", 3, cmd_erl_connect_init, - "erl_connect", 1, cmd_erl_connect, - "erl_close_connection", 1, cmd_erl_close_connection, - "erl_send", 3, cmd_erl_send, - "erl_reg_send", 3, cmd_erl_reg_send, -}; - - -/* - * Sends a list contaning all data types to the Erlang side. - */ - -TESTCASE(interpret) -{ - ETERM* term; - - erl_init(NULL, 0); - - outer_loop: - - term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { - ETERM* Func; - ETERM* Args; - int i; - - if (!ERL_IS_TUPLE(term) || ERL_TUPLE_SIZE(term) != 2) { - fail("term should be a tuple of size 2"); - } - - Func = erl_element(1, term); - if (!ERL_IS_ATOM(Func)) { - fail("function name should be an atom"); - } - Args = erl_element(2, term); - if (!ERL_IS_TUPLE(Args)) { - fail("function arguments should be a tuple"); - } - erl_free_term(term); - for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) { - int n = strlen(commands[i].name); - if (ERL_ATOM_SIZE(Func) != n) { - continue; - } - if (memcmp(ERL_ATOM_PTR(Func), commands[i].name, n) == 0) { - erl_free_term(Func); - if (ERL_TUPLE_SIZE(Args) != commands[i].num_args) { - fail("wrong number of arguments"); - } - commands[i].func(Args); - erl_free_term(Args); - goto outer_loop; - } - } - fail("bad command"); - } -} - -#define VERIFY_TYPE(Test, Term) \ -if (!Test(Term)) { \ - fail("wrong type for " #Term); \ -} else { \ -} - -static void -cmd_erl_connect_init(ETERM* args) -{ - ETERM* number; - ETERM* res; - ETERM* cookie; - char cookie_buffer[256]; - - number = ERL_TUPLE_ELEMENT(args, 0); - VERIFY_TYPE(ERL_IS_INTEGER, number); - cookie = ERL_TUPLE_ELEMENT(args, 1); - VERIFY_TYPE(ERL_IS_ATOM, cookie); - if (ERL_ATOM_SIZE(cookie) == 0) { - res = erl_mk_int(erl_connect_init(ERL_INT_VALUE(number), 0, 0)); - } else { - memcpy(cookie_buffer, ERL_ATOM_PTR(cookie), ERL_ATOM_SIZE(cookie)); - cookie_buffer[ERL_ATOM_SIZE(cookie)] = '\0'; - res = erl_mk_int(erl_connect_init(ERL_INT_VALUE(number), - cookie_buffer, 0)); - } - send_term(res); - erl_free_term(res); -} - -static void -cmd_erl_connect(ETERM* args) -{ - ETERM* node; - char node_buffer[256]; - - node = ERL_TUPLE_ELEMENT(args, 0); - VERIFY_TYPE(ERL_IS_ATOM, node); - memcpy(node_buffer, ERL_ATOM_PTR(node), ERL_ATOM_SIZE(node)); - node_buffer[ERL_ATOM_SIZE(node)] = '\0'; - send_errno_result(erl_connect(node_buffer)); -} - -static void -cmd_erl_close_connection(ETERM* args) -{ - ETERM* number; - ETERM* res; - - number = ERL_TUPLE_ELEMENT(args, 0); - VERIFY_TYPE(ERL_IS_INTEGER, number); - res = erl_mk_int(erl_close_connection(ERL_INT_VALUE(number))); - send_term(res); - erl_free_term(res); -} - -static void -cmd_erl_send(ETERM* args) -{ - ETERM* fd_term = ERL_TUPLE_ELEMENT(args, 0); - ETERM* to = ERL_TUPLE_ELEMENT(args, 1); - ETERM* msg = ERL_TUPLE_ELEMENT(args, 2); - - VERIFY_TYPE(ERL_IS_INTEGER, fd_term); - send_errno_result(erl_send(ERL_INT_VALUE(fd_term), to, msg)); -} - -static void -cmd_erl_reg_send(ETERM* args) -{ - ETERM* fd_term = ERL_TUPLE_ELEMENT(args, 0); - ETERM* to = ERL_TUPLE_ELEMENT(args, 1); - ETERM* msg = ERL_TUPLE_ELEMENT(args, 2); - char reg_name[256]; - - VERIFY_TYPE(ERL_IS_INTEGER, fd_term); - VERIFY_TYPE(ERL_IS_ATOM, to); - memcpy(reg_name, ERL_ATOM_PTR(to), ERL_ATOM_SIZE(to)); - reg_name[ERL_ATOM_SIZE(to)] = '\0'; - send_errno_result(erl_reg_send(ERL_INT_VALUE(fd_term), reg_name, msg)); -} - -static void -send_errno_result(int value) -{ - ETERM* res_array[2]; - ETERM* res_tuple; - - res_array[0] = erl_mk_int(value); - res_array[1] = erl_mk_int(erl_errno); - res_tuple = erl_mk_tuple(res_array, 2); - send_term(res_tuple); - erl_free_term(res_array[0]); - erl_free_term(res_array[1]); - erl_free_term(res_tuple); -} diff --git a/lib/erl_interface/test/erl_eterm_SUITE.erl b/lib/erl_interface/test/erl_eterm_SUITE.erl deleted file mode 100644 index 77910a9fc7..0000000000 --- a/lib/erl_interface/test/erl_eterm_SUITE.erl +++ /dev/null @@ -1,1084 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2018. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%% -%% %CopyrightEnd% -%% - -%% --module(erl_eterm_SUITE). - --include_lib("common_test/include/ct.hrl"). --include("erl_eterm_SUITE_data/eterm_test_cases.hrl"). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The tests are organised as follows: -%%% -%%% 1. Basic tests (encoding, decoding, memory allocation). -%%% 2. Constructing terms (the erl_mk_xxx() functions and erl_copy_term()). -%%% 3. Extracting & info functions (erl_hd(), erl_length() etc). -%%% 4. I/O list functions. -%%% 5. Miscellaneous functions. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - --export([all/0, suite/0, - init_per_testcase/2, - build_terms/1, round_trip_conversion/1, - decode_terms/1, decode_float/1, - t_erl_mk_int/1, t_erl_mk_list/1, - basic_copy/1, - t_erl_cons/1, - t_erl_mk_atom/1, - t_erl_mk_binary/1, - t_erl_mk_empty_list/1, - t_erl_mk_float/1, - t_erl_mk_pid/1, - t_erl_mk_xpid/1, - t_erl_mk_port/1, - t_erl_mk_xport/1, - t_erl_mk_ref/1, - t_erl_mk_long_ref/1, - t_erl_mk_string/1, - t_erl_mk_estring/1, - t_erl_mk_tuple/1, - t_erl_mk_uint/1, - t_erl_mk_var/1, - t_erl_size/1, - t_erl_var_content/1, - t_erl_element/1, - t_erl_length/1, t_erl_hd/1, t_erl_tl/1, - type_checks/1, extractor_macros/1, - t_erl_iolist_length/1, t_erl_iolist_to_binary/1, - t_erl_iolist_to_string/1, - erl_print_term/1, print_string/1, - t_erl_free_compound/1, - high_chaparal/1, - broken_data/1, - cnode_1/1]). - --export([start_cnode/1]). - --import(runner, [get_term/1]). - -%% This test suite controls the running of the C language functions -%% in eterm_test.c and print_term.c. - -suite() -> - [{ct_hooks,[ts_install_cth]}]. - -all() -> - [build_terms, round_trip_conversion, decode_terms, - decode_float, t_erl_mk_int, t_erl_mk_list, basic_copy, - t_erl_mk_atom, t_erl_mk_binary, t_erl_mk_empty_list, - t_erl_mk_float, t_erl_mk_pid, t_erl_mk_xpid, - t_erl_mk_port, t_erl_mk_xport, t_erl_mk_ref, - t_erl_mk_long_ref, t_erl_mk_string, t_erl_mk_estring, - t_erl_mk_tuple, t_erl_mk_uint, t_erl_mk_var, t_erl_size, - t_erl_var_content, t_erl_element, t_erl_cons, - t_erl_length, t_erl_hd, t_erl_tl, type_checks, - extractor_macros, t_erl_iolist_length, - t_erl_iolist_to_binary, t_erl_iolist_to_string, - erl_print_term, print_string, t_erl_free_compound, - high_chaparal, broken_data, cnode_1]. - - -init_per_testcase(Case, Config) -> - runner:init_per_testcase(?MODULE, Case, Config). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% -%%% 1. B a s i c t e s t s -%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% This test asks the C function to construct all data types in -%% a list and verifies that the result is as expected. - -build_terms(Config) when is_list(Config) -> - P = runner:start(Config, ?build_terms), - {term, Term} = get_term(P), - io:format("Received: ~p", [Term]), - [ARefLN, ARef, APortLN, APort, APidLN, APid, - {element1, 42, 767}, "A string", - 1, -1, 0, 3.0, ABin, 'I am an atom'] = Term, - "A binary" = binary_to_list(ABin), - case ARef of - R when is_reference(R), node(R) == kalle@localhost -> ok - end, - case ARefLN of - R1 when is_reference(R1), node(R1) == abcdefghijabcdefghij@localhost -> ok - end, - case APort of - Port when is_port(Port), node(Port) == kalle@localhost -> ok - end, - case APortLN of - Port1 when is_port(Port1), node(Port1) == abcdefghijabcdefghij@localhost -> ok - end, - case APid of - Pid when is_pid(Pid), node(Pid) == kalle@localhost -> ok - end, - case APidLN of - Pid1 when is_pid(Pid1), node(Pid1) == abcdefghijabcdefghij@localhost -> ok - end, - - runner:recv_eot(P), - ok. - -%% This test is run entirely in C code. - -round_trip_conversion(Config) when is_list(Config) -> - runner:test(Config, ?round_trip_conversion), - ok. - -%% This test sends a list of all data types to the C code function, -%% which decodes it and verifies it. - -decode_terms(Config) when is_list(Config) -> - Dummy1 = list_to_atom(filename:join(proplists:get_value(priv_dir, Config), - dummy_file1)), - Dummy2 = list_to_atom(filename:join(proplists:get_value(priv_dir, Config), - dummy_file2)), - Port1 = open_port(Dummy1, [out]), - Port2 = open_port(Dummy2, [out]), - ABinary = list_to_binary("A binary"), - Terms = [make_ref(), make_ref(), - Port1, Port2, - self(), self(), - {element1, 42, 767}, "A string", - 1, -1, 0, 3.0, ABinary, 'I am an atom'], - - P = runner:start(Config, ?decode_terms), - runner:send_term(P, Terms), - runner:recv_eot(P), - - ok. - -%% Decodes the floating point number 3.1415. - -decode_float(Config) when is_list(Config) -> - P = runner:start(Config, ?decode_float), - runner:send_term(P, 3.1415), - runner:recv_eot(P), - ok. - -%% Tests the erl_free_compound() function. - -t_erl_free_compound(Config) when is_list(Config) -> - runner:test(Config, ?t_erl_free_compound), - ok. - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% -%%% 2. C o n s t r u c t i n g t e r m s -%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% This tests the erl_mk_list() function. - -t_erl_mk_list(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_list), - - {term, []} = get_term(P), - {term, [abc]} = get_term(P), - {term, [abcdef, 42]} = get_term(P), - {term, [0.0, 23, [], 3.1415]} = get_term(P), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_int() function. - -t_erl_mk_int(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_int), - - {term, 0} = get_term(P), - {term, 127} = get_term(P), - {term, 128} = get_term(P), - {term, 255} = get_term(P), - {term, 256} = get_term(P), - - {term, 16#FFFF} = get_term(P), - {term, 16#10000} = get_term(P), - - {term, 16#07FFFFFF} = get_term(P), - {term, 16#0FFFFFFF} = get_term(P), - {term, 16#1FFFFFFF} = get_term(P), - {term, 16#3FFFFFFF} = get_term(P), - {term, 16#7FFFFFFF} = get_term(P), - - {term, 16#08000000} = get_term(P), - {term, 16#10000000} = get_term(P), - {term, 16#20000000} = get_term(P), - {term, 16#40000000} = get_term(P), - - - {term, -16#07FFFFFF} = get_term(P), - {term, -16#0FFFFFFF} = get_term(P), - {term, -16#1FFFFFFF} = get_term(P), - {term, -16#3FFFFFFF} = get_term(P), - {term, -16#7FFFFFFF} = get_term(P), - - {term, -16#08000000} = get_term(P), - {term, -16#10000000} = get_term(P), - {term, -16#20000000} = get_term(P), - {term, -16#40000000} = get_term(P), - - {term, -16#08000001} = get_term(P), - {term, -16#10000001} = get_term(P), - {term, -16#20000001} = get_term(P), - {term, -16#40000001} = get_term(P), - - {term, -16#08000002} = get_term(P), - {term, -16#10000002} = get_term(P), - {term, -16#20000002} = get_term(P), - {term, -16#40000002} = get_term(P), - - {term, -1999999999} = get_term(P), - {term, -2000000000} = get_term(P), - {term, -2000000001} = get_term(P), - - runner:recv_eot(P), - ok. - - -%% Basic test of erl_copy_term(). - -basic_copy(Config) when is_list(Config) -> - runner:test(Config, ?basic_copy), - ok. - - -%% This tests the erl_mk_tuple() function. - -t_erl_mk_tuple(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_tuple), - - {term, {madonna, 21, 'mad donna', 12}} = get_term(P), - {term, {'Madonna',21,{children,{"Isabella",2}}, - {'home page',"http://www.madonna.com/"}}} = get_term(P), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_atom() function. - -t_erl_mk_atom(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_atom), - - {term, madonna} = (get_term(P)), - {term, 'Madonna'} = (get_term(P)), - {term, 'mad donna'} = (get_term(P)), - {term, '_madonna_'} = (get_term(P)), - {term, '/home/madonna/tour_plan'} = (get_term(P)), - {term, 'http://www.madonna.com/tour_plan'} = (get_term(P)), - {term, '\'madonna\''} = (get_term(P)), - {term, '\"madonna\"'} = (get_term(P)), - {term, '\\madonna\\'} = (get_term(P)), - {term, '{madonna,21,\'mad donna\',12}'} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_binary() function. - -t_erl_mk_binary(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_binary), - - {term, Bin} = (get_term(P)), - "{madonna,21,'mad donna',1234.567.890, !#$%&/()=?+-@, \" \\}" = binary_to_list(Bin), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_empty_list() function. - -t_erl_mk_empty_list(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_empty_list), - - {term, []} = get_term(P), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_float() function. - -t_erl_mk_float(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skipped, "Floating point numbers never compare equal on PPC"}; - _ -> - P = runner:start(Config, ?t_erl_mk_float), - {term, {3.1415, 1.999999, 2.000000, 2.000001, - 2.000002, 12345.67890}} = get_term(P), - runner:recv_eot(P), - ok - end. - - -%% This tests the erl_mk_pid() function. - -t_erl_mk_pid(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_pid), - - {term, A_pid} = (get_term(P)), - {pid, kalle@localhost, 3, 2} = nc2vinfo(A_pid), - - runner:recv_eot(P), - ok. - -t_erl_mk_xpid(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_xpid), - - {term, A_pid} = (get_term(P)), - {pid, kalle@localhost, 32767, 8191} = nc2vinfo(A_pid), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_port() function. - -t_erl_mk_port(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_port), - - {term, A_port} = (get_term(P)), - {port, kalle@localhost, 4} = nc2vinfo(A_port), - - runner:recv_eot(P), - ok. - -t_erl_mk_xport(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_xport), - - {term, A_port} = (get_term(P)), - {port, kalle@localhost, 268435455} = nc2vinfo(A_port), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_ref() function. - -t_erl_mk_ref(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_ref), - - {term, A_ref} = (get_term(P)), - {ref, kalle@localhost, _Length, [6]} = nc2vinfo(A_ref), - - runner:recv_eot(P), - ok. - -t_erl_mk_long_ref(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_long_ref), - - {term, A_ref} = (get_term(P)), - {ref, kalle@localhost, _Length, [4294967295,4294967295,262143]} - = nc2vinfo(A_ref), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_string() function. - -t_erl_mk_string(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_string), - - {term, "madonna"} = (get_term(P)), - {term, "Madonna"} = (get_term(P)), - {term, "mad donna"} = (get_term(P)), - {term, "_madonna_"} = (get_term(P)), - {term, "/home/madonna/tour_plan"} = (get_term(P)), - {term, "http://www.madonna.com/tour_plan"} = (get_term(P)), - {term, "\'madonna\'"} = (get_term(P)), - {term, "\"madonna\""} = (get_term(P)), - {term, "\\madonna\\"} = (get_term(P)), - {term, "{madonna,21,'mad donna',12}"} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_estring() function. - -t_erl_mk_estring(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_estring), - - {term, "madonna"} = (get_term(P)), - {term, "Madonna"} = (get_term(P)), - {term, "mad donna"} = (get_term(P)), - {term, "_madonna_"} = (get_term(P)), - {term, "/home/madonna/tour_plan"} = (get_term(P)), - {term, "http://www.madonna.com/tour_plan"} = (get_term(P)), - {term, "\'madonna\'"} = (get_term(P)), - {term, "\"madonna\""} = (get_term(P)), - {term, "\\madonna\\"} = (get_term(P)), - {term, "{madonna,21,'mad donna',12}"} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_uint() function. - -t_erl_mk_uint(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_uint), - - {term, 54321} = (get_term(P)), - {term, 2147483647} = (get_term(P)), - {term, 2147483648} = (get_term(P)), - {term, 2147483649} = (get_term(P)), - {term, 2147483650} = (get_term(P)), - {term, 4294967295} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_mk_var() function. - -t_erl_mk_var(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_mk_var), - - {term, 1} = (get_term(P)), - {term, 0} = (get_term(P)), - {term, 1} = (get_term(P)), - {term, 0} = (get_term(P)), - {term, 1} = (get_term(P)), - {term, 0} = (get_term(P)), - {term, 1} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_cons() function. - -t_erl_cons(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_cons), - - {term, [madonna, 21]} = get_term(P), - - runner:recv_eot(P), - ok. - - - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% -%%% 3. E x t r a c t i n g & i n f o f u n c t i o n s -%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% Tests the erl_length() function. - -t_erl_length(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_length), - - 0 = erl_length(P, []), - 1 = erl_length(P, [a]), - 2 = erl_length(P, [a, b]), - 3 = erl_length(P, [a, b, c]), - - 4 = erl_length(P, [a, [x, y], c, []]), - - -1 = erl_length(P, [a|b]), - -1 = erl_length(P, a), - - runner:finish(P), - ok. - -%% Invokes the erl_length() function. - -erl_length(Port, List) -> - call_erl_function(Port, List). - -%% Tests the erl_hd() function. - -t_erl_hd(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_hd), - - 'NULL' = erl_hd(P, 42), - 'NULL' = erl_hd(P, abc), - 'NULL' = erl_hd(P, []), - - [] = erl_hd(P, [[], a]), - a = erl_hd(P, [a]), - a = erl_hd(P, [a, b]), - a = erl_hd(P, [a, b, c]), - a = erl_hd(P, [a|b]), - - runner:send_eot(P), - runner:recv_eot(P), - ok. - -%% Invokes the erl_hd() function. - -erl_hd(Port, List) -> - call_erl_function(Port, List). - -%% Tests the erl_tail() function. - -t_erl_tl(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_tl), - - 'NULL' = erl_tl(P, 42), - 'NULL' = erl_tl(P, abc), - 'NULL' = erl_tl(P, []), - - [] = erl_tl(P, [a]), - [b] = erl_tl(P, [a, b]), - [b, c] = erl_tl(P, [a, b, c]), - - b = erl_tl(P, [a|b]), - - runner:send_eot(P), - runner:recv_eot(P), - ok. - -%% Invokes the erl_tail() function in erl_interface. - -erl_tl(Port, List) -> - call_erl_function(Port, List). - -%% Tests the type checking macros (done in the C program). - -type_checks(Config) when is_list(Config) -> - runner:test(Config, ?type_checks), - ok. - -%% Tests the extractor macros (done in the C program). - -extractor_macros(Config) when is_list(Config) -> - runner:test(Config, ?extractor_macros), - ok. - - -%% This tests the erl_size() function. - -t_erl_size(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_size), - - {term, 0} = (get_term(P)), - {term, 4} = (get_term(P)), - - {term, 0} = (get_term(P)), - {term, 27} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_var_content() function. - -t_erl_var_content(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_var_content), - - {term, 17} = (get_term(P)), - {term, "http://www.madonna.com"} = (get_term(P)), - {term, 2} = (get_term(P)), - {term, "http://www.madonna.com"} = (get_term(P)), - {term, 2} = (get_term(P)), - - runner:recv_eot(P), - ok. - - -%% This tests the erl_element() function. - -t_erl_element(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_element), - - {term, madonna} = get_term(P), - {term, 21} = get_term(P), - {term, 'mad donna'} = get_term(P), - {term, 12} = get_term(P), - - {term, 'Madonna'} = get_term(P), - {term, 21} = get_term(P), - {term, {children,{"Isabella",2}}} = get_term(P), - {term, {'home page',"http://www.madonna.com/"}} = get_term(P), - - runner:recv_eot(P), - ok. - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% -%%% 4. I / O l i s t f u n c t i o n s -%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% Tests the erl_iolist_length() function. - -t_erl_iolist_length(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_iolist_length), - - %% Flat lists. - - 0 = erl_iolist_length(P, []), - 1 = erl_iolist_length(P, [10]), - 2 = erl_iolist_length(P, [10, 20]), - 3 = erl_iolist_length(P, [10, 20, 30]), - 256 = erl_iolist_length(P, lists:seq(0, 255)), - - %% Deep lists. - - 0 = erl_iolist_length(P, [[]]), - 1 = erl_iolist_length(P, [[], 42]), - 1 = erl_iolist_length(P, [42, []]), - 2 = erl_iolist_length(P, [42, [], 45]), - - 3 = erl_iolist_length(P, [42, [90], 45]), - 3 = erl_iolist_length(P, [[42, [90]], 45]), - 3 = erl_iolist_length(P, [[42, [90]], 45]), - - %% List with binaries. - - 0 = erl_iolist_length(P, [list_to_binary([])]), - 0 = erl_iolist_length(P, [[], list_to_binary([])]), - 1 = erl_iolist_length(P, [[1], list_to_binary([])]), - 1 = erl_iolist_length(P, [[], list_to_binary([2])]), - 2 = erl_iolist_length(P, [[42], list_to_binary([2])]), - 4 = erl_iolist_length(P, [[42], list_to_binary([2, 3, 4])]), - - %% Binaries as tail. - - 0 = erl_iolist_length(P, [[]| list_to_binary([])]), - 1 = erl_iolist_length(P, [[1]| list_to_binary([])]), - 1 = erl_iolist_length(P, [[]| list_to_binary([2])]), - 2 = erl_iolist_length(P, [[42]| list_to_binary([2])]), - - %% Binaries only. - - 0 = erl_iolist_length(P, list_to_binary("")), - 1 = erl_iolist_length(P, list_to_binary([1])), - 2 = erl_iolist_length(P, list_to_binary([1, 2])), - - %% Illegal cases. - - -1 = erl_iolist_length(P, [42|43]), - -1 = erl_iolist_length(P, a), - - -1 = erl_iolist_length(P, [a]), - -1 = erl_iolist_length(P, [256]), - -1 = erl_iolist_length(P, [257]), - -1 = erl_iolist_length(P, [-1]), - -1 = erl_iolist_length(P, [-2]), - -1 = erl_iolist_length(P, [-127]), - -1 = erl_iolist_length(P, [-128]), - - runner:finish(P), - ok. - -%% Invokes the erl_iolist_length() function. - -erl_iolist_length(Port, List) -> - call_erl_function(Port, List). - -%% Tests the erl_iolist_to_binary() function. - -t_erl_iolist_to_binary(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_iolist_to_binary), - - %% Flat lists. - - [] = iolist_to_list(P, []), - [10] = iolist_to_list(P, [10]), - [10, 20] = iolist_to_list(P, [10, 20]), - [10, 20, 30] = iolist_to_list(P, [10, 20, 30]), - AllBytes = lists:seq(0, 255), - AllBytes = iolist_to_list(P, AllBytes), - - %% Deep lists. - - [] = iolist_to_list(P, [[]]), - [42] = iolist_to_list(P, [[], 42]), - [42] = iolist_to_list(P, [42, []]), - [42, 45] = iolist_to_list(P, [42, [], 45]), - - [42, 90, 45] = iolist_to_list(P, [42, [90], 45]), - [42, 90, 45] = iolist_to_list(P, [[42, [90]], 45]), - [42, 90, 45] = iolist_to_list(P, [[42, [90]], 45]), - - %% List with binaries. - - [] = iolist_to_list(P, [list_to_binary([])]), - [] = iolist_to_list(P, [[], list_to_binary([])]), - [1] = iolist_to_list(P, [[1], list_to_binary([])]), - [2] = iolist_to_list(P, [[], list_to_binary([2])]), - [42, 2] = iolist_to_list(P, [[42], list_to_binary([2])]), - [42, 2, 3, 4] = iolist_to_list(P, [[42], list_to_binary([2, 3, 4])]), - - %% Binaries as tail. - - [] = iolist_to_list(P, [[]| list_to_binary([])]), - [1] = iolist_to_list(P, [[1]| list_to_binary([])]), - [2] = iolist_to_list(P, [[]| list_to_binary([2])]), - [42, 2] = iolist_to_list(P, [[42]| list_to_binary([2])]), - - %% Binaries only. - - [] = iolist_to_list(P, list_to_binary("")), - [1] = iolist_to_list(P, list_to_binary([1])), - [1, 2] = iolist_to_list(P, list_to_binary([1, 2])), - - %% Illegal cases. - - 'NULL' = iolist_to_list(P, [42|43]), - 'NULL' = iolist_to_list(P, a), - - 'NULL' = iolist_to_list(P, [a]), - 'NULL' = iolist_to_list(P, [256]), - 'NULL' = iolist_to_list(P, [257]), - 'NULL' = iolist_to_list(P, [-1]), - 'NULL' = iolist_to_list(P, [-2]), - 'NULL' = iolist_to_list(P, [-127]), - 'NULL' = iolist_to_list(P, [-128]), - - runner:finish(P), - ok. - -iolist_to_list(Port, Term) -> - case call_erl_function(Port, Term) of - 'NULL' -> - 'NULL'; - Bin when is_binary(Bin) -> - binary_to_list(Bin) - end. - -%% Tests the erl_iolist_to_string() function. - -t_erl_iolist_to_string(Config) when is_list(Config) -> - P = runner:start(Config, ?t_erl_iolist_to_string), - - %% Flat lists. - - [0] = iolist_to_string(P, []), - [10, 0] = iolist_to_string(P, [10]), - [10, 20, 0] = iolist_to_string(P, [10, 20]), - [10, 20, 30, 0] = iolist_to_string(P, [10, 20, 30]), - AllBytes = lists:seq(1, 255)++[0], - AllBytes = iolist_to_string(P, lists:seq(1, 255)), - - %% Deep lists. - - [0] = iolist_to_string(P, [[]]), - [42, 0] = iolist_to_string(P, [[], 42]), - [42, 0] = iolist_to_string(P, [42, []]), - [42, 45, 0] = iolist_to_string(P, [42, [], 45]), - - [42, 90, 45, 0] = iolist_to_string(P, [42, [90], 45]), - [42, 90, 45, 0] = iolist_to_string(P, [[42, [90]], 45]), - [42, 90, 45, 0] = iolist_to_string(P, [[42, [90]], 45]), - - %% List with binaries. - - [0] = iolist_to_string(P, [list_to_binary([])]), - [0] = iolist_to_string(P, [[], list_to_binary([])]), - [1, 0] = iolist_to_string(P, [[1], list_to_binary([])]), - [2, 0] = iolist_to_string(P, [[], list_to_binary([2])]), - [42, 2, 0] = iolist_to_string(P, [[42], list_to_binary([2])]), - [42, 2, 3, 4, 0] = iolist_to_string(P, [[42], - list_to_binary([2, 3, 4])]), - - %% Binaries as tail. - - [0] = iolist_to_string(P, [[]| list_to_binary([])]), - [1, 0] = iolist_to_string(P, [[1]| list_to_binary([])]), - [2, 0] = iolist_to_string(P, [[]| list_to_binary([2])]), - [42, 2, 0] = iolist_to_string(P, [[42]| list_to_binary([2])]), - - %% Binaries only. - - [0] = iolist_to_string(P, list_to_binary("")), - [1, 0] = iolist_to_string(P, list_to_binary([1])), - [1, 2, 0] = iolist_to_string(P, list_to_binary([1, 2])), - - %% Illegal cases. - - 'NULL' = iolist_to_string(P, [0]), - 'NULL' = iolist_to_string(P, [65, 0, 66]), - 'NULL' = iolist_to_string(P, [65, 66, 67, 0]), - - 'NULL' = iolist_to_string(P, [42|43]), - 'NULL' = iolist_to_string(P, a), - - 'NULL' = iolist_to_string(P, [a]), - 'NULL' = iolist_to_string(P, [256]), - 'NULL' = iolist_to_string(P, [257]), - 'NULL' = iolist_to_string(P, [-1]), - 'NULL' = iolist_to_string(P, [-2]), - 'NULL' = iolist_to_string(P, [-127]), - 'NULL' = iolist_to_string(P, [-128]), - - runner:finish(P), - ok. - -%% Invokes the erl_iolist_to_string() function. - -iolist_to_string(Port, Term) -> - runner:send_term(Port, Term), - case get_term(Port) of - {bytes, Result} -> Result; - 'NULL' -> 'NULL' - end. - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% -%%% 5. M i s c e l l a n o u s T e s t s -%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%% Tests the erl_print_term() function -erl_print_term(Config) when is_list(Config) -> - PrintTerm = print_term(Config), - P = open_port({spawn, PrintTerm}, [stream]), - - %% Lists. - - print(P, "[]", []), - print(P, "[a]", [a]), - print(P, "[[a]]", [[a]]), - print(P, "[[]]", [[]]), - print(P, "[a,b,c]", [a,b,c]), - print(P, "[a,b|c]", [a,b|c]), - print(P, "[a,[],c]", [a,[],c]), - print(P, "[a,[1000,1],c]", [a,[1000,1],c]), - - %% Tuples. - - print(P, "{}", {}), - print(P, "{ok}", {ok}), - print(P, "{1,2,3}", {1, 2, 3}), - - %% Pids. - - {_X, Y, Z} = split_pid(self()), - PidString = lists:flatten(io_lib:format("<~s.~w.~w>", - [node(), Y, Z])), - print(P, PidString, self()), - - unlink(P), - exit(P, die), - ok. - -split_pid(Pid) when is_pid(Pid) -> - split_pid(pid_to_list(Pid), 0, []). - -split_pid([$<|Rest], Cur, Result) -> - split_pid(Rest, Cur, Result); -split_pid([Digit|Rest], Cur, Result) when $0 =< Digit, Digit =< $9 -> - split_pid(Rest, 10*Cur+Digit-$0, Result); -split_pid([$.|Rest], Cur, Result) -> - split_pid(Rest, 0, Result++[Cur]); -split_pid([$>], Cur, Result) -> - list_to_tuple(Result++[Cur]). - -%% Test printing a string with erl_print_term() -print_string(Config) when is_list(Config) -> - PrintTerm = print_term(Config), - P = open_port({spawn, PrintTerm}, [stream]), - - %% Strings. - - print(P, "\"ABC\"", "ABC"), - {11, "\"\\tABC\\r\\n\""} = print(P, "\tABC\r\n"), - - %% Not strings. - - print(P, "[65,66,67,0]", "ABC\000"), - - unlink(P), - exit(P, die), - ok. - -print(Port, TermString, Term) -> - Length = length(TermString), - {Length, TermString} = print(Port, Term). - -%% This function uses the erl_print_term() function in erl_interface -%% to print a term. -%% Returns: {NumChars, Chars} - -print(Port, Term) -> - Bin = term_to_binary(Term), - Size = size(Bin), - Port ! {self(), {command, [Size div 256, Size rem 256, Bin]}}, - collect_line(Port, []). - -collect_line(Port, Result) -> - receive - {Port, {data, Data}} -> - case lists:reverse(Data) of - [$\n|Rest] -> - collect_line1(Rest++Result, []); - Chars -> - collect_line(Port, Chars++Result) - end - after 5000 -> - ct:fail("No response from C program") - end. - -collect_line1([$\r|Rest], Result) -> - {list_to_integer(Result), lists:reverse(Rest)}; -collect_line1([C|Rest], Result) -> - collect_line1(Rest, [C|Result]). - -%% Test case submitted by Per Lundgren, ERV. - -high_chaparal(Config) when is_list(Config) -> - P = runner:start(Config, ?high_chaparal), - {term, [hello, world]} = get_term(P), - runner:recv_eot(P), - ok. - -%% OTP-7448 -broken_data(Config) when is_list(Config) -> - P = runner:start(Config, ?broken_data), - runner:recv_eot(P), - ok. - -%% This calls a C function with one parameter and returns the result. - -call_erl_function(Port, Term) -> - runner:send_term(Port, Term), - case get_term(Port) of - {term, Result} -> Result; - 'NULL' -> 'NULL' - end. - -print_term(Config) when is_list(Config) -> - filename:join(proplists:get_value(data_dir, Config), "print_term"). - - - -%%% We receive a ref from the cnode, and expect it to be a long ref. -%%% We also send a ref we created ourselves, and expect to get it -%%% back, without having been mutated into short form. We must take -%%% care then to check the actual returned ref, and not the original -%%% one, which is equal to it. - -%% Tests involving cnode: sends a long ref from a cnode to us -cnode_1(Config) when is_list(Config) -> - Cnode = filename:join(proplists:get_value(data_dir, Config), "cnode"), - register(mip, self()), - spawn_link(?MODULE, start_cnode, [Cnode]), - Ref1 = get_ref(), - io:format("Ref1 ~p~n", [Ref1]), - check_ref(Ref1), - Ref2 = make_ref(), - Pid = receive - Msg -> Msg %% pid - end, - Fun1 = fun(X) -> {Pid, X} end, % sneak in a fun test here - %Fun1 = {wait_with_funs, new_dist_format}, - Term = {Ref2, Fun1, {1,2,3,4,5,6,7,8,9,10}}, - %% A term which will overflow the original buffer used in 'cnode'. - Pid ! Term, - receive - Term2 -> - io:format("received ~p~n", [Term2]), - case Term2 of - Term -> - {Ref22,_,_} = Term2, - check_ref(Ref22); - X -> - ct:fail({receive1,X}) - end - after 5000 -> - ct:fail(receive1) - end, - receive - Pid -> - ok; - Y -> - ct:fail({receive1,Y}) - after 5000 -> - ct:fail(receive2) - end, - io:format("ref = ~p~n", [Ref1]), - check_ref(Ref1), - ok. - -check_ref(Ref) -> - case bin_ext_type(Ref) of - 101 -> - ct:fail(oldref); - 114 -> - ok; - Type -> - ct:fail({type, Type}) - end. - -bin_ext_type(T) -> - [131, Type | _] = binary_to_list(term_to_binary(T)), - Type. - -get_ref() -> - receive - X when is_reference(X) -> - X - after 5000 -> - ct:fail({cnode, timeout}) - end. - -start_cnode(Cnode) -> - open_port({spawn, Cnode ++ " " ++ atom_to_list(erlang:get_cookie())}, []), - rec_cnode(). - -rec_cnode() -> - receive - X -> - io:format("from cnode: ~p~n", [X]), - rec_cnode() - end. - -nc2vinfo(Pid) when is_pid(Pid) -> - [_NodeStr, NumberStr, SerialStr] - = string:tokens(pid_to_list(Pid), "<.>"), - Number = list_to_integer(NumberStr), - Serial = list_to_integer(SerialStr), - {pid, node(Pid), Number, Serial}; -nc2vinfo(Port) when is_port(Port) -> - ["#Port", _NodeStr, NumberStr] - = string:tokens(erlang:port_to_list(Port), "<.>"), - Number = list_to_integer(NumberStr), - {port, node(Port), Number}; -nc2vinfo(Ref) when is_reference(Ref) -> - ["#Ref", _NodeStr | NumStrList] - = string:tokens(erlang:ref_to_list(Ref), "<.>"), - {Len, RevNumList} = lists:foldl(fun ("0", {N, []}) -> - {N+1, []}; - (IStr, {N, Is}) -> - {N+1, - [list_to_integer(IStr)|Is]} - end, - {0, []}, - NumStrList), - {ref, node(Ref), Len, lists:reverse(RevNumList)}; -nc2vinfo(Other) -> - {badarg, Other}. diff --git a/lib/erl_interface/test/erl_eterm_SUITE_data/Makefile.first b/lib/erl_interface/test/erl_eterm_SUITE_data/Makefile.first deleted file mode 100644 index 0ea872ef49..0000000000 --- a/lib/erl_interface/test/erl_eterm_SUITE_data/Makefile.first +++ /dev/null @@ -1,22 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2000-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -eterm_test_decl.c: eterm_test.c - erl -noinput -pa ../all_SUITE_data -s init_tc run eterm_test -s erlang halt diff --git a/lib/erl_interface/test/erl_eterm_SUITE_data/Makefile.src b/lib/erl_interface/test/erl_eterm_SUITE_data/Makefile.src deleted file mode 100644 index 4b1ddf77b6..0000000000 --- a/lib/erl_interface/test/erl_eterm_SUITE_data/Makefile.src +++ /dev/null @@ -1,50 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 1997-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -include @erl_interface_mk_include@ - -CC0 = @CC@ -CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" -LD = @LD@ -LIBERL = @erl_interface_lib@ -LIBEI = @erl_interface_eilib@ -LIBFLAGS = ../all_SUITE_data/runner@obj@ \ - $(LIBERL) $(LIBEI) @erl_interface_sock_libs@ @LIBS@ \ - @erl_interface_threadlib@ -CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data -ETERM_OBJS = eterm_test@obj@ eterm_test_decl@obj@ -CNODE_OBJS = cnode@obj@ -PRINT_OBJS = print_term@obj@ -EXE_FILES = eterm_test@exe@ print_term@exe@ cnode@exe@ - -all: $(EXE_FILES) - -eterm_test@exe@: $(ETERM_OBJS) $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(ETERM_OBJS) $(LIBFLAGS) - -cnode@exe@: $(CNODE_OBJS) $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(CNODE_OBJS) $(LIBFLAGS) - -print_term@exe@: print_term@obj@ $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(PRINT_OBJS) $(LIBFLAGS) - -clean: - $(RM) $(ETERM_OBJS) $(CNODE_OBJS) $(PRINT_OBJS) - $(RM) $(EXE_FILES) diff --git a/lib/erl_interface/test/erl_eterm_SUITE_data/cnode.c b/lib/erl_interface/test/erl_eterm_SUITE_data/cnode.c deleted file mode 100644 index b87feb9dfc..0000000000 --- a/lib/erl_interface/test/erl_eterm_SUITE_data/cnode.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1999-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include "ei.h" -#include "erl_interface.h" - -#define MSGSIZE 13 - -#define SELF(fd) erl_mk_pid(erl_thisnodename(),fd,0,erl_thiscreation()) - -#ifdef VXWORKS -#define MAIN cnode -#else -#define MAIN main -#endif - -/* FIXME uses mix och ei and erl_interface */ - -/* - A small cnode. - To be called from the test case erl_eterm_SUITE:cnode_1. - - 1) Set up connection to node 'test_server' on the same host. - All sends are done to a registered process named 'mip'. - 2) Create a long ref and send it. - 3) Create a pid for ourselves and send it. - 4) Receive a message. - 5) Send back the message part of the message. - 6) Send back the 'to' part of the message. - 7) Exit. -*/ - -MAIN(int argc, char **argv) - -{ - unsigned char *msgbufp; - int msgsize; - ErlMessage msg; - char msgbuf[MSGSIZE]; - char buf[100]; - char buf1[100]; - char buf2[100]; - int ix; - int s; - int fd; - char node[80]; - char server[80]; - char host[80]; - int number; - ETERM *ref, *ref1, *ref2; - FILE *dfile = fopen("cnode_debug_printout", "w"); - - erl_init(NULL, 0); - - number = 1; - if (argc >= 2) { - s = erl_connect_init(number, argv[1], 0); - } else { - s = erl_connect_init(number, (char *) 0, 0); - } - gethostname(host, sizeof(host)); - sprintf(node, "c%d@%s", number, host); - - fprintf(dfile, "s = %d\n", s); fflush(dfile); - - sprintf(server, "test_server@%s", host); - fd = erl_connect(server); - fprintf(dfile, "fd = %d\n", fd); - -/* fprintf(dfile, "dist = %d\n", erl_distversion(fd)); */ - -#if 1 - ref = erl_mk_long_ref(node, 4711, 113, 98, 0); -#else - ref = erl_mk_ref(node, 4711, 0); -#endif - fprintf(dfile, "ref = %p\n", ref); fflush(dfile); - - s = erl_reg_send(fd, "mip", ref); - fprintf(dfile, "s = %d\n", s); fflush(dfile); - - { - ETERM* emsg; - emsg = SELF(fd); - fprintf(dfile, "pid = %p\n", emsg); fflush(dfile); - s = erl_reg_send(fd,"mip",emsg); - fprintf(dfile, "s2 = %d\n", s); fflush(dfile); - erl_free_term(emsg); - } - - msgsize = 4; - msgbufp = (unsigned char *) malloc(msgsize); - - do { -#if 0 - s = erl_receive_msg(fd, msgbuf, MSGSIZE, &msg); -#else - s = erl_xreceive_msg(fd, &msgbufp, &msgsize, &msg); -#endif - switch (s) { - case ERL_TICK: - fprintf(dfile, "tick\n"); - break; - case ERL_ERROR: - fprintf(dfile, "error: %s (%d)\n", strerror(erl_errno), erl_errno); - break; - case ERL_MSG: - fprintf(dfile, "msg %d\n", msgsize); - break; - default: - fprintf(dfile, "unknown result %d\n", s); - break; - } - fflush(dfile); - } while (s == ERL_TICK); - - s = erl_reg_send(fd, "mip", msg.msg); - fprintf(dfile, "s = %d\n", s); fflush(dfile); - s = erl_reg_send(fd, "mip", msg.to); - fprintf(dfile, "s = %d\n", s); fflush(dfile); -#if 0 - /* from = NULL! */ - s = erl_reg_send(fd, "mip", msg.from); - fprintf(dfile, "s = %d\n", s); fflush(dfile); -#endif - -#if 0 - /* Unused code which tests refs in some ways. */ - ix = 0; - s = ei_encode_term(buf, &ix, ref); - printf ("ei encode = %d, ix = %d\n", s, ix); - - /* Compare old and new ref equal */ - ref1 = erl_mk_long_ref(node, 4711, 113, 98, 0); - ref2 = erl_mk_ref(node, 4711, 0); - s = erl_encode(ref1, buf1); - fprintf(dfile, "enc1 s = %d\n", s); fflush(dfile); - s = erl_encode(ref2, buf2); - fprintf(dfile, "enc2 s = %d\n", s); fflush(dfile); - s = erl_compare_ext(buf1, buf2); - fprintf(dfile, "comp s = %d\n", s); fflush(dfile); - - /* Compare, in another way */ - s = erl_match(ref1, ref2); - fprintf(dfile, "match s = %d\n", s); fflush(dfile); -#endif - - fclose(dfile); - - erl_close_connection(fd); - - return 0; -} diff --git a/lib/erl_interface/test/erl_eterm_SUITE_data/eterm_test.c b/lib/erl_interface/test/erl_eterm_SUITE_data/eterm_test.c deleted file mode 100644 index d97f218a26..0000000000 --- a/lib/erl_interface/test/erl_eterm_SUITE_data/eterm_test.c +++ /dev/null @@ -1,1604 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -/* - * Purpose: Tests the functions in erl_eterm.c and erl_malloc.c. - * Author: Bjorn Gustavsson - * - * See the erl_eterm_SUITE.erl file for a "table of contents". - */ - -#include <stdio.h> -#include <string.h> - -#include "runner.h" - -/* - * Find out which version of erl_interface we are using. - */ - -#ifdef ERL_IS_STRING -#undef NEW_ERL_INTERFACE -#else -#define NEW_ERL_INTERFACE -#endif - -void dump_term (FILE *fp, ETERM *t); - -static ETERM* all_types(); - -/*********************************************************************** - * - * 1. B a s i c t e s t s - * - ***********************************************************************/ - -/* - * Sends a list contaning all data types to the Erlang side. - */ - -TESTCASE(build_terms) -{ - ETERM* t; - - erl_init(NULL, 0); - t = all_types(); - send_term(t); - report(1); -} - -static int abs_and_sign(ETERM* v, unsigned long long* av, int* sign) -{ - long long sv; - switch (ERL_TYPE(v)) { - case ERL_INTEGER: sv = ERL_INT_VALUE(v); break; - case ERL_U_INTEGER: *av = ERL_INT_UVALUE(v); *sign = 0; return 1; - case ERL_LONGLONG: sv = ERL_LL_VALUE(v); break; - case ERL_U_LONGLONG: *av = ERL_LL_UVALUE(v); *sign = 0; return 1; - default: return 0; - } - if (sv < 0) { - *av = -sv; - *sign = 1; - } - else { - *av = sv; - *sign = 0; - } - return 1; -} - -/* Shouldn't erl_match() cope with this? -*/ -static int eq_ints(ETERM* a, ETERM* b) -{ - unsigned long long a_abs, b_abs; - int a_sign, b_sign; - return abs_and_sign(a, &a_abs, &a_sign) && abs_and_sign(b, &b_abs, &b_sign) - && (a_abs == b_abs) && (a_sign == b_sign); -} - -static void encode_decode(ETERM* original, const char* text) -{ - static unsigned char encoded[16*1024]; - ETERM* new_terms; - ETERM* head; - int bytes; - int len; - - /* If a list, check the elements one by one first */ - head = erl_hd(original); - if (head != NULL) { - encode_decode(head, "CAR"); - encode_decode(erl_tl(original), "CDR"); - } - - bytes = erl_encode(original, encoded); - if (bytes == 0) { - fail("failed to encode terms"); - } - else if (bytes > sizeof(encoded)) { - fail("encoded terms buffer overflow"); - } - else if (bytes != (len=erl_term_len(original))) { - fprintf(stderr, "bytes(%d) != len(%d) for term ", bytes, len); - erl_print_term(stderr, original); - fprintf(stderr, " [%s]\r\n", text); - fail("erl_encode and erl_term_len do not agree"); - } - else if ((new_terms = erl_decode(encoded)) == NULL) { - fail("failed to decode terms"); - } - else if (!erl_match(original, new_terms) && !eq_ints(original, new_terms)) { - erl_print_term(stderr, original); - fprintf(stderr, "(%i) != (%i)", ERL_TYPE(original), ERL_TYPE(new_terms)); - erl_print_term(stderr, new_terms); - fprintf(stderr, " [%s]\r\n", text); - fail("decoded terms didn't match original"); - } - erl_free_term(original); - erl_free_term(new_terms); -} -/* - * Converts an Erlang term to the external term format and back again. - */ - -TESTCASE(round_trip_conversion) -{ - int n, i; - - erl_init(NULL, 0); - encode_decode(all_types(), "ALL"); - - { - int v; - for (v = 8, n = 0; n < (sizeof(v)*8-4-1); v <<= 1, n++) { - for (i=-4; i<4; i++) { - encode_decode(erl_mk_int(v+i), "INT"); - encode_decode(erl_mk_int(-(v+i)), "NEG INT"); - } - } - } - { - unsigned int v; - for (v = 8; v; v <<= 1) { - for (i=-4; i<4; i++) { - encode_decode(erl_mk_uint(v+i), "UINT"); - } - } - } - { - long long v; - for (v = 8, n = 0; n < (sizeof(v)*8-4-1); v <<= 1, n++) { - for (i=-4; i<4; i++) { - encode_decode(erl_mk_longlong(v+i), "LONGLONG"); - encode_decode(erl_mk_longlong(-(v+i)), "NEG LONGLONG"); - } - } - } - { - unsigned long long v; - for (v = 8; v; v <<= 1) { - for (i=-4; i<4; i++) { - encode_decode(erl_mk_ulonglong(v+i), "ULONGLONG"); - } - } - } - - report(1); -} - -/* - * Decodes data from the Erlang side and verifies. - */ - -TESTCASE(decode_terms) -{ - ETERM* terms; - char* message; - - erl_init(NULL, 0); - terms = get_term(); - if (terms == NULL) { - fail("unexpected end of file"); - } else { - ETERM* all; - ETERM* p; - ETERM* t; - int i; - - all = p = all_types(); - t = terms; - - /* - * XXX For now, skip the reference, pid, and port, because - * the match will fail. Must write code here to do some other - * validating. - */ - - for (i=0; i<6; i++) { - - p = erl_tl(p); - t = erl_tl(t); - erl_free_term(p); - erl_free_term(t); - - } - - /* - * Match the tail of the lists. - */ - - if (!erl_match(p, t)) - { - fail("Received terms didn't match expected"); - } - erl_free_term(all); - erl_free_term(terms); - report(1); - } -} - -/* - * Decodes a float from the Erlang side and verifies. - */ - -TESTCASE(decode_float) -{ - ETERM* afnum; - ETERM* efnum; - int result; - - erl_init(NULL, 0); - afnum = get_term(); - efnum = erl_mk_float(3.1415); - result = erl_match(efnum, afnum); - erl_free_term(afnum); - erl_free_term(efnum); - report(result); -} - -/* - * Tests the erl_free_compound() function. - */ - -TESTCASE(t_erl_free_compound) -{ - ETERM* t; - - erl_init(NULL, 0); - - t = all_types(); - erl_free_compound(t); - report(1); -} - - -/*********************************************************************** - * - * 2. C o n s t r u c t i n g t e r m s - * - ***********************************************************************/ - -/* - * Makes various integers, and sends them to Erlang for verification. - */ - -TESTCASE(t_erl_mk_int) -{ -#define SEND_INT(i) \ - do { \ - ETERM* t = erl_mk_int(i); \ - send_term(t); \ - } while (0); - - erl_init(NULL, 0); - - SEND_INT(0); - SEND_INT(127); - SEND_INT(128); - SEND_INT(255); - SEND_INT(256); - - SEND_INT(0xFFFF); - SEND_INT(0x10000); - - SEND_INT(0x07FFFFFF); - SEND_INT(0x0FFFFFFF); - SEND_INT(0x1FFFFFFF); - SEND_INT(0x3FFFFFFF); - SEND_INT(0x7FFFFFFF); - - SEND_INT(0x08000000); - SEND_INT(0x10000000); - SEND_INT(0x20000000); - SEND_INT(0x40000000); - - SEND_INT(-0x07FFFFFF); - SEND_INT(-0x0FFFFFFF); - SEND_INT(-0x1FFFFFFF); - SEND_INT(-0x3FFFFFFF); - SEND_INT(-0x7FFFFFFF); - - SEND_INT(-0x08000000); - SEND_INT(-0x10000000); - SEND_INT(-0x20000000); - SEND_INT(-0x40000000); - - SEND_INT(-0x08000001); - SEND_INT(-0x10000001); - SEND_INT(-0x20000001); - SEND_INT(-0x40000001); - - SEND_INT(-0x08000002); - SEND_INT(-0x10000002); - SEND_INT(-0x20000002); - SEND_INT(-0x40000002); - - SEND_INT(-1999999999); - SEND_INT(-2000000000); - SEND_INT(-2000000001); - - report(1); -} - - -/* - * Makes lists of various sizes, and sends them to Erlang for verification. - */ - -TESTCASE(t_erl_mk_list) -{ - ETERM* a[4]; - - erl_init(NULL, 0); - - /* - * Empty list. - */ - - send_term(erl_mk_list(a, 0)); - - /* - * One element: [abc] - */ - - a[0] = erl_mk_atom("abc"); - send_term(erl_mk_list(a, 1)); - erl_free_term(a[0]); - - /* - * Two elements: [abcdef, 42]. - */ - - a[0] = erl_mk_atom("abcdef"); - a[1] = erl_mk_int(42); - send_term(erl_mk_list(a, 2)); - erl_free_term(a[0]); - erl_free_term(a[1]); - - /* - * Four elements. - */ - - a[0] = erl_mk_float(0.0); - a[1] = erl_mk_int(23); - a[2] = erl_mk_empty_list(); - a[3] = erl_mk_float(3.1415); - send_term(erl_mk_list(a, 4)); - erl_free_term(a[0]); - erl_free_term(a[1]); - erl_free_term(a[2]); - erl_free_term(a[3]); - - report(1); -} - -/* - * A basic test of erl_copy_term(). - */ - -TESTCASE(basic_copy) -{ - ETERM* original; - ETERM* copy; - int result; - - erl_init(NULL, 0); - original = all_types(); - copy = erl_copy_term(original); - if (copy == NULL) { - fail("erl_copy_term() failed"); - } else if (!erl_match(original, copy)) - { - fail("copy doesn't match original"); - } - - erl_free_term(original); - erl_free_term(copy); - report(1); -} - - -/* - * A basic test of erl_mk_atom(). - */ - -TESTCASE(t_erl_mk_atom) -{ - erl_init(NULL, 0); - - send_term(erl_mk_atom("madonna")); - send_term(erl_mk_atom("Madonna")); - send_term(erl_mk_atom("mad donna")); - send_term(erl_mk_atom("_madonna_")); - send_term(erl_mk_atom("/home/madonna/tour_plan")); - send_term(erl_mk_atom("http://www.madonna.com/tour_plan")); - send_term(erl_mk_atom("\'madonna\'")); - send_term(erl_mk_atom("\"madonna\"")); - send_term(erl_mk_atom("\\madonna\\")); - send_term(erl_mk_atom("{madonna,21,'mad donna',12}")); - - report(1); -} - - -/* - * A basic test of erl_mk_binary(). - */ - -TESTCASE(t_erl_mk_binary) -{ - - char* string; - erl_init(NULL, 0); - - string = "{madonna,21,'mad donna',1234.567.890, !#$%&/()=?+-@, \" \\}"; - send_term(erl_mk_binary(string,strlen(string))); - - report(1); -} - - -/* - * A basic test of erl_mk_empty_list(). - */ - -TESTCASE(t_erl_mk_empty_list) -{ - erl_init(NULL, 0); - - send_term(erl_mk_empty_list()); - report(1); -} - - -/* - * A basic test of erl_mk_float(). - */ - -TESTCASE(t_erl_mk_float) -{ - ETERM* arr[6]; - ETERM* emsg; - - erl_init(NULL, 0); - - arr[0] = erl_mk_float(3.1415); - arr[1] = erl_mk_float(1.999999); - arr[2] = erl_mk_float(2.000000); - arr[3] = erl_mk_float(2.000001); - arr[4] = erl_mk_float(2.000002); - arr[5] = erl_mk_float(12345.67890); - emsg = (erl_mk_tuple(arr,6)); - - send_term(emsg); - - erl_free_array(arr,6); - /* emsg already freed by send_term() */ - /* erl_free_term(emsg); */ - - report(1); -} - - -/* - * A basic test of erl_mk_pid(). - */ - -TESTCASE(t_erl_mk_pid) -{ - erl_init(NULL, 0); - - send_term(erl_mk_pid("kalle@localhost", 3, 2, 1)); - report(1); -} - -/* - * A basic test of erl_mk_pid(). - */ - -TESTCASE(t_erl_mk_xpid) -{ - erl_init(NULL, 0); - - send_term(erl_mk_pid("kalle@localhost", 32767, 8191, 1)); - report(1); -} - - -/* - * A basic test of erl_mk_port(). - */ - -TESTCASE(t_erl_mk_port) -{ - erl_init(NULL, 0); - - send_term(erl_mk_port("kalle@localhost", 4, 1)); - report(1); -} - -/* - * A basic test of erl_mk_port(). - */ - -TESTCASE(t_erl_mk_xport) -{ - erl_init(NULL, 0); - - send_term(erl_mk_port("kalle@localhost", 268435455, 1)); - report(1); -} - -/* - * A basic test of erl_mk_ref(). - */ - -TESTCASE(t_erl_mk_ref) -{ - erl_init(NULL, 0); - - send_term(erl_mk_ref("kalle@localhost", 6, 1)); - report(1); -} - -/* - * A basic test of erl_mk_long_ref(). - */ - - -TESTCASE(t_erl_mk_long_ref) -{ - erl_init(NULL, 0); - - send_term(erl_mk_long_ref("kalle@localhost", - 4294967295, 4294967295, 262143, - 1)); - report(1); -} - - -/* - * A basic test of erl_mk_string(). - */ - -TESTCASE(t_erl_mk_string) -{ - - erl_init(NULL, 0); - - send_term(erl_mk_string("madonna")); - send_term(erl_mk_string("Madonna")); - send_term(erl_mk_string("mad donna")); - send_term(erl_mk_string("_madonna_")); - send_term(erl_mk_string("/home/madonna/tour_plan")); - send_term(erl_mk_string("http://www.madonna.com/tour_plan")); - send_term(erl_mk_string("\'madonna\'")); - send_term(erl_mk_string("\"madonna\"")); - send_term(erl_mk_string("\\madonna\\")); - send_term(erl_mk_string("{madonna,21,'mad donna',12}")); - - report(1); -} - - -/* - * A basic test of erl_mk_estring(). - */ - -TESTCASE(t_erl_mk_estring) -{ - char* string; - erl_init(NULL, 0); - - string = "madonna"; - send_term(erl_mk_estring(string,strlen(string))); - string = "Madonna"; - send_term(erl_mk_estring(string,strlen(string))); - string = "mad donna"; - send_term(erl_mk_estring(string,strlen(string))); - string = "_madonna_"; - send_term(erl_mk_estring(string,strlen(string))); - string = "/home/madonna/tour_plan"; - send_term(erl_mk_estring(string,strlen(string))); - string = "http://www.madonna.com/tour_plan"; - send_term(erl_mk_estring(string,strlen(string))); - string = "\'madonna\'"; - send_term(erl_mk_estring(string,strlen(string))); - string = "\"madonna\""; - send_term(erl_mk_estring(string,strlen(string))); - string = "\\madonna\\"; - send_term(erl_mk_estring(string,strlen(string))); - string = "{madonna,21,'mad donna',12}"; - send_term(erl_mk_estring(string,strlen(string))); - - report(1); -} - - -/* - * A basic test of erl_mk_tuple(). - */ - -TESTCASE(t_erl_mk_tuple) -{ - ETERM* arr[4]; - ETERM* arr2[2]; - ETERM* arr3[2]; - ETERM* arr4[2]; - - erl_init(NULL, 0); - - /* {madonna,21,'mad donna',12} */ - arr[0] = erl_mk_atom("madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_atom("mad donna"); - arr[3] = erl_mk_int(12); - - send_term(erl_mk_tuple(arr,4)); - - erl_free_array(arr,4); - - - /* {'Madonna',21,{children,{"Isabella",2}},{'home page',"http://www.madonna.com/"} */ - arr4[0] = erl_mk_atom("home page"); - arr4[1] = erl_mk_string("http://www.madonna.com/"); - - arr3[0] = erl_mk_string("Isabella"); - arr3[1] = erl_mk_int(2); - - arr2[0] = erl_mk_atom("children"); - arr2[1] = erl_mk_tuple(arr3,2); - - arr[0] = erl_mk_atom("Madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_tuple(arr2,2); - arr[3] = erl_mk_tuple(arr4,2); - - send_term(erl_mk_tuple(arr,4)); - - erl_free_array(arr,4); - erl_free_array(arr2,2); - erl_free_array(arr3,2); - erl_free_array(arr4,2); - - - report(1); -} - - -/* - * A basic test of erl_mk_uint(). - */ - -TESTCASE(t_erl_mk_uint) -{ - unsigned i; - - erl_init(NULL, 0); - - send_term(erl_mk_uint(54321)); - i = 2147483647; - send_term(erl_mk_uint(i)); - send_term(erl_mk_uint(i+1)); - send_term(erl_mk_uint(i+2)); - send_term(erl_mk_uint(i+3)); - send_term(erl_mk_uint(i+i+1)); - - report(1); -} - - -/* - * A basic test of erl_mk_var(). - */ - -TESTCASE(t_erl_mk_var) -{ - ETERM* mk_var; - ETERM* term; - ETERM* term2; - ETERM* arr[4]; - ETERM* arr_term[2]; - ETERM* mk_var_tuple; - ETERM* term_tuple; - - erl_init(NULL, 0); - - - /* match unbound/bound variable against an integer */ - term = erl_mk_int(17); - term2 = erl_mk_int(2); - mk_var = erl_mk_var("New_var"); - send_term(erl_mk_int(erl_match(mk_var, term))); /* should be ok */ - send_term(erl_mk_int(erl_match(mk_var, term2))); /* should fail */ - send_term(erl_mk_int(erl_match(mk_var, term))); /* should be ok */ - send_term(erl_mk_int(erl_match(mk_var, term2))); /* should fail */ - erl_free_term(mk_var); - erl_free_term(term); - erl_free_term(term2); - - /* match unbound variable against a tuple */ - arr[0] = erl_mk_atom("madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_atom("mad donna"); - arr[3] = erl_mk_int(12); - mk_var = erl_mk_var("New_var"); - term = erl_mk_tuple(arr,4); - send_term(erl_mk_int(erl_match(mk_var, term))); /* should be ok */ - erl_free_term(mk_var); - erl_free_term(term); - erl_free_array(arr,4); - - - /* match (twice) unbound variable against an incorrect tuple */ - arr[0] = erl_mk_var("New_var"); - arr[1] = erl_mk_var("New_var"); - arr_term[0] = erl_mk_int(17); - arr_term[1] = erl_mk_int(27); - mk_var_tuple = erl_mk_tuple(arr,2); - term_tuple = erl_mk_tuple(arr_term,2); - send_term(erl_mk_int(erl_match(mk_var_tuple, term_tuple))); /* should fail */ - erl_free_array(arr,2); - erl_free_array(arr_term,2); - erl_free_term(mk_var_tuple); - erl_free_term(term_tuple); - - - /* match (twice) unbound variable against a correct tuple */ - arr[0] = erl_mk_var("New_var"); - arr[1] = erl_mk_var("New_var"); - arr_term[0] = erl_mk_int(17); - arr_term[1] = erl_mk_int(17); - mk_var_tuple = erl_mk_tuple(arr,2); - term_tuple = erl_mk_tuple(arr_term,2); - send_term(erl_mk_int(erl_match(mk_var_tuple, term_tuple))); /* should be ok */ - erl_free_array(arr,2); - erl_free_array(arr_term,2); - erl_free_term(mk_var_tuple); - erl_free_term(term_tuple); - - report(1); -} - - -/* - * A basic test of erl_size(). - */ - -TESTCASE(t_erl_size) -{ - ETERM* arr[4]; - ETERM* tuple; - ETERM* bin; - char* string; - - erl_init(NULL, 0); - - /* size of a tuple */ - tuple = erl_format("{}"); - send_term(erl_mk_int(erl_size(tuple))); - erl_free_term(tuple); - - arr[0] = erl_mk_atom("madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_atom("mad donna"); - arr[3] = erl_mk_int(12); - tuple = erl_mk_tuple(arr,4); - - send_term(erl_mk_int(erl_size(tuple))); - - erl_free_array(arr,4); - erl_free_term(tuple); - - /* size of a binary */ - string = ""; - bin = erl_mk_binary(string,strlen(string)); - send_term(erl_mk_int(erl_size(bin))); - erl_free_term(bin); - - string = "{madonna,21,'mad donna',12}"; - bin = erl_mk_binary(string,strlen(string)); - send_term(erl_mk_int(erl_size(bin))); - erl_free_term(bin); - - report(1); -} - - -/* - * A basic test of erl_var_content(). - */ - -TESTCASE(t_erl_var_content) -{ - ETERM* mk_var; - ETERM* term; - ETERM* tuple; - ETERM* list; - ETERM* a; - ETERM* b; - ETERM* arr[4]; - ETERM* arr2[2]; - ETERM* arr3[2]; - ETERM* arr4[2]; - - erl_init(NULL, 0); - - term = erl_mk_int(17); - mk_var = erl_mk_var("Var"); - - /* unbound, should return NULL */ - if (erl_var_content(mk_var,"Var") != NULL) - fail("t_erl_var_content() failed"); - - erl_match(mk_var, term); - send_term(erl_var_content(mk_var,"Var")); /* should return 17 */ - - /* integer, should return NULL */ - if (erl_var_content(term,"Var") != NULL) - fail("t_erl_var_content() failed"); - - /* unknown variable, should return NULL */ - if (erl_var_content(mk_var,"Unknown_Var") != NULL) - fail("t_erl_var_content() failed"); - - erl_free_term(mk_var); - erl_free_term(term); - - /* {'Madonna',21,{children,{"Name","Age"}},{"Home_page","Tel_no"}} */ - arr4[0] = erl_mk_var("Home_page"); - arr4[1] = erl_mk_var("Tel_no"); - a = erl_mk_string("http://www.madonna.com"); - erl_match(arr4[0], a); - - arr3[0] = erl_mk_var("Name"); - arr3[1] = erl_mk_var("Age"); - b = erl_mk_int(2); - erl_match(arr3[1], b); - - arr2[0] = erl_mk_atom("children"); - arr2[1] = erl_mk_tuple(arr3,2); - - arr[0] = erl_mk_atom("Madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_tuple(arr2,2); - arr[3] = erl_mk_tuple(arr4,2); - - tuple = erl_mk_tuple(arr,4); - - /* should return "http://www.madonna.com" */ - send_term(erl_var_content(tuple,"Home_page")); - - /* unbound, should return NULL */ - if (erl_var_content(tuple,"Tel_no") != NULL) - fail("t_erl_var_content() failed"); - - /* unbound, should return NULL */ - if (erl_var_content(tuple,"Name") != NULL) - fail("t_erl_var_content() failed"); - - /* should return 2 */ - send_term(erl_var_content(tuple,"Age")); - - erl_free_array(arr,4); - erl_free_array(arr2,2); - erl_free_array(arr3,2); - erl_free_array(arr4,2); - erl_free_term(tuple); - erl_free_term(a); - erl_free_term(b); - - - /* [] */ - list = erl_mk_empty_list(); - if (erl_var_content(list,"Tel_no") != NULL) - fail("t_erl_var_content() failed"); - erl_free_term(list); - - - /* ['Madonna',[],{children,{"Name","Age"}},{"Home_page","Tel_no"}] */ - arr4[0] = erl_mk_var("Home_page"); - arr4[1] = erl_mk_var("Tel_no"); - a = erl_mk_string("http://www.madonna.com"); - erl_match(arr4[0], a); - - arr3[0] = erl_mk_var("Name"); - arr3[1] = erl_mk_var("Age"); - b = erl_mk_int(2); - erl_match(arr3[1], b); - - arr2[0] = erl_mk_atom("children"); - arr2[1] = erl_mk_tuple(arr3,2); - - arr[0] = erl_mk_atom("Madonna"); - arr[1] = erl_mk_empty_list(); - arr[2] = erl_mk_tuple(arr2,2); - arr[3] = erl_mk_tuple(arr4,2); - - list = erl_mk_list(arr,4); - - /* should return "http://www.madonna.com" */ - send_term(erl_var_content(list,"Home_page")); - - /* unbound, should return NULL */ - if (erl_var_content(list,"Tel_no") != NULL) - fail("t_erl_var_content() failed"); - - /* unbound, should return NULL */ - if (erl_var_content(list,"Name") != NULL) - fail("t_erl_var_content() failed"); - - /* should return 2 */ - send_term(erl_var_content(list,"Age")); - - erl_free_array(arr,4); - erl_free_array(arr2,2); - erl_free_array(arr3,2); - erl_free_array(arr4,2); - erl_free_term(list); - erl_free_term(a); - erl_free_term(b); - - report(1); -} - - -/* - * A basic test of erl_element(). - */ - -TESTCASE(t_erl_element) -{ - ETERM* arr[4]; - ETERM* arr2[2]; - ETERM* arr3[2]; - ETERM* arr4[2]; - ETERM* tuple; - - erl_init(NULL, 0); - - arr[0] = erl_mk_atom("madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_atom("mad donna"); - arr[3] = erl_mk_int(12); - tuple = erl_mk_tuple(arr,4); - - send_term(erl_element(1,tuple)); - send_term(erl_element(2,tuple)); - send_term(erl_element(3,tuple)); - send_term(erl_element(4,tuple)); - - erl_free_array(arr,4); - erl_free_term(tuple); - - /* {'Madonna',21,{children,{"Isabella",2}},{'home page',"http://www.madonna.com/"} */ - arr4[0] = erl_mk_atom("home page"); - arr4[1] = erl_mk_string("http://www.madonna.com/"); - - arr3[0] = erl_mk_string("Isabella"); - arr3[1] = erl_mk_int(2); - - arr2[0] = erl_mk_atom("children"); - arr2[1] = erl_mk_tuple(arr3,2); - - arr[0] = erl_mk_atom("Madonna"); - arr[1] = erl_mk_int(21); - arr[2] = erl_mk_tuple(arr2,2); - arr[3] = erl_mk_tuple(arr4,2); - - tuple = erl_mk_tuple(arr,4); - send_term(erl_element(1,tuple)); - send_term(erl_element(2,tuple)); - send_term(erl_element(3,tuple)); - send_term(erl_element(4,tuple)); - - erl_free_term(tuple); - erl_free_array(arr,4); - erl_free_array(arr2,2); - erl_free_array(arr3,2); - erl_free_array(arr4,2); - - report(1); -} - - -/* - * A basic test of erl_cons(). - */ - -TESTCASE(t_erl_cons) -{ - ETERM* list; - ETERM* anAtom; - ETERM* anInt; - - erl_init(NULL, 0); - - anAtom = erl_mk_atom("madonna"); - anInt = erl_mk_int(21); - list = erl_mk_empty_list(); - list = erl_cons(anInt, list); - send_term(erl_cons(anAtom, list)); - - erl_free_term(anAtom); - erl_free_term(anInt); - erl_free_compound(list); - - report(1); -} - - - - -/*********************************************************************** - * - * 3. E x t r a c t i n g & i n f o f u n c t i o n s - * - ***********************************************************************/ - -/* - * Calculates the length of each list sent to it and sends back the result. - */ - -TESTCASE(t_erl_length) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { - ETERM* len_term; - - len_term = erl_mk_int(erl_length(term)); - erl_free_term(term); - send_term(len_term); - } - } -} - -/* - * Gets the head of each term and sends the result back. - */ - -TESTCASE(t_erl_hd) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { - ETERM* head; - - head = erl_hd(term); - send_term(head); - erl_free_term(term); - } - } -} - -/* - * Gets the tail of each term and sends the result back. - */ - -TESTCASE(t_erl_tl) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { - ETERM* tail; - - tail = erl_tl(term); - send_term(tail); - erl_free_term(term); - } - } -} - -/* - * Checks the type checking macros. - */ - -TESTCASE(type_checks) -{ - ETERM* t; - ETERM* atom; - - erl_init(NULL, 0); - atom = erl_mk_atom("an_atom"); - -#define TYPE_CHECK(macro, term) \ - { ETERM* t = term; \ - if (macro(t)) { \ - erl_free_term(t); \ - } else { \ - fail("Macro " #macro " failed on " #term); \ - } \ - } - - TYPE_CHECK(ERL_IS_INTEGER, erl_mk_int(0x7FFFFFFF)); -#ifdef NEW_ERL_INTERFACE - TYPE_CHECK(ERL_IS_UNSIGNED_INTEGER, erl_mk_uint(0x7FFFFFFF)); -#endif - TYPE_CHECK(ERL_IS_FLOAT, erl_mk_float(5.5)); - TYPE_CHECK(ERL_IS_ATOM, erl_mk_atom("another_atom")); - - TYPE_CHECK(ERL_IS_EMPTY_LIST, erl_mk_empty_list()); - TYPE_CHECK(!ERL_IS_EMPTY_LIST, erl_cons(atom, atom)); - -#ifdef NEW_ERL_INTERFACE - TYPE_CHECK(!ERL_IS_CONS, erl_mk_empty_list()); - TYPE_CHECK(ERL_IS_CONS, erl_cons(atom, atom)); -#endif - - TYPE_CHECK(ERL_IS_LIST, erl_mk_empty_list()); - TYPE_CHECK(ERL_IS_LIST, erl_cons(atom, atom)); - - TYPE_CHECK(ERL_IS_PID, erl_mk_pid("a@a", 42, 1, 1)); - TYPE_CHECK(ERL_IS_PORT, erl_mk_port("a@a", 42, 1)); - TYPE_CHECK(ERL_IS_REF, erl_mk_ref("a@a", 42, 1)); - - TYPE_CHECK(ERL_IS_BINARY, erl_mk_binary("a", 1)); - TYPE_CHECK(ERL_IS_TUPLE, erl_mk_tuple(&atom, 1)); -#undef TYPE_CHECK - - erl_free_term(atom); - - report(1); -} - -/* - * Checks the extractor macros. - */ - -TESTCASE(extractor_macros) -{ - ETERM* t; - - erl_init(NULL, 0); - -#ifdef NEW_ERL_INTERFACE -#define MATCH(a, b) ((a) == (b) ? 1 : fail("bad match: " #a)) -#define STR_MATCH(a, b) (strcmp((a), (b)) ? fail("bad match: " #a) : 0) - - { /* Integer */ - int anInt = 0x7FFFFFFF; - t = erl_mk_int(anInt); - MATCH(ERL_INT_VALUE(t), anInt); - MATCH(ERL_INT_UVALUE(t), anInt); - erl_free_term(t); - } - - { /* Float */ - double aFloat = 3.1415; - t = erl_mk_float(aFloat); - MATCH(ERL_FLOAT_VALUE(t), aFloat); - erl_free_term(t); - } - - { /* Atom. */ - char* aString = "nisse"; - t = erl_mk_atom(aString); - if (memcmp(ERL_ATOM_PTR(t), aString, strlen(aString)) != 0) - fail("bad match"); - MATCH(ERL_ATOM_SIZE(t), strlen(aString)); - erl_free_term(t); - } - - { /* Pid. */ - char* node = "arne@strider"; - int number = 42; - int serial = 5; - int creation = 1; - - t = erl_mk_pid(node, number, serial, creation); - STR_MATCH(ERL_PID_NODE(t), node); - MATCH(ERL_PID_NUMBER(t), number); - MATCH(ERL_PID_SERIAL(t), serial); - MATCH(ERL_PID_CREATION(t), creation); - erl_free_term(t); - } - - { /* Port. */ - char* node = "kalle@strider"; - int number = 45; - int creation = 1; - - t = erl_mk_port(node, number, creation); - STR_MATCH(ERL_PORT_NODE(t), node); - MATCH(ERL_PORT_NUMBER(t), number); - MATCH(ERL_PORT_CREATION(t), creation); - erl_free_term(t); - } - - { /* Reference. */ - char* node = "kalle@strider"; - int number = 48; - int creation = 1; - - t = erl_mk_ref(node, number, creation); - STR_MATCH(ERL_REF_NODE(t), node); - MATCH(ERL_REF_NUMBER(t), number); - MATCH(ERL_REF_CREATION(t), creation); - erl_free_term(t); - } - - { /* Tuple. */ - ETERM* arr[2]; - - arr[0] = erl_mk_int(51); - arr[1] = erl_mk_int(52); - t = erl_mk_tuple(arr, ASIZE(arr)); - MATCH(ERL_TUPLE_SIZE(t), ASIZE(arr)); - MATCH(ERL_TUPLE_ELEMENT(t, 0), arr[0]); - MATCH(ERL_TUPLE_ELEMENT(t, 1), arr[1]); - erl_free_array(arr, ASIZE(arr)); - erl_free_term(t); - } - - { /* Binary. */ - static char bin[] = {1, 2, 3, 0, 4, 5}; - - t = erl_mk_binary(bin, ASIZE(bin)); - MATCH(ERL_BIN_SIZE(t), ASIZE(bin)); - if (memcmp(ERL_BIN_PTR(t), bin, ASIZE(bin)) != 0) - fail("bad match"); - erl_free_term(t); - } - - { - ETERM* head = erl_mk_atom("head"); - ETERM* tail = erl_mk_atom("tail"); - - t = erl_cons(head, tail); - MATCH(ERL_CONS_HEAD(t), head); - MATCH(ERL_CONS_TAIL(t), tail); - erl_free_term(head); - erl_free_term(tail); - erl_free_term(t); - } -#undef MATCH -#undef STR_MATCH -#endif - - report(1); -} - - - -/*********************************************************************** - * - * 4. I / O l i s t f u n c t i o n s - * - ***********************************************************************/ - -/* - * Invokes erl_iolist_length() on each term and send backs the result. - */ - -TESTCASE(t_erl_iolist_length) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { -#ifndef NEW_ERL_INTERFACE - fail("Function not present in this version of erl_interface"); -#else - ETERM* len_term; - - len_term = erl_mk_int(erl_iolist_length(term)); - erl_free_term(term); - send_term(len_term); -#endif - } - } -} - -/* - * Invokes erl_iolist_to_binary() on each term and send backs the result. - */ - -TESTCASE(t_erl_iolist_to_binary) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { -#ifndef NEW_ERL_INTERFACE - fail("Function not present in this version of erl_interface"); -#else - ETERM* new_term; - - new_term = erl_iolist_to_binary(term); - - erl_free_term(term); - send_term(new_term); -#endif - } - } -} - -/* - * Invokes erl_iolist_to_string() on each term and send backs the result. - */ - -TESTCASE(t_erl_iolist_to_string) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { -#ifndef NEW_ERL_INTERFACE - fail("Function not present in this version of erl_interface"); -#else - char* result; - - result = erl_iolist_to_string(term); - erl_free_term(term); - if (result != NULL) { - send_buffer(result, strlen(result)+1); - erl_free(result); - } else { - send_term(NULL); - } -#endif - } - } -} - - -/*********************************************************************** - * - * 5. M i s c e l l a n o u s T e s t s - * - ***********************************************************************/ - -/* - * Test some combinations of operations to verify that the reference pointers - * are handled correctly. - * - * "Det verkar vara lite High Chaparal med minneshanteringen i erl_interface" - * Per Lundgren, ERV. - */ - -TESTCASE(high_chaparal) -{ - ETERM *L1, *A1, *L2, *A2, *L3; - - erl_init(NULL, 0); - - L1 = erl_mk_empty_list(); - A1 = erl_mk_atom("world"); - L2 = erl_cons(A1, L1); - A2 = erl_mk_atom("hello"); - L3 = erl_cons(A2, L2); - - erl_free_term(L1); - erl_free_term(A1); - erl_free_term(L2); - erl_free_term(A2); - - send_term(L3); - - /* already freed by send_term() */ - /* erl_free_term(L3);*/ - - report(1); -} - -/* - * Test erl_decode to recover from broken list data (OTP-7448) - */ -TESTCASE(broken_data) -{ - ETERM* original; - ETERM* new_terms; - char encoded[16*1024]; - int n; - - erl_init(NULL, 0); - original = all_types(); - if ((n=erl_encode(original, encoded)) == 0) - { - fail("failed to encode terms"); - } else - { - int offs = n/2; - memset(encoded+offs,0,n-offs); /* destroy */ - - if ((new_terms = erl_decode(encoded)) != NULL) - { - fail("decode accepted broken data"); - erl_free_term(new_terms); - } - } - erl_free_term(original); - report(1); -} - -/* - * Returns a list containing instances of all types. - * - * Be careful changing the contents of the list returned, because both - * the build_terms() and decode_terms() test cases depend on it. - */ - -static ETERM* -all_types(void) -{ - ETERM* t; - ETERM* terms[3]; - int i; - static char a_binary[] = "A binary"; - -#define CONS_AND_FREE(expr, tail) \ - do { \ - ETERM* term = expr; \ - ETERM* nl = erl_cons(term, tail); \ - erl_free_term(term); \ - erl_free_term(tail); \ - tail = nl; \ - } while (0) - - t = erl_mk_empty_list(); - - CONS_AND_FREE(erl_mk_atom("I am an atom"), t); - CONS_AND_FREE(erl_mk_binary("A binary", sizeof(a_binary)-1), t); - CONS_AND_FREE(erl_mk_float(3.0), t); - CONS_AND_FREE(erl_mk_int(0), t); - CONS_AND_FREE(erl_mk_int(-1), t); - CONS_AND_FREE(erl_mk_int(1), t); - - CONS_AND_FREE(erl_mk_string("A string"), t); - - terms[0] = erl_mk_atom("element1"); - terms[1] = erl_mk_int(42); - terms[2] = erl_mk_int(767); - CONS_AND_FREE(erl_mk_tuple(terms, ASIZE(terms)), t); - for (i = 0; i < ASIZE(terms); i++) { - erl_free_term(terms[i]); - } - - CONS_AND_FREE(erl_mk_pid("kalle@localhost", 3, 2, 1), t); - CONS_AND_FREE(erl_mk_pid("abcdefghijabcdefghij@localhost", 3, 2, 1), t); - CONS_AND_FREE(erl_mk_port("kalle@localhost", 4, 1), t); - CONS_AND_FREE(erl_mk_port("abcdefghijabcdefghij@localhost", 4, 1), t); - CONS_AND_FREE(erl_mk_ref("kalle@localhost", 6, 1), t); - CONS_AND_FREE(erl_mk_ref("abcdefghijabcdefghij@localhost", 6, 1), t); - return t; - -#undef CONS_AND_FREE -} - -/* - * Dump (print for debugging) a term. Useful if/when things go wrong. - */ -void -dump_term (FILE *fp, ETERM *t) -{ - if (fp == NULL) return; - - fprintf(fp, "#<%p ", t); - - if(t != NULL) - { - fprintf(fp, "count:%d, type:%d", ERL_COUNT(t), ERL_TYPE(t)); - - switch(ERL_TYPE(t)) - { - case ERL_UNDEF: - fprintf(fp, "==undef"); - break; - case ERL_INTEGER: - fprintf(fp, "==int, val:%d", ERL_INT_VALUE(t)); - break; - case ERL_U_INTEGER: - fprintf(fp, "==uint, val:%u", ERL_INT_UVALUE(t)); - break; - case ERL_FLOAT: - fprintf(fp, "==float, val:%g", ERL_FLOAT_VALUE(t)); - break; - case ERL_ATOM: - fprintf(fp, "==atom, name:%p \"%s\"", - ERL_ATOM_PTR(t), ERL_ATOM_PTR(t)); - break; - case ERL_BINARY: - fprintf(fp, "==binary, data:%p,%u", - ERL_BIN_PTR(t), ERL_BIN_SIZE(t)); - break; - case ERL_PID: - fprintf(fp, "==pid, node:%p \"%s\"", - ERL_PID_NODE(t), ERL_PID_NODE(t)); - break; - case ERL_PORT: - fprintf(fp, "==port, node:%p \"%s\"", - ERL_PORT_NODE(t), ERL_PORT_NODE(t)); - break; - case ERL_REF: - fprintf(fp, "==ref, node:%p \"%s\"", - ERL_REF_NODE(t), ERL_REF_NODE(t)); - break; - case ERL_CONS: - fprintf(fp, "==cons"); - fprintf(fp, ", car:"); - dump_term(fp, ERL_CONS_HEAD(t)); - fprintf(fp, ", cdr:"); - dump_term(fp, ERL_CONS_TAIL(t)); - break; - case ERL_NIL: - fprintf(fp, "==nil"); - break; - case ERL_TUPLE: - fprintf(fp, "==tuple, elems:%p,%u", - ERL_TUPLE_ELEMS(t), ERL_TUPLE_SIZE(t)); - { - size_t i; - for(i = 0; i < ERL_TUPLE_SIZE(t); i++) - { - fprintf(fp, "elem[%u]:", i); - dump_term(fp, ERL_TUPLE_ELEMENT(t, i)); - } - } - break; - case ERL_VARIABLE: - fprintf(fp, "==variable, name:%p \"%s\"", - ERL_VAR_NAME(t), ERL_VAR_NAME(t)); - fprintf(fp, ", value:"); - dump_term(fp, ERL_VAR_VALUE(t)); - break; - - default: - break; - } - } - fprintf(fp, ">"); -} - diff --git a/lib/erl_interface/test/erl_eterm_SUITE_data/print_term.c b/lib/erl_interface/test/erl_eterm_SUITE_data/print_term.c deleted file mode 100644 index 5b7cb1aec8..0000000000 --- a/lib/erl_interface/test/erl_eterm_SUITE_data/print_term.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -/* - * Purpose: Test the erl_print_term() function. - * Author: Bjorn Gustavsson - */ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#ifndef __WIN32__ -#include <unistd.h> -#endif - -#include "erl_interface.h" - -#ifndef __WIN32__ -#define _O_BINARY 0 -#define _setmode(fd, mode) -#endif - -#define HEADER_SIZE 2 - -static int readn(int, unsigned char*, int); - -/* - * This program doesn't use the runner, because it needs a packet - * on input, but the result will be as a stream of bytes (since - * erl_print_term() prints directly on a file). - * - * Input is a package of with a packet header size of two bytes. - * - * +------------------------------------------------------------+ - * | length | Encoded term... | - * | (2 bytes) | (as given by "length") | - * +------------------------------------------------------------+ - * - * <------------------- length ---------------------> - * - * This program decodes the encoded terms and passes it to - * erl_print_term(). Then this program prints - * - * CR <result> LF - * - * and waits for a new package. <result> is the return value from - * erl_print_term(), formatted as an ASCII string. - */ - -#ifdef VXWORKS -int print_term() -#else -int main() -#endif -{ - _setmode(0, _O_BINARY); - _setmode(1, _O_BINARY); - - erl_init(NULL, 0); - - for (;;) { - char buf[4*1024]; - ETERM* term; - char* message; - int n; - - if (readn(0, buf, 2) <= 0) { - /* fprintf(stderr, "error reading message header\n"); */ - /* actually this is where we leave the infinite loop */ - exit(1); - } - n = buf[0] * 256 + buf[1]; - if (readn(0, buf, n) < 0) { - fprintf(stderr, "error reading message contents\n"); - exit(1); - } - - term = erl_decode(buf); - if (term == NULL) { - fprintf(stderr, "erl_decode() failed\n"); - exit(1); - } - n = erl_print_term(stdout, term); - erl_free_compound(term); - fprintf(stdout,"\r%d\n", n); - fflush(stdout); - } -} - -/* - * Reads len number of bytes. - */ - -static int -readn(fd, buf, len) - int fd; /* File descriptor to read from. */ - unsigned char *buf; /* Store in this buffer. */ - int len; /* Number of bytes to read. */ -{ - int n; /* Byte count in last read call. */ - int sofar = 0; /* Bytes read so far. */ - - do { - if ((n = read(fd, buf+sofar, len-sofar)) <= 0) - /* error or EOF in read */ - return(n); - sofar += n; - } while (sofar < len); - return sofar; -} - diff --git a/lib/erl_interface/test/erl_format_SUITE.erl b/lib/erl_interface/test/erl_format_SUITE.erl deleted file mode 100644 index 69dfdcc4c8..0000000000 --- a/lib/erl_interface/test/erl_format_SUITE.erl +++ /dev/null @@ -1,135 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2018. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%% -%% %CopyrightEnd% -%% - -%% --module(erl_format_SUITE). - --include_lib("common_test/include/ct.hrl"). --include("erl_format_SUITE_data/format_test_cases.hrl"). - --export([all/0, suite/0, - init_per_testcase/2, - atoms/1, tuples/1, lists/1]). - --import(runner, [get_term/1]). - -%% This test suite test the erl_format() function. -%% It uses the port program "format_test". - -suite() -> - [{ct_hooks,[ts_install_cth]}]. - -all() -> - [atoms, tuples, lists]. - -init_per_testcase(Case, Config) -> - runner:init_per_testcase(?MODULE, Case, Config). - -%% Tests formatting various atoms. - -atoms(Config) when is_list(Config) -> - P = runner:start(Config, ?atoms), - - {term, ''} = get_term(P), - {term, 'a'} = get_term(P), - {term, 'A'} = get_term(P), - {term, 'abc'} = get_term(P), - {term, 'Abc'} = get_term(P), - {term, 'ab@c'} = get_term(P), - {term, 'The rain in Spain stays mainly in the plains'} = get_term(P), - - {term, a} = get_term(P), - {term, ab} = get_term(P), - {term, abc} = get_term(P), - {term, ab@c} = get_term(P), - {term, abcdefghijklmnopq} = get_term(P), - - {term, ''} = get_term(P), - {term, 'a'} = get_term(P), - {term, 'A'} = get_term(P), - {term, 'abc'} = get_term(P), - {term, 'Abc'} = get_term(P), - {term, 'ab@c'} = get_term(P), - {term, 'The rain in Spain stays mainly in the plains'} = get_term(P), - - {term, a} = get_term(P), - {term, ab} = get_term(P), - {term, abc} = get_term(P), - {term, ab@c} = get_term(P), - {term, ' abcdefghijklmnopq '} = get_term(P), - - runner:recv_eot(P), - ok. - - - -%% Tests formatting various tuples - -tuples(Config) when is_list(Config) -> - P = runner:start(Config, ?tuples), - - {term, {}} = get_term(P), - {term, {a}} = get_term(P), - {term, {a, b}} = get_term(P), - {term, {a, b, c}} = get_term(P), - {term, {1}} = get_term(P), - {term, {[]}} = get_term(P), - {term, {[], []}} = get_term(P), - {term, {[], a, b, c}} = get_term(P), - {term, {[], a, [], b, c}} = get_term(P), - {term, {[], a, '', b, c}} = get_term(P), - - runner:recv_eot(P), - ok. - - - -%% Tests formatting various lists - -lists(Config) when is_list(Config) -> - P = runner:start(Config, ?lists), - - {term, []} = get_term(P), - {term, [a]} = get_term(P), - {term, [a, b]} = get_term(P), - {term, [a, b, c]} = get_term(P), - {term, [1]} = get_term(P), - {term, [[]]} = get_term(P), - {term, [[], []]} = get_term(P), - {term, [[], a, b, c]} = get_term(P), - {term, [[], a, [], b, c]} = get_term(P), - {term, [[], a, '', b, c]} = get_term(P), - - {term, [{name, 'Madonna'}, {age, 21}, {data, [{addr, "E-street", 42}]}]} = get_term(P), - case os:type() of - vxworks -> - {term, [{pi, _}, {'cos(70)', _}]} = get_term(P), - {term, [[pi, _], ['cos(70)', _]]} = get_term(P), - {term, [[pi, _], [], ["cos(70)", _]]} = get_term(P); - _ -> - {term, [{pi, 3.1415}, {'cos(70)', 0.34202}]} = get_term(P), - {term, [[pi, 3.1415], ['cos(70)', 0.34202]]} = get_term(P), - {term, [[pi, 3.1415], [], ["cos(70)", 0.34202]]} = get_term(P) - end, - - {term, [-1]} = get_term(P), - - runner:recv_eot(P), - ok. diff --git a/lib/erl_interface/test/erl_format_SUITE_data/Makefile.first b/lib/erl_interface/test/erl_format_SUITE_data/Makefile.first deleted file mode 100644 index acbb8c98bb..0000000000 --- a/lib/erl_interface/test/erl_format_SUITE_data/Makefile.first +++ /dev/null @@ -1,22 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2000-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -format_test_decl.c: format_test.c - erl -noinput -pa ../all_SUITE_data -s init_tc run format_test -s erlang halt diff --git a/lib/erl_interface/test/erl_format_SUITE_data/Makefile.src b/lib/erl_interface/test/erl_format_SUITE_data/Makefile.src deleted file mode 100644 index 2ba59ab651..0000000000 --- a/lib/erl_interface/test/erl_format_SUITE_data/Makefile.src +++ /dev/null @@ -1,43 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 1997-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -include @erl_interface_mk_include@ - -CC0 = @CC@ -CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" -LD = @LD@ -LIBERL = @erl_interface_lib@ -LIBEI = @erl_interface_eilib@ -LIBFLAGS = ../all_SUITE_data/runner@obj@ \ - $(LIBERL) $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ - @erl_interface_threadlib@ -CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data -FORMAT_OBJS = format_test@obj@ format_test_decl@obj@ - -all: format_test@exe@ - -clean: - $(RM) $(FORMAT_OBJS) - $(RM) format_test@exe@ - -format_test@exe@: $(FORMAT_OBJS) $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(FORMAT_OBJS) $(LIBFLAGS) - - diff --git a/lib/erl_interface/test/erl_format_SUITE_data/format_test.c b/lib/erl_interface/test/erl_format_SUITE_data/format_test.c deleted file mode 100644 index 258ae92e0f..0000000000 --- a/lib/erl_interface/test/erl_format_SUITE_data/format_test.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -#include "runner.h" - -/* - * Purpose: Tests the erl_format() function. - * Author: Bjorn Gustavsson - */ - -static void -send_format(char* format) -{ - send_term(erl_format(format)); -} - -TESTCASE(atoms) -{ - erl_init(NULL, 0); - - send_format("''"); - send_format("'a'"); - send_format("'A'"); - send_format("'abc'"); - send_format("'Abc'"); - send_format("'ab@c'"); - send_format("'The rain in Spain stays mainly in the plains'"); - - send_format("a"); - send_format("ab"); - send_format("abc"); - send_format("ab@c"); - send_format(" abcdefghijklmnopq "); - - send_term(erl_format("~a", "")); - send_term(erl_format("~a", "a")); - send_term(erl_format("~a", "A")); - send_term(erl_format("~a", "abc")); - send_term(erl_format("~a", "Abc")); - send_term(erl_format("~a", "ab@c")); - send_term(erl_format("~a", "The rain in Spain stays mainly in the plains")); - - send_term(erl_format("~a", "a")); - send_term(erl_format("~a", "ab")); - send_term(erl_format("~a", "abc")); - send_term(erl_format("~a","ab@c")); - send_term(erl_format("~a", " abcdefghijklmnopq ")); - - - report(1); -} - -TESTCASE(tuples) -{ - erl_init(NULL, 0); - - send_format("{}"); - send_format("{a}"); - send_format("{a, b}"); - send_format("{a, b, c}"); - send_format("{1}"); - send_format("{[]}"); - send_format("{[], []}"); - send_format("{[], a, b, c}"); - send_format("{[], a, [], b, c}"); - send_format("{[], a, '', b, c}"); - - report(1); -} - - - -TESTCASE(lists) -{ - ETERM* a; - ETERM* b; - ETERM* c; - - erl_init(NULL, 0); - - send_format("[]"); - send_format("[a]"); - send_format("[a, b]"); - send_format("[a, b, c]"); - send_format("[1]"); - send_format("[[]]"); - send_format("[[], []]"); - send_format("[[], a, b, c]"); - send_format("[[], a, [], b, c]"); - send_format("[[], a, '', b, c]"); - - b = erl_format("[{addr, ~s, ~i}]", "E-street", 42); - a = erl_format("[{name, ~a}, {age, ~i}, {data, ~w}]", "Madonna", 21, b); - send_term(a); - erl_free_term(b); - - send_term(erl_format("[{pi, ~f}, {'cos(70)', ~f}]", 3.1415, 0.34202)); - - a = erl_mk_float(3.1415); - b = erl_mk_float(0.34202); - send_term(erl_format("[[pi, ~w], ['cos(70)', ~w]]", a, b)); - erl_free_term(a); - erl_free_term(b); - - a = erl_mk_float(3.1415); - b = erl_mk_float(0.34202); - c = erl_mk_empty_list(); - send_term(erl_format("[[~a, ~w], ~w, [~s, ~w]]", "pi", a, c, "cos(70)", b)); - erl_free_term(a); - erl_free_term(b); - erl_free_term(c); - - send_term(erl_format("[~i]", -1)); - - report(1); -} diff --git a/lib/erl_interface/test/erl_global_SUITE_data/erl_global_test.c b/lib/erl_interface/test/erl_global_SUITE_data/erl_global_test.c deleted file mode 100644 index 0f08727225..0000000000 --- a/lib/erl_interface/test/erl_global_SUITE_data/erl_global_test.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 2000-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -/* - * Purpose: Tests the functions in erl_global.c. - * - * See the erl_global_SUITE.erl file for a "table of contents". - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "runner.h" - -static void cmd_erl_connect(ETERM* args); -static void cmd_erl_global_register(ETERM *args); -static void cmd_erl_global_whereis(ETERM *args); -static void cmd_erl_global_names(ETERM *args); -static void cmd_erl_global_unregister(ETERM *args); -static void cmd_erl_close_connection(ETERM *args); - -static void send_errno_result(int value); - -static struct { - char* name; - int num_args; /* Number of arguments. */ - void (*func)(ETERM* args); -} commands[] = { - "erl_connect", 4, cmd_erl_connect, - "erl_close_connection", 1, cmd_erl_close_connection, - "erl_global_register", 2, cmd_erl_global_register, - "erl_global_whereis", 2, cmd_erl_global_whereis, - "erl_global_names", 1, cmd_erl_global_names, - "erl_global_unregister", 2, cmd_erl_global_unregister, -}; - - -/* - * Sends a list contaning all data types to the Erlang side. - */ - -TESTCASE(interpret) -{ - ETERM* term; - - erl_init(NULL, 0); - - outer_loop: - - term = get_term(); - - if (term == NULL) { - report(1); - return; - } else { - ETERM* Func; - ETERM* Args; - int i; - - if (!ERL_IS_TUPLE(term) || ERL_TUPLE_SIZE(term) != 2) { - fail("term should be a tuple of size 2"); - } - - Func = erl_element(1, term); - if (!ERL_IS_ATOM(Func)) { - fail("function name should be an atom"); - } - Args = erl_element(2, term); - if (!ERL_IS_TUPLE(Args)) { - fail("function arguments should be a tuple"); - } - erl_free_term(term); - for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) { - int n = strlen(commands[i].name); - if (ERL_ATOM_SIZE(Func) != n) { - continue; - } - if (memcmp(ERL_ATOM_PTR(Func), commands[i].name, n) == 0) { - erl_free_term(Func); - if (ERL_TUPLE_SIZE(Args) != commands[i].num_args) { - fail("wrong number of arguments"); - } - commands[i].func(Args); - erl_free_term(Args); - goto outer_loop; - } - } - fail("bad command"); - } -} - -#define VERIFY_TYPE(Test, Term) \ -if (!Test(Term)) { \ - fail("wrong type for " #Term); \ -} else { \ -} - -static void -cmd_erl_connect(ETERM* args) -{ - ETERM* number; - ETERM* node; - ETERM* cookie; - - int res; - char buffer[256]; - - number = ERL_TUPLE_ELEMENT(args, 0); - VERIFY_TYPE(ERL_IS_INTEGER, number); - node = ERL_TUPLE_ELEMENT(args, 1); - VERIFY_TYPE(ERL_IS_ATOM, node); - cookie = ERL_TUPLE_ELEMENT(args, 2); - VERIFY_TYPE(ERL_IS_ATOM, cookie); - - if (ERL_ATOM_SIZE(cookie) == 0) { - res = erl_connect_init(ERL_INT_VALUE(number), 0, 0); - } else { - memcpy(buffer, ERL_ATOM_PTR(cookie), ERL_ATOM_SIZE(cookie)); - buffer[ERL_ATOM_SIZE(cookie)] = '\0'; - res = erl_connect_init(ERL_INT_VALUE(number), buffer, 0); - } - - if(!res) { - send_errno_result(res); - return; - } - - memcpy(buffer, ERL_ATOM_PTR(node), ERL_ATOM_SIZE(node)); - buffer[ERL_ATOM_SIZE(node)] = '\0'; - send_errno_result(erl_connect(buffer)); -} - -static void -cmd_erl_close_connection(ETERM* args) -{ - ETERM* number; - ETERM* res; - - number = ERL_TUPLE_ELEMENT(args, 0); - VERIFY_TYPE(ERL_IS_INTEGER, number); - res = erl_mk_int(erl_close_connection(ERL_INT_VALUE(number))); - send_term(res); - erl_free_term(res); -} - -static void -cmd_erl_global_register(ETERM* args) -{ - ETERM* fd_term = ERL_TUPLE_ELEMENT(args, 0); - ETERM* name = ERL_TUPLE_ELEMENT(args, 1); - ETERM* pid = erl_mk_pid(erl_thisnodename(), 14, 0, 0); - - char buffer[256]; - - VERIFY_TYPE(ERL_IS_INTEGER, fd_term); - VERIFY_TYPE(ERL_IS_ATOM, name); - - memcpy(buffer, ERL_ATOM_PTR(name), ERL_ATOM_SIZE(name)); - buffer[ERL_ATOM_SIZE(name)] = '\0'; - - send_errno_result(erl_global_register(ERL_INT_VALUE(fd_term), buffer, pid)); - erl_free_term(pid); -} - -static void -cmd_erl_global_whereis(ETERM* args) -{ - ETERM* fd_term = ERL_TUPLE_ELEMENT(args, 0); - ETERM* name = ERL_TUPLE_ELEMENT(args, 1); - ETERM* pid = NULL; - - char buffer[256]; - - VERIFY_TYPE(ERL_IS_INTEGER, fd_term); - VERIFY_TYPE(ERL_IS_ATOM, name); - - memcpy(buffer, ERL_ATOM_PTR(name), ERL_ATOM_SIZE(name)); - buffer[ERL_ATOM_SIZE(name)] = '\0'; - - pid = erl_global_whereis(ERL_INT_VALUE(fd_term), buffer, NULL); - send_term(pid); - erl_free_term(pid); -} - -static void -cmd_erl_global_names(ETERM* args) -{ - ETERM* fd_term = ERL_TUPLE_ELEMENT(args, 0); - - ETERM* res_array[2], *res_tuple, *name; - char** names = NULL; - int count = 0, i; - - VERIFY_TYPE(ERL_IS_INTEGER, fd_term); - - names = erl_global_names(ERL_INT_VALUE(fd_term), &count); - - res_array[0] = erl_mk_empty_list(); - for(i=0; i<count; i++) { - name = erl_mk_string(names[i]); - res_array[0] = erl_cons(name, res_array[0]); - } - - free(names); - - res_array[1] = erl_mk_int(count); - res_tuple = erl_mk_tuple(res_array, 2); - - send_term(res_tuple); - - erl_free_compound(res_array[0]); - erl_free_term(res_array[1]); - erl_free_term(res_tuple); -} - -static void -cmd_erl_global_unregister(ETERM* args) -{ - ETERM* fd_term = ERL_TUPLE_ELEMENT(args, 0); - ETERM* name = ERL_TUPLE_ELEMENT(args, 1); - - char buffer[256]; - - VERIFY_TYPE(ERL_IS_INTEGER, fd_term); - VERIFY_TYPE(ERL_IS_ATOM, name); - - memcpy(buffer, ERL_ATOM_PTR(name), ERL_ATOM_SIZE(name)); - buffer[ERL_ATOM_SIZE(name)] = '\0'; - - send_errno_result(erl_global_unregister(ERL_INT_VALUE(fd_term), buffer)); -} - -static void -send_errno_result(int value) -{ - ETERM* res_array[2]; - ETERM* res_tuple; - - res_array[0] = erl_mk_int(value); - res_array[1] = erl_mk_int(erl_errno); - res_tuple = erl_mk_tuple(res_array, 2); - send_term(res_tuple); - erl_free_term(res_array[0]); - erl_free_term(res_array[1]); - erl_free_term(res_tuple); -} diff --git a/lib/erl_interface/test/erl_match_SUITE.erl b/lib/erl_interface/test/erl_match_SUITE.erl deleted file mode 100644 index bb62d6288d..0000000000 --- a/lib/erl_interface/test/erl_match_SUITE.erl +++ /dev/null @@ -1,280 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2018. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%% -%% %CopyrightEnd% -%% - -%% --module(erl_match_SUITE). - --include_lib("common_test/include/ct.hrl"). --include("erl_match_SUITE_data/match_test_cases.hrl"). - --export([all/0, suite/0, - init_per_testcase/2, - atoms/1, lists/1, tuples/1, references/1, pids/1, ports/1, - bind/1, integers/1, floats/1, binaries/1, strings/1]). - -%% For interactive running of matcher. --export([start_matcher/1, erl_match/3]). - -%% This test suite tests the erl_match() function. - -suite() -> - [{ct_hooks,[ts_install_cth]}]. - -all() -> - [atoms, lists, tuples, references, pids, ports, bind, - integers, floats, binaries, strings]. - -init_per_testcase(Case, Config) -> - runner:init_per_testcase(?MODULE, Case, Config). - -atoms(Config) when is_list(Config) -> - P = start_matcher(Config), - - eq(P, '', ''), - eq(P, a, a), - ne(P, a, b), - ne(P, a, aa), - eq(P, kalle, kalle), - ne(P, kalle, arne), - - ne(P, kalle, 42), - ne(P, 42, kalle), - - runner:finish(P), - ok. - -lists(Config) when is_list(Config) -> - P = start_matcher(Config), - eq(P, [], []), - - ne(P, [], [a]), - ne(P, [a], []), - - eq(P, [a], [a]), - ne(P, [a], [b]), - - eq(P, [a|b], [a|b]), - ne(P, [a|b], [a|x]), - - eq(P, [a, b], [a, b]), - ne(P, [a, b], [a, x]), - - eq(P, [a, b, c], [a, b, c]), - ne(P, [a, b|c], [a, b|x]), - ne(P, [a, b, c], [a, b, x]), - ne(P, [a, b|c], [a, b|x]), - ne(P, [a, x|c], [a, b|c]), - ne(P, [a, b, c], [a, x, c]), - - runner:finish(P), - ok. - -tuples(Config) when is_list(Config) -> - P = start_matcher(Config), - - ne(P, {}, {a, b}), - ne(P, {a, b}, {}), - ne(P, {a}, {a, b}), - ne(P, {a, b}, {a}), - - eq(P, {}, {}), - - eq(P, {a}, {a}), - ne(P, {a}, {b}), - - eq(P, {1}, {1}), - ne(P, {1}, {2}), - - eq(P, {a, b}, {a, b}), - ne(P, {x, b}, {a, b}), - - ne(P, {error, x}, {error, y}), - ne(P, {error, {undefined, {subscriber, last}}}, - {error, {undefined, {subscriber, name}}}), - - runner:finish(P), - ok. - - -references(Config) when is_list(Config) -> - P = start_matcher(Config), - Ref1 = make_ref(), - Ref2 = make_ref(), - - eq(P, Ref1, Ref1), - eq(P, Ref2, Ref2), - ne(P, Ref1, Ref2), - ne(P, Ref2, Ref1), - - runner:finish(P), - ok. - - -pids(Config) when is_list(Config) -> - P = start_matcher(Config), - Pid1 = c:pid(0,1,2), - Pid2 = c:pid(0,1,3), - - eq(P, self(), self()), - eq(P, Pid1, Pid1), - ne(P, Pid1, self()), - ne(P, Pid2, Pid1), - - runner:finish(P), - ok. - - -ports(Config) when is_list(Config) -> - case os:type() of - vxworks -> - {skipped,"not on vxworks, pucko"}; - _ -> - P = start_matcher(Config), - P2 = start_matcher(Config), - - eq(P, P, P), - ne(P, P, P2), - - runner:finish(P), - runner:finish(P2), - ok - end. - -integers(Config) when is_list(Config) -> - P = start_matcher(Config), - I1 = 123, - I2 = 12345, - I3 = -123, - I4 = 2234, - - eq(P, I1, I1), - eq(P, I2, I2), - ne(P, I1, I2), - ne(P, I1, I3), - eq(P, I4, I4), - - runner:finish(P), - ok. - - - -floats(Config) when is_list(Config) -> - P = start_matcher(Config), - F1 = 3.1414, - F2 = 3.1415, - F3 = 3.1416, - - S1 = "string", - S2 = "string2", - - eq(P, F1, F1), - eq(P, F2, F2), - ne(P, F1, F2), - ne(P, F3, F2), - - eq(P, S2, S2), - ne(P, S1, S2), - - runner:finish(P), - ok. - - - -binaries(Config) when is_list(Config) -> - P = start_matcher(Config), - Bin1 = term_to_binary({kalle, 146015, {kungsgatan, 23}}), - Bin2 = term_to_binary(sune), - Bin3 = list_to_binary("sune"), - - eq(P, Bin1, Bin1), - eq(P, Bin2, Bin2), - eq(P, Bin3, Bin3), - ne(P, Bin1, Bin2), - ne(P, Bin1, Bin3), - ne(P, Bin2, Bin3), - - runner:finish(P), - ok. - - -strings(Config) when is_list(Config) -> - P = start_matcher(Config), - - S1 = "string", - S2 = "streng", - S3 = "String", - - eq(P, S1, S1), - ne(P, S1, S2), - ne(P, S1, S3), - - runner:finish(P), - ok. - - -bind(Config) when is_list(Config) -> - P = start_bind(Config), - S = "[X,Y,Z]", - L1 = [301,302,302], - L2 = [65,66,67], - - bind_ok(P, S, L1), - bind_ok(P, S, L2), - - runner:finish(P), - ok. - -start_bind(Config) -> - runner:start(Config, ?erl_match_bind). - -bind_ok(Port, Bind, Term) -> - true = erl_bind(Port, Bind, Term). - -%bind_nok(Port, Bind, Term) -> -% false = erl_bind(Port, Bind, Term). - -erl_bind(Port, Pattern, Term) -> - Port ! {self(), {command, [$b, Pattern, 0]}}, - runner:send_term(Port, Term), - case runner:get_term(Port) of - {term, 0} -> false; - {term, 1} -> true - end. - - - -start_matcher(Config) -> - runner:start(Config, ?erl_match_server). - -eq(Port, Pattern, Term) -> - true = erl_match(Port, Pattern, Term). - -ne(Port, Pattern, Term) -> - false = erl_match(Port, Pattern, Term). - - - -erl_match(Port, Pattern, Term) -> - runner:send_term(Port, Pattern), - runner:send_term(Port, Term), - case runner:get_term(Port) of - {term, 0} -> false; - {term, 1} -> true - end. diff --git a/lib/erl_interface/test/erl_match_SUITE_data/Makefile.first b/lib/erl_interface/test/erl_match_SUITE_data/Makefile.first deleted file mode 100644 index 459b5c14c2..0000000000 --- a/lib/erl_interface/test/erl_match_SUITE_data/Makefile.first +++ /dev/null @@ -1,22 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 2000-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -match_test_decl.c: match_test.c - erl -noinput -pa ../all_SUITE_data -s init_tc run match_test -s erlang halt diff --git a/lib/erl_interface/test/erl_match_SUITE_data/Makefile.src b/lib/erl_interface/test/erl_match_SUITE_data/Makefile.src deleted file mode 100644 index 156214a269..0000000000 --- a/lib/erl_interface/test/erl_match_SUITE_data/Makefile.src +++ /dev/null @@ -1,42 +0,0 @@ -# -# %CopyrightBegin% -# -# Copyright Ericsson AB 1997-2016. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# %CopyrightEnd% -# - -include @erl_interface_mk_include@ - -CC0 = @CC@ -CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" -LD = @LD@ -LIBERL = @erl_interface_lib@ -LIBEI = @erl_interface_eilib@ -LIBFLAGS = ../all_SUITE_data/runner@obj@ \ - $(LIBERL) $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ - @erl_interface_threadlib@ -CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data -MATCH_OBJS = match_test@obj@ match_test_decl@obj@ - -all: match_test@exe@ - -clean: - $(RM) $(MATCH_OBJS) - $(RM) match_test@exe@ - -match_test@exe@: $(MATCH_OBJS) $(LIBERL) $(LIBEI) - $(LD) @CROSSLDFLAGS@ -o $@ $(MATCH_OBJS) $(LIBFLAGS) - diff --git a/lib/erl_interface/test/erl_match_SUITE_data/match_test.c b/lib/erl_interface/test/erl_match_SUITE_data/match_test.c deleted file mode 100644 index d577417f5b..0000000000 --- a/lib/erl_interface/test/erl_match_SUITE_data/match_test.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ - -/* - * Purpose: Tests the erl_match() function. - * Author: Bjorn Gustavsson - */ - -#include "runner.h" - -TESTCASE(erl_match_server) -{ - erl_init(NULL, 0); - - for (;;) { - ETERM* pattern; - ETERM* term; - - pattern = get_term(); - if (pattern == NULL) { - report(1); - return; - } else { - term = get_term(); - if (term == NULL) { - fail("Unexpected EOF term"); - } else { - send_term(erl_mk_int(erl_match(pattern, term))); - erl_free_term(pattern); - erl_free_term(term); - } - } - } - -} - -TESTCASE(erl_match_bind) -{ - erl_init(NULL, 0); - - for (;;) { - char* pattern; - ETERM* term; - - pattern=read_packet(NULL); - - switch (pattern[0]) { - case 'e': - free(pattern); - report(1); - return; - - case 'b': - { - ETERM* patt_term; - - /* - * Get the pattern string and convert it using erl_format(). - * - * Note that the call to get_term() below destroys the buffer - * that the pattern variable points to. Therefore, it is - * essential to call erl_format() here, before - * calling get_term(). - */ - - message("Pattern: %s", pattern+1); - patt_term = erl_format(pattern+1); - free(pattern); - - if (patt_term == NULL) { - fail("erl_format() failed"); - } - - /* - * Get the term and send back the result of the erl_match() - * call. - */ - - term = get_term(); - if (term == NULL) { - fail("Unexpected eof term"); - } - else { - send_term(erl_mk_int(erl_match(patt_term, term))); - } - erl_free_term(patt_term); - erl_free_term(term); - } - break; - - default: - free(pattern); - fail("Illegal character received"); - } - - } -} diff --git a/lib/erl_interface/test/port_call_SUITE_data/Makefile.src b/lib/erl_interface/test/port_call_SUITE_data/Makefile.src index 0f97ce9f70..0088c11a14 100644 --- a/lib/erl_interface/test/port_call_SUITE_data/Makefile.src +++ b/lib/erl_interface/test/port_call_SUITE_data/Makefile.src @@ -23,10 +23,9 @@ include @erl_interface_mk_include@ CC0 = @CC@ CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" LD = @LD@ -LIBERL = @erl_interface_lib_drv@ LIBEI = @erl_interface_eilib_drv@ -SHLIB_EXTRA_LDLIBS = $(LIBERL) $(LIBEI) @erl_interface_threadlib@ +SHLIB_EXTRA_LDLIBS = $(LIBEI) @erl_interface_threadlib@ SHLIB_EXTRA_CFLAGS = -I@erl_interface_include@ -I../all_SUITE_data diff --git a/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c b/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c index 4617cb0316..8f7303d645 100644 --- a/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c +++ b/lib/erl_interface/test/port_call_SUITE_data/port_call_drv.c @@ -21,7 +21,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include "erl_interface.h" +#include "ei.h" #include "erl_driver.h" static ErlDrvPort my_erlang_port; |