From 84adefa331c4159d432d22840663c38f155cd4c1 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Fri, 20 Nov 2009 14:54:40 +0000 Subject: The R13B03 release. --- .../test/busy_port_SUITE_data/Makefile.src | 25 ++++++ erts/emulator/test/busy_port_SUITE_data/busy_drv.c | 97 ++++++++++++++++++++++ .../test/busy_port_SUITE_data/hard_busy_drv.c | 23 +++++ .../test/busy_port_SUITE_data/hs_busy_drv.c | 94 +++++++++++++++++++++ .../test/busy_port_SUITE_data/soft_busy_drv.c | 23 +++++ 5 files changed, 262 insertions(+) create mode 100644 erts/emulator/test/busy_port_SUITE_data/Makefile.src create mode 100644 erts/emulator/test/busy_port_SUITE_data/busy_drv.c create mode 100644 erts/emulator/test/busy_port_SUITE_data/hard_busy_drv.c create mode 100644 erts/emulator/test/busy_port_SUITE_data/hs_busy_drv.c create mode 100644 erts/emulator/test/busy_port_SUITE_data/soft_busy_drv.c (limited to 'erts/emulator/test/busy_port_SUITE_data') diff --git a/erts/emulator/test/busy_port_SUITE_data/Makefile.src b/erts/emulator/test/busy_port_SUITE_data/Makefile.src new file mode 100644 index 0000000000..664909db71 --- /dev/null +++ b/erts/emulator/test/busy_port_SUITE_data/Makefile.src @@ -0,0 +1,25 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 1997-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# + +all: busy_drv@dll@ hard_busy_drv@dll@ soft_busy_drv@dll@ + +@SHLIB_RULES@ + +hard_busy_drv@obj@: hard_busy_drv.c hs_busy_drv.c +soft_busy_drv@obj@: soft_busy_drv.c hs_busy_drv.c diff --git a/erts/emulator/test/busy_port_SUITE_data/busy_drv.c b/erts/emulator/test/busy_port_SUITE_data/busy_drv.c new file mode 100644 index 0000000000..1273d610ba --- /dev/null +++ b/erts/emulator/test/busy_port_SUITE_data/busy_drv.c @@ -0,0 +1,97 @@ +/* + * Purpose: Provides a driver whose busy state can be controlled from Erlang. + * Author: Bjorn Gustavsson + */ + +#include "erl_driver.h" +#include +#include + +#define NO 0 +#define YES 1 + +static ErlDrvData busy_start(ErlDrvPort, char*); +static void busy_stop(ErlDrvData), busy_from_erlang(ErlDrvData, char*, int); + +ErlDrvEntry busy_driver_entry = +{ + NULL, + busy_start, + busy_stop, + busy_from_erlang, + NULL, + NULL, + "busy_drv", + NULL, + NULL +}; + +static ErlDrvPort master_port; +static ErlDrvPort slave_port; +static int next_slave_state; + +DRIVER_INIT(busy_drv) +{ + master_port = (ErlDrvPort)-1; + slave_port = (ErlDrvPort)-1; + return &busy_driver_entry; +} + +static ErlDrvData busy_start(ErlDrvPort port, char* buf) +{ + char *s; + int slave = YES; + + s = strchr(buf, ' '); + if (s && s[1] == 'm') { + /* This is the master port */ + if (master_port != (ErlDrvPort)-1) + return ERL_DRV_ERROR_GENERAL; /* Already open */ + if (slave_port != (ErlDrvPort)-1) { + return ERL_DRV_ERROR_GENERAL; + } + master_port = port; + next_slave_state = 1; + } else { + if (slave_port != (ErlDrvPort)-1) + return ERL_DRV_ERROR_GENERAL; /* Already open */ + if (master_port == (ErlDrvPort)-1) { + return ERL_DRV_ERROR_GENERAL; + } + slave_port = port; + } + return (ErlDrvData)port; +} + +static void busy_stop(ErlDrvData port) +{ + if ((ErlDrvPort)port == master_port) { + master_port = (ErlDrvPort)-1; + } else if ((ErlDrvPort)port == slave_port) { + slave_port = (ErlDrvPort)-1; + } +} + +static void +busy_from_erlang(ErlDrvData port, char* buf, int count) +{ + if ((ErlDrvPort)port == slave_port) { + set_busy_port(slave_port, next_slave_state); + next_slave_state = 0; + return; + } + + if (slave_port == (ErlDrvPort)-1 || count < 1) { + driver_failure((ErlDrvPort)port, -1); + return; + } + + switch (buf[0]) { + case 'l': /* Lock port (set to busy) */ + set_busy_port(slave_port, 1); + break; + case 'u': /* Unlock port (not busy) */ + set_busy_port(slave_port, 0); + break; + } +} diff --git a/erts/emulator/test/busy_port_SUITE_data/hard_busy_drv.c b/erts/emulator/test/busy_port_SUITE_data/hard_busy_drv.c new file mode 100644 index 0000000000..52c41f8ca5 --- /dev/null +++ b/erts/emulator/test/busy_port_SUITE_data/hard_busy_drv.c @@ -0,0 +1,23 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2009. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + */ +#define ERTS_TEST_BUSY_DRV_NAME "hard_busy_drv" +#define ERTS_TEST_BUSY_DRV_FLAGS \ + ERL_DRV_FLAG_USE_PORT_LOCKING + +#include "hs_busy_drv.c" diff --git a/erts/emulator/test/busy_port_SUITE_data/hs_busy_drv.c b/erts/emulator/test/busy_port_SUITE_data/hs_busy_drv.c new file mode 100644 index 0000000000..35919da2d0 --- /dev/null +++ b/erts/emulator/test/busy_port_SUITE_data/hs_busy_drv.c @@ -0,0 +1,94 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2009. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + */ + +#include +#include "erl_driver.h" + +ErlDrvData start(ErlDrvPort port, char *command); +void output(ErlDrvData drv_data, char *buf, int len); +int control(ErlDrvData drv_data, unsigned int command, char *buf, + int len, char **rbuf, int rlen); + +static ErlDrvEntry busy_drv_entry = { + NULL /* init */, + start, + NULL /* stop */, + output, + NULL /* ready_input */, + NULL /* ready_output */, + ERTS_TEST_BUSY_DRV_NAME, + NULL /* finish */, + NULL /* handle */, + control, + NULL /* timeout */, + NULL /* outputv */, + NULL /* ready_async */, + NULL /* flush */, + NULL /* call */, + NULL /* event */, + ERL_DRV_EXTENDED_MARKER, + ERL_DRV_EXTENDED_MAJOR_VERSION, + ERL_DRV_EXTENDED_MINOR_VERSION, + ERTS_TEST_BUSY_DRV_FLAGS, + NULL /* handle2 */, + NULL /* handle_monitor */, + NULL /* stop_select */ +}; + +DRIVER_INIT(busy_drv) +{ + return &busy_drv_entry; +} + +ErlDrvData start(ErlDrvPort port, char *command) +{ + return (ErlDrvData) port; +} + +void output(ErlDrvData drv_data, char *buf, int len) +{ + int res; + ErlDrvPort port = (ErlDrvPort) drv_data; + ErlDrvTermData msg[] = { + ERL_DRV_PORT, driver_mk_port(port), + ERL_DRV_ATOM, driver_mk_atom("caller"), + ERL_DRV_PID, driver_caller(port), + ERL_DRV_TUPLE, (ErlDrvTermData) 3 + }; + res = driver_output_term(port, msg, sizeof(msg)/sizeof(ErlDrvTermData)); + if (res <= 0) + driver_failure_atom(port, "driver_output_term failed"); +} + +int control(ErlDrvData drv_data, unsigned int command, char *buf, + int len, char **rbuf, int rlen) +{ + switch (command) { + case 'B': /* busy */ + set_busy_port((ErlDrvPort) drv_data, 1); + break; + case 'N': /* not busy */ + set_busy_port((ErlDrvPort) drv_data, 0); + break; + default: + driver_failure_posix((ErlDrvPort) drv_data, EINVAL); + break; + } + return 0; +} diff --git a/erts/emulator/test/busy_port_SUITE_data/soft_busy_drv.c b/erts/emulator/test/busy_port_SUITE_data/soft_busy_drv.c new file mode 100644 index 0000000000..30bcd86d1d --- /dev/null +++ b/erts/emulator/test/busy_port_SUITE_data/soft_busy_drv.c @@ -0,0 +1,23 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2009. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + */ +#define ERTS_TEST_BUSY_DRV_NAME "soft_busy_drv" +#define ERTS_TEST_BUSY_DRV_FLAGS \ + (ERL_DRV_FLAG_USE_PORT_LOCKING|ERL_DRV_FLAG_SOFT_BUSY) + +#include "hs_busy_drv.c" -- cgit v1.2.3