libubox/tests/cram/test_json_script.t
Petr Štetiar bf680707ac tests: add unit tests covered with Clang sanitizers
Currently we run all tests via Valgrind. This patch adds 2nd batch of
tests which are compiled with Clang AddressSanitizer[1],
LeakSanitizer[2] and UndefinedBehaviorSanitizer[3] in order to catch
more issues during QA on CI.

AddressSanitizer is a fast memory error detector.  The tool can detect
the following types of bugs:

 * Out-of-bounds accesses to heap, stack and globals
 * Use-after-free, use-after-return, use-after-scope
 * Double-free, invalid free

LeakSanitizer is a run-time memory leak detector. It can be combined
with AddressSanitizer to get both memory error and leak detection, or
used in a stand-alone mode.

UndefinedBehaviorSanitizer (UBSan) is a fast undefined behavior
detector. UBSan modifies the program at compile-time to catch various
kinds of undefined behavior during program execution, for example:

 * Using misaligned or null pointer
 * Signed integer overflow
 * Conversion to, from, or between floating-point types which would
   overflow the destination

1. http://clang.llvm.org/docs/AddressSanitizer.html
2. http://http://clang.llvm.org/docs/LeakSanitizer.html
3. http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-25 10:31:58 +01:00

151 lines
2.6 KiB
Perl

set test bin path:
$ [ -n "$TEST_BIN_DIR" ] && export PATH="$TEST_BIN_DIR:$PATH"
$ export TEST_INPUTS="$TESTDIR/inputs"
$ alias js="valgrind --quiet --leak-check=full test-json-script"
$ alias js-san="test-json-script-san"
check that json-script is producing expected results:
$ js
Usage: test-json-script [VARNAME=value] <filename_json_script>
[254]
$ js-san
Usage: test-json-script-san [VARNAME=value] <filename_json_script>
[254]
$ echo '}' > test.json; js test.json
load JSON data from test.json failed.
$ echo '}' > test.json; js-san test.json
load JSON data from test.json failed.
$ js nada.json 2>&1 | grep load.*failed
load JSON data from nada.json failed.
$ js-san nada.json 2>&1 | grep load.*failed
load JSON data from nada.json failed.
$ echo '[ [ ] [ ] ]' > test.json; js test.json
load JSON data from test.json failed.
$ echo '[ [ ] [ ] ]' > test.json; js-san test.json
load JSON data from test.json failed.
check example json-script:
$ js $TEST_INPUTS/json-script.json
exec /%/
exec_if_or
$ js-san $TEST_INPUTS/json-script.json
exec /%/
exec_if_or
$ js EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
exec meh /%/
exec_if_or meep
$ js-san EXECVAR=meh ORVAR=meep $TEST_INPUTS/json-script.json
exec meh /%/
exec_if_or meep
check has expression:
$ echo '
> [
> [ "if",
> [ "has", "VAR" ],
> [ "echo", "bar" ],
> [ "echo", "baz" ]
> ]
> ]' > test.json
$ js VAR=foo test.json
echo bar
$ js-san VAR=foo test.json
echo bar
$ js VAR=bar test.json
echo bar
$ js-san VAR=bar test.json
echo bar
$ js test.json
echo baz
$ js-san test.json
echo baz
check eq expression:
$ echo '
> [
> [ "if",
> [ "eq", "VAR", "bar" ],
> [ "echo", "foo" ],
> [ "echo", "baz" ]
> ]
> ]' > test.json
$ js VAR=bar test.json
echo foo
$ js-san VAR=bar test.json
echo foo
$ js VAR=xxx test.json
echo baz
$ js-san VAR=xxx test.json
echo baz
$ js test.json
echo baz
$ js-san test.json
echo baz
check regex single expression:
$ echo '
> [
> [ "if",
> [ "regex", "VAR", ".ell." ],
> [ "echo", "bar" ],
> [ "echo", "baz" ]
> ]
> ]' > test.json
$ js VAR=hello test.json
echo bar
$ js-san VAR=hello test.json
echo bar
$ js VAR=.ell. test.json
echo bar
$ js-san VAR=.ell. test.json
echo bar
$ js test.json
echo baz
$ js-san test.json
echo baz
$ js VAR= test.json
echo baz
$ js-san VAR= test.json
echo baz
$ js VAR=hell test.json
echo baz
$ js-san VAR=hell test.json
echo baz