summaryrefslogtreecommitdiff
blob: 96a5af77861bce284a11b82ad20aff88f7aee6d3 (plain)
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
#!/usr/bin/env python
# -*- Mode: python -*-

# Copyright (C) 2001-2020 Artifex Software, Inc.
# All Rights Reserved.
#
# This software is provided AS-IS with no warranty, either express or
# implied.
#
# This software is distributed under license and may not be copied,
# modified or distributed except as expressly authorized under the terms
# of the license contained in the file LICENSE in this distribution.
#
# Refer to licensing information at http://www.artifex.com or contact
# Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
# CA 94945, U.S.A., +1(415)492-9861, for further information.
#


#
# run_regression.py
#
# runs ghostscript regression tests

import sys, os, time, myoptparse, optparse, shutil
import anydbm
import gstestutils, gsconf, gsparamsets
import check_all
import gscheck_all

def get_revision_of_HEAD(dir=None):
    if dir:
        cwd=os.getcwd()
        os.chdir(dir)
    p = os.popen("svn info")
    for line in p:
        if "Revision:" in line:
            revision=line.strip('Revision: ')
            revision=revision.strip('\n')
	    break
    else:
        revision = None
    if dir:
        os.chdir(cwd)
    return revision

def testAll(track,gsroot,now,options):
    suite = gstestutils.GSTestSuite()

    print options.myself,gsconf.comparefiledir
    print options.myself,"test parameter set: "+gsparamsets.testparamsets_name

    if not os.path.exists(gsroot):
        print options.myself,"FATAL: gsroot directory does not exist",gsroot        
        sys.exit(1)

    gsexecutable=gsroot+"bin/gs"
    if not os.path.exists(gsexecutable):
        print options.myself,"FATAL: gsexecutable does not exist",gsexecutable        
        sys.exit(1)

    revision=get_revision_of_HEAD(dir=gsroot)
    print options.myself,"from tree:",gsroot,"revision is:",revision
    
    # Add tests based on running Ghostscript.
    gscheck_all.addTests(suite, gsroot=gsroot, track=track, now=now, options=options)

    # Add tests not based on actually running Ghostscript.
    check_all.addTests(suite, gsroot=gsroot)

    # run all the tests
    runner = gstestutils.GSTestRunner(verbosity=2)

    cwd=os.getcwd()

    start_time=time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime())
    print options.myself,start_time,"executing in",gsroot
    os.chdir(gsroot)

    result = runner.run(suite)

    end_time=time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime())
    print options.myself,end_time,"complete",cwd
    os.chdir(cwd)

if __name__ == "__main__":

    optionsParser=optparse.OptionParser()
    optionsParser.add_option('--track',action='store_true',help="track sums in baseline db")
    optionsParser.add_option('--time',action='store',help="provide start time",default=None)
    optionsParser.add_option('--revision_value',action='store',help="revision - always an svn revision number",default=None)

    (options,arguments)=myoptparse.parseCommandLine(optionsParser,testfileSkip=True,listfileSkip=True,deviceSkip=True)

    now=options.time
    revision=options.revision
    revision_value=options.revision_value

    if revision != "HEAD":
        gsconf.checksumdb = gsconf.dailydir+revision # mhw +".db"

    if revision != "HEAD":
        gsroot=gsconf.root+"gs."+revision+"/"
    else:
        gsroot=gsconf.gsroot

    if options.track:
        if gsconf.__dict__.has_key("checksumdb") and gsconf.checksumdb:
            dbname=gsconf.checksumdb
        else:
            dbname=gsconf.get_dailydb_name()

        # create (truncate) the database for the daily checksums
        db = anydbm.open(dbname, "n")
        db.close()
        print options.myself,"daily database for checksums",dbname
    
    testAll(options.track,gsroot,now,options)

    if options.track:
        dbname = dbname + ".db" # mhw
        if not os.path.exists(dbname):
            print options.myself,"ERROR","the checksum database does not exist",dbname

        # copy from the db by date to the db by revision
        if revision == "HEAD":
            dbname_by_revision_value = gsconf.dailydir+revision_value+".db"

        print options.myself,"copy from",dbname,"to",dbname_by_revision_value
        shutil.copy(dbname,dbname_by_revision_value)