Skip to content

Commit 4c87485

Browse files
committed
Bug 1682829 - Automate a fuzzing smoke test in the CI r=decoder
Adds a smoke test script we can use in the CI to smoke test Firefox prior to bigger tests. Differential Revision: https://phabricator.services.mozilla.com/D100008
1 parent 04b73ee commit 4c87485

File tree

10 files changed

+199
-1
lines changed

10 files changed

+199
-1
lines changed

build/gen_test_packages_manifest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"updater-dep",
2626
"jsreftest",
2727
"perftests",
28+
"fuzztest",
2829
]
2930

3031
PACKAGE_SPECIFIED_HARNESSES = [
@@ -41,6 +42,7 @@
4142
"jittest",
4243
"jsreftest",
4344
"perftests",
45+
"fuzztest",
4446
]
4547

4648
# These packages are not present for every build configuration.

python/mozbuild/mozbuild/action/test_archive.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"jit-test/**",
9999
"jittest/**", # To make the ignore checker happy
100100
"perftests/**",
101+
"fuzztest/**",
101102
],
102103
},
103104
{
@@ -670,6 +671,12 @@
670671
"pattern": "jsreftest/**",
671672
},
672673
],
674+
"fuzztest": [
675+
{
676+
"source": buildconfig.topsrcdir,
677+
"pattern": "tools/fuzzing/smoke/**",
678+
},
679+
],
673680
"jittest": [
674681
{
675682
"source": buildconfig.topsrcdir,

python/mozbuild/mozbuild/schedules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"condprofile",
5050
"cppunittest",
5151
"firefox-ui",
52+
"fuzztest",
5253
"geckoview-junit",
5354
"gtest",
5455
"marionette",

taskcluster/ci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ treeherder:
174174
'GhS': 'GitHub Synchronization'
175175
'perftest': 'Performance tests'
176176
'perftest-http3': 'Performance tests with HTTP/3'
177+
'fuzzing': 'Fuzzing checks'
177178

178179
index:
179180
products:

taskcluster/ci/fuzzing/kind.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
---
5+
loader: taskgraph.loader.transform:loader
6+
7+
transforms:
8+
- taskgraph.transforms.source_test:transforms
9+
- taskgraph.transforms.job:transforms
10+
- taskgraph.transforms.task:transforms
11+
12+
kind-dependencies:
13+
- fetch
14+
- toolchain
15+
- build
16+
17+
job-defaults:
18+
platform: linux64-shippable/opt
19+
require-build:
20+
linux64-shippable/opt: build-linux64-shippable/opt
21+
dependencies:
22+
linux64-opt: build-linux64/opt
23+
worker-type: b-linux
24+
worker:
25+
max-run-time: 3600
26+
docker-image: {in-tree: debian10-amd64-build}
27+
env:
28+
LD_LIBRARY_PATH: /builds/worker/fetches
29+
JSSHELL: ./js
30+
treeherder:
31+
kind: test
32+
tier: 3
33+
fetches:
34+
build:
35+
- target.jsshell.zip
36+
- target.fuzztest.tests.tar.gz
37+
38+
jobs:
39+
simple:
40+
description: Simple Fuzzing Test
41+
treeherder:
42+
symbol: simple-fuzzing
43+
run:
44+
using: run-task
45+
command: >-
46+
cd $MOZ_FETCHES_DIR &&
47+
python tools/fuzzing/smoke/smoke.py

taskcluster/docs/kinds.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,9 @@ Push tasks to try to test new scriptworker deployments.
715715

716716
updatebot
717717
------------------
718-
Check for updates to (supported) third party libraries, and manage their lifecycle.
718+
Check for updates to (supported) third party libraries, and manage their lifecycle.
719+
720+
fuzzing
721+
-------
722+
723+
Performs fuzzing smoke tests

testing/testsuite-targets.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ TEST_PKGS_TARGZ := \
122122
jsreftest \
123123
jittest \
124124
perftests \
125+
fuzztest \
125126
$(NULL)
126127

127128
ifdef LINK_GTEST_DURING_COMPILE

tools/fuzzing/smoke/js.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
""" Hello I am a fake jsshell for testing purpose.
6+
Add more features!
7+
"""
8+
from __future__ import absolute_import
9+
import argparse
10+
import sys
11+
12+
13+
def run():
14+
parser = argparse.ArgumentParser(description="Process some integers.")
15+
parser.add_argument("-e", type=str, default=None)
16+
17+
parser.add_argument("--fuzzing-safe", action="store_true", default=False)
18+
19+
args = parser.parse_args()
20+
21+
if args.e is not None:
22+
if "crash()" in args.e:
23+
sys.exit(1)
24+
25+
26+
if __name__ == "__main__":
27+
run()

tools/fuzzing/smoke/smoke.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
""" Smoke test script for Fuzzing
5+
6+
This script can be used to perform simple calls using `jsshell`
7+
or whatever other tools you may add.
8+
9+
The call is done via `taskcluster/ci/fuzzing/kind.yml` and
10+
files contained in the `target.jsshell.zip` and `target.fuzztest.tests.tar.gz`
11+
build artifacts are downloaded to run things.
12+
13+
Everything included in this directory will be added in
14+
`target.fuzztest.tests.tar.gz` at build time, so you can add more scripts and
15+
tools if you need. They will be located in `$MOZ_FETCHES_DIR` and follow the
16+
same directory structure than the source tree.
17+
"""
18+
from __future__ import absolute_import
19+
from distutils.spawn import find_executable
20+
import os
21+
import os.path
22+
import subprocess
23+
import shlex
24+
import sys
25+
26+
27+
def run_jsshell(command, label=None):
28+
"""Invokes `jsshell` with command.
29+
30+
This function will use the `JSSHELL` environment variable,
31+
and fallback to a `js` executable if it finds one
32+
"""
33+
shell = os.environ.get("JSSHELL")
34+
if shell is None:
35+
shell = find_executable("js")
36+
if shell is None:
37+
raise FileNotFoundError(shell)
38+
else:
39+
if not os.path.exists(shell) or not os.path.isfile(shell):
40+
raise FileNotFoundError(shell)
41+
42+
if label is None:
43+
label = command
44+
sys.stdout.write(label)
45+
cmd = [shell] + shlex.split(command)
46+
sys.stdout.flush()
47+
try:
48+
subprocess.check_call(cmd)
49+
finally:
50+
sys.stdout.write("\n")
51+
sys.stdout.flush()
52+
53+
54+
def smoke_test():
55+
# first, let's make sure it catches crashes so we don't have false
56+
# positives.
57+
try:
58+
run_jsshell("-e 'crash();'", "Testing for crash\n")
59+
except subprocess.CalledProcessError:
60+
pass
61+
else:
62+
raise Exception("Could not get the process to crash")
63+
64+
# now let's proceed with some tests
65+
run_jsshell("--fuzzing-safe -e 'print(\"PASSED\")'", "Simple Fuzzing...")
66+
67+
# add more smoke tests here
68+
69+
70+
if __name__ == "__main__":
71+
# if this calls raises an error, the job will turn red in the CI.
72+
smoke_test()

tools/fuzzing/smoke/tests.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
from __future__ import absolute_import
5+
import os
6+
import pytest
7+
from contextlib import contextmanager
8+
9+
import smoke
10+
11+
JS = os.path.join(os.path.dirname(__file__), "js.py")
12+
13+
14+
@contextmanager
15+
def fake_js():
16+
os.environ["JSSHELL"] = JS
17+
try:
18+
yield
19+
finally:
20+
del os.environ["JSSHELL"]
21+
22+
23+
def test_run_no_jsshell():
24+
with pytest.raises(FileNotFoundError):
25+
smoke.run_jsshell("--fuzzing-safe -e 'print(\"PASSED\")'")
26+
27+
28+
def test_run_jsshell_set():
29+
with fake_js():
30+
smoke.run_jsshell("--fuzzing-safe -e 'print(\"PASSED\")'")
31+
32+
33+
def test_smoke_test():
34+
with fake_js():
35+
smoke.smoke_test()

0 commit comments

Comments
 (0)