PICT (Pairwise Independent Combinatorial Testing)

repository·main·Indexed 23 days ago

https://github.com/microsoft/pict

A command-line tool for generating compact test suites that provide comprehensive combinatorial coverage by testing all possible pairs of parameter values. It includes a model-based approach for defining parameters and constraints, a benchmark harness (pict-benchmark), and helper scripts for analyzing and comparing output files.

Tokens
7.4K
Snippets
18
Records
36
Agent score
81%

What's inside PICT

  1. What is PICT and how does it work?

    main

    PICT (Pairwise Independent Combinatorial Testing) is a command-line tool used to generate test cases and configurations. Instead of performing exhaustive testing of every possible combination of parameters—which can result in thousands of combinations—PICT generates a compact set of test cases that provide comprehensive combinatorial coverage by testing all possible pairs of values.

    To use PICT, you prepare a model file that details the parameters of the interface or data you want to test. Each parameter in the model has a limited number of possible values. PICT then processes this model to output a manageable suite of test cases that cover all pairs of values across all parameters.

  2. Assign weights to parameter values

    main

    Weights allow you to suggest a preference for certain parameter values. Weights are positive integers.

    Usage: Value (Weight)

    Important Notes:

    • Weights are opportunistic hints, not guarantees. PICT's primary goal is to minimize the number of test cases while maintaining coverage. Weights are only used when multiple valid combinations exist that satisfy the coverage criteria.
    • A weight does not mean a value will appear $N$ times more often; it means it is $N$ times more likely to be chosen when the choice does not affect coverage.
    Type:           Primary (10), Logical, Single, Span, Stripe, Mirror, RAID-5
    Format method:  quick, slow
    File system:    FAT, FAT32, NTFS (10)
  3. Define Constraints in PICT

    main

    Constraints allow you to model the inherent limitations of your domain to prevent PICT from generating invalid test cases. There are two main types:

    Conditional Constraints

    Use IF...THEN...[ELSE] logic to express dependencies between parameters.

    Supported Operators:

    • Comparison: =, <>, >, >=, <, <=
    • String Matching: LIKE (uses * for any character and ? for one character)
    • Set Membership: IN {val1, val2, ...}
    • Logical Operators: NOT, AND, OR (use parentheses for priority)

    Example: IF [File system] = "FAT" THEN [Size] <= 4096;

    Unconditional Constraints (Invariants)

    These are rules that must always be true for every test case, regardless of other parameters.

    Example: [OS_1] <> [OS_2] OR [SKU_1] <> [SKU_2];

    IF [File system] IN {"FAT", "FAT32"} THEN [Compression] = "Off";
    
    IF [File system] <> "NTFS" OR ([File system] = "NTFS" AND [Cluster size] > 4096) 
    THEN [Compression] = "Off";
  4. Understand PICT Parameter Types

    main

    PICT uses a simple type system to evaluate constraints. Types are inferred automatically:

    • Numeric Type: A parameter is considered numeric if all its values can be converted to an integer or a float. Numeric parameters can be compared using >, <, >=, <=, etc.
    • String Type: All other parameters are treated as strings. String parameters are compared using =, <>, or LIKE.

    Note: If a value has multiple names, PICT uses only the first name to determine the type.

  5. Use sub-models to group parameters

    main

    Sub-models allow you to bundle specific parameters into groups that follow their own combinatory orders. This is useful for testing certain parameter combinations more or less thoroughly, or isolating them from the rest of the model (e.g., grouping hardware parameters separately from software parameters).

    Syntax: { <ParamName1>, <ParamName2>, ... } @ <Order>

    Key Rules:

    • The order of a sub-model cannot exceed the number of its parameters.
    • If you do not specify an order for a sub-model, PICT uses the global order specified by the /o option.
    • The model hierarchy can only be one level deep.
    • A parameter can belong to multiple sub-models.
    PLATFORM:  x86, x64, arm
    CPUS:      1, 2, 4
    RAM:       1GB, 4GB, 64GB
    HDD:       SCSI, IDE
    OS:        Win7, Win8, Win10
    Browser:   Edge, Opera, Chrome, Firefox
    APP:       Word, Excel, Powerpoint
    
    { PLATFORM, CPUS, RAM, HDD } @ 2
  6. Use aliasing to specify multiple names for a value

    main

    Aliasing allows you to provide multiple names for a single value. This does not increase combinatorial complexity; PICT treats them as one entity and rotates the names among test cases in the output.

    Configuration:

    • By default, names are separated by the | character.
    • Use the /a option to change the alias separator.

    Important Constraints Note: When evaluating constraints, only the first name counts. For example, if SKU_1 is aliased as Server | Datacenter, the constraint [SKU_1] = "Server" will match, but [SKU_1] = "Datacenter" will not. Similarly, only the first name is used for type detection or determining if a value is "negative" (out-of-range).

    OS_1:   Win2008, Win2012, Win2016
    SKU_1:  Professional, Server | Datacenter
  7. Use PICT as a command-line tool

    main

    PICT runs as a command-line tool. You provide it with a model file describing your parameters and their possible values.

    Example model structure:

    Type:          Single, Span, Stripe, Mirror, RAID-5
    Size:          10, 100, 500, 1000, 5000, 10000, 40000
    Format method: Quick, Slow
    File system:   FAT, FAT32, NTFS
    Cluster size:  512, 1024, 2048, 4096, 8192, 16384, 32768, 65536
    Compression:   On, Off

    Download the latest pict.exe from the official releases page.

  8. Build PICT on Linux, OS/X, or *BSD

    main

    PICT uses CMake for building on Linux-based systems. Assuming you have CMake and a C++ toolchain installed, follow these steps:

    cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
    cmake --build build
    pushd build && ctest -V && popd
    cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
    cmake --build build
    pushd build && ctest -V && popd
  9. Build PICT on Windows with MsBuild

    main

    To build PICT on Windows, use the provided Visual Studio solution or the command-line script.

    Using Visual Studio

    1. Open pict.sln in Visual Studio 2022.
    2. Ensure VC++ build tools are installed.

    Using Command Line

    Run the _build.cmd script in the root directory to build both Debug and Release configurations.

    Running Tests

    1. Ensure Perl is installed.
    2. Run the _test.cmd script.
    3. Check the generated logs (dbg.log for Debug or rel.log for Release) against committed baselines.
  10. Create a PICT Model File

    main

    A model file is a plain-text file that defines the parameters and constraints of your test domain. The sections must follow this specific order:

    1. Parameter definitions (Required): List parameters and their values.
    2. Sub-model definitions (Optional): Define reusable parameter sets.
    3. Constraint definitions (Optional): Define rules and limitations.

    Parameter Syntax: <ParamName> : <Value1>, <Value2>, <Value3>, ...

    Rules:

    • Use # for comments.
    • Parameters are separated from values by a colon :.
    • Values are delimited by a comma , (unless changed via /d).
    • Parameters can be reused in sub-models using the <ParamName> syntax.
    # This is a sample model
    
    Type:          Primary, Logical, Single, Span, Stripe, Mirror, RAID-5
    Size:          10, 100, 500, 1000, 5000, 10000, 40000
    Format method: quick, slow
    File system:   FAT, FAT32, NTFS
    Cluster size:  512, 1024, 2048, 4096, 8192, 16384, 32768, 65536
    Compression:   on, off
  11. Perform negative testing with the tilde (~) prefix

    main

    Negative testing involves using values outside the allowable range to ensure error handling. To prevent "input masking" (where one invalid input prevents another from being tested), PICT ensures that out-of-range values are paired only with valid values.

    Usage:

    • Prefix an invalid value with ~ (tilde) to mark it as out-of-range.
    • Use the /n option to specify a different prefix if desired.

    Behavior:

    • The ~ prefix is not part of the value during constraint evaluation or type detection. For example, if A has value ~-1, the constraint if [A] = -1 then ... will work correctly.
    • The ~ prefix will appear in the final output.
    • If a value has multiple names (aliases), only prefixing the first name makes the entire value out-of-range.
    A: ~-1, 0, 1, 2
    B: ~-1, 0, 1, 2
  12. Run PICT via Command Line

    main

    PICT is a command-line tool that generates test cases from a plain-text model file. The basic usage pattern is:

    pict model [options]

    By default, PICT generates a pairwise test suite (covering all pairs of values). You can increase the combination order using the /o option (e.g., /o:3 for triplets). The output is printed to standard output as a tab-separated value format, where the first line contains parameter names and subsequent lines contain the generated test cases.

    pict model [options]