diff options
author | jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> | 2021-02-16 06:14:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-16 06:14:53 -0800 |
commit | a98d7f1ca476de0bec415e08ff48cc9952a2b078 (patch) | |
tree | f35985e2884a94054498cd195e75551aa0e71cc4 | |
parent | 248b4eb7976b9c0eba1cb81bd0970080fd5855a1 (diff) | |
download | oss-fuzz-a98d7f1ca476de0bec415e08ff48cc9952a2b078.tar.gz |
[base-runner][NFC] Replace test_one with test_one.py (#5179)
-rwxr-xr-x[-rw-r--r--] | infra/base-images/base-runner/Dockerfile | 2 | ||||
-rwxr-xr-x | infra/base-images/base-runner/test_one | 58 | ||||
-rwxr-xr-x | infra/base-images/base-runner/test_one.py | 43 | ||||
-rwxr-xr-x | infra/helper.py | 2 |
4 files changed, 45 insertions, 60 deletions
diff --git a/infra/base-images/base-runner/Dockerfile b/infra/base-images/base-runner/Dockerfile index f0a264fa7..7378c4a96 100644..100755 --- a/infra/base-images/base-runner/Dockerfile +++ b/infra/base-images/base-runner/Dockerfile @@ -82,5 +82,5 @@ COPY bad_build_check \ parse_options.py \ targets_list \ test_all.py \ - test_one \ + test_one.py \ /usr/local/bin/ diff --git a/infra/base-images/base-runner/test_one b/infra/base-images/base-runner/test_one deleted file mode 100755 index 23b7fd932..000000000 --- a/infra/base-images/base-runner/test_one +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -u -# Copyright 2020 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ - -# Wrapper around bad_build_check that moves the /out directory to /tmp/not-out. -# This is useful when bad_build_check isn't called from test_all which does the -# same thing. - -function main { - # Move the directory the fuzzer is located in to somewhere that doesn't exist - # on the builder to make it more likely that hardcoding /out fails here (since - # it will fail on ClusterFuzz). - local fuzzer=$1 - fuzzer=$(realpath $fuzzer) - local initial_fuzzer_dir=$(dirname $fuzzer) - - local tmp_fuzzer_dir=/tmp/not-out - rm -rf $tmp_fuzzer_dir - mkdir $tmp_fuzzer_dir - # Move the contents of $initial_fuzzer_dir rather than the directory itself in - # case it is a mount. - mv $initial_fuzzer_dir/* $tmp_fuzzer_dir - fuzzer="$tmp_fuzzer_dir/$(basename $fuzzer)" - - # Change OUT to the temporary fuzzer dir. - local initial_out=$OUT - export OUT=$tmp_fuzzer_dir - - bad_build_check $fuzzer - returncode=$? - - # Restore OUT and $initial_fuzzer_dir - export OUT=$initial_out - mv $tmp_fuzzer_dir/* $initial_fuzzer_dir - - return $returncode -} - -if [ $# -ne 1 ]; then - echo "Usage: $0 <fuzz_target_binary>" - exit 1 -fi - -main $1 -exit $? diff --git a/infra/base-images/base-runner/test_one.py b/infra/base-images/base-runner/test_one.py new file mode 100755 index 000000000..9bdb75faf --- /dev/null +++ b/infra/base-images/base-runner/test_one.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +"""Does bad_build_check on a fuzz target in $OUT.""" +import os +import sys + +import test_all + + +def test_one(fuzz_target): + """Does bad_build_check on one fuzz target. Returns True on success.""" + with test_all.use_different_out_dir(): + fuzz_target_path = os.path.join(os.environ['OUT'], fuzz_target) + return test_all.do_bad_build_check(fuzz_target_path).returncode == 0 + + +def main(): + """Does bad_build_check on one fuzz target. Returns 1 on failure, 0 on + success.""" + if len(sys.argv) != 2: + print('Usage: %d <fuzz_target>', sys.argv[0]) + return 1 + + fuzz_target_binary = sys.argv[1] + return 0 if test_one(fuzz_target_binary) else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/infra/helper.py b/infra/helper.py index 8a0a640c1..6ac03776a 100755 --- a/infra/helper.py +++ b/infra/helper.py @@ -632,7 +632,7 @@ def check_build(args): ] if args.fuzzer_name: - run_args += ['test_one', os.path.join('/out', args.fuzzer_name)] + run_args += ['test_one.py', args.fuzzer_name] else: run_args.append('test_all.py') |