1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
# -*- coding: utf-8 -*-
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#
import glob
def test(process, current, match, enc, mapping):
cmd = process.getCommandLine(current)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=mapping.getEnv(process, current))
out, err = p.communicate()
ret = p.poll()
if ret != 0:
raise RuntimeError("%s failed! status %s " % (cmd, ret))
if out.decode(enc).find(match.decode(enc)) == -1:
raise RuntimeError("test failed")
class IceLoggerTestCase(ClientTestCase):
def runClientSide(self, current):
client1 = Client(exe="client1")
client2 = Client(exe="client2")
client3 = Client(exe="client3")
client4 = Client(exe="client4")
client5 = Client(exe="client5")
client1.run(current)
sys.stdout.write("testing logger ISO-8859-15 output... ")
test(client2, current, b'aplicaci\xf3n', "ISO-8859-15", self.getMapping())
print("ok")
sys.stdout.write("testing logger UTF8 output without string converter... ")
test(client3, current, b'aplicaci\xc3\xb3n', "UTF8", self.getMapping())
print("ok")
sys.stdout.write("testing logger UTF8 output with ISO-8859-15 narrow string converter... ")
#
# In Windows expected output is UTF8, because the console output code page is set to UTF-8
# in Linux and OS X, the expected output is ISO-8859-15 because that is the narrow string
# encoding used by the application.
#
if isinstance(platform, Windows):
test(client4, current, b'aplicaci\xc3\xb3n', "UTF8", self.getMapping())
else:
test(client4, current, b'aplicaci\xf3n', "ISO-8859-15", self.getMapping())
print("ok")
sys.stdout.write("testing logger file rotation... ")
self.clean()
os.makedirs("log")
open("log/client5-4.log", 'a').close()
if isinstance(platform, Windows):
os.system("echo Y|cacls log /P \"%USERNAME%\":R 1> nul")
else:
os.system("chmod -w log")
client5.run(current)
if isinstance(platform, Windows):
os.system("echo Y|cacls log /P \"%USERNAME%\":F 1> nul")
else:
os.system("chmod +w log")
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):
raise RuntimeError("failed!")
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):
raise RuntimeError("failed!")
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):
raise RuntimeError("failed!")
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))
raise RuntimeError("failed!")
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):
raise RuntimeError("failed!")
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))
raise RuntimeError("failed!")
#
# When running as root log rotation will not fail as
# root always has write access.
#
if isinstance(platform, Windows) or os.getuid() != 0:
if (not os.path.isfile("log/client5-4.log") or
os.stat("log/client5-4.log").st_size < 1024 or
len(glob.glob("log/client5-4-*.log")) > 0):
raise RuntimeError("failed!")
with open("log/client5-4.log", 'r') as f:
if f.read().count("error: FileLogger: cannot rename `log/client5-4.log'") != 1:
raise RuntimeError("failed!")
print("ok")
def teardownClientSide(self, current, success):
self.clean()
def clean(self):
for f in glob.glob("client5-*.log"):
os.remove(f)
if os.path.exists("log"):
if isinstance(platform, Windows):
os.system("echo Y|cacls log /P \"%USERNAME%\":F 1> nul")
else:
os.system("chmod +w log")
for f in glob.glob("log/client5-*.log"):
os.remove(f)
os.rmdir("log")
TestSuite(__name__, [ IceLoggerTestCase() ], chdir=True)
|