1
1
#!/usr/bin/env python
2
2
#
3
- # Usage: 3c-regtest -t TMPNAME [options...] SRC_FILE
3
+ # 3c-regtest.py: Run a 3C regression test using a standard RUN script.
4
4
#
5
- # TMPNAME corresponds to %t and SRC_FILE corresponds to %s. Both are required.
5
+ # 3c-regtest.py is intended to be invoked by a single RUN command in the test
6
+ # file. The canonical form is:
6
7
#
7
- # --subst can be used for things such as %clang, for example (assuming single
8
- # --quotes are removed by the shell):
8
+ # // RUN: %S/3c-regtest.py TEST_TYPE_FLAGS %s -t %t --clang '%clang'
9
9
#
10
- # --subst %clang 'clang -some-flag'
10
+ # 3c-regtest.py generates a RUN script based on the TEST_TYPE_FLAGS (using
11
+ # script_generator.py) and runs it using code from `lit`.
11
12
#
12
- # (Note: A literal % has to be represented as %% in a RUN line. If we instead
13
- # established the convention of automatically prepending the % here, then the
14
- # RUN line would trip the "Do not use 'clang' in tests, use '%clang'." error.)
15
- #
16
- # Example RUN line:
17
- #
18
- # // RUN: %S/3c-regtest.py -t %t --subst %%clang '%clang' %s
19
- #
20
- # Soon, we'll add options for different kinds of 3C regression tests.
13
+ # The -t and --clang flags are used to pass substitution values from the outer
14
+ # `lit` configuration so that 3c-regtest.py knows what to substitute for
15
+ # occurrences of %t and %clang in its script. We'll add flags like this for all
16
+ # % codes that appear in the scripts.
21
17
22
- # TODO: Add Windows compatibility code once we have an easy way to test on Windows.
18
+ # TODO: Add Windows compatibility code once we have an easy way to test on
19
+ # Windows.
23
20
24
21
import sys
25
22
import os
26
23
import platform
27
24
import argparse
28
25
26
+ import script_generator
27
+
29
28
sys .path .insert (0 , os .path .dirname (os .path .abspath (__file__ )) +
30
29
'/../../../llvm/utils/lit' )
31
30
import lit .TestRunner
32
31
33
- print "NOTICE: cwd is %s" % os .getcwd ()
34
-
35
- def die (msg ):
36
- sys .stderr .write ('Error: %s\n ' % msg )
37
- sys .exit (1 )
32
+ parser = argparse .ArgumentParser (description = 'Run a 3C regression test.' ,
33
+ parents = [script_generator .parser ])
34
+ # Substitution arguments. The test file name is already in
35
+ # script_generator.parser.
36
+ parser .add_argument ('-t' )
37
+ parser .add_argument ('--clang' )
38
38
39
- parser = argparse .ArgumentParser (description = 'Run a 3C regression test.' )
40
- # TODO: Add help
41
- parser .add_argument ('test_file' )
42
- parser .add_argument ('-t' , required = True )
43
- parser .add_argument ('--subst' , action = 'append' , nargs = 2 , default = [])
44
- args = parser .parse_args ()
39
+ argobj = parser .parse_args ()
45
40
46
- test_dir = os .path .dirname (args .test_file )
47
- if test_dir == '' :
48
- test_dir = '.'
41
+ test_dir = os .path .dirname (os .path .abspath (argobj .test_file ))
49
42
50
- tmpName = args .t
51
- tmpNameSuffix = '.tmp'
52
- if tmpName .endswith (tmpNameSuffix ):
53
- tmpBase = tmpName [:- len (tmpNameSuffix )]
54
- else :
55
- die ('-t argument %s does not end with %s' % (tmpName , tmpNameSuffix ))
43
+ tmpName = argobj .t
44
+ tmpBase = script_generator .remove_suffix (tmpName , '.tmp' )
45
+ if tmpBase is None :
46
+ sys .exit ('-t argument %s does not end with .tmp' % tmpName )
56
47
48
+ # `lit` supports more substitutions, but these are the only ones needed by the
49
+ # tests that use 3c-regtest.py so far.
57
50
substitutions = [
58
51
# #_MARKER_# is a hack copied from getDefaultSubstitutions in
59
52
# llvm/utils/lit/lit/TestRunner.py. To explain it a bit more fully:
@@ -66,23 +59,14 @@ def die(msg):
66
59
# over the input from left to right, replacing codes as they are found, but
67
60
# apparently that wasn't worth the extra code in `lit`.
68
61
('%%' , '#_MARKER_#' ),
69
- ('%s' , args .test_file ),
62
+ ('%s' , argobj .test_file ),
70
63
('%S' , test_dir ),
71
64
('%t' , tmpName ),
65
+ ('%clang' , argobj .clang ),
66
+ ('#_MARKER_#' , '%' )
72
67
]
73
- substitutions .extend (args .subst )
74
- substitutions .append (('#_MARKER_#' , '%' ))
75
68
76
- # Starting with processor.py because it's always the same.
77
- commands = [
78
- # FIXME: 'foo.c' + 'hecked.c' is a terrible hack; find the right way to do this.
79
- '3c -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s' ,
80
- '3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s' ,
81
- '3c -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -' ,
82
- '3c -output-postfix=checked -alltypes %s' ,
83
- '3c -alltypes %shecked.c -- | count 0' ,
84
- 'rm %shecked.c' ,
85
- ]
69
+ commands = script_generator .generate_commands (argobj )
86
70
commands = lit .TestRunner .applySubstitutions (commands , substitutions )
87
71
88
72
class FakeTestConfig :
0 commit comments