X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fplugins%2Fsink.text.pretty%2Ftest_enum;h=1d6b723de1c87eba14d60e1c4182ff5ff50c9fbd;hb=ffa209addac22ab2fddcd18f42bafaa0410068e4;hp=c00e6ac783670e70e514c2d497e00e9cc6e57132;hpb=ed30eb8d59e3bc1d26808d3414a1fbc5f8bb23d8;p=babeltrace.git diff --git a/tests/plugins/sink.text.pretty/test_enum b/tests/plugins/sink.text.pretty/test_enum index c00e6ac7..1d6b723d 100755 --- a/tests/plugins/sink.text.pretty/test_enum +++ b/tests/plugins/sink.text.pretty/test_enum @@ -8,7 +8,7 @@ # not all covered by the main babeltrace tests with traces. SH_TAP=1 -if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then +if [ -n "${BT_TESTS_SRCDIR:-}" ]; then UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" else UTILSSH="$(dirname "$0")/../../utils/utils.sh" @@ -19,9 +19,8 @@ source "$UTILSSH" data_dir="$BT_TESTS_DATADIR/plugins/sink.text.pretty" temp_stdout_expected_file=$(mktemp -t test_pretty_expected_stdout.XXXXXX) -temp_stderr_expected="/dev/null" -plan_tests 14 +plan_tests 31 function compare_enum_sorted { @@ -36,8 +35,8 @@ function compare_enum_sorted # data structures differently (e.g. dictionaries are insertion sorted # since Python 3.7). - run_python_bt2 python3 "${BT_TESTS_SRCDIR}/utils/python/split_sort_compare.py" \ - "$(cat $expected_file)" "$(cat $actual_file)" + run_python_bt2 "${BT_TESTS_PYTHON_BIN}" "${BT_TESTS_SRCDIR}/utils/python/split_sort_compare.py" \ + "$(cat "$expected_file")" "$(cat "$actual_file")" } function run_test @@ -46,7 +45,6 @@ function run_test local expected_to_fail="$2" local value="$3" local expected_stdout_file="$4" - local test_text= local actual_stdout_file local actual_stderr_file local ret=0 @@ -57,6 +55,7 @@ function run_test "-p" "value=$value" "-p" "enum-signed=$enum_signed" "-c" "sink.text.pretty" + "-p" "print-enum-flags=true" ) actual_stdout_file="$(mktemp -t actual_pretty_stdout.XXXXXX)" @@ -76,7 +75,7 @@ function run_test rm -f "$actual_stdout_file" "$actual_stderr_file" - if (($expected_to_fail)); then + if [ "$expected_to_fail" = "1" ]; then isnt $ret 0 "$test_name signed=$enum_signed with value=$value doesn't match as expected" else ok $ret "$test_name signed=$enum_signed with value=$value matches" @@ -101,6 +100,18 @@ function test_normal_enum { END run_test "$test_name" 0 7 "$temp_stdout_expected_file" + # Hit a range and a value + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( { "single3", "range" } : container = 4 ) } + END + run_test "$test_name" 0 4 "$temp_stdout_expected_file" + + # Hit a range and a value + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( { "NOT_A_LABEL", "DOESNT_EXIST" } : container = 4 ) } + END + run_test "$test_name" 1 4 "$temp_stdout_expected_file" + # Unknown cat <<- 'END' > "$temp_stdout_expected_file" with_enum: { enum_field = ( : container = 21 ) } @@ -150,11 +161,107 @@ function test_normal_enum_negative { run_test "$test_name" 0 0 "$temp_stdout_expected_file" } +function test_bit_flag_enum { + test_name="Bit flag enum" + enum_signed="false" + enum_values="bit0,1,1 bit0bis,1,1 bit1,2,2 bit3,4,4 bit4,8,8 bit5,16,16 bit5,32,32" + + # Single value hit + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "bit1" : container = 2 ) } + END + run_test "$test_name" 0 2 "$temp_stdout_expected_file" + + # Multiple flags set + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "bit3" | "bit4" : container = 12 ) } + END + run_test "$test_name" 0 12 "$temp_stdout_expected_file" + + # Some unknown bit + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( : container = 68 ) } + END + run_test "$test_name" 0 68 "$temp_stdout_expected_file" + + # Multiple labels for bit 0 + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( { "bit0", "bit0bis" } : container = 1 ) } + END + run_test "$test_name" 0 1 "$temp_stdout_expected_file" + + # Two labels for bit 0 and one label for bit 1 + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( { "bit0", "bit0bis" } | "bit1" : container = 3 ) } + END + run_test "$test_name" 0 3 "$temp_stdout_expected_file" + + # Single label for bit 0 + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "bit5" | "bit5" : container = 48 ) } + END + run_test "$test_name" 0 48 "$temp_stdout_expected_file" + + # negative value + enum_signed="true" + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( : container = -1 ) } + END + run_test "$test_name" 0 -1 "$temp_stdout_expected_file" +} + +function test_mixed_enum { + test_name="Mixed enum bits at beginning" + enum_signed="false" + enum_values="bit0,1,1 bit1,2,2 bit2,4,4 bit3,8,8 bit4,16,16 range,32,44 singleValue,45,45" + + # Value with bit fields + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "bit0" | "bit1" | "bit2" | "bit3" | "bit4" : container = 31 ) } + END + run_test "$test_name" 0 31 "$temp_stdout_expected_file" + + # A value with some bit flags set, but within another range + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "range" : container = 36 ) } + END + run_test "$test_name" 0 36 "$temp_stdout_expected_file" + + # A value with some bit flags set, but corresponding to another value + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "singleValue" : container = 45 ) } + END + run_test "$test_name" 0 45 "$temp_stdout_expected_file" + + # Value above the ranges + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( : container = 46 ) } + END + run_test "$test_name" 0 46 "$temp_stdout_expected_file" + + # Since low values are often powers of 2, they may be considered bit flags too + test_name="Mixed enum bits at end" + enum_signed="false" + enum_values="val1,1,1 val2,2,2 val3,3,3 val4,4,4 val5,5,5 bit3,8,8 bit4,16,16 bit5,32,32" + + # Value with bit fields + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "bit4" : container = 16 ) } + END + run_test "$test_name" 0 16 "$temp_stdout_expected_file" + + # Value with a bit field set both at beginning and end + cat <<- 'END' > "$temp_stdout_expected_file" + with_enum: { enum_field = ( "val1" | "bit4" : container = 17 ) } + END + run_test "$test_name" 0 17 "$temp_stdout_expected_file" +} + # Enumerations tests test_normal_enum "false" test_normal_enum "true" test_normal_enum_negative +test_bit_flag_enum +test_mixed_enum -# Do not `rm` $temp_stderr_expected because it's set to `/dev/null` right now -# and that would print an error. rm -f "$temp_stdout_expected_file"