Page Breaks: IsLeaveWindow() is unreliable, we do not need it here.
[LibreOffice.git] / smoketest / losmoketest.py
blob4c8699763fb3669a6b11756c0c0051ca12dd3aa1
1 #!/usr/bin/env python
2 # Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License or as specified alternatively below. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
14 # The Initial Developer of the Original Code is
15 # Yifan Jiang, SUSE <yfjiang@suse.com>
16 # Portions created by the Initial Developer are Copyright (C) 2011 the
17 # Initial Developer. All Rights Reserved.
19 # Major Contributor(s):
21 # Portions created by the Ted are Copyright (C) 2010 Ted. All Rights Reserved.
23 # For minor contributions see the git repository.
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 3 or later (the "GPLv3+"), or
27 # the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
28 # in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
29 # instead of those above.
31 # The tool is designed to enable test machine fully automatically run smoketest
32 # with both daily and pre release build located in dev-build.libreoffice.org.
34 # The tool is named as losmoketest for its purpose, meanwhile it help you to
35 # check, download and install the latest build. By the fact the installation is
36 # designed not to be different from manually doing these repeated work, the
37 # installed libreoffice build can also be good for manual test.
39 import sys, os, platform
40 import datetime, time
41 import subprocess, shutil
42 import glob, re
43 import urllib, urllib2
44 import logging, getopt
45 try:
46 import ConfigParser as configparser # Python 3.0 change
47 except ImportError:
48 import configparser
50 # FIXME: make this configurable via options or autodetect it
51 build_version = "3.5"
52 tag_version = "3-5"
53 # devel build
54 install_dirname="lo-dev"
55 branding_pack="libo-dev"
56 basis_pack="libobasis-dev"
57 ure_pack="lodev"
58 # stable build
59 #install_dirname="libreoffice" + build_version
60 #branding_pack="libreoffice"
61 #basis_pack="libobasis"
62 #ure_pack="libreoffice"
64 build_check_interval = 5 #seconds
66 # Distro list
67 RPM_DISTRO_LIST = ['SuSE', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'yellowdog', 'turbolinux']
68 DEB_DISTRO_LIST = ['debian', 'ubuntu', 'Ubuntu']
70 # Server urls
71 SERVER_URL = "http://dev-builds.libreoffice.org"
73 # Local dirs
74 root_dir = os.getcwd()
75 DOWNLOAD_DIR = os.path.join(root_dir, "_download")
76 USR_DIR = os.path.join(root_dir, "_libo_smoke_user")
77 LOCAL_BUILD_INFO_FILE = "build.cfg"
79 ROOT_DIR_LIB = os.path.join(root_dir, 'lib')
80 ROOT_DIR_LIB32 = os.path.join(root_dir, 'lib32')
81 ROOT_DIR_LIB64 = os.path.join(root_dir, 'lib64')
82 ROOT_DIR_BIN32 = os.path.join(root_dir, 'bin32')
83 ROOT_DIR_BIN64 = os.path.join(root_dir, 'bin64')
85 CPPUNITTESTER = os.path.join(root_dir, 'cppunittester')
87 # INSTALL_DIR = os.path.join(root_dir, "_libo_smoke_installation")
88 INSTALL_DIR = "" # Installation dir
90 # SOFFICE_BIN bin
91 if platform.system() == "Linux":
92 SOFFICE_BIN= INSTALL_DIR + os.sep + "opt" + os.sep + install_dirname + os.sep + "program" + os.sep + "soffice"
94 # Relative build url
95 ## pre-releases
96 PR_RPM_X86_PATH = "pre-releases/rpm/x86/"
97 PR_RPM_X86_64_PATH = "pre-releases/rpm/x86_64/"
99 PR_DEB_X86_PATH = "pre-releases/deb/x86/"
100 PR_DEB_X86_64_PATH = "pre-releases/deb/x86_64/"
102 PR_MAC_X86_PATH = "pre-releases/mac/x86/"
103 PR_MAC_PPC_PATH = "pre-releases/mac/ppc/"
105 PR_WIN_X86_PATH = "pre-releases/win/x86/"
107 ## daily_master
108 DAILY_MASTER_RPM_X86_PATH = "daily/Linux_x86_Release_Configuration/master/current"
109 DAILY_MASTER_RPM_X86_64_PATH = "daily/Linux_x86_64_Release_Configuration/master/current"
111 DAILY_MASTER_DEB_X86_PATH = "daily/Linux_x86_Release_Configuration/master/current"
112 DAILY_MASTER_DEB_X86_64_PATH = "daily/Linux_x86_64_Release_Configuration/master/current" # No build yet
114 DAILY_MASTER_MAC_X86_PATH = "daily/MacOSX_10.6.7_Intel_no-moz/master/current"
115 DAILY_MASTER_MAC_PPC_PATH = "^$" # No build yet
117 DAILY_MASTER_WIN_X86_PATH = "daily/Windows_Release_Configuration/master/current"
119 ## daily_branch
120 DAILY_BRANCH_RPM_X86_PATH = "daily/Linux_x86_Release_Configuration/libreoffice-" + tag_version + "/current"
121 DAILY_BRANCH_RPM_X86_64_PATH = "daily/Linux_x86_64_Release_Configuration/libreoffice-" + tag_version + "/current"
123 DAILY_BRANCH_DEB_X86_PATH = "daily/Linux_x86_Release_Configuration/libreoffice-" + tag_version + "/current"
124 DAILY_BRANCH_DEB_X86_64_PATH = "daily/Linux_x86_64_Release_Configuration/libreoffice-" + tag_version + "/current"
126 DAILY_BRANCH_MAC_X86_PATH = "daily/MacOSX_10.6.7_Intel_no-moz/libreoffice-" + tag_version + "/current"
127 DAILY_BRANCH_MAC_PPC_PATH = "^$" # No build yet
129 DAILY_BRANCH_WIN_X86_PATH = "daily/Windows_Release_Configuration/libreoffice-" + tag_version + "/current"
133 def platform_info():
135 s = platform.system()
136 arch_name = platform.machine()
138 if arch_name in ['x86', 'i386', 'i586', 'i686']:
139 arch_name = 'x86'
141 if s == "Linux":
142 if platform.dist()[0] in RPM_DISTRO_LIST:
143 distro_name = platform.dist()[0]
144 pck_name = 'rpm'
145 elif platform.dist()[0] in DEB_DISTRO_LIST:
146 distro_name = platform.dist()[0]
147 pck_name = 'deb'
148 elif s == "Windows":
149 distro_name = platform.dist()[0]
150 pck_name = 'exe'
151 else:
152 distro_name = platform.dist()[0]
153 pck_name = 'dmg'
155 return distro_name, pck_name, arch_name
157 def local_build_info(t):
159 if not os.path.exists(LOCAL_BUILD_INFO_FILE):
160 logger.error("Can't find the file: " + LOCAL_BUILD_INFO_FILE)
161 sys.exit()
163 config = configparser.RawConfigParser()
164 config.read(LOCAL_BUILD_INFO_FILE)
166 try:
167 build_name = config.get(t, 'build_name').strip('\n')
168 build_time = datetime.datetime.strptime(config.get(t, 'build_time').strip('\n'), '%d-%b-%Y %H:%M')
169 except ValueError:
170 build_name = ''
171 build_time = datetime.datetime.min
173 return build_name, build_time
175 def get_url_regexp(t, package, arch):
177 return a url containing download links, i.e:
179 http://dev-builds.libreoffice.org/pre-releases/rpm/x86_64/
180 http://dev-builds.libreoffice.org/daily/Windows_Release_Configuration/libreoffice-3-4/current/
181 http://dev-builds.libreoffice.org/daily/Linux_x86_Release_Configuration/libreoffice-3-4/current/
183 meanwhile return a regexp object that matching corresponding downloadable
184 package and its timestamp '''
186 url = ""
187 reg = re.compile('^$')
188 pck = package
189 arc = arch
191 if t == 'pre-releases':
192 if pck == "rpm" and arc == "x86":
193 url = SERVER_URL + "/" + PR_RPM_X86_PATH
194 reg = re.compile('\<a\ href=\"(LibO_\d.*x86_install-rpm.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
195 elif pck == "rpm" and arc == "x86_64":
196 url = SERVER_URL + "/" + PR_RPM_X86_64_PATH
197 reg = re.compile('\<a\ href=\"(LibO_\d.*x86-64_install-rpm.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
198 elif pck == "deb" and arc == "x86":
199 url = SERVER_URL + "/" + PR_DEB_X86_PATH
200 reg = re.compile('\<a\ href=\"(LibO_\d.*x86_install-deb.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
201 elif pck == "deb" and arc == "x86_64":
202 url = SERVER_URL + "/" + PR_DEB_X86_64_PATH
203 reg = re.compile('\<a\ href=\"(LibO_\d.*x86-64_install-deb.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
204 elif pck == "exe" and arc == "x86":
205 url = SERVER_URL + "/" + PR_WIN_X86_PATH
206 reg = re.compile('\<a\ href=\"(LibO_\d.*Win_x86_install_multi.exe)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
207 elif pck == "dmg" and arc == "x86":
208 url = SERVER_URL + "/" + PR_MAC_X86_PATH
209 reg = re.compile('\<a\ href=\"(LibO_\d.*MacOS_x86_install_en-US.dmg)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
210 elif pck == "dmg" and arc == "ppc":
211 url = SERVER_URL + "/" + PR_MAC_PPC_PATH
212 reg = re.compile('\<a\ href=\"(LibO_\d.*MacOS_PPC_install_en-US.dmg)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
213 else:
214 logger.error("Unable to handle the system or arch!")
215 elif t == 'daily_master':
216 if pck == "rpm" and arc == "x86":
217 url = SERVER_URL + "/" + DAILY_MASTER_RPM_X86_PATH
218 reg = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86_install-rpm_en-US.tar.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
219 elif pck == "rpm" and arc == "x86_64":
220 url = SERVER_URL + "/" + DAILY_MASTER_RPM_X86_64_PATH
221 reg = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86-64_install-rpm_en-US.tar.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
222 elif pck == "deb" and arc == "x86":
223 url = SERVER_URL + "/" + DAILY_MASTER_DEB_X86_PATH
224 reg = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86_install-deb_en-US.tar.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
225 elif pck == "deb" and arc == "x86_64":
226 url = SERVER_URL + "/" + DAILY_MASTER_DEB_X86_64_PATH
227 reg = re.compile('^$') # No build yet
228 elif pck == "exe" and arc == "x86":
229 url = SERVER_URL + "/" + DAILY_MASTER_WIN_X86_PATH
230 reg = re.compile('^$') # No build yet
231 elif pck == "dmg" and arc == "x86":
232 url = SERVER_URL + "/" + DAILY_MASTER_MAC_X86_PATH
233 reg = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86_install_en-US.dmg)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
234 elif pck == "dmg" and arc == "ppc":
235 url = SERVER_URL + "/" + DAILY_MASTER_MAC_PPC_PATH
236 reg = re.compile('^$') # No build yet
237 else:
238 logger.error("Unable to handle the system or arch!")
239 elif t == 'daily_branch':
240 if pck == "rpm" and arc == "x86":
241 url = SERVER_URL + "/" + DAILY_BRANCH_RPM_X86_PATH
242 reg = re.compile('\<a\ href=\"(.*LibO_.*x86_install-rpm_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
243 elif pck == "rpm" and arc == "x86_64":
244 url = SERVER_URL + "/" + DAILY_BRANCH_RPM_X86_64_PATH
245 reg = re.compile('\<a\ href=\"(.*LibO_.*x86-64_install-rpm_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
246 elif pck == "deb" and arc == "x86":
247 url = SERVER_URL + "/" + DAILY_BRANCH_DEB_X86_PATH
248 reg = re.compile('\<a\ href=\"(.*LibO_.*x86_install-deb_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
249 elif pck == "deb" and arc == "x86_64":
250 url = SERVER_URL + "/" + DAILY_BRANCH_DEB_X86_64_PATH
251 reg = re.compile('\<a\ href=\"(.*LibO_.*x86-64_install-deb_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
252 elif pck == "exe" and arc == "x86":
253 url = SERVER_URL + "/" + DAILY_BRANCH_WIN_X86_PATH
254 reg = re.compile('\<a\ href=\"(.*LibO_.*install_.*\.exe)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
255 elif pck == "dmg" and arc == "x86":
256 url = SERVER_URL + "/" + DAILY_BRANCH_MAC_X86_PATH
257 reg = re.compile('^$') # No build yet
258 elif pck == "dmg" and arc == "ppc":
259 url = SERVER_URL + "/" + DAILY_BRANCH_MAC_PPC_PATH
260 reg = re.compile('^$') # No build yet
261 else:
262 logger.error("Unable to handle the system or arch!")
263 else:
264 logger.error("Error build type! The build type has to be:\n pre-releases, daily_master, daily_branch")
266 return url, reg
268 def remote_build_info(url_reg):
269 ''' Get the latest proper build info (build_name, build_time) from
270 url. '''
272 p = platform_info()
273 pck = p[1]
274 arc = p[2]
275 r = url_reg[1]
277 f = urllib2.urlopen(url_reg[0])
278 c = ''.join(f.readlines())
279 f.close()
281 build_list = r.findall(c)
283 build_name = ''
284 build_time = datetime.datetime.min
286 for b in build_list:
287 if datetime.datetime.strptime(b[1] + ' ' + b[2], '%d-%b-%Y %H:%M') > build_time:
288 build_name = b[0]
289 try:
290 build_time = datetime.datetime.strptime(b[1] + ' ' + b[2], '%d-%b-%Y %H:%M')
291 except:
292 print "remote_build_info: wrong time date&format"
294 return build_name, build_time
296 # return True when something was downloaded
297 def download(url_reg, build_type):
298 logger.info('Checking new build ...')
300 try:
301 remote_build = remote_build_info(url_reg)
302 local_build = local_build_info(build_type)
304 # print 'remote_build[1]=' + remote_build[1].isoformat()
305 # print 'local_build[1]=' + local_build[1].isoformat()
306 if remote_build[1] > local_build[1]:
307 logger.info('Found New build: ' + remote_build[0])
308 if fetch_build(url_reg[0], remote_build[0]):
309 set_build_config(build_type, 'build_name', remote_build[0])
310 set_build_config(build_type, 'build_time', datetime.datetime.strftime(remote_build[1], '%d-%b-%Y %H:%M'))
311 else:
312 logger.error('Download build failed!')
313 else:
314 return False
316 except urllib2.URLError, HTTPError:
317 logger.error('Error fetch remote build info.')
318 return False
319 except KeyboardInterrupt:
320 sys.exit()
321 except:
322 print "Some Error"
323 return False
325 return True
328 def fetch_build(url, filename):
329 ''' Download a build from address url/filename '''
331 logger.info("Downloading ... " + filename)
333 u = urllib2.urlopen(url + '/' + filename)
335 try:
336 f = open(DOWNLOAD_DIR + '/' + filename, 'wb')
337 f.write(u.read())
338 finally:
339 f.close()
341 return True
343 def set_build_config(section, option, value):
345 config = configparser.RawConfigParser()
346 config.readfp(open(LOCAL_BUILD_INFO_FILE))
347 config.set(section, option, value)
348 with open(LOCAL_BUILD_INFO_FILE, 'wb') as cfgfile:
349 config.write(cfgfile)
351 def uninstall():
352 ''' Kill libreoffice processes and uninstall all previously installed
353 libreoffice packages '''
355 logger.info("Uninstalling ...")
357 pck = platform_info()[1]
359 if pck == 'rpm':
360 cmd_query = ["rpm", "-qa"]
361 cmd_filter = ["grep", "-e", branding_pack+build_version, "-e", basis_pack+build_version, "-e", ure_pack+build_version]
363 P_query = subprocess.Popen(cmd_query, stdout = subprocess.PIPE)
364 P_filter = subprocess.Popen(cmd_filter, stdin = P_query.stdout, stdout = subprocess.PIPE)
365 P_query.stdout.close() # protection when P_filter exit before P_query
366 str_filter = P_filter.communicate()[0]
368 if str_filter == "":
369 logger.warning("Nothing to uninstall")
370 return
371 else:
372 cmd = ["sudo", "rpm", "-e"] + str_filter.split()
373 elif pck == 'deb':
374 cmd_query = ["dpkg", "--get-selections", branding_pack+build_version+"*", basis_pack+build_version+"*", ure_pack+build_version+"*"]
375 cmd_filter = ["cut", "-f", "1"]
377 P_query = subprocess.Popen(cmd_query, stdout = subprocess.PIPE)
378 P_filter = subprocess.Popen(cmd_filter, stdin = P_query.stdout, stdout = subprocess.PIPE)
379 P_query.stdout.close()
380 str_filter = P_filter.communicate()[0]
382 if str_filter == "":
383 logger.warning("Nothing to uninstall")
384 return
385 else:
386 cmd = ["sudo", "dpkg ", "-P"] + str_filter.split()
387 elif pck == 'exe':
388 pass
389 elif pck == 'dmg':
390 pass
391 else:
392 logger.warning("Non supported package system")
394 subprocess.check_call(cmd)
396 def init_testing():
397 logger.info("Initializing ...")
399 post_testing()
401 if not os.path.exists(DOWNLOAD_DIR):
402 os.mkdir(DOWNLOAD_DIR)
404 if not os.path.exists(USR_DIR):
405 os.mkdir(USR_DIR)
407 # create set up links
408 try:
409 if platform.system() == "Linux":
410 # remove old symlinks if they exists
411 for p in ROOT_DIR_LIB, CPPUNITTESTER:
412 if os.path.exists(p) and os.path.islink(p):
413 os.remove(p)
415 if platform_info()[2] == "x86":
416 os.symlink(ROOT_DIR_LIB32, ROOT_DIR_LIB)
417 os.symlink(os.path.join(ROOT_DIR_BIN32, 'cppunittester'), CPPUNITTESTER)
418 elif platform_info()[2] == "x86_64":
419 os.symlink(ROOT_DIR_LIB64, ROOT_DIR_LIB)
420 os.symlink(os.path.join(ROOT_DIR_BIN64, 'cppunittester'), CPPUNITTESTER)
421 else:
422 pass
424 elif platform.system() == "Windows" and platform_info()[2] == "x86":
425 pass
426 else:
427 pass
429 except OSError:
430 pass
432 def post_testing():
433 logger.info("Cleaning up ...")
435 # clean up the extracted installer dir
436 for r in os.walk(DOWNLOAD_DIR):
437 if r[0] == DOWNLOAD_DIR:
438 for d in r[1]:
439 shutil.rmtree(os.path.join(r[0], d))
441 def install(filename):
442 ''' filename: local file path of tar.gz, dmg or exe. The script will
443 extract the package and then install it '''
445 logger.info("Installing ... " + filename)
447 def _is_not_filtered(s):
448 ''' True if the package s is not intended to installed. '''
449 filter_pattern_list = ['.*kde.*', '.*gnome.*', '.*desktop.*', '!.*\.rpm$', '!.*\.deb$']
450 for p in filter_pattern_list:
451 r = re.compile(p)
452 if r.match(s):
453 return False
454 return True
456 fn, ext = os.path.splitext(filename)
457 pcklist = []
459 if ext == '.exe':
460 # extract
461 installer_dir = os.path.join(DOWNLOAD_DIR, filename.strip(ext))
462 subprocess.check_call([filename, '/EXTRACTONLY=ON', '/S', '/D='+installer_dir])
463 # install
464 installer = glob.glob(os.path.join(installer_dir, 'libreoffice*msi'))[0]
465 subprocess.check_call(['msiexec', '-i', installer, '-passive', 'ADDLOCAL=all'])
466 elif ext == '.dmg':
467 return
468 elif ext == '.gz':
469 # extract
470 subprocess.check_call(['tar', 'xzf', filename, '-C', DOWNLOAD_DIR])
472 # get a filtered install list
473 for root, dirs, files in os.walk(DOWNLOAD_DIR):
474 if 'RPMS' in root or 'DEBS' in root:
475 pcklist = pcklist + [os.path.join(root_dir, root, f) for f in files]
476 pcklist = filter(_is_not_filtered, pcklist)
478 # install
479 if platform_info()[1] == 'rpm':
480 install_cmd = ["sudo", "rpm", "-iv"] + pcklist
481 elif platform_info()[1] == 'deb':
482 install_cmd = ["sudo", "dpkg", "-i"] + pcklist
483 else:
484 logger.error('Cannot generate install command')
485 return
487 subprocess.check_call(install_cmd)
489 else:
490 logger.info("Unrecognized file extension")
492 def verify_smoketest(headless):
493 logger.info("Testing ...")
495 s = platform.system()
496 p = platform_info()
497 pck = p[1]
498 arc = p[2]
500 if s == "Linux":
501 if headless:
502 os.environ['SAL_USE_VCLPLUGIN'] = "svp"
503 os.environ['LD_LIBRARY_PATH'] = ""
504 os.environ['LD_LIBRARY_PATH'] = ':'.join([os.path.join(root_dir, 'lib'), INSTALL_DIR + '/opt/' + install_dirname + '/ure/lib', os.environ['LD_LIBRARY_PATH']])
505 cmd_cppu = [
506 CPPUNITTESTER,
507 "-env:UNO_SERVICES=file://"+ INSTALL_DIR + "/opt/" + install_dirname + "/ure/share/misc/services.rdb",
508 "-env:UNO_TYPES=" + os.path.join(os.path.join(root_dir, 'lib'), "types.rdb"),
509 "-env:arg-soffice=path:" + SOFFICE_BIN,
510 "-env:arg-user=" + USR_DIR,
511 "-env:arg-env=" + os.environ['LD_LIBRARY_PATH'],
512 "-env:arg-testarg.smoketest.doc=" + os.path.join(root_dir, "doc/smoketestdoc.sxw"),
513 "--protector",
514 os.path.join(root_dir, "lib/unoexceptionprotector.so"), "unoexceptionprotector",
515 os.path.join(root_dir, "lib/libsmoketest.so")
517 else:
518 logger.warning('The smoketest does not support this platform yet!')
520 try:
521 subprocess.check_call(cmd_cppu)
522 logger.info(" Smoketest PASSED")
523 except:
524 logger.error(" Smoketest FAILED")
527 def usage():
529 print "\n[Usage]\n\n -f Force testing without asking \n\
530 -t Testing type pre-release/daily \n\
531 -l Download and test last builds in a loop \n\
532 -v Run smoketest verification directly \n\
533 -s Use the headless mode when running the tests \n\
534 -i Install the latest build in the DOWNLOAD directory \n\
535 -u Uninstall any existed libreoffice build \n\
536 -d Download the latest build for the given test type \n\
539 def main():
541 interactive = True
542 build_type = "pre-releases"
544 package_type = platform_info()[1]
545 arch_type = platform_info()[2]
547 loop = False
548 interactive = True
549 headless = False
550 build_type = "pre-releases"
552 # Handling options and arguments
553 try:
554 opts, args = getopt.getopt(sys.argv[1:], "dluihfvst:", ["download", "loop", "uninstall", "install", "help", "force", "verify", "headless", "type="])
555 except getopt.GetoptError, err:
556 logger.error(str(err))
557 usage()
558 sys.exit(2)
560 for o, a in opts:
561 if ("-t" in o) or ("--type" in o):
562 build_type = a
563 elif o in ("-s", "--headless"):
564 headless = True
566 url_reg = get_url_regexp(build_type, package_type, arch_type)
568 for o, a in opts:
569 if o in ("-f", "--force"):
570 interactive = False
571 elif o in ("-t", "--type"):
572 pass
573 elif o in ("-s", "--headless"):
574 pass
575 elif o in ("-h", "--help"):
576 usage()
577 sys.exit()
578 elif o in ("-v", "--verify"):
579 init_testing()
580 verify_smoketest(headless)
581 sys.exit()
582 elif o in ("-i", "--install"):
583 init_testing()
584 uninstall()
585 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[0])
586 sys.exit()
587 elif o in ("-u", "--uninstall"):
588 uninstall()
589 sys.exit()
590 elif o in ("-d", "--download"):
591 download(url_reg, build_type)
592 sys.exit()
593 elif o in ("-l", "--loop"):
594 loop = True
595 else:
596 assert False, "Unhandled option: " + o
598 if interactive == True:
599 key = raw_input("The testing will OVERRIDE existed libreoffice, continue(y/N)? ")
600 if not (key == "y" or key == "Y" or key == "yes"):
601 sys.exit()
603 init_testing()
604 first_run = True
605 while loop or first_run:
606 if download(url_reg, build_type):
607 try:
608 # FIXME: uninstall script fails but it need not break the whole game; so try it twice
609 try:
610 uninstall()
611 except:
612 logger.error("Some errors happend during uninstall. Trying once again.")
613 uninstall()
615 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[0])
616 verify_smoketest(headless)
618 except KeyboardInterrupt:
619 sys.exit()
620 except:
621 pass
623 if loop:
624 time.sleep(build_check_interval)
626 first_run = False
629 if __name__ == '__main__':
631 # logging
632 logger = logging.getLogger('')
633 logger.setLevel(logging.DEBUG)
635 fh = logging.FileHandler('losmoketest.log')
636 ch = logging.StreamHandler()
638 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
639 ch.setFormatter(formatter)
640 fh.setFormatter(formatter)
642 logger.addHandler(ch)
643 logger.addHandler(fh)
645 main()