Skip to content

Commit 1e527ec

Browse files
authored
Introduce lit/FileCheck tests (#3367)
lit and FileCheck are the tools used to run the majority of tests in LLVM. Each lit test file contains the commands to be run for that test, so lit tests are much more flexible and can be more precise than our current ad hoc testing system. FileCheck reads expected test output from comments, so it allows test output to be written alongside and interspersed with test input, making tests more readable and precise than in our current system. This PR adds a new suite to check.py that runs lit tests in the test/lit directory. A few tests have been ported to demonstrate the features of the new test runner. This change is motivated by a need for greater flexibility in testing wasm-split. See #3359.
1 parent 3b5a675 commit 1e527ec

File tree

19 files changed

+161
-97
lines changed

19 files changed

+161
-97
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ ignore =
33
E501, # line too long
44
E241, # space after comma (ignored for list in gen-s-parser.py)
55
W504 # line break after binary operator
6-
exclude = ./test/emscripten,./test/spec,./test/wasm-install
6+
exclude = ./test/emscripten,./test/spec,./test/wasm-install,./test/lit

.github/workflows/ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ jobs:
4747
python-version: '3.x'
4848
- uses: actions/checkout@v1
4949

50+
- name: install Python dev dependencies
51+
run: pip3 install -r requirements-dev.txt
52+
5053
- name: install ninja (linux)
5154
run: sudo apt-get install ninja-build
5255
if: matrix.os == 'ubuntu-latest'
@@ -92,7 +95,7 @@ jobs:
9295
path: out/install
9396

9497
- name: test
95-
run: python check.py --binaryen-bin=out/install/bin
98+
run: python check.py --binaryen-bin=out/bin
9699

97100
build-clang:
98101
name: clang
@@ -104,6 +107,8 @@ jobs:
104107
- uses: actions/checkout@v1
105108
- name: install ninja
106109
run: sudo apt-get install ninja-build
110+
- name: install Python dev dependencies
111+
run: pip3 install -r requirements-dev.txt
107112
- name: cmake
108113
run: |
109114
mkdir -p out
@@ -127,6 +132,8 @@ jobs:
127132
- uses: actions/checkout@v1
128133
- name: install ninja
129134
run: sudo apt-get install ninja-build
135+
- name: install Python dev dependencies
136+
run: pip3 install -r requirements-dev.txt
130137
- name: cmake
131138
run: |
132139
mkdir -p out
@@ -151,6 +158,8 @@ jobs:
151158
- uses: actions/checkout@v1
152159
- name: install ninja
153160
run: sudo apt-get install ninja-build
161+
- name: install Python dev dependencies
162+
run: pip3 install -r requirements-dev.txt
154163
- name: cmake
155164
run: |
156165
mkdir -p out
@@ -174,6 +183,8 @@ jobs:
174183
- uses: actions/checkout@v1
175184
- name: install ninja
176185
run: sudo apt-get install ninja-build
186+
- name: install Python dev dependencies
187+
run: pip3 install -r requirements-dev.txt
177188
- name: cmake
178189
run: |
179190
mkdir -p out

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CMakeFiles
2525
*.o
2626
*.obj
2727
compile_commands.json
28+
test/lit/lit.site.cfg.py
2829

2930
# files related to bulding in-tree on windows
3031
/.vs/

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ add_subdirectory(src/support)
278278
add_subdirectory(src/wasm)
279279
add_subdirectory(third_party)
280280

281+
# Configure lit tests
282+
add_subdirectory(test/lit)
283+
281284
# Object files
282285
set(binaryen_objs
283286
$<TARGET_OBJECTS:passes>

check.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,18 @@ def run_unittest():
328328
raise Exception("unittest failed")
329329

330330

331+
def run_lit():
332+
lit_script = os.path.join(shared.options.binaryen_root, 'scripts', 'lit_wrapper.py')
333+
lit_cfg = os.path.join(shared.options.binaryen_build, 'test', 'lit')
334+
# lit expects to be run as its own executable
335+
cmd = [sys.executable, lit_script, lit_cfg, '-vv']
336+
result = subprocess.run(cmd)
337+
if result.returncode != 0:
338+
shared.num_failures += 1
339+
if shared.options.abort_on_first_failure and shared.num_failures:
340+
raise Exception("lit test failed")
341+
342+
331343
TEST_SUITES = OrderedDict([
332344
('help-messages', run_help_tests),
333345
('wasm-opt', wasm_opt.test_wasm_opt),
@@ -345,6 +357,7 @@ def run_unittest():
345357
('unit', run_unittest),
346358
('binaryenjs', binaryenjs.test_binaryen_js),
347359
('binaryenjs_wasm', binaryenjs.test_binaryen_wasm),
360+
('lit', run_lit),
348361
])
349362

350363

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
# Install with `pip3 install -r requirements-dev.txt`
55

66
flake8==3.7.8
7+
filecheck==0.0.17
8+
lit==0.11.0.post1

scripts/lit_wrapper.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2020 WebAssembly Community Group participants
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from lit.main import main
18+
19+
# A simple wrapper around `lit`'s main function, since it isn't otherwise
20+
# exposed.
21+
if __name__ == '__main__':
22+
main()

scripts/not.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2020 WebAssembly Community Group participants
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
import subprocess
19+
20+
21+
# Emulate the `not` tool from LLVM's test infrastructure for use with lit and
22+
# FileCheck. It succeeds if the given subcommand fails and vice versa.
23+
def main():
24+
cmd = sys.argv[1:]
25+
result = subprocess.run(cmd)
26+
sys.exit(0 if result.returncode != 0 else 1)
27+
28+
29+
if __name__ == '__main__':
30+
main()

scripts/test/lld.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def args_for_finalize(filename):
2626
ret += ['--side-module']
2727
if 'standalone-wasm' in filename:
2828
ret += ['--standalone-wasm']
29-
if 'bigint' in filename:
30-
ret += ['--bigint']
3129
return ret
3230

3331

scripts/test/shared.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ def parse_args(args):
5050
' earlier errors.'))
5151
parser.add_argument(
5252
'--binaryen-bin', dest='binaryen_bin', default='',
53-
help=('Specifies a path to where the built Binaryen executables reside at.'
54-
' Default: bin/ of current directory (i.e. assume an in-tree build).'
53+
help=('Specifies the path to the Binaryen executables in the CMake build'
54+
' directory. Default: bin/ of current directory (i.e. assume an'
55+
' in-tree build).'
5556
' If not specified, the environment variable BINARYEN_ROOT= can also'
5657
' be used to adjust this.'))
5758
parser.add_argument(
@@ -129,6 +130,8 @@ def warn(text):
129130

130131
options.binaryen_lib = os.path.normpath(os.path.abspath(options.binaryen_lib))
131132

133+
options.binaryen_build = os.path.dirname(options.binaryen_bin)
134+
132135
# ensure BINARYEN_ROOT is set up
133136
os.environ['BINARYEN_ROOT'] = os.path.dirname(options.binaryen_bin)
134137

0 commit comments

Comments
 (0)