diff options
author | Jose <jose@zeroc.com> | 2016-04-07 10:29:11 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2016-04-07 10:29:11 +0200 |
commit | 058a0c6c3ee2f059be0d8c7eba940aa31463fa7f (patch) | |
tree | a52b7eb37253b8da13db2b7f617f3233b440bbfb /cpp/test | |
parent | Fixed issue with IE where accessing the stack from Exception.toString leads t... (diff) | |
download | ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.tar.bz2 ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.tar.xz ice-058a0c6c3ee2f059be0d8c7eba940aa31463fa7f.zip |
ICE-7035 - Add option to roll log files
Diffstat (limited to 'cpp/test')
-rw-r--r-- | cpp/test/Ice/logger/.gitignore | 1 | ||||
-rw-r--r-- | cpp/test/Ice/logger/Client5.cpp | 138 | ||||
-rw-r--r-- | cpp/test/Ice/logger/Makefile | 11 | ||||
-rw-r--r-- | cpp/test/Ice/logger/Makefile.mak | 13 | ||||
-rwxr-xr-x | cpp/test/Ice/logger/run.py | 63 |
5 files changed, 221 insertions, 5 deletions
diff --git a/cpp/test/Ice/logger/.gitignore b/cpp/test/Ice/logger/.gitignore index a918a882f43..b92e9bec8ae 100644 --- a/cpp/test/Ice/logger/.gitignore +++ b/cpp/test/Ice/logger/.gitignore @@ -6,4 +6,5 @@ client1 client2 client3 client4 +client5 .depend diff --git a/cpp/test/Ice/logger/Client5.cpp b/cpp/test/Ice/logger/Client5.cpp new file mode 100644 index 00000000000..5948e2eed9c --- /dev/null +++ b/cpp/test/Ice/logger/Client5.cpp @@ -0,0 +1,138 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <TestCommon.h> + +using namespace std; + +namespace +{ + +class Client : public Ice::Application +{ +public: + virtual int + run(int, char*[]) + { + int count = communicator()->getProperties()->getPropertyAsInt("Client.Iterations"); + const string message = communicator()->getProperties()->getProperty("Client.Message"); + for(int i = 0; i < count; ++i) + { + communicator()->getLogger()->print(message); + } + return EXIT_SUCCESS; + }; +}; + +} + +// +// We use messages with different sizes to compensate the different line end used in Windows +// and Unix. The Win32 message is 126 bytes plus 2 bytes for the Windows line end \r\n and +// that makes a total of 128 bytes. For all other platforms the message is 127 bytes plus 1 +// byte for the line end \n and that makes a total of 128 bytes. +// +#ifdef _WIN32 +const string message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Vestibulum ornare, ex non bibendum hendrerit, felis tortor cras amet."; +#else +const string message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Fusce dictum turpis ante, sit amet finibus eros commodo vel. Sed amet."; +#endif + +int +main(int argc, char* argv[]) +{ +#ifdef ICE_STATIC_LIBS + Ice::registerIceSSL(); +#endif + + // + // Run Client application 20 times, each times it generate 512 bytes of log messages, + // the application logger is configured to archive log files larger than 512 bytes. + // + // This will generate 19 archived log files, all files including current log file + // must have 512 bytes length. + // + for(int i = 0; i < 20; ++i) + { + Ice::InitializationData id; + id.properties = Ice::createProperties(); + id.properties->load("config.client"); + id.properties->setProperty("Client.Iterations", "4"); + id.properties->setProperty("Client.Message", message); + id.properties->setProperty("Ice.LogFile", "client5-0.log"); + id.properties->setProperty("Ice.LogFile.SizeMax", "512"); + Client c; + if(c.main(argc, argv, id) != EXIT_SUCCESS) + { + return EXIT_FAILURE; + } + } + + // + // Run Client application configured to generate 1024 bytes, the application is configured + // to not archive log files, there must not be any archived log files, and log file must + // have 1024 bytes size. + // + { + Ice::InitializationData id; + id.properties = Ice::createProperties(); + id.properties->load("config.client"); + id.properties->setProperty("Client.Iterations", "8"); + id.properties->setProperty("Client.Message", message); + id.properties->setProperty("Ice.LogFile", "client5-1.log"); + id.properties->setProperty("Ice.LogFile.SizeMax", "0"); + Client c; + if(c.main(argc, argv, id) != EXIT_SUCCESS) + { + return EXIT_FAILURE; + } + } + + // + // Run Client application configured to generate 1024 bytes, the application is configured + // to archive log files when size is greatert than 128 bytes, there should be 7 archived files + // and current log file, all files must have 128 bytes size. + // + { + Ice::InitializationData id; + id.properties = Ice::createProperties(); + id.properties->load("config.client"); + id.properties->setProperty("Client.Iterations", "8"); + id.properties->setProperty("Client.Message", message); + id.properties->setProperty("Ice.LogFile", "client5-2.log"); + id.properties->setProperty("Ice.LogFile.SizeMax", "128"); + Client c; + if(c.main(argc, argv, id) != EXIT_SUCCESS) + { + return EXIT_FAILURE; + } + } + + // + // Same as above but maximum size is lower than the message size, in this case we should + // get the same result as messages are not trucated. + // + { + Ice::InitializationData id; + id.properties = Ice::createProperties(); + id.properties->load("config.client"); + id.properties->setProperty("Client.Iterations", "8"); + id.properties->setProperty("Client.Message", message); + id.properties->setProperty("Ice.LogFile", "client5-3.log"); + id.properties->setProperty("Ice.LogFile.SizeMax", "64"); + Client c; + if(c.main(argc, argv, id) != EXIT_SUCCESS) + { + return EXIT_FAILURE; + } + } +} diff --git a/cpp/test/Ice/logger/Makefile b/cpp/test/Ice/logger/Makefile index 4ac48f3c39c..48c270503ad 100644 --- a/cpp/test/Ice/logger/Makefile +++ b/cpp/test/Ice/logger/Makefile @@ -13,18 +13,21 @@ CLIENT1 = $(call mktestname,client1) CLIENT2 = $(call mktestname,client2) CLIENT3 = $(call mktestname,client3) CLIENT4 = $(call mktestname,client4) +CLIENT5 = $(call mktestname,client5) -TARGETS = $(CLIENT1) $(CLIENT2) $(CLIENT3) $(CLIENT4) +TARGETS = $(CLIENT1) $(CLIENT2) $(CLIENT3) $(CLIENT4) $(CLIENT5) C1OBJS = Client1.o C2OBJS = Client2.o C3OBJS = Client3.o C4OBJS = Client4.o +C5OBJS = Client5.o OBJS = $(C1OBJS) \ $(C2OBJS) \ $(C3OBJS) \ - $(C4OBJS) + $(C4OBJS) \ + $(C5OBJS) include $(top_srcdir)/config/Make.rules @@ -47,3 +50,7 @@ $(CLIENT3): $(C3OBJS) $(CLIENT4): $(C4OBJS) rm -f $@ $(call mktest,$@,$(C4OBJS),$(LINKWITH)) + +$(CLIENT5): $(C5OBJS) + rm -f $@ + $(call mktest,$@,$(C5OBJS),$(LINKWITH)) diff --git a/cpp/test/Ice/logger/Makefile.mak b/cpp/test/Ice/logger/Makefile.mak index 9fd96d5f8e6..131b68210ac 100644 --- a/cpp/test/Ice/logger/Makefile.mak +++ b/cpp/test/Ice/logger/Makefile.mak @@ -13,18 +13,21 @@ CLIENT1 = client1.exe CLIENT2 = client2.exe CLIENT3 = client3.exe CLIENT4 = client4.exe +CLIENT5 = client5.exe -TARGETS = $(CLIENT1) $(CLIENT2) $(CLIENT3) $(CLIENT4) +TARGETS = $(CLIENT1) $(CLIENT2) $(CLIENT3) $(CLIENT4) $(CLIENT5) C1OBJS = .\Client1.obj C2OBJS = .\Client2.obj C3OBJS = .\Client3.obj C4OBJS = .\Client4.obj +C5OBJS = .\Client5.obj OBJS = $(C1OBJS) \ $(C2OBJS) \ $(C3OBJS) \ - $(C4OBJS) + $(C4OBJS) \ + $(C5OBJS) !include $(top_srcdir)/config/Make.rules.mak @@ -35,6 +38,7 @@ C1PDBFLAGS = /pdb:$(CLIENT1:.exe=.pdb) C2PDBFLAGS = /pdb:$(CLIENT2:.exe=.pdb) C3PDBFLAGS = /pdb:$(CLIENT3:.exe=.pdb) C4PDBFLAGS = /pdb:$(CLIENT4:.exe=.pdb) +C5PDBFLAGS = /pdb:$(CLIENT5:.exe=.pdb) !endif $(CLIENT1): $(C1OBJS) @@ -56,3 +60,8 @@ $(CLIENT4): $(C4OBJS) $(LINK) $(LD_EXEFLAGS) $(C4PDBFLAGS) $(SETARGV) $(C4OBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +$(CLIENT5): $(C5OBJS) + $(LINK) $(LD_EXEFLAGS) $(C5PDBFLAGS) $(SETARGV) $(C5OBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest diff --git a/cpp/test/Ice/logger/run.py b/cpp/test/Ice/logger/run.py index 2665663ca2b..1b645a5a5d2 100755 --- a/cpp/test/Ice/logger/run.py +++ b/cpp/test/Ice/logger/run.py @@ -9,7 +9,7 @@ # # ********************************************************************** -import os, sys, subprocess +import os, sys, subprocess, glob, atexit path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] head = os.path.dirname(sys.argv[0]) @@ -52,3 +52,64 @@ if TestUtil.isWin32(): else: test(os.path.join(os.getcwd(), "client4"), b'aplicaci\xf3n', "ISO-8859-15") print("ok") + +sys.stdout.write("testing logger file rotation... ") + +def cleanup(): + for f in glob.glob("client5-*.log"): + os.remove(f) + +cleanup() + +atexit.register(cleanup) + +def client5(): + p = subprocess.Popen(os.path.join(os.getcwd(), "client5"), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) + out, err = p.communicate() + ret = p.poll() + if ret != 0: + print("failed! status %s " % ret) + sys.exit(1) + +client5() + +if (not os.path.isfile("client5-0.log") or + not os.stat("client5-0.log").st_size == 512 or + len(glob.glob("client5-0-*.log")) != 19): + print("failed!") + sys.exit(1) + +for f in glob.glob("client5-0-*.log"): + if not os.stat(f).st_size == 512: + print("failed! file {0} size: {1} unexpected".format(f, os.stat(f).st_size)) + sys.exit(1) + +if (not os.path.isfile("client5-1.log") or + not os.stat("client5-1.log").st_size == 1024 or + len(glob.glob("client5-1-*.log")) != 0): + print("failed!") + sys.exit(1) + +if (not os.path.isfile("client5-2.log") or + not os.stat("client5-2.log").st_size == 128 or + len(glob.glob("client5-2-*.log")) != 7): + print("failed!") + sys.exit(1) + +for f in glob.glob("client5-2-*.log"): + if not os.stat(f).st_size == 128: + print("failed! file {0} size: {1} unexpected".format(f, os.stat(f).st_size)) + sys.exit(1) + +if (not os.path.isfile("client5-3.log") or + not os.stat("client5-2.log").st_size == 128 or + len(glob.glob("client5-2-*.log")) != 7): + print("failed!") + sys.exit(1) + +for f in glob.glob("client5-3-*.log"): + if not os.stat(f).st_size == 128: + print("failed! file {0} size: {1} unexpected".format(f, os.stat(f).st_size)) + sys.exit(1) + +print("ok") |