diff options
author | Matthew Newhook <matthew@zeroc.com> | 2007-08-24 14:41:39 +0800 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2007-08-24 14:41:39 +0800 |
commit | 9ff48829c8669fbef8c7ca6a9b8bab99c77db2f9 (patch) | |
tree | 7fa0a0406be0386a8314b2e8c742f29bf127b70d /cpp/demo | |
parent | Merge branch 'bug1319' (diff) | |
download | ice-9ff48829c8669fbef8c7ca6a9b8bab99c77db2f9.tar.bz2 ice-9ff48829c8669fbef8c7ca6a9b8bab99c77db2f9.tar.xz ice-9ff48829c8669fbef8c7ca6a9b8bab99c77db2f9.zip |
Squashed commit of the following:
commit d74cec9e6c77e70b33883f517b1bb6f97b2ffa5e
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 14:33:06 2007 +0800
updates.
commit 643b31f979a00ea5397206ca59f20bb58c62660e
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 14:32:35 2007 +0800
added some .gitignore rules.
commit 1510d38798976753b435f32308e79acd9fcd2722
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 14:05:10 2007 +0800
removed bogus use of 127.0.0.1
commit 3c91e89b01af20a0dacfdbc1fbeca1c67c796656
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 14:01:43 2007 +0800
Verify that cygwin python is used under Windows.
commit ff160725c051eedb28a42d9dd69f0d8aa297e522
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 13:55:03 2007 +0800
bump timeout for the node to terminate. killing the node leaves the servers running under cygwin
commit ec3bddb58e861f906bf39aee1fa818c3e9a50000
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 13:48:55 2007 +0800
added back accidently removed files.
commit f9ea2f552d7f576ebfa878669925f4184a89257b
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 13:47:47 2007 +0800
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=2427, http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=2422
commit 8a309ca0036dba7ecbd577edb2d737fa41174a5a
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 10:06:53 2007 +0800
added ruby support to the expect scripts.
commit 34597c1ee6d80d6754c9e925bd376125dd104a5f
Author: Matthew Newhook <matthew@zeroc.com>
Date: Fri Aug 24 09:26:10 2007 +0800
added pexpect to git repository.
commit 4bd2e1f2b52bcb9906b03ac216db686b8229b545
Author: Matthew Newhook <matthew@zeroc.com>
Date: Thu Aug 23 18:49:51 2007 +0800
numerous UNIX expect script fixes.
commit 25ab4a812f45a6e908d5d2d7ab03e557d79afa9f
Author: Matthew Newhook <matthew@zeroc.com>
Date: Thu Aug 23 16:47:08 2007 +0800
generate configuration files for IceGrid icebox/iceboxd
commit 6bb57bf7ed21d7256963c228aaf0b20657367a47
Author: Matthew Newhook <matthew@zeroc.com>
Date: Thu Aug 23 15:16:55 2007 +0800
added python & C# support to the expect scripts.
commit 08f1a59971ad3a52a4357069554dcc309b2d062b
Author: Matthew Newhook <matthew@zeroc.com>
Date: Wed Aug 22 14:23:53 2007 +0800
java expect scripts complete.
commit 3918f4ff3beea3005001bc55c5502c0825d8b7ea
Author: Matthew Newhook <matthew@zeroc.com>
Date: Wed Aug 22 13:30:31 2007 +0800
first set of expect changes.
Diffstat (limited to 'cpp/demo')
45 files changed, 320 insertions, 901 deletions
diff --git a/cpp/demo/Freeze/backup/expect.py b/cpp/demo/Freeze/backup/expect.py index 1b37cdc5718..98c530a84e8 100755 --- a/cpp/demo/Freeze/backup/expect.py +++ b/cpp/demo/Freeze/backup/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,7 +23,9 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import signal, time +import demoscript.pexpect as pexpect print "cleaning databases...", sys.stdout.flush() @@ -49,8 +51,7 @@ print "performing full backup...", sys.stdout.flush() backup = demoscript.Util.spawn('./backup full') backup.expect('hot backup started', timeout=30) -backup.expect(pexpect.EOF, timeout=30) -assert backup.wait() == 0 +backup.waitTestSuccess(timeout=30) print "ok" print "sleeping 5s...", @@ -62,7 +63,7 @@ print "performing incremental backup...", sys.stdout.flush() backup = demoscript.Util.spawn('./backup incremental') backup.expect('hot backup started', timeout=30) -backup.expect(pexpect.EOF, timeout=30) +backup.waitTestSuccess(timeout=30) print "ok" print "sleeping 30s...", @@ -76,7 +77,8 @@ print "killing client with SIGTERM...", sys.stdout.flush() client.kill(signal.SIGTERM) client.expect(pexpect.EOF, timeout=30) -assert client.wait() != 0 +client.wait() +assert client.signalstatus == signal.SIGTERM print "ok" print "Client output: ", @@ -88,9 +90,9 @@ os.system('rm -fr db/data/* db/logs/* db/__*') os.system('cp -Rp hotbackup/* db') sys.stdout.flush() -rclient = demoscript.Util.spawn('./client') -rclient.expect('(.*)Updating map', timeout=60) -assert rclient.match.group(1).find('Creating new map') == -1 +client = demoscript.Util.spawn('./client') +client.expect('(.*)Updating map', timeout=60) +assert client.match.group(1).find('Creating new map') == -1 print "ok" print "sleeping 5s...", @@ -99,10 +101,11 @@ time.sleep(5) print "ok" print "killing client with SIGTERM...", -rclient.kill(signal.SIGTERM) -rclient.expect(pexpect.EOF, timeout=30) -assert rclient.wait() != 0 +client.kill(signal.SIGTERM) +client.expect(pexpect.EOF, timeout=30) +client.wait() +assert client.signalstatus == signal.SIGTERM print "ok" print "Restarted client output:", -print "%s " % (rclient.before) +print "%s " % (client.before) diff --git a/cpp/demo/Freeze/bench/expect.py b/cpp/demo/Freeze/bench/expect.py index fa0e0ea8e41..aa61a4b3012 100755 --- a/cpp/demo/Freeze/bench/expect.py +++ b/cpp/demo/Freeze/bench/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.Freeze.bench print "cleaning databases...", diff --git a/cpp/demo/Freeze/customEvictor/expect.py b/cpp/demo/Freeze/customEvictor/expect.py index ff7ddf43115..005e9e93ee9 100755 --- a/cpp/demo/Freeze/customEvictor/expect.py +++ b/cpp/demo/Freeze/customEvictor/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os, signal +import sys, os, signal try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" if demoscript.Util.isDarwin(): print "This demo is not supported under MacOS." @@ -38,22 +39,19 @@ server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect(".* ready", timeout=120) client = demoscript.Util.spawn('./client') -client.expect(pexpect.EOF, timeout=200) +client.waitTestSuccess(timeout=8 * 60) print client.before server.kill(signal.SIGINT) -server.expect(pexpect.EOF, timeout=60) -assert server.wait() == 0 +server.waitTestSuccess(timeout=60) print "testing simple evictor" server = demoscript.Util.spawn('./server simple --Ice.PrintAdapterReady') server.expect(".* ready") client = demoscript.Util.spawn('./client') -client.expect(pexpect.EOF, timeout=200) -assert client.wait() == 0 +client.waitTestSuccess(timeout=8*60) print client.before server.kill(signal.SIGINT) -server.expect(pexpect.EOF, timeout=60) -assert server.wait() == 0 +server.waitTestSuccess(timeout=60) diff --git a/cpp/demo/Freeze/library/Parser.cpp b/cpp/demo/Freeze/library/Parser.cpp index c884b42fd6e..257ac8ca43b 100644 --- a/cpp/demo/Freeze/library/Parser.cpp +++ b/cpp/demo/Freeze/library/Parser.cpp @@ -40,10 +40,9 @@ Parser::usage() "shutdown Shut the library server down.\n"; } -ParserPtr -Parser::createParser(const LibraryPrx& library) +Parser::Parser(const LibraryPrx& library) : + _library(library) { - return new Parser(library); } void @@ -354,114 +353,73 @@ Parser::shutdown() void Parser::getInput(char* buf, int& result, int maxSize) { - if(!_commands.empty()) +#ifdef HAVE_READLINE + + const char* prompt = parser->getPrompt(); + char* line = readline(const_cast<char*>(prompt)); + if(!line) { - if(_commands == ";") - { - result = 0; - } - else - { -#if defined(_MSC_VER) && !defined(_STLP_MSVC) - // COMPILERBUG: Stupid Visual C++ defines min and max as macros - result = _MIN(maxSize, static_cast<int>(_commands.length())); -#else - result = min(maxSize, static_cast<int>(_commands.length())); -#endif - strncpy(buf, _commands.c_str(), result); - _commands.erase(0, result); - if(_commands.empty()) - { - _commands = ";"; - } - } + result = 0; } - else if(isatty(fileno(yyin))) + else { -#ifdef HAVE_READLINE - - const char* prompt = parser->getPrompt(); - char* line = readline(const_cast<char*>(prompt)); - if(!line) + if(*line) + { + add_history(line); + } + + result = strlen(line) + 1; + if(result > maxSize) { + free(line); + error("input line too long"); result = 0; } else { - if(*line) - { - add_history(line); - } - - result = strlen(line) + 1; - if(result > maxSize) - { - free(line); - error("input line too long"); - result = 0; - } - else - { - strcpy(buf, line); - strcat(buf, "\n"); - free(line); - } + strcpy(buf, line); + strcat(buf, "\n"); + free(line); } - + } + #else - cout << parser->getPrompt() << flush; + cout << parser->getPrompt() << flush; - string line; - while(true) + string line; + while(true) + { + char c = static_cast<char>(getc(yyin)); + if(c == EOF) { - char c = static_cast<char>(getc(yyin)); - if(c == EOF) + if(line.size()) { - if(line.size()) - { - line += '\n'; - } - break; + line += '\n'; } + break; + } - line += c; + line += c; - if(c == '\n') - { - break; - } - } - - result = static_cast<int>(line.length()); - if(result > maxSize) - { - error("input line too long"); - buf[0] = EOF; - result = 1; - } - else + if(c == '\n') { - strcpy(buf, line.c_str()); + break; } + } -#endif + result = static_cast<int>(line.length()); + if(result > maxSize) + { + error("input line too long"); + buf[0] = EOF; + result = 1; } else { - if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) - { - error("input in flex scanner failed"); - buf[0] = EOF; - result = 1; - } + strcpy(buf, line.c_str()); } -} - -void -Parser::nextLine() -{ - _currentLine++; +#endif } void @@ -473,8 +431,6 @@ Parser::continueLine() const char* Parser::getPrompt() { - assert(_commands.empty() && isatty(fileno(yyin))); - if(_continue) { _continue = false; @@ -489,14 +445,7 @@ Parser::getPrompt() void Parser::error(const char* s) { - if(_commands.empty() && !isatty(fileno(yyin))) - { - cerr << _currentFile << ':' << _currentLine << ": " << s << endl; - } - else - { - cerr << "error: " << s << endl; - } + cerr << "error: " << s << endl; _errors++; } @@ -509,14 +458,7 @@ Parser::error(const string& s) void Parser::warning(const char* s) { - if(_commands.empty() && !isatty(fileno(yyin))) - { - cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; - } - else - { - cerr << "warning: " << s << endl; - } + cerr << "warning: " << s << endl; } void @@ -526,7 +468,7 @@ Parser::warning(const string& s) } int -Parser::parse(FILE* file, bool debug) +Parser::parse(bool debug) { extern int yydebug; yydebug = debug ? 1 : 0; @@ -535,46 +477,10 @@ Parser::parse(FILE* file, bool debug) parser = this; _errors = 0; - _commands.empty(); - yyin = file; + yyin = stdin; assert(yyin); - _currentFile = ""; - _currentLine = 0; - _continue = false; - nextLine(); - - _foundBooks.clear(); - _current = _foundBooks.end(); - - int status = yyparse(); - if(_errors) - { - status = EXIT_FAILURE; - } - - parser = 0; - return status; -} - -int -Parser::parse(const string& commands, bool debug) -{ - extern int yydebug; - yydebug = debug ? 1 : 0; - - assert(!parser); - parser = this; - - _errors = 0; - _commands = commands; - assert(!_commands.empty()); - yyin = 0; - - _currentFile = "<command line>"; - _currentLine = 0; _continue = false; - nextLine(); _foundBooks.clear(); _current = _foundBooks.end(); @@ -588,8 +494,3 @@ Parser::parse(const string& commands, bool debug) parser = 0; return status; } - -Parser::Parser(const LibraryPrx& library) : - _library(library) -{ -} diff --git a/cpp/demo/Freeze/library/Parser.h b/cpp/demo/Freeze/library/Parser.h index 0cb997203f4..6acc6283938 100644 --- a/cpp/demo/Freeze/library/Parser.h +++ b/cpp/demo/Freeze/library/Parser.h @@ -15,16 +15,6 @@ #include <list> #include <stdio.h> -#ifdef _WIN32 -# include <io.h> -# ifdef _MSC_VER -# define isatty _isatty -# define fileno _fileno -// '_isatty' : inconsistent dll linkage. dllexport assumed. -# pragma warning( disable : 4273 ) -# endif -#endif - // // Stuff for flex and bison // @@ -57,7 +47,7 @@ class Parser : public IceUtil::SimpleShared { public: - static ParserPtr createParser(const Demo::LibraryPrx&); + Parser(const Demo::LibraryPrx&); void usage(); @@ -73,7 +63,6 @@ public: void shutdown(); void getInput(char*, int&, int); - void nextLine(); void continueLine(); const char* getPrompt(); @@ -83,22 +72,16 @@ public: void warning(const char*); void warning(const std::string&); - int parse(FILE*, bool); - int parse(const std::string&, bool); + int parse(bool = false); private: - Parser(const Demo::LibraryPrx&); - Demo::BookPrxSeq _foundBooks; Demo::BookPrxSeq::iterator _current; - std::string _commands; const Demo::LibraryPrx _library; bool _continue; int _errors; - int _currentLine; - std::string _currentFile; }; extern Parser* parser; // The current parser for bison/flex diff --git a/cpp/demo/Freeze/library/RunParser.cpp b/cpp/demo/Freeze/library/RunParser.cpp index 034a708e745..4cb286f04cf 100644 --- a/cpp/demo/Freeze/library/RunParser.cpp +++ b/cpp/demo/Freeze/library/RunParser.cpp @@ -13,84 +13,9 @@ using namespace std; using namespace Demo; -void -usage(const char* appName) -{ - cerr << "Usage: " << appName << " [options] [file...]\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "-e COMMANDS Execute COMMANDS.\n" - "-d, --debug Print debug messages.\n" - ; -} - int runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { - string commands; - bool debug = false; - - int idx = 1; - while(idx < argc) - { - if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) - { - usage(argv[0]); - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) - { - cout << ICE_STRING_VERSION << endl; - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-e") == 0) - { - if(idx + 1 >= argc) - { - cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - commands += argv[idx + 1]; - commands += ';'; - - for(int i = idx ; i + 2 < argc ; ++i) - { - argv[i] = argv[i + 2]; - } - argc -= 2; - } - else if(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) - { - debug = true; - for(int i = idx ; i + 1 < argc ; ++i) - { - argv[i] = argv[i + 1]; - } - --argc; - } - else if(argv[idx][0] == '-') - { - cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - else - { - ++idx; - } - } - - if(argc >= 2 && !commands.empty()) - { - cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - LibraryPrx library = LibraryPrx::checkedCast(communicator->propertyToProxy("Library.Proxy")); if(!library) { @@ -98,49 +23,6 @@ runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) return EXIT_FAILURE; } - ParserPtr p = Parser::createParser(library); - int status = EXIT_SUCCESS; - - if(argc < 2) // No files given - { - if(!commands.empty()) // Commands were given - { - int parseStatus = p->parse(commands, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - else // No commands, let's use standard input - { - int parseStatus = p->parse(stdin, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - } - else // Process files given on the command line - { - for(idx = 1 ; idx < argc ; ++idx) - { - FILE* file = fopen(argv[idx], "r"); - if(file == NULL) - { - cerr << argv[0] << ": can't open file `" << argv[idx] << "': " << strerror(errno) << endl; - return EXIT_FAILURE; - } - - int parseStatus = p->parse(file, debug); - - fclose(file); - - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - } - - return status; + ParserPtr p = new Parser(library); + return p->parse(); } diff --git a/cpp/demo/Freeze/library/Scanner.l b/cpp/demo/Freeze/library/Scanner.l index dc635df98f7..88645927ce1 100644 --- a/cpp/demo/Freeze/library/Scanner.l +++ b/cpp/demo/Freeze/library/Scanner.l @@ -40,10 +40,6 @@ NL [\n] do { c = yyinput(); - if(c == '\n') - { - parser->nextLine(); - } } while(c != '\n' && c != EOF); } @@ -53,11 +49,7 @@ NL [\n] while(true) { int c = yyinput(); - if(c == '\n') - { - parser->nextLine(); - } - else if(c == '*') + if(c == '*') { int next = yyinput(); if(next == '/') @@ -133,22 +125,10 @@ NL [\n] { parser->continueLine(); } - else if(yytext[i] == '\n') - { - parser->nextLine(); - } } } {NL}|; { - size_t len = strlen(yytext); - for(size_t i = 0; i < len; ++i) - { - if(yytext[i] == '\n') - { - parser->nextLine(); - } - } return ';'; } @@ -167,11 +147,6 @@ NL [\n] parser->warning("EOF in string"); break; } - else if(c == '\n') - { - s += c; - parser->nextLine(); - } else if(c == '\\') { char next = static_cast<char>(yyinput()); @@ -246,11 +221,6 @@ NL [\n] parser->warning("EOF in string"); break; } - else if(c == '\n') - { - s += c; - parser->nextLine(); - } else { s += c; diff --git a/cpp/demo/Freeze/library/expect.py b/cpp/demo/Freeze/library/expect.py index 4e75062933c..4251370723e 100755 --- a/cpp/demo/Freeze/library/expect.py +++ b/cpp/demo/Freeze/library/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.Freeze.library print "cleaning databases...", @@ -33,18 +34,10 @@ print "ok" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady --Freeze.Trace.Evictor=0 --Freeze.Trace.DbEnv=0') server.expect('.* ready') client = demoscript.Util.spawn('./client') -client.expect('>>> ') +client.expect('>') demoscript.Freeze.library.run(client, server) -client.sendline('shutdown') -server.expect(pexpect.EOF) -assert server.wait() == 0 - -client.sendline('exit') -client.expect(pexpect.EOF) -assert server.wait() == 0 - print "running with collocated server" print "cleaning databases...", @@ -56,7 +49,3 @@ server = demoscript.Util.spawn('./collocated --Freeze.Trace.Evictor=0 --Freeze.T server.expect('>>> ') demoscript.Freeze.library.run(server, server) - -server.sendline('exit') -server.expect(pexpect.EOF) -assert server.wait() == 0 diff --git a/cpp/demo/Freeze/phonebook/Parser.cpp b/cpp/demo/Freeze/phonebook/Parser.cpp index a93bab7648d..d041f001ffa 100644 --- a/cpp/demo/Freeze/phonebook/Parser.cpp +++ b/cpp/demo/Freeze/phonebook/Parser.cpp @@ -41,10 +41,9 @@ Parser::usage() "shutdown Shut the phonebook server down.\n"; } -ParserPtr -Parser::createParser(const PhoneBookPrx& phoneBook) +Parser::Parser(const PhoneBookPrx& phoneBook) : + _phoneBook(phoneBook) { - return new Parser(phoneBook); } void @@ -333,114 +332,73 @@ Parser::shutdown() void Parser::getInput(char* buf, int& result, int maxSize) { - if(!_commands.empty()) +#ifdef HAVE_READLINE + + const char* prompt = parser->getPrompt(); + char* line = readline(const_cast<char*>(prompt)); + if(!line) { - if(_commands == ";") - { - result = 0; - } - else - { -#if defined(_MSC_VER) && !defined(_STLP_MSVC) - // COMPILERBUG: Stupid Visual C++ defines min and max as macros - result = _MIN(maxSize, static_cast<int>(_commands.length())); -#else - result = min(maxSize, static_cast<int>(_commands.length())); -#endif - strncpy(buf, _commands.c_str(), result); - _commands.erase(0, result); - if(_commands.empty()) - { - _commands = ";"; - } - } + result = 0; } - else if(isatty(fileno(yyin))) + else { -#ifdef HAVE_READLINE + if(*line) + { + add_history(line); + } - const char* prompt = parser->getPrompt(); - char* line = readline(const_cast<char*>(prompt)); - if(!line) + result = strlen(line) + 1; + if(result > maxSize) { + free(line); + error("input line too long"); result = 0; } else { - if(*line) - { - add_history(line); - } - - result = strlen(line) + 1; - if(result > maxSize) - { - free(line); - error("input line too long"); - result = 0; - } - else - { - strcpy(buf, line); - strcat(buf, "\n"); - free(line); - } + strcpy(buf, line); + strcat(buf, "\n"); + free(line); } + } #else - cout << parser->getPrompt() << flush; + cout << parser->getPrompt() << flush; - string line; - while(true) + string line; + while(true) + { + char c = static_cast<char>(getc(yyin)); + if(c == EOF) { - char c = static_cast<char>(getc(yyin)); - if(c == EOF) + if(line.size()) { - if(line.size()) - { - line += '\n'; - } - break; + line += '\n'; } + break; + } - line += c; + line += c; - if(c == '\n') - { - break; - } - } - - result = static_cast<int>(line.length()); - if(result > maxSize) - { - error("input line too long"); - buf[0] = EOF; - result = 1; - } - else + if(c == '\n') { - strcpy(buf, line.c_str()); + break; } + } -#endif + result = static_cast<int>(line.length()); + if(result > maxSize) + { + error("input line too long"); + buf[0] = EOF; + result = 1; } else { - if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) - { - error("input in flex scanner failed"); - buf[0] = EOF; - result = 1; - } + strcpy(buf, line.c_str()); } -} - -void -Parser::nextLine() -{ - _currentLine++; +#endif } void @@ -452,8 +410,6 @@ Parser::continueLine() const char* Parser::getPrompt() { - assert(_commands.empty() && isatty(fileno(yyin))); - if(_continue) { _continue = false; @@ -468,14 +424,7 @@ Parser::getPrompt() void Parser::error(const char* s) { - if(_commands.empty() && !isatty(fileno(yyin))) - { - cerr << _currentFile << ':' << _currentLine << ": " << s << endl; - } - else - { - cerr << "error: " << s << endl; - } + cerr << "error: " << s << endl; _errors++; } @@ -488,14 +437,7 @@ Parser::error(const string& s) void Parser::warning(const char* s) { - if(_commands.empty() && !isatty(fileno(yyin))) - { - cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; - } - else - { - cerr << "warning: " << s << endl; - } + cerr << "warning: " << s << endl; } void @@ -505,7 +447,7 @@ Parser::warning(const string& s) } int -Parser::parse(FILE* file, bool debug) +Parser::parse(bool debug) { extern int yydebug; yydebug = debug ? 1 : 0; @@ -514,46 +456,10 @@ Parser::parse(FILE* file, bool debug) parser = this; _errors = 0; - _commands.empty(); - yyin = file; + yyin = stdin; assert(yyin); - _currentFile = ""; - _currentLine = 0; - _continue = false; - nextLine(); - - _foundContacts.clear(); - _current = _foundContacts.end(); - - int status = yyparse(); - if(_errors) - { - status = EXIT_FAILURE; - } - - parser = 0; - return status; -} - -int -Parser::parse(const string& commands, bool debug) -{ - extern int yydebug; - yydebug = debug ? 1 : 0; - - assert(!parser); - parser = this; - - _errors = 0; - _commands = commands; - assert(!_commands.empty()); - yyin = 0; - - _currentFile = "<command line>"; - _currentLine = 0; _continue = false; - nextLine(); _foundContacts.clear(); _current = _foundContacts.end(); @@ -568,7 +474,3 @@ Parser::parse(const string& commands, bool debug) return status; } -Parser::Parser(const PhoneBookPrx& phoneBook) : - _phoneBook(phoneBook) -{ -} diff --git a/cpp/demo/Freeze/phonebook/Parser.h b/cpp/demo/Freeze/phonebook/Parser.h index 5f5dfe2ba7d..5e889a02a35 100644 --- a/cpp/demo/Freeze/phonebook/Parser.h +++ b/cpp/demo/Freeze/phonebook/Parser.h @@ -15,16 +15,6 @@ #include <list> #include <stdio.h> -#ifdef _WIN32 -# include <io.h> -# ifdef _MSC_VER -# define isatty _isatty -# define fileno _fileno -// '_isatty' : inconsistent dll linkage. dllexport assumed. -# pragma warning( disable : 4273 ) -# endif -#endif - // // Stuff for flex and bison // @@ -57,7 +47,7 @@ class Parser : public ::IceUtil::SimpleShared { public: - static ParserPtr createParser(const Demo::PhoneBookPrx&); + Parser(const Demo::PhoneBookPrx&); void usage(); @@ -73,7 +63,6 @@ public: void shutdown(); void getInput(char*, int&, int); - void nextLine(); void continueLine(); const char* getPrompt(); @@ -83,22 +72,17 @@ public: void warning(const char*); void warning(const std::string&); - int parse(FILE*, bool); - int parse(const std::string&, bool); + int parse(bool = false); private: - Parser(const Demo::PhoneBookPrx&); Demo::Contacts _foundContacts; Demo::Contacts::iterator _current; - std::string _commands; const Demo::PhoneBookPrx _phoneBook; bool _continue; int _errors; - int _currentLine; - std::string _currentFile; }; extern Parser* parser; // The current parser for bison/flex diff --git a/cpp/demo/Freeze/phonebook/RunParser.cpp b/cpp/demo/Freeze/phonebook/RunParser.cpp index 6fce1244c50..17a5f4a61e7 100644 --- a/cpp/demo/Freeze/phonebook/RunParser.cpp +++ b/cpp/demo/Freeze/phonebook/RunParser.cpp @@ -13,84 +13,9 @@ using namespace std; using namespace Demo; -void -usage(const char* appName) -{ - cerr << "Usage: " << appName << " [options] [file...]\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "-e COMMANDS Execute COMMANDS.\n" - "-d, --debug Print debug messages.\n" - ; -} - int runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { - string commands; - bool debug = false; - - int idx = 1; - while(idx < argc) - { - if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) - { - usage(argv[0]); - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) - { - cout << ICE_STRING_VERSION << endl; - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-e") == 0) - { - if(idx + 1 >= argc) - { - cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - commands += argv[idx + 1]; - commands += ';'; - - for(int i = idx ; i + 2 < argc ; ++i) - { - argv[i] = argv[i + 2]; - } - argc -= 2; - } - else if(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) - { - debug = true; - for(int i = idx ; i + 1 < argc ; ++i) - { - argv[i] = argv[i + 1]; - } - --argc; - } - else if(argv[idx][0] == '-') - { - cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - else - { - ++idx; - } - } - - if(argc >= 2 && !commands.empty()) - { - cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - PhoneBookPrx phoneBook = PhoneBookPrx::checkedCast(communicator->propertyToProxy("PhoneBook.Proxy")); if(!phoneBook) { @@ -98,49 +23,6 @@ runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) return EXIT_FAILURE; } - ParserPtr p = Parser::createParser(phoneBook); - int status = EXIT_SUCCESS; - - if(argc < 2) // No files given - { - if(!commands.empty()) // Commands were given - { - int parseStatus = p->parse(commands, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - else // No commands, let's use standard input - { - int parseStatus = p->parse(stdin, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - } - else // Process files given on the command line - { - for(idx = 1 ; idx < argc ; ++idx) - { - FILE* file = fopen(argv[idx], "r"); - if(file == NULL) - { - cerr << argv[0] << ": can't open file `" << argv[idx] << "': " << strerror(errno) << endl; - return EXIT_FAILURE; - } - - int parseStatus = p->parse(file, debug); - - fclose(file); - - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - } - - return status; + ParserPtr p = new Parser(phoneBook); + return p->parse(); } diff --git a/cpp/demo/Freeze/phonebook/Scanner.l b/cpp/demo/Freeze/phonebook/Scanner.l index 8fccc203d10..69b015c1c3e 100644 --- a/cpp/demo/Freeze/phonebook/Scanner.l +++ b/cpp/demo/Freeze/phonebook/Scanner.l @@ -40,10 +40,6 @@ NL [\n] do { c = yyinput(); - if(c == '\n') - { - parser->nextLine(); - } } while(c != '\n' && c != EOF); } @@ -53,11 +49,7 @@ NL [\n] while(true) { int c = yyinput(); - if(c == '\n') - { - parser->nextLine(); - } - else if(c == '*') + if(c == '*') { int next = yyinput(); if(next == '/') @@ -133,22 +125,10 @@ NL [\n] { parser->continueLine(); } - else if(yytext[i] == '\n') - { - parser->nextLine(); - } } } {NL}|; { - size_t len = strlen(yytext); - for(size_t i = 0; i < len; ++i) - { - if(yytext[i] == '\n') - { - parser->nextLine(); - } - } return ';'; } @@ -167,11 +147,6 @@ NL [\n] parser->warning("EOF in string"); break; } - else if(c == '\n') - { - s += c; - parser->nextLine(); - } else if(c == '\\') { char next = static_cast<char>(yyinput()); @@ -246,11 +221,6 @@ NL [\n] parser->warning("EOF in string"); break; } - else if(c == '\n') - { - s += c; - parser->nextLine(); - } else { s += c; diff --git a/cpp/demo/Freeze/phonebook/expect.py b/cpp/demo/Freeze/phonebook/expect.py index 1bf5b900509..a5ace6318c0 100755 --- a/cpp/demo/Freeze/phonebook/expect.py +++ b/cpp/demo/Freeze/phonebook/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.Freeze.phonebook print "cleaning databases...", @@ -37,12 +38,6 @@ client.expect('>>> ') demoscript.Freeze.phonebook.run(client, server) -client.sendline('shutdown') -server.expect(pexpect.EOF) - -client.sendline('exit') -client.expect(pexpect.EOF) - print "running with collocated server" print "cleaning databases...", @@ -54,6 +49,3 @@ server = demoscript.Util.spawn('./collocated --Freeze.Trace.Evictor=0 --Freeze.T server.expect('>>> ') demoscript.Freeze.phonebook.run(server, server) - -server.sendline('exit') -server.expect(pexpect.EOF) diff --git a/cpp/demo/Glacier2/callback/Client.cpp b/cpp/demo/Glacier2/callback/Client.cpp index 5c310a4717b..baf24c50747 100644 --- a/cpp/demo/Glacier2/callback/Client.cpp +++ b/cpp/demo/Glacier2/callback/Client.cpp @@ -217,6 +217,10 @@ CallbackClient::run(int argc, char* argv[]) { router->destroySession(); } + catch(const Glacier2::SessionNotExistException& ex) + { + cerr << ex << endl; + } catch(const Ice::ConnectionLostException&) { // diff --git a/cpp/demo/Glacier2/callback/expect.py b/cpp/demo/Glacier2/callback/expect.py index 19db7e98914..7700c5e2d0f 100755 --- a/cpp/demo/Glacier2/callback/expect.py +++ b/cpp/demo/Glacier2/callback/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.Glacier2.callback server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') diff --git a/cpp/demo/Glacier2/chat/expect.py b/cpp/demo/Glacier2/chat/expect.py index b78f32706c2..28cae21f1db 100755 --- a/cpp/demo/Glacier2/chat/expect.py +++ b/cpp/demo/Glacier2/chat/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os, signal try: import demoscript except ImportError: @@ -22,6 +22,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') @@ -61,11 +62,15 @@ client2.expect("bar says: hello") client1.expect("bar says: hello") client1.sendline("/quit") -client1.expect(pexpect.EOF) -assert client1.wait() == 0 +client1.waitTestSuccess() client2.expect("foo has left the chat room") client2.sendline("/quit") -client2.expect(pexpect.EOF) -assert client2.wait() == 0 +client2.waitTestSuccess() print "ok" + +server.kill(signal.SIGINT) +server.waitTestSuccess() + +glacier2.kill(signal.SIGINT) +glacier2.waitTestSuccess() diff --git a/cpp/demo/Ice/async/expect.py b/cpp/demo/Ice/async/expect.py index d5f6cf69b56..abdc336cd71 100755 --- a/cpp/demo/Ice/async/expect.py +++ b/cpp/demo/Ice/async/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.async +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/bidir/expect.py b/cpp/demo/Ice/bidir/expect.py index 58cbc023aab..b6c9b8c477c 100755 --- a/cpp/demo/Ice/bidir/expect.py +++ b/cpp/demo/Ice/bidir/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.bidir +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/callback/expect.py b/cpp/demo/Ice/callback/expect.py index ff556c54954..03610876eba 100755 --- a/cpp/demo/Ice/callback/expect.py +++ b/cpp/demo/Ice/callback/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.callback +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/converter/expect.py b/cpp/demo/Ice/converter/expect.py index f6f31af7378..6a8c8818a8d 100755 --- a/cpp/demo/Ice/converter/expect.py +++ b/cpp/demo/Ice/converter/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') @@ -43,9 +44,7 @@ client.expect('Received \\(LATIN-1\\): "Bonne journ\\\\351e"') print "ok" client.sendline('s') -server.expect(pexpect.EOF) -assert server.wait() == 0 +server.waitTestSuccess() client.sendline('x') -client.expect(pexpect.EOF) -assert client.wait() == 0 +client.waitTestSuccess() diff --git a/cpp/demo/Ice/hello/expect.py b/cpp/demo/Ice/hello/expect.py index ccfe9c90ab4..90191bc82e1 100755 --- a/cpp/demo/Ice/hello/expect.py +++ b/cpp/demo/Ice/hello/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.hello +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/invoke/expect.py b/cpp/demo/Ice/invoke/expect.py index 7ac50f77917..127c09ed6e9 100755 --- a/cpp/demo/Ice/invoke/expect.py +++ b/cpp/demo/Ice/invoke/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.invoke +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/latency/expect.py b/cpp/demo/Ice/latency/expect.py index 24bdb1e2e31..3ef21814490 100755 --- a/cpp/demo/Ice/latency/expect.py +++ b/cpp/demo/Ice/latency/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') @@ -30,8 +31,11 @@ server.expect('.* ready') print "testing ping... ", sys.stdout.flush() client = demoscript.Util.spawn('./client') -client.expect(pexpect.EOF, timeout=100) -assert client.wait() == 0 +client.waitTestSuccess(timeout=100) print "ok" +import signal +server.kill(signal.SIGINT) +server.waitTestSuccess() + print client.before diff --git a/cpp/demo/Ice/minimal/expect.py b/cpp/demo/Ice/minimal/expect.py index e4246cbf6d6..bc0fa8a901c 100755 --- a/cpp/demo/Ice/minimal/expect.py +++ b/cpp/demo/Ice/minimal/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,7 +23,7 @@ except ImportError: import demoscript import demoscript.Util -import signal +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') @@ -31,11 +31,10 @@ server.expect('.* ready') print "testing...", sys.stdout.flush() client = demoscript.Util.spawn('./client') -client.expect(pexpect.EOF) -assert client.wait() == 0 +client.waitTestSuccess() server.expect('Hello World!') print "ok" +import signal server.kill(signal.SIGINT) -server.expect(pexpect.EOF) -assert server.wait() == 0 +server.waitTestSuccess() diff --git a/cpp/demo/Ice/nested/expect.py b/cpp/demo/Ice/nested/expect.py index 0d4434fb857..eea9bf7019a 100755 --- a/cpp/demo/Ice/nested/expect.py +++ b/cpp/demo/Ice/nested/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.nested +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/session/expect.py b/cpp/demo/Ice/session/expect.py index 7093707b625..0366cc47e93 100755 --- a/cpp/demo/Ice/session/expect.py +++ b/cpp/demo/Ice/session/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.session +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/throughput/expect.py b/cpp/demo/Ice/throughput/expect.py index 262a3b92f56..b9fa0b26075 100755 --- a/cpp/demo/Ice/throughput/expect.py +++ b/cpp/demo/Ice/throughput/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.throughput +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/Ice/value/expect.py b/cpp/demo/Ice/value/expect.py index 039264a9e1a..41a66b74078 100755 --- a/cpp/demo/Ice/value/expect.py +++ b/cpp/demo/Ice/value/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -24,6 +24,7 @@ except ImportError: import demoscript.Util import demoscript.Ice.value +demoscript.Util.defaultLanguage = "C++" server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') diff --git a/cpp/demo/IceBox/hello/expect.py b/cpp/demo/IceBox/hello/expect.py index 2c0f7ce07cf..8b740d1d553 100755 --- a/cpp/demo/IceBox/hello/expect.py +++ b/cpp/demo/IceBox/hello/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.IceBox.hello if demoscript.Util.defaultHost: diff --git a/cpp/demo/IceGrid/allocate/expect.py b/cpp/demo/IceGrid/allocate/expect.py index 6755f0d69e1..6639f83c081 100755 --- a/cpp/demo/IceGrid/allocate/expect.py +++ b/cpp/demo/IceGrid/allocate/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.IceGrid.allocate demoscript.IceGrid.allocate.run('./client') diff --git a/cpp/demo/IceGrid/replication/expect.py b/cpp/demo/IceGrid/replication/expect.py index 5921f418b7f..2ccac6abb76 100755 --- a/cpp/demo/IceGrid/replication/expect.py +++ b/cpp/demo/IceGrid/replication/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import signal @@ -73,8 +74,7 @@ def runtest(): client.sendline('x') client.kill(signal.SIGINT) - client.expect(pexpect.EOF, timeout=1) - assert client.wait() == 0 + client.waitTestSuccess(timeout=1) print "testing client...", sys.stdout.flush() @@ -85,31 +85,25 @@ print "testing replication...", sys.stdout.flush() admin.sendline('registry shutdown Replica1') admin.expect('>>>') -replica1.expect(pexpect.EOF) -assert replica1.wait() == 0 +replica1.waitTestSuccess() runtest() admin.sendline('registry shutdown Replica2') admin.expect('>>>') -replica2.expect(pexpect.EOF) -assert replica2.wait() == 0 +replica2.waitTestSuccess() runtest() print "ok" admin.sendline('node shutdown node1') admin.expect('>>>') -node1.expect(pexpect.EOF) -assert node1.wait() == 0 +node1.waitTestSuccess(timeout=120) admin.sendline('node shutdown node2') admin.expect('>>>') -node2.expect(pexpect.EOF) -assert node2.wait() == 0 +node2.waitTestSuccess(timeout=120) admin.sendline('registry shutdown Master') admin.expect('>>>') -master.expect(pexpect.EOF) -assert master.wait() == 0 +master.waitTestSuccess() admin.sendline('exit') -admin.expect(pexpect.EOF) -assert admin.wait() == 0 +admin.waitTestSuccess() diff --git a/cpp/demo/IceGrid/sessionActivation/expect.py b/cpp/demo/IceGrid/sessionActivation/expect.py index da0dfced31a..f992c4d1369 100755 --- a/cpp/demo/IceGrid/sessionActivation/expect.py +++ b/cpp/demo/IceGrid/sessionActivation/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.IceGrid.sessionActivation demoscript.IceGrid.sessionActivation.run('./client') diff --git a/cpp/demo/IceGrid/simple/expect.py b/cpp/demo/IceGrid/simple/expect.py index 2bc8048ca31..cf54b840838 100755 --- a/cpp/demo/IceGrid/simple/expect.py +++ b/cpp/demo/IceGrid/simple/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.IceGrid.simple demoscript.IceGrid.simple.run('./client') diff --git a/cpp/demo/IceStorm/clock/expect.py b/cpp/demo/IceStorm/clock/expect.py index b303c340957..ab7032b1e7d 100755 --- a/cpp/demo/IceStorm/clock/expect.py +++ b/cpp/demo/IceStorm/clock/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.IceStorm.clock demoscript.IceStorm.clock.run('./subscriber', './publisher') diff --git a/cpp/demo/IceStorm/counter/expect.py b/cpp/demo/IceStorm/counter/expect.py index 95c7cf9285a..8b33014fb20 100755 --- a/cpp/demo/IceStorm/counter/expect.py +++ b/cpp/demo/IceStorm/counter/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,7 +23,7 @@ except ImportError: import demoscript import demoscript.Util - +demoscript.Util.defaultLanguage = "C++" import signal print "cleaning databases...", @@ -69,22 +69,20 @@ print "ok" print "testing removing client...", client3.sendline('x') -client3.expect(pexpect.EOF) -assert client3.wait() == 0 +client3.waitTestSuccess() client2.sendline('d') client1.expect('int: -1 total: 0') client2.expect('int: -1 total: 0') client1.sendline('x') -client1.expect(pexpect.EOF) -assert client1.wait() == 0 +client1.waitTestSuccess() client2.sendline('x') -client2.expect(pexpect.EOF) -assert client2.wait() == 0 +client2.waitTestSuccess() print "ok" +server.kill(signal.SIGINT) +server.waitTestSuccess() + admin = demoscript.Util.spawn('iceboxadmin --Ice.Config=config.icebox shutdown') -admin.expect(pexpect.EOF) -assert admin.wait() == 0 -icestorm.expect(pexpect.EOF) -assert icestorm.wait() == 0 +admin.waitTestSuccess() +icestorm.waitTestSuccess() diff --git a/cpp/demo/IceStorm/replicated/expect.py b/cpp/demo/IceStorm/replicated/expect.py index 3f6869b0b90..ae59e22f77b 100755 --- a/cpp/demo/IceStorm/replicated/expect.py +++ b/cpp/demo/IceStorm/replicated/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,9 +23,21 @@ except ImportError: import demoscript import demoscript.Util - +demoscript.Util.defaultLanguage = "C++" import time, signal +desc = 'application.xml' +if demoscript.Util.mode == 'debug': + fi = open(desc, "r") + desc = 'tmp_application.xml' + fo = open(desc, "w") + for l in fi: + if l.find('exe="icebox"'): + l = l.replace('exe="icebox"', 'exe="iceboxd.exe"') + fo.write(l) + fi.close() + fo.close() + print "cleaning databases...", sys.stdout.flush() demoscript.Util.cleanDbDir("db/node") @@ -47,7 +59,7 @@ print "deploying application...", sys.stdout.flush() admin = demoscript.Util.spawn('icegridadmin --Ice.Config=config.grid') admin.expect('>>>') -admin.sendline("application add \'application.xml\'") +admin.sendline("application add \'%s\'" %(desc)) admin.expect('>>>') print "ok" @@ -89,18 +101,15 @@ admin.sendline('server stop DemoIceStorm-3') admin.expect('>>>') pub.expect('Ice::NoEndpointException') -pub.expect(pexpect.EOF) -assert pub.wait() != 0 +pub.waitTestSuccess(1) sub.kill(signal.SIGINT) -sub.expect('NoEndpointException') -sub.expect(pexpect.EOF) -assert sub.wait() != 0 +if not demoscript.Util.isCygwin(): + sub.expect('NoEndpointException') +pub.waitTestSuccess(1) print "ok" admin.sendline('registry shutdown Master') admin.sendline('exit') -admin.expect(pexpect.EOF) -assert admin.wait() == 0 -node.expect(pexpect.EOF) -assert node.wait() == 0 +admin.waitTestSuccess() +node.waitTestSuccess() diff --git a/cpp/demo/IceUtil/workqueue/expect.py b/cpp/demo/IceUtil/workqueue/expect.py index 31f2c87ddfe..1a5ff9b7a04 100755 --- a/cpp/demo/IceUtil/workqueue/expect.py +++ b/cpp/demo/IceUtil/workqueue/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.Ice.hello server = demoscript.Util.spawn('./workqueue') @@ -35,6 +36,5 @@ server.expect('work item: item2') server.expect('work item: item3') server.expect('work item: item4') server.expect('work item: item5') -server.expect(pexpect.EOF, timeout=10) -assert server.wait() == 0 +server.waitTestSuccess(timeout=10) print "ok" diff --git a/cpp/demo/book/freeze_filesystem/expect.py b/cpp/demo/book/freeze_filesystem/expect.py index d44c2014af3..e012b924ff4 100755 --- a/cpp/demo/book/freeze_filesystem/expect.py +++ b/cpp/demo/book/freeze_filesystem/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.book.freeze_filesystem print "cleaning databases...", diff --git a/cpp/demo/book/lifecycle/Client.cpp b/cpp/demo/book/lifecycle/Client.cpp index 329d6bac954..25ce2362747 100644 --- a/cpp/demo/book/lifecycle/Client.cpp +++ b/cpp/demo/book/lifecycle/Client.cpp @@ -18,9 +18,11 @@ class FilesystemClient : virtual public Ice::Application { public: virtual int run(int, char * []) { - // Terminate cleanly on receipt of a signal. + // Since this is an interactive demo we want the custom + // interrupt callback to be called when the process is + // interrupted. // - shutdownOnInterrupt(); + callbackOnInterrupt(); // Create a proxy for the root directory // @@ -40,7 +42,23 @@ public: ParserPtr p = new Parser(rootDir); return p->parse(); - }; + } + + virtual void interruptCallback(int) { + try + { + communicator()->destroy(); + } + catch(const IceUtil::Exception& ex) + { + cerr << appName() << ": " << ex << endl; + } + catch(...) + { + cerr << appName() << ": unknown exception" << endl; + } + exit(EXIT_SUCCESS); + } }; int diff --git a/cpp/demo/book/lifecycle/Parser.cpp b/cpp/demo/book/lifecycle/Parser.cpp index c81038284a6..eff78f9076c 100644 --- a/cpp/demo/book/lifecycle/Parser.cpp +++ b/cpp/demo/book/lifecycle/Parser.cpp @@ -297,92 +297,74 @@ Parser::destroy(const std::list<string>& names) void Parser::getInput(char* buf, int& result, int maxSize) { - if(isatty(fileno(yyin))) - { #ifdef HAVE_READLINE - const char* prompt = parser->getPrompt(); - char* line = readline(const_cast<char*>(prompt)); - if(!line) + const char* prompt = parser->getPrompt(); + char* line = readline(const_cast<char*>(prompt)); + if(!line) + { + result = 0; + } + else + { + if(*line) { + add_history(line); + } + + result = strlen(line) + 1; + if(result > maxSize) + { + free(line); + error("input line too long"); result = 0; } else { - if(*line) - { - add_history(line); - } - - result = strlen(line) + 1; - if(result > maxSize) - { - free(line); - error("input line too long"); - result = 0; - } - else - { - strcpy(buf, line); - strcat(buf, "\n"); - free(line); - } + strcpy(buf, line); + strcat(buf, "\n"); + free(line); } + } #else - cout << parser->getPrompt() << flush; + cout << parser->getPrompt() << flush; - string line; - while(true) + string line; + while(true) + { + char c = static_cast<char>(getc(yyin)); + if(c == EOF) { - char c = static_cast<char>(getc(yyin)); - if(c == EOF) + if(line.size()) { - if(line.size()) - { - line += '\n'; - } - break; + line += '\n'; } + break; + } - line += c; + line += c; - if(c == '\n') - { - break; - } - } - - result = static_cast<int>(line.length()); - if(result > maxSize) + if(c == '\n') { - error("input line too long"); - buf[0] = EOF; - result = 1; - } - else - { - strcpy(buf, line.c_str()); + break; } + } -#endif + result = static_cast<int>(line.length()); + if(result > maxSize) + { + error("input line too long"); + buf[0] = EOF; + result = 1; } else { - if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) - { - error("input in flex scanner failed"); - buf[0] = EOF; - result = 1; - } + strcpy(buf, line.c_str()); } -} -void -Parser::nextLine() -{ - _currentLine++; +#endif } void @@ -394,8 +376,6 @@ Parser::continueLine() const char* Parser::getPrompt() { - assert(isatty(fileno(yyin))); - if(_continue) { _continue = false; @@ -410,15 +390,8 @@ Parser::getPrompt() void Parser::error(const char* s) { - if(!isatty(fileno(yyin))) - { - cerr << _currentFile << ':' << _currentLine << ": " << s << endl; - _errors++; - } - else - { - cerr << "error: " << s << endl; - } + cerr << "error: " << s << endl; + _errors++; } void @@ -430,14 +403,7 @@ Parser::error(const string& s) void Parser::warning(const char* s) { - if(!isatty(fileno(yyin))) - { - cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; - } - else - { - cerr << "warning: " << s << endl; - } + cerr << "warning: " << s << endl; } void @@ -459,13 +425,7 @@ Parser::parse(bool debug) yyin = stdin; assert(yyin); - _currentFile = ""; - _currentLine = 0; _continue = false; - nextLine(); - - //_foundBooks.clear(); - //_current = _foundBooks.end(); int status = yyparse(); if(_errors) diff --git a/cpp/demo/book/lifecycle/Parser.h b/cpp/demo/book/lifecycle/Parser.h index 8c0747d6b41..af204120af2 100644 --- a/cpp/demo/book/lifecycle/Parser.h +++ b/cpp/demo/book/lifecycle/Parser.h @@ -15,16 +15,6 @@ #include <list> #include <stdio.h> -#ifdef _WIN32 -# include <io.h> -# ifdef _MSC_VER -# define isatty _isatty -# define fileno _fileno -// '_isatty' : inconsistent dll linkage. dllexport assumed. -# pragma warning( disable : 4273 ) -# endif -#endif - // // Stuff for flex and bison // @@ -70,7 +60,6 @@ public: void destroy(const ::std::list< ::std::string>&); void getInput(char*, int&, int); - void nextLine(); void continueLine(); const char* getPrompt(); @@ -87,8 +76,6 @@ private: bool _continue; int _errors; - int _currentLine; - std::string _currentFile; }; extern Parser* parser; // The current parser for bison/flex diff --git a/cpp/demo/book/lifecycle/Scanner.l b/cpp/demo/book/lifecycle/Scanner.l index b3f9524eba5..4a728481d61 100644 --- a/cpp/demo/book/lifecycle/Scanner.l +++ b/cpp/demo/book/lifecycle/Scanner.l @@ -40,10 +40,6 @@ NL [\n] do { c = yyinput(); - if(c == '\n') - { - parser->nextLine(); - } } while(c != '\n' && c != EOF); } @@ -53,11 +49,7 @@ NL [\n] while(true) { int c = yyinput(); - if(c == '\n') - { - parser->nextLine(); - } - else if(c == '*') + if(c == '*') { int next = yyinput(); if(next == '/') @@ -129,22 +121,10 @@ NL [\n] { parser->continueLine(); } - else if(yytext[i] == '\n') - { - parser->nextLine(); - } } } {NL}|; { - size_t len = strlen(yytext); - for(size_t i = 0; i < len; ++i) - { - if(yytext[i] == '\n') - { - parser->nextLine(); - } - } return ';'; } @@ -163,11 +143,6 @@ NL [\n] parser->warning("EOF in string"); break; } - else if(c == '\n') - { - s += c; - parser->nextLine(); - } else if(c == '\\') { char next = static_cast<char>(yyinput()); @@ -242,11 +217,6 @@ NL [\n] parser->warning("EOF in string"); break; } - else if(c == '\n') - { - s += c; - parser->nextLine(); - } else { s += c; diff --git a/cpp/demo/book/lifecycle/expect.py b/cpp/demo/book/lifecycle/expect.py index 94f8c96dd43..807aad16a0e 100755 --- a/cpp/demo/book/lifecycle/expect.py +++ b/cpp/demo/book/lifecycle/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import demoscript.book.lifecycle server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') diff --git a/cpp/demo/book/printer/expect.py b/cpp/demo/book/printer/expect.py index 2325f6f7917..2628316536a 100755 --- a/cpp/demo/book/printer/expect.py +++ b/cpp/demo/book/printer/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import signal server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') @@ -31,11 +32,9 @@ server.expect('.* ready') print "testing...", sys.stdout.flush() client = demoscript.Util.spawn('./client') -client.expect(pexpect.EOF) -assert client.wait() == 0 +client.waitTestSuccess() server.expect('Hello World!') +server.kill(signal.SIGTERM) +server.wait() +server.signalstatus == signal.SIGTERM print "ok" -server.kill(signal.SIGINT) -server.expect(pexpect.EOF) -# This server doesn't exit with a non-zero exit status. -assert server.wait() != 0 diff --git a/cpp/demo/book/simple_filesystem/expect.py b/cpp/demo/book/simple_filesystem/expect.py index 238ed5c45c7..2766b4ee5c1 100755 --- a/cpp/demo/book/simple_filesystem/expect.py +++ b/cpp/demo/book/simple_filesystem/expect.py @@ -8,7 +8,7 @@ # # ********************************************************************** -import pexpect, sys, os +import sys, os try: import demoscript @@ -23,6 +23,7 @@ except ImportError: import demoscript import demoscript.Util +demoscript.Util.defaultLanguage = "C++" import signal server = demoscript.Util.spawn('./server --Ice.PrintAdapterReady') @@ -32,9 +33,7 @@ print "testing...", sys.stdout.flush() client = demoscript.Util.spawn('./client') client.expect('Contents of root directory:\r{1,2}\n.*Down to a sunless sea.') -client.expect(pexpect.EOF) -assert client.wait() == 0 -print "ok" +client.waitTestSuccess() server.kill(signal.SIGINT) -server.expect(pexpect.EOF) -assert server.wait() == 0 +server.waitTestSuccess() +print "ok" |