diff options
author | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
commit | 84adefa331c4159d432d22840663c38f155cd4c1 (patch) | |
tree | bff9a9c66adda4df2106dfd0e5c053ab182a12bd /erts/emulator/test/send_term_SUITE_data | |
download | otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2 otp-84adefa331c4159d432d22840663c38f155cd4c1.zip |
The R13B03 release.OTP_R13B03
Diffstat (limited to 'erts/emulator/test/send_term_SUITE_data')
-rw-r--r-- | erts/emulator/test/send_term_SUITE_data/Makefile.src | 3 | ||||
-rw-r--r-- | erts/emulator/test/send_term_SUITE_data/ext_terms.bin | bin | 0 -> 476 bytes | |||
-rw-r--r-- | erts/emulator/test/send_term_SUITE_data/ext_terms.h | 110 | ||||
-rw-r--r-- | erts/emulator/test/send_term_SUITE_data/send_term_drv.c | 718 |
4 files changed, 831 insertions, 0 deletions
diff --git a/erts/emulator/test/send_term_SUITE_data/Makefile.src b/erts/emulator/test/send_term_SUITE_data/Makefile.src new file mode 100644 index 0000000000..41a96ff626 --- /dev/null +++ b/erts/emulator/test/send_term_SUITE_data/Makefile.src @@ -0,0 +1,3 @@ +all: send_term_drv@dll@ + +@SHLIB_RULES@ diff --git a/erts/emulator/test/send_term_SUITE_data/ext_terms.bin b/erts/emulator/test/send_term_SUITE_data/ext_terms.bin Binary files differnew file mode 100644 index 0000000000..b239284323 --- /dev/null +++ b/erts/emulator/test/send_term_SUITE_data/ext_terms.bin diff --git a/erts/emulator/test/send_term_SUITE_data/ext_terms.h b/erts/emulator/test/send_term_SUITE_data/ext_terms.h new file mode 100644 index 0000000000..08134f3b05 --- /dev/null +++ b/erts/emulator/test/send_term_SUITE_data/ext_terms.h @@ -0,0 +1,110 @@ +/* ``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 via the world wide web 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. + * + * The Initial Developer of the Original Code is Ericsson AB. + * Portions created by Ericsson are Copyright 2007, Ericsson AB. + * All Rights Reserved.'' + * + * $Id$ + */ + +/* + * Do not modify this file. This file and ext_terms.bin were + * automatically generated by send_term_SUITE:generate_external_terms_files/1 + * and needs to be consistent with each other. + */ +#ifndef EXT_TERMS_H__ +#define EXT_TERMS_H__ +static struct { + unsigned char ext[162]; + int ext_size; + unsigned char cext[162]; + int cext_size; +} ext_terms[] = { + {{131,104,3,98,0,0,18,103,98,255,255,237,153,108,0,0,0,2,100,0,7,97,110,95,97,116,111,109,107,0,6,97,32,108,105,115,116,106}, + 38, + {131,104,3,98,0,0,18,103,98,255,255,237,153,108,0,0,0,2,100,0,7,97,110,95,97,116,111,109,107,0,6,97,32,108,105,115,116,106}, + 38}, + {{131,108,0,0,0,4,110,9,0,0,0,160,222,197,173,201,53,54,110,7,1,199,113,21,183,140,242,3,107,0,6,98,108,117,112,112,33,100,0,5,98,108,105,112,112,106}, + 46, + {131,108,0,0,0,4,110,9,0,0,0,160,222,197,173,201,53,54,110,7,1,199,113,21,183,140,242,3,107,0,6,98,108,117,112,112,33,100,0,5,98,108,105,112,112,106}, + 46}, + {{131,104,5,103,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,38,0,0,0,0,3,104,2,114,0,3,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,40,0,0,0,0,0,0,0,0,102,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3,103,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,37,0,0,0,0,3,102,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,59,0,0,0,0,0,0,0,0}, + 162, + {131,80,0,0,0,161,120,156,203,96,77,79,97,224,77,140,207,203,79,73,117,72,207,47,74,74,76,103,96,96,80,3,98,6,230,12,166,34,6,102,116,89,102,160,140,6,3,20,164,97,209,203,200,12,52,145,39,17,85,80,21,108,96,26,166,4,35,51,216,14,20,97,144,21,214,48,43,0,1,209,36,52}, + 82}, + {{131,104,5,104,0,106,106,112,0,0,0,79,0,21,87,190,182,1,38,106,214,65,228,1,52,27,227,2,212,0,0,0,1,0,0,0,0,100,0,15,115,101,110,100,95,116,101,114,109,95,83,85,73,84,69,97,1,98,0,184,11,180,103,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,37,0,0,0,0,3,109,0,0,0,31,104,101,106,32,104,111,112,112,32,116,114,97,108,108,97,108,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97}, + 123, + {131,80,0,0,0,122,120,156,203,96,205,96,200,202,42,96,96,96,240,103,16,13,223,183,141,81,45,235,154,227,19,70,19,233,199,76,87,128,130,140,64,204,144,194,192,95,156,154,151,18,95,146,90,148,27,31,28,234,25,226,154,200,152,196,176,131,123,75,122,10,3,79,98,94,126,74,170,67,122,126,81,82,98,58,80,173,42,72,3,115,46,144,144,207,72,205,82,200,200,47,40,80,40,41,74,204,201,73,204,73,68,5,0,18,237,35,68}, + 117}, + {{131,108,0,0,0,4,110,10,0,28,199,113,166,118,185,145,86,105,9,110,5,1,28,103,24,89,10,107,0,2,98,33,100,0,10,98,108,105,112,112,112,112,112,112,112,106}, + 46, + {131,108,0,0,0,4,110,10,0,28,199,113,166,118,185,145,86,105,9,110,5,1,28,103,24,89,10,107,0,2,98,33,100,0,10,98,108,105,112,112,112,112,112,112,112,106}, + 46}, + {{131,104,5,98,0,0,18,103,103,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,38,0,0,0,0,3,104,2,114,0,3,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,40,0,0,0,0,0,0,0,0,102,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3,98,255,255,237,153,108,0,0,0,2,100,0,7,97,110,95,97,116,111,109,107,0,6,97,32,108,105,115,116,106}, + 120, + {131,80,0,0,0,119,120,156,203,96,77,98,96,16,74,79,79,97,224,77,140,207,203,79,73,117,72,207,47,74,74,76,103,96,96,80,3,98,6,230,12,166,34,6,102,116,89,102,160,140,6,3,20,164,97,209,203,200,156,244,255,255,219,153,57,64,38,83,10,3,123,98,94,124,98,73,126,110,54,3,91,162,66,78,102,113,73,22,0,167,192,30,158}, + 93}, + {{131,104,4,103,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,38,0,0,0,0,3,104,2,114,0,3,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,40,0,0,0,0,0,0,0,0,102,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3,103,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,0,0,0,0,0,3,102,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3}, + 131, + {131,80,0,0,0,130,120,156,203,96,73,79,97,224,77,140,207,203,79,73,117,72,207,47,74,74,76,103,96,96,80,3,98,6,230,12,166,34,6,102,116,89,102,160,140,6,3,20,164,97,209,203,200,12,52,145,39,17,85,16,12,152,211,48,37,24,153,1,215,214,30,50}, + 72}, + {{131,104,3,98,0,0,18,103,98,255,255,237,153,108,0,0,0,2,100,0,7,97,110,95,97,116,111,109,107,0,6,97,32,108,105,115,116,106}, + 38, + {131,104,3,98,0,0,18,103,98,255,255,237,153,108,0,0,0,2,100,0,7,97,110,95,97,116,111,109,107,0,6,97,32,108,105,115,116,106}, + 38}, + {{131,104,3,98,0,0,18,103,98,255,255,237,153,108,0,0,0,2,100,0,4,97,116,111,109,107,0,4,108,105,115,116,106}, + 33, + {131,104,3,98,0,0,18,103,98,255,255,237,153,108,0,0,0,2,100,0,4,97,116,111,109,107,0,4,108,105,115,116,106}, + 33}, + {{131,104,4,103,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,38,0,0,0,0,3,104,2,114,0,3,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,40,0,0,0,0,0,0,0,0,102,100,0,13,97,95,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3,103,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,0,0,0,0,0,3,102,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,1,3}, + 131, + {131,80,0,0,0,130,120,156,203,96,73,79,97,224,77,140,207,203,79,73,117,72,207,47,74,74,76,103,96,96,80,3,98,6,230,12,166,34,6,102,116,89,102,160,140,6,3,20,164,97,209,203,200,12,52,145,39,17,85,16,12,152,211,48,37,24,153,1,215,214,30,50}, + 72}, + {{131,104,4,110,8,0,28,199,17,175,172,214,173,61,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,0,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,60,0,0,0,0,0,0,0,0}, + 74, + {131,80,0,0,0,73,120,156,203,96,201,227,96,144,57,46,184,126,205,181,181,182,73,255,255,7,165,100,48,98,133,12,69,12,204,41,12,60,137,121,249,41,169,14,233,249,69,73,137,233,204,12,12,12,54,12,80,0,0,73,17,18,208}, + 63}, + {{131,104,4,110,9,0,28,199,241,98,116,219,231,23,24,98,255,255,82,100,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,107,0,1,1,106,106,106,106,106,106,106,106,106,106,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,61,0,0,0,0,0,0,0,0}, + 115, + {131,80,0,0,0,114,120,156,203,96,201,227,100,144,57,254,49,169,228,246,115,113,137,164,255,255,131,82,114,24,24,24,24,73,34,178,25,24,25,179,224,160,136,129,57,133,129,39,49,47,63,37,213,33,61,191,40,41,49,157,25,168,200,150,1,10,0,208,188,23,70}, + 71}, + {{131,104,4,110,8,0,28,199,129,17,222,251,42,6,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,97,2,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,62,0,0,0,0,0,0,0,0}, + 76, + {131,80,0,0,0,75,120,156,203,96,201,227,96,144,57,222,40,120,239,183,22,91,210,255,255,65,41,25,140,216,97,34,83,17,3,115,10,3,79,98,94,126,74,170,67,122,126,81,82,98,58,51,3,3,131,29,3,20,0,0,76,82,18,165}, + 64}, + {{131,104,4,110,9,0,28,199,113,221,139,146,14,239,240,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,97,3,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,63,0,0,0,0,0,0,0,0}, + 77, + {131,80,0,0,0,76,120,156,203,96,201,227,100,144,57,94,120,183,123,18,223,251,15,73,255,255,7,165,100,48,98,135,137,204,69,12,204,41,12,60,137,121,249,41,169,14,233,249,69,73,137,233,204,12,12,12,246,12,80,0,0,192,110,20,101}, + 65}, + {{131,104,4,110,9,0,28,199,177,214,190,98,202,104,2,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,97,4,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,64,0,0,0,0,0,0,0,0}, + 77, + {131,80,0,0,0,76,120,156,203,96,201,227,100,144,57,190,241,218,190,164,83,25,76,73,255,255,7,165,100,48,98,135,137,44,69,12,204,41,12,60,137,121,249,41,169,14,233,249,69,73,137,233,204,12,12,12,14,12,80,0,0,164,94,19,234}, + 65}, + {{131,104,4,110,7,0,28,199,85,220,50,202,15,98,255,255,82,100,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,108,0,0,0,1,107,0,1,5,106,106,106,106,106,106,106,106,106,106,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,65,0,0,0,0,0,0,0,0}, + 113, + {131,80,0,0,0,112,120,156,203,96,201,99,103,144,57,30,122,199,232,20,127,210,255,255,65,41,57,12,12,12,140,36,17,217,12,140,172,89,112,80,196,192,156,194,192,147,152,151,159,146,234,144,158,95,148,148,152,206,12,84,228,200,0,5,0,46,116,21,208}, + 69}, + {{131,104,4,110,9,0,28,199,241,98,116,219,231,23,24,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,97,6,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,66,0,0,0,0,0,0,0,0}, + 77, + {131,80,0,0,0,76,120,156,203,96,201,227,100,144,57,254,49,169,228,246,115,113,137,164,255,255,131,82,50,24,177,195,68,182,34,6,230,20,6,158,196,188,252,148,84,135,244,252,162,164,196,116,102,6,6,6,39,6,40,0,0,155,123,19,203}, + 65}, + {{131,104,4,110,7,0,28,199,59,73,56,148,1,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,97,7,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,67,0,0,0,0,0,0,0,0}, + 75, + {131,80,0,0,0,74,120,156,203,96,201,99,103,144,57,110,237,105,49,133,49,233,255,255,160,148,12,70,236,48,145,189,136,129,57,133,129,39,49,47,63,37,213,33,61,191,40,41,49,157,153,129,129,193,153,1,10,0,245,21,17,100}, + 62}, + {{131,104,4,110,8,0,28,199,17,175,172,214,173,61,98,255,255,82,100,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,104,1,97,8,114,0,3,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,3,0,0,0,68,0,0,0,0,0,0,0,0}, + 76, + {131,80,0,0,0,75,120,156,203,96,201,227,96,144,57,46,184,126,205,181,181,182,73,255,255,7,165,100,48,98,135,137,28,69,12,204,41,12,60,137,121,249,41,169,14,233,249,69,73,137,233,204,12,12,12,46,12,80,0,0,112,226,19,66}, + 64} +}; +#define NO_OF_EXT_TERMS 19 +#endif diff --git a/erts/emulator/test/send_term_SUITE_data/send_term_drv.c b/erts/emulator/test/send_term_SUITE_data/send_term_drv.c new file mode 100644 index 0000000000..6638de0560 --- /dev/null +++ b/erts/emulator/test/send_term_SUITE_data/send_term_drv.c @@ -0,0 +1,718 @@ +/* ``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 via the world wide web 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. + * + * The Initial Developer of the Original Code is Ericsson Utvecklings AB. + * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings + * AB. All Rights Reserved.'' + * + * $Id$ + */ + +#include "erl_driver.h" +#include <errno.h> +#include <string.h> + +static ErlDrvPort erlang_port; +static ErlDrvData send_term_drv_start(ErlDrvPort port, char *command); +static void send_term_drv_stop(ErlDrvData drv_data); +static void send_term_drv_run(ErlDrvData drv_data, char *buf, int len); + + +static int make_ext_term_list(ErlDrvTermData *td, int bad); + +#define FAIL_TERM(M, L) fail_term((M), (L), __LINE__) + +static ErlDrvEntry send_term_drv_entry = { + NULL, + send_term_drv_start, + send_term_drv_stop, + send_term_drv_run, + NULL, + NULL, + "send_term_drv", +}; + +DRIVER_INIT(send_term_drv) +{ + erlang_port = (ErlDrvPort)-1; + return &send_term_drv_entry; +} + +static ErlDrvData send_term_drv_start(ErlDrvPort port, char *buf) +{ + if (erlang_port != (ErlDrvPort)-1) { + return ERL_DRV_ERROR_GENERAL; + } + + erlang_port = port; + return (ErlDrvData)port; +} + +static void send_term_drv_stop(ErlDrvData drv_data) +{ +} + +static void output_term(ErlDrvTermData* msg, int len); +static void fail_term(ErlDrvTermData* msg, int len, int line); + +static void send_term_drv_run(ErlDrvData port, char *buf, int count) +{ + ErlDrvTermData msg[1024]; + + switch (*buf) { + case 0: + msg[0] = ERL_DRV_NIL; + output_term(msg, 1); + break; + + case 1: /* Most term types inside a tuple. */ + { + double f = 3.1416; + + msg[0] = ERL_DRV_ATOM; + msg[1] = driver_mk_atom("blurf"), + msg[2] = ERL_DRV_INT; + msg[3] = (ErlDrvTermData) 42; + msg[4] = ERL_DRV_NIL; + msg[5] = ERL_DRV_INT; + msg[6] = (ErlDrvTermData) -42; + msg[7] = ERL_DRV_TUPLE; + msg[8] = (ErlDrvTermData) 0; + msg[9] = ERL_DRV_PORT; + msg[10] = driver_mk_port(erlang_port); + msg[11] = ERL_DRV_STRING_CONS; + msg[12] = (ErlDrvTermData) "abc"; + msg[13] = (ErlDrvTermData) 3; + msg[14] = ERL_DRV_LIST; + msg[15] = (ErlDrvTermData) 3; + msg[16] = ERL_DRV_STRING; + msg[17] = (ErlDrvTermData) "kalle"; + msg[18] = (ErlDrvTermData) 5; + msg[19] = ERL_DRV_FLOAT; + msg[20] = (ErlDrvTermData) &f; + msg[21] = ERL_DRV_PID; + msg[22] = driver_connected(erlang_port); + msg[23] = ERL_DRV_TUPLE; + msg[24] = (ErlDrvTermData) 7; + output_term(msg, 25); + } + break; + + case 2: /* Deep stack */ + { + int i; + + for (i = 0; i < 400; i += 2) { + msg[i] = ERL_DRV_INT; + msg[i+1] = (ErlDrvTermData) (i / 2); + } + msg[i] = ERL_DRV_NIL; + msg[i+1] = ERL_DRV_LIST; + msg[i+2] = (ErlDrvTermData) 201; + output_term(msg, i+3); + } + break; + + case 3: /* Binaries */ + { + ErlDrvBinary* bin; + int i; + + bin = driver_alloc_binary(256); + for (i = 0; i < 256; i++) { + bin->orig_bytes[i] = i; + } + msg[0] = ERL_DRV_BINARY; + msg[1] = (ErlDrvTermData) bin; + msg[2] = (ErlDrvTermData) 256; + msg[3] = (ErlDrvTermData) 0; + msg[4] = ERL_DRV_BINARY; + msg[5] = (ErlDrvTermData) bin; + msg[6] = (ErlDrvTermData) 256-23-17; + msg[7] = (ErlDrvTermData) 23; + msg[8] = ERL_DRV_TUPLE; + msg[9] = (ErlDrvTermData) 2; + output_term(msg, 10); + driver_free_binary(bin); + } + break; + + case 4: /* Pids */ + msg[0] = ERL_DRV_PID; + msg[1] = driver_connected(erlang_port); + msg[2] = ERL_DRV_PID; + msg[3] = driver_caller(erlang_port); + msg[4] = ERL_DRV_TUPLE; + msg[5] = (ErlDrvTermData) 2; + output_term(msg, 6); + break; + + case 5: + output_term(msg, make_ext_term_list(msg, 0)); + break; + + case 6: + msg[0] = ERL_DRV_INT; + msg[1] = ~((ErlDrvTermData) 0); + msg[2] = ERL_DRV_UINT; + msg[3] = ~((ErlDrvTermData) 0); + msg[4] = ERL_DRV_TUPLE; + msg[5] = (ErlDrvTermData) 2; + output_term(msg, 6); + break; + + case 7: { + int len = 0; + char buf[1024]; + memset(buf, 17, sizeof(buf)); + /* empty heap binary */ + msg[len++] = ERL_DRV_BUF2BINARY; + msg[len++] = (ErlDrvTermData) NULL; /* NULL is ok if size == 0 */ + msg[len++] = (ErlDrvTermData) 0; + /* empty heap binary again */ + msg[len++] = ERL_DRV_BUF2BINARY; + msg[len++] = (ErlDrvTermData) &buf[0]; /* ptr is ok if size == 0 */ + msg[len++] = (ErlDrvTermData) 0; + /* heap binary */ + msg[len++] = ERL_DRV_BUF2BINARY; + msg[len++] = (ErlDrvTermData) &buf[0]; + msg[len++] = (ErlDrvTermData) 17; + /* off heap binary */ + msg[len++] = ERL_DRV_BUF2BINARY; + msg[len++] = (ErlDrvTermData) &buf[0]; + msg[len++] = (ErlDrvTermData) sizeof(buf); + + msg[len++] = ERL_DRV_TUPLE; + msg[len++] = (ErlDrvTermData) 4; + + output_term(msg, len); + break; + } + + case 8: + msg[0] = ERL_DRV_NIL; + output_term(msg, 1); + break; + + case 9: + msg[0] = ERL_DRV_ATOM; + msg[1] = (ErlDrvTermData) driver_mk_atom(""); + output_term(msg, 2); + break; + + case 10: + msg[0] = ERL_DRV_ATOM; + msg[1] = (ErlDrvTermData) driver_mk_atom("an_atom"); + output_term(msg, 2); + break; + + case 11: + msg[0] = ERL_DRV_INT; + msg[1] = (ErlDrvTermData) -4711; + output_term(msg, 2); + break; + + case 12: + msg[0] = ERL_DRV_UINT; + msg[1] = (ErlDrvTermData) 4711; + output_term(msg, 2); + + break; + case 13: + msg[0] = ERL_DRV_PORT; + msg[1] = driver_mk_port(erlang_port); + output_term(msg, 2); + break; + + case 14: { + ErlDrvBinary *dbin = driver_alloc_binary(0); + msg[0] = ERL_DRV_BINARY; + msg[1] = (ErlDrvTermData) dbin; + msg[2] = (ErlDrvTermData) 0; + msg[3] = (ErlDrvTermData) 0; + output_term(msg, 4); + driver_free_binary(dbin); + break; + } + + case 15: { + char buf[] = "hejsan"; + ErlDrvBinary *dbin = driver_alloc_binary(sizeof(buf)-1); + if (dbin) + memcpy((void *) dbin->orig_bytes, (void *) buf, sizeof(buf)-1); + msg[0] = ERL_DRV_BINARY; + msg[1] = (ErlDrvTermData) dbin; + msg[2] = (ErlDrvTermData) (dbin ? sizeof(buf)-1 : 0); + msg[3] = (ErlDrvTermData) 0; + output_term(msg, 4); + driver_free_binary(dbin); + break; + } + + case 16: + msg[0] = ERL_DRV_BUF2BINARY; + msg[1] = (ErlDrvTermData) NULL; + msg[2] = (ErlDrvTermData) 0; + output_term(msg, 3); + break; + + case 17: { + char buf[] = ""; + msg[0] = ERL_DRV_BUF2BINARY; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + output_term(msg, 3); + break; + } + + case 18: { + char buf[] = "hoppsan"; + msg[0] = ERL_DRV_BUF2BINARY; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + output_term(msg, 3); + break; + } + + case 19: + msg[0] = ERL_DRV_STRING; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) 0; + output_term(msg, 3); + break; + + case 20: { + char buf[] = ""; + msg[0] = ERL_DRV_STRING; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + output_term(msg, 3); + break; + } + + case 21: { + char buf[] = "hippsan"; + msg[0] = ERL_DRV_STRING; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + output_term(msg, 3); + break; + } + + case 22: + msg[0] = ERL_DRV_TUPLE; + msg[1] = (ErlDrvTermData) 0; + output_term(msg, 2); + break; + + case 23: + msg[0] = ERL_DRV_NIL; + msg[1] = ERL_DRV_LIST; + msg[2] = (ErlDrvTermData) 1; + output_term(msg, 3); + break; + + case 24: + msg[0] = ERL_DRV_PID; + msg[1] = driver_connected(erlang_port); + output_term(msg, 2); + break; + + case 25: + msg[0] = ERL_DRV_NIL; + msg[1] = ERL_DRV_STRING_CONS; + msg[2] = (ErlDrvTermData) ""; + msg[3] = (ErlDrvTermData) 0; + output_term(msg, 4); + break; + + case 26: { + double my_float = 0.0; + msg[0] = ERL_DRV_FLOAT; + msg[1] = (ErlDrvTermData) &my_float; + output_term(msg, 2); + break; + } + + case 27: { + char buf[] = {131, 106}; /* [] */ + msg[0] = ERL_DRV_EXT2TERM; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf); + output_term(msg, 3); + break; + } + + case 28: { + ErlDrvUInt64 x = ~((ErlDrvUInt64) 0); + msg[0] = ERL_DRV_UINT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 29: { + ErlDrvUInt64 x = ((ErlDrvUInt64) 4711) << 32; + msg[0] = ERL_DRV_UINT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 30: { + ErlDrvUInt64 x = 4711; + msg[0] = ERL_DRV_UINT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 31: { + ErlDrvUInt64 x = 0; + msg[0] = ERL_DRV_UINT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 32: { + ErlDrvSInt64 x = ((((ErlDrvUInt64) 0x7fffffff) << 32) + | ((ErlDrvUInt64) 0xffffffff)); + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 33: { + ErlDrvSInt64 x = (ErlDrvSInt64) (((ErlDrvUInt64) 4711) << 32); + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 34: { + ErlDrvSInt64 x = 4711; + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 35: { + ErlDrvSInt64 x = 0; + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 36: { + ErlDrvSInt64 x = -1; + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 37: { + ErlDrvSInt64 x = -4711; + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 38: { + ErlDrvSInt64 x = ((ErlDrvSInt64) ((ErlDrvUInt64) 4711) << 32)*-1; + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + case 39: { + ErlDrvSInt64 x = ((ErlDrvSInt64) 1) << 63; + msg[0] = ERL_DRV_INT64; + msg[1] = (ErlDrvTermData) &x; + output_term(msg, 2); + + break; + } + + + case 127: /* Error cases */ + { + long refc; + ErlDrvBinary* bin = driver_alloc_binary(256); + + FAIL_TERM(msg, 0); + + msg[0] = ERL_DRV_LIST; + msg[1] = (ErlDrvTermData) 0; + FAIL_TERM(msg, 2); + + /* Not an atom */ + msg[0] = ERL_DRV_ATOM; + msg[1] = (ErlDrvTermData) driver_connected(erlang_port); + FAIL_TERM(msg, 2); + msg[0] = ERL_DRV_ATOM; + msg[1] = driver_term_nil; + FAIL_TERM(msg, 2); + + /* Not a pid */ + msg[0] = ERL_DRV_PID; + msg[1] = (ErlDrvTermData) driver_mk_atom("blurf"); + FAIL_TERM(msg, 2); + msg[0] = ERL_DRV_PID; + msg[1] = driver_term_nil; + FAIL_TERM(msg, 2); + + /* Not a port */ + msg[0] = ERL_DRV_PORT; + msg[1] = (ErlDrvTermData) driver_mk_atom("blurf"); + FAIL_TERM(msg, 2); + msg[0] = ERL_DRV_PORT; + msg[1] = driver_term_nil; + FAIL_TERM(msg, 2); + + /* Missing parameter on stack */ + msg[0] = ERL_DRV_STRING_CONS; + msg[1] = (ErlDrvTermData) "abc"; + msg[2] = (ErlDrvTermData) 3; + FAIL_TERM(msg, 3); + + /* + * The first binary reference is correct, the second is incorrect. + * There should not be any "binary leak". + */ + msg[0] = ERL_DRV_BINARY; + msg[1] = (ErlDrvTermData) bin; + msg[2] = (ErlDrvTermData) 256; + msg[3] = (ErlDrvTermData) 0; + msg[4] = ERL_DRV_BINARY; + msg[5] = (ErlDrvTermData) bin; + msg[6] = (ErlDrvTermData) 257; + msg[7] = (ErlDrvTermData) 0; + msg[8] = ERL_DRV_TUPLE; + msg[9] = (ErlDrvTermData) 2; + FAIL_TERM(msg, 10); + + msg[0] = ERL_DRV_BINARY; + msg[1] = (ErlDrvTermData) bin; + msg[2] = (ErlDrvTermData) 256; + msg[3] = (ErlDrvTermData) 0; + msg[4] = ERL_DRV_BINARY; + msg[5] = (ErlDrvTermData) bin; + msg[6] = (ErlDrvTermData) 256; + msg[7] = (ErlDrvTermData) 50; + msg[8] = ERL_DRV_TUPLE; + msg[9] = (ErlDrvTermData) 2; + FAIL_TERM(msg, 10); + + /* + * We have succefully built two binaries. We expect the ref count + * to be 1 (SMP) or 3 (non-SMP). + */ + refc = driver_binary_get_refc(bin); + if (refc > 3) { + char sbuf[128]; + sprintf(sbuf, "bad_refc:%d", refc); + driver_failure_atom(erlang_port, sbuf); + } + driver_free_binary(bin); + + + FAIL_TERM(msg, make_ext_term_list(msg, 1)); + + + /* + * Check that we fail for missing args. + * + * We setup valid terms but pass a too small size. We + * want valid terms since we want to verify that the + * failure really is due to the small size. + */ + msg[0] = ERL_DRV_ATOM; + msg[1] = (ErlDrvTermData) driver_mk_atom("an_atom"); + FAIL_TERM(msg, 1); + + msg[0] = ERL_DRV_INT; + msg[1] = (ErlDrvTermData) -4711; + FAIL_TERM(msg, 1); + + msg[0] = ERL_DRV_UINT; + msg[1] = (ErlDrvTermData) 4711; + FAIL_TERM(msg, 1); + + msg[0] = ERL_DRV_PORT; + msg[1] = driver_mk_port(erlang_port); + FAIL_TERM(msg, 1); + + { + char buf[] = "hejsan"; + ErlDrvBinary *dbin = driver_alloc_binary(sizeof(buf)-1); + if (!dbin) + driver_failure_posix(erlang_port, ENOMEM); + else { + memcpy((void *) dbin->orig_bytes, (void *) buf, sizeof(buf)-1); + msg[0] = ERL_DRV_BINARY; + msg[1] = (ErlDrvTermData) dbin; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + msg[3] = (ErlDrvTermData) 0; + FAIL_TERM(msg, 1); + FAIL_TERM(msg, 2); + FAIL_TERM(msg, 3); + driver_free_binary(dbin); + } + } + + { + char buf[] = "hoppsan"; + msg[0] = ERL_DRV_BUF2BINARY; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + FAIL_TERM(msg, 1); + FAIL_TERM(msg, 2); + } + + { + char buf[] = "hippsan"; + msg[0] = ERL_DRV_STRING; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf)-1; + FAIL_TERM(msg, 1); + FAIL_TERM(msg, 2); + } + + msg[0] = ERL_DRV_TUPLE; + msg[1] = (ErlDrvTermData) 0; + FAIL_TERM(msg, 1); + + msg[0] = ERL_DRV_NIL; + msg[1] = ERL_DRV_LIST; + msg[2] = (ErlDrvTermData) 1; + FAIL_TERM(msg, 2); + + msg[0] = ERL_DRV_PID; + msg[1] = driver_connected(erlang_port); + FAIL_TERM(msg, 1); + + msg[0] = ERL_DRV_NIL; + msg[1] = ERL_DRV_STRING_CONS; + msg[2] = (ErlDrvTermData) ""; + msg[3] = (ErlDrvTermData) 0; + FAIL_TERM(msg, 2); + FAIL_TERM(msg, 3); + + { + double my_float = 0.0; + msg[0] = ERL_DRV_FLOAT; + msg[1] = (ErlDrvTermData) &my_float; + FAIL_TERM(msg, 1); + } + + { + char buf[] = {131, 106}; /* [] */ + msg[0] = ERL_DRV_EXT2TERM; + msg[1] = (ErlDrvTermData) buf; + msg[2] = (ErlDrvTermData) sizeof(buf); + FAIL_TERM(msg, 1); + FAIL_TERM(msg, 2); + } + + /* Signal end of test case */ + msg[0] = ERL_DRV_NIL; + driver_output_term(erlang_port, msg, 1); + } + break; + + default: + driver_failure_atom(erlang_port, "bad_request"); + break; + } +} + +static void output_term(ErlDrvTermData* msg, int len) +{ + if (driver_output_term(erlang_port, msg, len) <= 0) { + driver_failure_atom(erlang_port, "driver_output_term_failed"); + } +} + +static void fail_term(ErlDrvTermData* msg, int len, int line) +{ + int status = driver_output_term(erlang_port, msg, len); + + if (status == 1) { + char buf[1024]; + sprintf(buf, "%s:%d: unexpected success", __FILE__, line); + driver_failure_atom(erlang_port, buf); + } else if (status == 0) { + char buf[1024]; + sprintf(buf, "%s:%d: unexpected port error", __FILE__, line); + driver_failure_atom(erlang_port, buf); + } +} + +#include "ext_terms.h" + +/* + * <<131,103,100,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,36,0,0,0,0,1>> + * is a valid pid: <0.36.0> + * + * We replace the nodename tag (atom tag: 100) with a pid tag (103) to get an + * invalid pid. + */ +static unsigned char bad_ext_term[] = { + 131,103,103,0,12,97,110,111,100,101,64,103,111,114,98,97,103,0,0,0,36,0,0,0,0,1 + /* ^ + * | + * The bad tag. + */ +}; + +static int make_ext_term_list(ErlDrvTermData *td, int bad) +{ + int tdix = 0; + int i; + for (i = 0; i < NO_OF_EXT_TERMS; i++) { + td[tdix++] = ERL_DRV_EXT2TERM; + td[tdix++] = (ErlDrvTermData) &ext_terms[i].ext[0]; + td[tdix++] = (ErlDrvTermData) ext_terms[i].ext_size; + td[tdix++] = ERL_DRV_EXT2TERM; + td[tdix++] = (ErlDrvTermData) &ext_terms[i].cext[0]; + td[tdix++] = (ErlDrvTermData) ext_terms[i].cext_size; + td[tdix++] = ERL_DRV_TUPLE; + td[tdix++] = (ErlDrvTermData) 2; + } + if (bad) { /* Include a bad ext term */ + td[tdix++] = ERL_DRV_EXT2TERM; + td[tdix++] = (ErlDrvTermData) &bad_ext_term[0]; + td[tdix++] = (ErlDrvTermData) sizeof(bad_ext_term); + } + td[tdix++] = ERL_DRV_NIL; + td[tdix++] = ERL_DRV_LIST; + td[tdix++] = (ErlDrvTermData) (NO_OF_EXT_TERMS + (bad ? 2 : 1)); + return tdix; +} |