Skip to content

Commit

Permalink
Fix bug in ldflags_to_sanitizers.py.
Browse files Browse the repository at this point in the history
The Python tests were passing because we only tested the individual
functions, not the program as a whole.

The run_tests.py tests were passing because errors from $(shell) do
not cause the build to fail; ndk-build just ended up parsing the
error message and not finding any sanitizers.

The asan-smoke test passed because A) I hadn't run `./run_tests.py
--clean-device` to purge the old tests, so the libraries were still
on the device and B) running the tests in the r17 branch had led to
asan_device_setup running again, installing the libraries to the
system partition once again.

Test: nose2 build
Test: ./run_tests.py --clean-device  # After purging asan /system libs
Bug: android/ndk#540
Change-Id: I85a30cc198be4a0f39548271f56112835805ca76
  • Loading branch information
DanAlbert committed Feb 22, 2018
1 parent f64cba3 commit 5db8785
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions build/ldflags_to_sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ def argv_to_module_arg_lists(args):
return modules[0], modules[1:]


def main(argv):
def main(argv, stream=sys.stdout):
"""Program entry point."""
if len(argv) < 4:
sys.exit(
'usage: ldflags_to_sanitizers.py GLOBAL_FLAGS '
'--module MODULE_FLAGS [--module MODULE_FLAGS...]')

all_sanitizers = list(sanitizers_from_args(sys.argv[1]))
modules_flags = argv_to_module_arg_lists(argv[2:])
global_flags, modules_flags = argv_to_module_arg_lists(argv[1:])
all_sanitizers = list(sanitizers_from_args(global_flags))
for module_flags in modules_flags:
all_sanitizers.extend(sanitizers_from_args(module_flags))
print(' '.join(sorted(set(all_sanitizers))))
print(' '.join(sorted(set(all_sanitizers))), file=stream)


if __name__ == '__main__':
Expand Down
15 changes: 15 additions & 0 deletions build/test_ldflags_to_sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
from __future__ import absolute_import
import unittest

try:
from StringIO import StringIO
except ImportError:
from io import StringIO

from build.ldflags_to_sanitizers import argv_to_module_arg_lists
from build.ldflags_to_sanitizers import main as ldflags_main
from build.ldflags_to_sanitizers import sanitizers_from_args


Expand Down Expand Up @@ -87,3 +93,12 @@ def test_argv_to_module_arg_lists(self):
self.assertTupleEqual(
(['foo', 'bar'], [['baz']]),
argv_to_module_arg_lists(['foo', 'bar', '--module', 'baz']))

def test_main(self):
"""Test that the program itself works."""
sio = StringIO()
ldflags_main(
['ldflags_to_sanitizers.py', '-fsanitize=undefined', '--module',
'-fsanitize=address,thread', '-fno-sanitize=thread',
'--module', '-fsanitize=undefined'], sio)
self.assertEqual('address undefined', sio.getvalue().strip())

0 comments on commit 5db8785

Please sign in to comment.