policy_parser_stress_test

Comprehensive stress test for the ABE policy parser.

This script tests the PolicyParser and MSP classes for expressiveness, correctness, and robustness. It can be run independently to verify the policy parser functionality.

Usage:

python -m charm.test.toolbox.policy_parser_stress_test

# Or with pytest: pytest charm/test/toolbox/policy_parser_stress_test.py -v

class policy_parser_stress_test.NumericAttributeEdgeCaseTest(methodName='runTest')[source]

Bases: TestCase

Tests for edge cases in numeric attribute handling.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_attr_name_all_caps()[source]

Test attribute name in all caps.

test_attr_name_mixed_case()[source]

Test attribute name in mixed case.

test_attribute_name_with_encoding_pattern()[source]

Test that attribute names with #b# pattern are rejected.

test_attribute_name_with_partial_pattern()[source]

Test attribute names with partial encoding pattern.

test_bit_overflow_error_in_int_to_bits()[source]

Test that int_to_bits raises BitOverflowError on overflow.

test_bit_overflow_in_expand()[source]

Test that values exceeding bit width raise BitOverflowError.

test_bit_overflow_in_user_attributes()[source]

Test that user_attributes raises error for overflow values.

test_boundary_value_at_max()[source]

Test value exactly at maximum (255 for 8-bit).

test_boundary_value_just_over_max()[source]

Test value just over maximum.

test_empty_policy()[source]

Test that empty policy returns empty string.

test_equal_zero()[source]

Test attr == 0 correctly encodes all zeros.

test_excessive_bit_width()[source]

Test that num_bits > 64 raises InvalidBitWidthError.

test_extra_spaces_around_operator()[source]

Test numeric comparison with extra spaces.

test_greater_equal_zero_is_tautology()[source]

Test attr >= 0 returns None (always true for non-negative).

test_greater_than_zero()[source]

Test attr > 0 works correctly.

test_helper_max_value_property()[source]

Test that NumericAttributeHelper exposes max_value correctly.

test_invalid_operator_exclamation_equal()[source]

Test that != operator is rejected.

test_invalid_operator_not_equal_diamond()[source]

Test that <> operator is rejected.

test_invalid_operator_tilde()[source]

Test that arbitrary operators are rejected.

test_less_than_zero_is_contradiction()[source]

Test attr < 0 handling.

test_mixed_spacing()[source]

Test numeric comparison with mixed spacing.

test_multiple_parentheses()[source]

Test policy with multiple levels of parentheses.

test_negative_bit_width()[source]

Test that negative num_bits raises InvalidBitWidthError.

test_negative_value_in_expand()[source]

Test that negative values raise ValueError.

test_negative_value_in_user_attributes()[source]

Test that user_attributes raises error for negative values.

test_negative_value_message()[source]

Test that error message mentions negative values.

test_no_spaces_around_operator()[source]

Test numeric comparison without spaces.

test_non_integer_bit_width()[source]

Test that non-integer num_bits raises InvalidBitWidthError.

test_non_strict_mode_continues_on_error()[source]

Test that non-strict mode leaves problematic expression unchanged.

test_none_policy()[source]

Test that None policy raises ValueError.

test_policy_without_numeric()[source]

Test that policy without numeric comparisons is unchanged.

test_strict_helper_raises_on_overflow()[source]

Test that helper in strict mode raises exceptions.

test_strict_mode_raises_on_overflow()[source]

Test that strict mode raises exceptions.

test_string_bit_width()[source]

Test that string num_bits raises InvalidBitWidthError.

test_valid_attribute_names()[source]

Test that normal attribute names are accepted.

test_valid_operators_all_work()[source]

Test that all supported operators work.

test_whitespace_only_policy()[source]

Test that whitespace-only policy returns empty string.

test_zero_bit_width()[source]

Test that num_bits=0 raises InvalidBitWidthError.

class policy_parser_stress_test.NumericAttributeTest(methodName='runTest')[source]

Bases: TestCase

Tests for numeric attribute support using bag of bits encoding.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

test_bit_encoding_correctness()[source]

Test that bit encoding is correct for various values.

test_boundary_values()[source]

Test boundary conditions for numeric comparisons.

test_compound_numeric_policy()[source]

Test combined numeric comparisons.

test_equality()[source]

Test attr == value comparison.

test_greater_than()[source]

Test attr > value comparison.

test_greater_than_or_equal()[source]

Test attr >= value comparison.

test_less_than()[source]

Test attr < value comparison.

test_less_than_or_equal()[source]

Test attr <= value comparison.

test_mixed_numeric_and_string_policy()[source]

Test policies mixing numeric comparisons and string attributes.

test_zero_comparisons()[source]

Test comparisons with zero.

class policy_parser_stress_test.NumericNegationTest(methodName='runTest')[source]

Bases: TestCase

Tests for negation of numeric comparisons.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_helper_expand_negated_policy_equality()[source]

Test expand_negated_policy for equality.

test_helper_expand_negated_policy_simple()[source]

Test expand_negated_policy for simple operators.

test_helper_negate_comparison()[source]

Test NumericAttributeHelper.negate_comparison method.

test_negate_at_max()[source]

Test negation at max value boundary.

test_negate_at_zero()[source]

Test negation at zero boundary.

test_negate_equality()[source]

Test NOT (age == 21) becomes (age < 21) OR (age > 21).

test_negate_greater_equal()[source]

Test NOT (age >= 21) becomes age < 21.

test_negate_greater_than()[source]

Test NOT (age > 21) becomes age <= 21.

test_negate_invalid_operator()[source]

Test that negating invalid operators raises error.

test_negate_less_equal()[source]

Test NOT (age <= 21) becomes age > 21.

test_negate_less_than()[source]

Test NOT (age < 21) becomes age >= 21.

test_negate_to_policy_equality()[source]

Test negate_comparison_to_policy for equality.

test_negate_to_policy_simple()[source]

Test negate_comparison_to_policy for simple operators.

test_negated_equality_satisfaction()[source]

Test that negated equality works correctly end-to-end.

test_negated_policy_satisfaction()[source]

Test that negated policies work correctly end-to-end.

class policy_parser_stress_test.PolicyParserEdgeCaseTest(methodName='runTest')[source]

Bases: TestCase

Edge case tests for the policy parser.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

test_case_insensitive_operators()[source]

Test that AND/OR operators are case-insensitive.

test_parentheses_variations()[source]

Test various parentheses patterns.

test_whitespace_handling()[source]

Test handling of extra whitespace.

class policy_parser_stress_test.PolicyParserStressTest(methodName='runTest')[source]

Bases: TestCase

Comprehensive stress tests for the ABE policy parser.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

test_attribute_with_index()[source]

Test attributes with numeric index suffix (used for duplicates).

test_balanced_tree()[source]

Test balanced binary tree structure.

test_basic_and()[source]

Test basic AND operations.

test_basic_or()[source]

Test basic OR operations.

test_deep_nesting()[source]

Test deeply nested expressions (20 levels).

test_duplicate_attributes()[source]

Test handling of duplicate attributes.

test_duplicate_labeling()[source]

Test that duplicate attributes get unique labels.

test_many_attributes()[source]

Test policy with 100 attributes.

test_msp_coefficient_recovery()[source]

Test coefficient recovery from MSP.

test_msp_complex_policy()[source]

Test MSP conversion for complex policy.

test_msp_conversion_performance()[source]

Test MSP conversion performance.

test_msp_simple_and()[source]

Test MSP conversion for AND policy.

test_msp_simple_or()[source]

Test MSP conversion for OR policy.

test_negated_attributes()[source]

Test negated attribute parsing.

test_nested_expressions()[source]

Test nested policy expressions.

test_parsing_performance()[source]

Test parsing performance with 1000 iterations.

test_prune_and_policy()[source]

Test policy satisfaction for AND policies.

test_prune_complex_policy()[source]

Test policy satisfaction for complex policies.

test_prune_or_policy()[source]

Test policy satisfaction for OR policies.

test_random_policies()[source]

Generate and parse 100 random valid policies.

test_single_attribute()[source]

Test parsing single attributes.

test_special_characters_in_attributes()[source]

Test attributes with special characters.

test_underscore_limitation()[source]

Test that underscore + non-digits fails (known limitation).

test_wide_or_tree()[source]

Test wide OR tree with 50 branches.

policy_parser_stress_test.run_stress_test()[source]

Run the stress test suite and print results.