X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fplugins%2Fsink.text.pretty%2Ftest_enum;fp=tests%2Fplugins%2Fsink.text.pretty%2Ftest_enum;h=ed241c3b39cac53722e878b30f54e6cd2e2bc796;hb=5288c8aef93013b72a48cec6851a00b0c91f09dc;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..ed241c3b 100755 --- a/tests/plugins/sink.text.pretty/test_enum +++ b/tests/plugins/sink.text.pretty/test_enum @@ -21,7 +21,7 @@ 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 { @@ -57,6 +57,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)" @@ -101,6 +102,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,10 +163,108 @@ 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.