diff options
author | Benoit Foucher <benoit@zeroc.com> | 2018-12-27 18:34:51 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2018-12-27 18:34:51 +0100 |
commit | d57bd8450ed96196f11f7e7f024a75a182750632 (patch) | |
tree | d3f307542071c2ea81db67326150bab42d44ca43 | |
parent | CHANGELOG updates (diff) | |
download | ice-d57bd8450ed96196f11f7e7f024a75a182750632.tar.bz2 ice-d57bd8450ed96196f11f7e7f024a75a182750632.tar.xz ice-d57bd8450ed96196f11f7e7f024a75a182750632.zip |
Thread safe redirect for controller applications
-rw-r--r-- | cpp/test/Common/TestHelper.cpp | 88 | ||||
-rw-r--r-- | cpp/test/include/TestHelper.h | 69 | ||||
-rw-r--r-- | cpp/test/ios/controller/Bundle/ControllerI.mm | 14 | ||||
-rw-r--r-- | cpp/test/uwp/controller/ControllerView.xaml.cpp | 13 | ||||
-rw-r--r-- | objective-c/test/Common/TestCommon.m | 31 | ||||
-rw-r--r-- | objective-c/test/include/TestCommon.h | 2 | ||||
-rw-r--r-- | objective-c/test/ios/controller/Classes/ViewController.m | 28 | ||||
-rw-r--r-- | scripts/Util.py | 4 |
8 files changed, 167 insertions, 82 deletions
diff --git a/cpp/test/Common/TestHelper.cpp b/cpp/test/Common/TestHelper.cpp index 55849584e00..018f134d665 100644 --- a/cpp/test/Common/TestHelper.cpp +++ b/cpp/test/Common/TestHelper.cpp @@ -30,6 +30,94 @@ shutdownOnInterruptCallback(int) } +StreamHelper::StreamHelper() : _controllerHelper(0) +{ + setp(&data[0], &data[sizeof(data) - 1]); + + _previousCoutBuffer = std::cout.rdbuf(); + std::cout.rdbuf(this); + + _previousCerrBuffer = std::cerr.rdbuf(); + std::cerr.rdbuf(this); +} + +StreamHelper::~StreamHelper() +{ + std::cout.rdbuf(_previousCoutBuffer); + std::cerr.rdbuf(_previousCerrBuffer); +} + +void +StreamHelper::setControllerHelper(ControllerHelper* controllerHelper) +{ + IceUtil::Mutex::Lock sync(_mutex); + assert(_controllerHelper && !controllerHelper || !_controllerHelper && controllerHelper); + _controllerHelper = controllerHelper; + + if(_controllerHelper) + { + _previousLogger = Ice::getProcessLogger(); + Ice::setProcessLogger(Ice::getProcessLogger()->cloneWithPrefix(_controllerHelper->loggerPrefix())); + } + else + { + Ice::setProcessLogger(_previousLogger); + } +} + +void +StreamHelper::flush() +{ +} + +void +StreamHelper::newLine() +{ + IceUtil::Mutex::Lock sync(_mutex); + if(_controllerHelper) + { + _controllerHelper->print("\n"); + } +} + +int +StreamHelper::sync() +{ + assert(_controllerHelper); + std::streamsize n = pptr() - pbase(); + { + IceUtil::Mutex::Lock sync(_mutex); + if(_controllerHelper) + { + _controllerHelper->print(std::string(pbase(), static_cast<int>(n))); + } + } + pbump(-static_cast<int>(pptr() - pbase())); + return 0; +} + +int +StreamHelper::overflow(int ch) +{ + sync(); + if(ch != EOF) + { + assert(pptr() != epptr()); + sputc(static_cast<char>(ch)); + } + return 0; +} + +int +StreamHelper::sputc(char c) +{ + if(c == '\n') + { + pubsync(); + } + return std::streambuf::sputc(c); +} + Test::TestHelper::TestHelper(bool registerPlugins) : _controllerHelper(0) #if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0) diff --git a/cpp/test/include/TestHelper.h b/cpp/test/include/TestHelper.h index bad48159649..56ce76e31c7 100644 --- a/cpp/test/include/TestHelper.h +++ b/cpp/test/include/TestHelper.h @@ -63,72 +63,21 @@ class StreamHelper : public std::streambuf { public: - StreamHelper(ControllerHelper* controllerHelper, bool redirect) : _controllerHelper(controllerHelper) - { - setp(&data[0], &data[sizeof(data) - 1]); - if(redirect) - { - _previousLogger = Ice::getProcessLogger(); - Ice::setProcessLogger(Ice::getProcessLogger()->cloneWithPrefix(_controllerHelper->loggerPrefix())); - - _previousCoutBuffer = std::cout.rdbuf(); - std::cout.rdbuf(this); - - _previousCerrBuffer = std::cerr.rdbuf(); - std::cerr.rdbuf(this); - } - } - - ~StreamHelper() - { - if(_previousLogger) - { - Ice::setProcessLogger(_previousLogger); - std::cout.rdbuf(_previousCoutBuffer); - std::cerr.rdbuf(_previousCerrBuffer); - } - } + StreamHelper(); + ~StreamHelper(); - virtual void flush() - { - } + void setControllerHelper(ControllerHelper*); - virtual void newLine() - { - _controllerHelper->print("\n"); - } + virtual void flush(); + virtual void newLine(); private: - int sync() - { - assert(_controllerHelper); - std::streamsize n = pptr() - pbase(); - _controllerHelper->print(std::string(pbase(), static_cast<int>(n))); - pbump(-static_cast<int>(pptr() - pbase())); - return 0; - } - - int overflow(int ch) - { - sync(); - if(ch != EOF) - { - assert(pptr() != epptr()); - sputc(static_cast<char>(ch)); - } - return 0; - } - - int sputc(char c) - { - if(c == '\n') - { - pubsync(); - } - return std::streambuf::sputc(c); - } + virtual int sync(); + virtual int overflow(int); + virtual int sputc(char); + IceUtil::Mutex _mutex; ControllerHelper* _controllerHelper; char data[1024]; Ice::LoggerPtr _previousLogger; diff --git a/cpp/test/ios/controller/Bundle/ControllerI.mm b/cpp/test/ios/controller/Bundle/ControllerI.mm index 8bcbbb84697..46cf7739c9f 100644 --- a/cpp/test/ios/controller/Bundle/ControllerI.mm +++ b/cpp/test/ios/controller/Bundle/ControllerI.mm @@ -109,6 +109,8 @@ namespace Ice::CommunicatorPtr _communicator; }; + + Test::StreamHelper streamRedirect; } ControllerHelperI::ControllerHelperI(id<ControllerView> controller, const string& dll, const StringSeq& args) : @@ -197,6 +199,11 @@ ControllerHelperI::run() return; } + if(_dll.find("client") != string::npos || _dll.find("collocated") != string::npos) + { + streamRedirect.setControllerHelper(this); + } + CREATE_HELPER_ENTRY_POINT createHelper = (CREATE_HELPER_ENTRY_POINT)sym; char** argv = new char*[_args.size() + 1]; for(unsigned int i = 0; i < _args.size(); ++i) @@ -206,8 +213,6 @@ ControllerHelperI::run() argv[_args.size()] = 0; try { - Test::StreamHelper streamHelper(this, - _dll.find("client") != string::npos || _dll.find("collocated") != string::npos); IceInternal::UniquePtr<Test::TestHelper> helper(createHelper()); helper->setControllerHelper(this); helper->run(static_cast<int>(_args.size()), argv); @@ -225,6 +230,11 @@ ControllerHelperI::run() } delete[] argv; + if(_dll.find("client") != string::npos || _dll.find("collocated") != string::npos) + { + streamRedirect.setControllerHelper(0); + } + CFBundleUnloadExecutable(handle); CFRelease(handle); } diff --git a/cpp/test/uwp/controller/ControllerView.xaml.cpp b/cpp/test/uwp/controller/ControllerView.xaml.cpp index 4d17ef2960b..2a118ee658b 100644 --- a/cpp/test/uwp/controller/ControllerView.xaml.cpp +++ b/cpp/test/uwp/controller/ControllerView.xaml.cpp @@ -131,6 +131,8 @@ private: shared_ptr<Test::Common::ProcessControllerRegistryPrx> _registry; }; +Test::StreamHelper streamRedirect; + } ControllerHelperI::ControllerHelperI(const string& dll, const StringSeq& args) : @@ -199,10 +201,13 @@ ControllerHelperI::run() argv[i] = const_cast<char*>(_args[i].c_str()); } argv[_args.size()] = 0; + + if(_dll.find("client") != string::npos || _dll.find("collocated") != string::npos) + { + streamRedirect.setControllerHelper(this); + } try { - StreamHelper streamHelper(this, - _dll.find("client") != string::npos || _dll.find("collocated") != string::npos); auto helper = unique_ptr<Test::TestHelper>(createHelper()); helper->setControllerHelper(this); helper->run(static_cast<int>(_args.size()), argv); @@ -218,6 +223,10 @@ ControllerHelperI::run() print("unexpected unknown exception while running `" + _args[0] + "'"); completed(1); } + if(_dll.find("client") != string::npos || _dll.find("collocated") != string::npos) + { + streamRedirect.setControllerHelper(0); + } delete[] argv; }); _thread = move(t); diff --git a/objective-c/test/Common/TestCommon.m b/objective-c/test/Common/TestCommon.m index dbb88815e42..4b296ee9347 100644 --- a/objective-c/test/Common/TestCommon.m +++ b/objective-c/test/Common/TestCommon.m @@ -27,6 +27,7 @@ #import <Foundation/NSString.h> #import <Foundation/NSObject.h> #import <Foundation/NSThread.h> +#import <Foundation/NSLock.h> #include <objc/Ice.h> @@ -36,6 +37,7 @@ static SEL readySelector; static SEL outputSelector; static id<ICECommunicator> communicator = nil; static NSString* protocol; +static NSLock* mutex = nil; static BOOL sliced; static BOOL encoding10; @@ -157,10 +159,25 @@ defaultClientProperties(int* argc, char** argv) #if TARGET_OS_IPHONE void -TestCommonInit(id target, SEL output) +TestCommonSetOutput(id target, SEL output) { - outputTarget = target; - outputSelector = output; + if(mutex == nil) + { + mutex = [NSLock new]; + } + [mutex lock]; + if(target != nil) + { + outputTarget = ICE_RETAIN(target); + outputSelector = output; + } + else + { + ICE_RELEASE(outputTarget); + outputTarget = nil; + outputSelector = nil; + } + [mutex unlock]; } void @@ -203,7 +220,13 @@ tprintf(const char* fmt, ...) encoding:NSUTF8StringEncoding] arguments:va]); va_end(va); - [outputTarget performSelectorOnMainThread:outputSelector withObject:s waitUntilDone:NO]; + + [mutex lock]; + if(outputTarget != nil) + { + [outputTarget performSelectorOnMainThread:outputSelector withObject:s waitUntilDone:NO]; + } + [mutex unlock]; } void diff --git a/objective-c/test/include/TestCommon.h b/objective-c/test/include/TestCommon.h index b3f65c087bb..052e95701bf 100644 --- a/objective-c/test/include/TestCommon.h +++ b/objective-c/test/include/TestCommon.h @@ -22,7 +22,7 @@ TEST_API @interface TestFailedException : NSException @end #if TARGET_OS_IPHONE -TEST_API void TestCommonInit(id, SEL); +TEST_API void TestCommonSetOutput(id, SEL); TEST_API void TestCommonTestInit(id, SEL, NSString*, BOOL, BOOL); #endif diff --git a/objective-c/test/ios/controller/Classes/ViewController.m b/objective-c/test/ios/controller/Classes/ViewController.m index 803d411011d..da565850060 100644 --- a/objective-c/test/ios/controller/Classes/ViewController.m +++ b/objective-c/test/ios/controller/Classes/ViewController.m @@ -17,6 +17,7 @@ { id<ViewController> _controller; void* _func; + NSString* _exe; NSArray* _args; BOOL _ready; BOOL _completed; @@ -55,7 +56,7 @@ @end @implementation MainHelper --(id) init:(id<ViewController>)controller func:(void*)func args:(NSArray*)args +-(id) init:(id<ViewController>)controller func:(void*)func exe:(NSString*)exe args:(NSArray*)args { self = [super init]; if(self == nil) @@ -64,6 +65,7 @@ } _controller = ICE_RETAIN(controller); _func = func; + _exe = ICE_RETAIN(exe); _args = ICE_RETAIN(args); _ready = FALSE; _completed = FALSE; @@ -76,6 +78,7 @@ -(void) dealloc { [_controller release]; + [_exe release]; [_args release]; [_cond release]; [_out release]; @@ -125,6 +128,14 @@ argv[i++] = (char*)[arg UTF8String]; } argv[_args.count] = 0; + if([_exe isEqualToString:@"client"] || [_exe isEqualToString:@"collocated"]) + { + TestCommonSetOutput(self, @selector(print:)); + } + else + { + TestCommonTestInit(self, @selector(serverReady), @"", NO, NO); + } @try { [self completed:mainEntryPoint((int)_args.count, argv)]; @@ -134,6 +145,10 @@ [self print:[NSString stringWithFormat:@"unexpected exception while running `%s':%@\n", argv[0], ex]]; [self completed:EXIT_FAILURE]; } + if([_exe isEqualToString:@"client"] || [_exe isEqualToString:@"collocated"]) + { + TestCommonSetOutput(nil, nil); + } free(argv); } -(void) completed:(int)status @@ -287,16 +302,7 @@ [NSString stringWithFormat:@"couldn't find %@", func]]; } args = [@[[NSString stringWithFormat:@"%@ %@", testSuite, exe]] arrayByAddingObjectsFromArray:args]; - MainHelper* helper = ICE_AUTORELEASE([[MainHelper alloc] init:_controller func:sym args:args]); - if([exe isEqualToString:@"client"] || [exe isEqualToString:@"collocated"]) - { - TestCommonInit(helper, @selector(print:)); - } - else - { - TestCommonInit(helper, @selector(print:)); - TestCommonTestInit(helper, @selector(serverReady), @"", NO, NO); - } + MainHelper* helper = ICE_AUTORELEASE([[MainHelper alloc] init:_controller func:sym exe:exe args:args]); // // Use a 768KB thread stack size for the objects test. This is necessary when running the diff --git a/scripts/Util.py b/scripts/Util.py index cd4578d6b6e..3288d3d5129 100644 --- a/scripts/Util.py +++ b/scripts/Util.py @@ -2373,7 +2373,7 @@ class AndroidProcessController(RemoteProcessController): class iOSSimulatorProcessController(RemoteProcessController): device = "iOSSimulatorProcessController" - deviceID = "com.apple.CoreSimulator.SimDeviceType.iPhone-6" + deviceID = "com.apple.CoreSimulator.SimDeviceType.iPhone-X" def __init__(self, current): RemoteProcessController.__init__(self, current, "tcp -h 0.0.0.0 -p 15001" if current.config.xamarin else None) @@ -2388,7 +2388,7 @@ class iOSSimulatorProcessController(RemoteProcessController): except: pass if not self.runtimeID: - self.runtimeID = "com.apple.CoreSimulator.SimRuntime.iOS-11-0" # Default value + self.runtimeID = "com.apple.CoreSimulator.SimRuntime.iOS-12-0" # Default value def __str__(self): return "iOS Simulator" |