1#!/usr/bin/env python
2# -*- Mode: python -*-
3
4#    Copyright (C) 2001 Artifex Software Inc.
5#    All Rights Reserved.
6#
7# This software is provided AS-IS with no warranty, either express or
8# implied.
9#
10# This software is distributed under license and may not be copied, modified
11# or distributed except as expressly authorized under the terms of that
12# license.  Refer to licensing information at http://www.artifex.com/
13# or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
14# San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
15
16# $Id$
17
18#
19# run_regression.py
20#
21# runs ghostscript regression tests
22
23import sys, os, time, myoptparse, optparse, shutil
24import anydbm
25import gstestutils, gsconf, gsparamsets
26import check_all
27import gscheck_all
28
29def get_revision_of_HEAD(dir=None):
30    if dir:
31        cwd=os.getcwd()
32        os.chdir(dir)
33    p = os.popen("svn info")
34    for line in p:
35        if "Revision:" in line:
36            revision=line.strip('Revision: ')
37            revision=revision.strip('\n')
38	    break
39    else:
40        revision = None
41    if dir:
42        os.chdir(cwd)
43    return revision
44
45def testAll(track,gsroot,now,options):
46    suite = gstestutils.GSTestSuite()
47
48    print options.myself,gsconf.comparefiledir
49    print options.myself,"test parameter set: "+gsparamsets.testparamsets_name
50
51    if not os.path.exists(gsroot):
52        print options.myself,"FATAL: gsroot directory does not exist",gsroot
53        sys.exit(1)
54
55    gsexecutable=gsroot+"bin/gs"
56    if not os.path.exists(gsexecutable):
57        print options.myself,"FATAL: gsexecutable does not exist",gsexecutable
58        sys.exit(1)
59
60    revision=get_revision_of_HEAD(dir=gsroot)
61    print options.myself,"from tree:",gsroot,"revision is:",revision
62
63    # Add tests based on running Ghostscript.
64    gscheck_all.addTests(suite, gsroot=gsroot, track=track, now=now, options=options)
65
66    # Add tests not based on actually running Ghostscript.
67    check_all.addTests(suite, gsroot=gsroot)
68
69    # run all the tests
70    runner = gstestutils.GSTestRunner(verbosity=2)
71
72    cwd=os.getcwd()
73
74    start_time=time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime())
75    print options.myself,start_time,"executing in",gsroot
76    os.chdir(gsroot)
77
78    result = runner.run(suite)
79
80    end_time=time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime())
81    print options.myself,end_time,"complete",cwd
82    os.chdir(cwd)
83
84if __name__ == "__main__":
85
86    optionsParser=optparse.OptionParser()
87    optionsParser.add_option('--track',action='store_true',help="track sums in baseline db")
88    optionsParser.add_option('--time',action='store',help="provide start time",default=None)
89    optionsParser.add_option('--revision_value',action='store',help="revision - always an svn revision number",default=None)
90
91    (options,arguments)=myoptparse.parseCommandLine(optionsParser,testfileSkip=True,listfileSkip=True,deviceSkip=True)
92
93    now=options.time
94    revision=options.revision
95    revision_value=options.revision_value
96
97    if revision != "HEAD":
98        gsconf.checksumdb = gsconf.dailydir+revision # mhw +".db"
99
100    if revision != "HEAD":
101        gsroot=gsconf.root+"gs."+revision+"/"
102    else:
103        gsroot=gsconf.gsroot
104
105    if options.track:
106        if gsconf.__dict__.has_key("checksumdb") and gsconf.checksumdb:
107            dbname=gsconf.checksumdb
108        else:
109            dbname=gsconf.get_dailydb_name()
110
111        # create (truncate) the database for the daily checksums
112        db = anydbm.open(dbname, "n")
113        db.close()
114        print options.myself,"daily database for checksums",dbname
115
116    testAll(options.track,gsroot,now,options)
117
118    if options.track:
119        dbname = dbname + ".db" # mhw
120        if not os.path.exists(dbname):
121            print options.myself,"ERROR","the checksum database does not exist",dbname
122
123        # copy from the db by date to the db by revision
124        if revision == "HEAD":
125            dbname_by_revision_value = gsconf.dailydir+revision_value+".db"
126
127        print options.myself,"copy from",dbname,"to",dbname_by_revision_value
128        shutil.copy(dbname,dbname_by_revision_value)
129