Skip to content

Commit

Permalink
[Build] Modify run test script to filter by lang (uber#423)
Browse files Browse the repository at this point in the history
### Summary:
Now we have CC and Java tests (cc_test and java_test targets). 
Script build/run_bazel_tests.sh allows to specify --lang flag. For example:
python ../build/run_bazel_tests.py --lang java
python ../build/run_bazel_tests.py --lang cc

By default it runs tests for all langs:
python ../build/run_bazel_tests.py

### Test Plan:
Run 
build/test.sh 
python ../build/run_bazel_tests.py --lang java
python ../build/run_bazel_tests.py --lang cc
  • Loading branch information
vkuzmin-uber authored Aug 28, 2020
1 parent 9992207 commit c110f41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions build/run_cpp_tests.py → build/run_bazel_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ def test(self):

if __name__ == '__main__':
# Parse args
parser = argparse.ArgumentParser(description='Run C++ Neuropod tests')
parser = argparse.ArgumentParser(description='Run Neuropod tests')

# --lang flag allows cc, java. Default is empty that means all.
parser.add_argument('--lang', action='store', default="")
parser.add_argument('--run-gpu-tests', action='store_true')
args = parser.parse_args()

# Get all the bazel test targets
cpp_tests = []
cpp_tests_xml = subprocess.check_output(['bazel', 'query', 'kind(".*_test rule", //...)', '--output=xml'])
# Get all the bazel test targets that match lang argument
lang_tests = []
kind_pattern = 'kind(".*{lang}_test rule", //...)'.format(lang=args.lang)
lang_tests_xml = subprocess.check_output(['bazel', 'query', kind_pattern, '--output=xml'])

# Parse the xml
root = ET.fromstring(cpp_tests_xml)
root = ET.fromstring(lang_tests_xml)
for child in root:

# Get tags (if any)
Expand All @@ -70,11 +74,11 @@ def test(self):
for tag in prop:
tags.append(tag.attrib["value"])

cpp_tests.append((child.attrib["name"], tags))
lang_tests.append((child.attrib["name"], tags))


# Generate unittests for each bazel test target
for test_target, tags in cpp_tests:
for test_target, tags in lang_tests:
# Skip GPU tests by default
if "gpu" in tags and not args.run_gpu_tests:
continue
Expand Down
4 changes: 2 additions & 2 deletions build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ NEUROPOD_LOG_LEVEL=TRACE python -m unittest discover --verbose neuropod/tests
NEUROPOD_LOG_LEVEL=TRACE NEUROPOD_RUN_NATIVE_TESTS=true python -m unittest discover --verbose neuropod/tests
popd

# Run native tests
python ../build/run_cpp_tests.py
# Run native and java tests
python ../build/run_bazel_tests.py
popd

# Maybe upload a release
Expand Down
2 changes: 1 addition & 1 deletion build/test_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ NEUROPOD_LOG_LEVEL=TRACE NEUROPOD_RUN_NATIVE_TESTS=true python -m unittest disco
popd

# Run native tests
python ../build/run_cpp_tests.py --run-gpu-tests
python ../build/run_bazel_tests.py --run-gpu-tests
popd

# Maybe upload a release
Expand Down

0 comments on commit c110f41

Please sign in to comment.