-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Usage: 3c-regtest -t TMPNAME [options...] SRC_FILE | ||
# | ||
# TMPNAME corresponds to %t and SRC_FILE corresponds to %s. Both are required. | ||
# | ||
# --subst can be used for things such as %clang, for example (assuming single | ||
# --quotes are removed by the shell): | ||
# | ||
# --subst %clang 'clang -some-flag' | ||
# | ||
# (Note: A literal % has to be represented as %% in a RUN line. If we instead | ||
# established the convention of automatically prepending the % here, then the | ||
# RUN line would trip the "Do not use 'clang' in tests, use '%clang'." error.) | ||
# | ||
# Example RUN line: | ||
# | ||
# // RUN: %S/3c-regtest.py -t %t --subst %%clang '%clang' %s | ||
# | ||
# Soon, we'll add options for different kinds of 3C regression tests. | ||
|
||
# TODO: Add Windows compatibility code once we have an easy way to test on Windows. | ||
|
||
import sys | ||
import os | ||
import platform | ||
import argparse | ||
|
||
sys.path.insert(0, os.path.dirname(__file__) + '/../../../llvm/utils/lit') | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mwhicks1
Member
|
||
import lit.TestRunner | ||
This comment has been minimized.
Sorry, something went wrong.
mwhicks1
Member
|
||
|
||
print "NOTICE: cwd is %s" % os.getcwd() | ||
|
||
def die(msg): | ||
sys.stderr.write('Error: %s\n' % msg) | ||
sys.exit(1) | ||
|
||
parser = argparse.ArgumentParser(description='Run a 3C regression test.') | ||
# TODO: Add help | ||
parser.add_argument('test_file') | ||
parser.add_argument('-t', required=True) | ||
parser.add_argument('--subst', action='append', nargs=2, default=[]) | ||
args = parser.parse_args() | ||
|
||
test_dir = os.path.dirname(args.test_file) | ||
if test_dir == '': | ||
test_dir = '.' | ||
|
||
tmpName = args.t | ||
tmpNameSuffix = '.tmp' | ||
if tmpName.endswith(tmpNameSuffix): | ||
tmpBase = tmpName[:-len(tmpNameSuffix)] | ||
else: | ||
die('-t argument %s does not end with %s' % (tmpName, tmpNameSuffix)) | ||
|
||
substitutions = [ | ||
('%%', '#_MARKER_#'), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
('%s', args.test_file), | ||
('%S', test_dir), | ||
('%t', tmpName), | ||
] | ||
substitutions.extend(args.subst) | ||
substitutions.append(('#_MARKER_#', '%')) | ||
|
||
# Starting with processor.py because it's always the same. | ||
commands = [ | ||
# FIXME: 'foo.c' + 'hecked.c' is a terrible hack; find the right way to do this. | ||
'3c -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s', | ||
'3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s', | ||
'3c -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -', | ||
'3c -output-postfix=checked -alltypes %s', | ||
'3c -alltypes %shecked.c -- | count 0', | ||
'rm %shecked.c', | ||
] | ||
commands = lit.TestRunner.applySubstitutions(commands, substitutions) | ||
|
||
class FakeTestConfig: | ||
def __init__(self): | ||
self.pipefail = True # Is this always OK? | ||
self.environment = dict(os.environ) | ||
|
||
class FakeTest: | ||
def __init__(self): | ||
self.config = FakeTestConfig() | ||
|
||
class FakeLitConfig: | ||
def __init__(self): | ||
self.isWindows = platform.system() == 'windows' | ||
# Let the calling `lit` handle any timeout. | ||
self.maxIndividualTestTime = 0 | ||
|
||
res = lit.TestRunner.executeScriptInternal( | ||
FakeTest(), FakeLitConfig(), tmpBase, commands, os.getcwd()) | ||
if isinstance(res, lit.Test.Result): | ||
die('Error: executeScriptInternal returned unexpected Result(%s, %r)' % | ||
(res.code.name, res.output)) | ||
|
||
out, err, exitCode, timeoutInfo = res | ||
sys.stdout.write(out) | ||
sys.stderr.write(err) | ||
sys.exit(exitCode) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
// RUN: 3c -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s | ||
// RUN: 3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s | ||
// RUN: 3c -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - | ||
// RUN: 3c -output-postfix=checked -alltypes %s | ||
// RUN: 3c -alltypes %S/b9_allsafestructp.checked.c -- | count 0 | ||
// RUN: rm %S/b9_allsafestructp.checked.c | ||
This comment has been minimized.
Sorry, something went wrong.
kyleheadley
Member
|
||
// RUN: %S/3c-regtest.py -t %t --subst %%clang '%clang' %s | ||
#include <stddef.h> | ||
#include <stddef.h> | ||
extern _Itype_for_any(T) void *calloc(size_t nmemb, size_t size) : itype(_Array_ptr<T>) byte_count(nmemb * size); | ||
|
1 comment
on commit 41740eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've answered all the questions here. Please post any further questions on #355. (I probably should have gone ahead and filed the draft PR, but I wasn't sure yet what I wanted to name the source branch and GitHub doesn't let me change it after creating a PR.)
What is
__file__
in this context (I'm not a Python programmer)?Are we confident that this relative path makes sense in all contexts?