Analyze Python code for correctness using symbolic execution and SMT solving to automatically find counterexamples for functions with type annotations and contracts.
86
Build a system that uses symbolic execution to find valid configuration parameters that satisfy system constraints.
You need to implement configuration validation functions for a server deployment system. The system must find valid configuration values that satisfy multiple interdependent constraints.
Implement a function validate_server_config that verifies a server configuration is valid. The configuration has the following parameters:
worker_threads: Number of worker threads (must be positive integer)connection_pool_size: Size of connection pool (must be positive integer)max_memory_mb: Maximum memory in MB (must be positive integer)timeout_seconds: Request timeout in seconds (must be positive integer)The configuration must satisfy these constraints:
worker_threads must be between 1 and 32connection_pool_size must be at least worker_threads * 2max_memory_mb must be at least connection_pool_size * 10timeout_seconds must be between 1 and 300(worker_threads * 100 + connection_pool_size * 10) must not exceed 5000The function should raise a ValueError with a descriptive message if any constraint is violated.
Implement a second function find_optimal_config that uses symbolic execution to find a configuration that maximizes worker_threads while satisfying all constraints, given a fixed max_memory_mb budget.
worker_threads=4, connection_pool_size=8, max_memory_mb=80, timeout_seconds=30 is valid @testworker_threads=4, connection_pool_size=6, max_memory_mb=80, timeout_seconds=30 raises ValueError because pool size is too small @testmax_memory_mb=500 returns a valid configuration that maximizes worker threads @test@generates
from typing import NamedTuple
class ServerConfig(NamedTuple):
"""Server configuration parameters."""
worker_threads: int
connection_pool_size: int
max_memory_mb: int
timeout_seconds: int
def validate_server_config(config: ServerConfig) -> None:
"""
Validate a server configuration against system constraints.
Raises:
ValueError: If any constraint is violated, with a message describing the issue.
"""
pass
def find_optimal_config(max_memory_mb: int) -> ServerConfig:
"""
Find a valid configuration that maximizes worker_threads given a memory budget.
Uses symbolic execution to search the constraint space.
Args:
max_memory_mb: The memory budget constraint
Returns:
An optimal ServerConfig that maximizes worker_threads
Raises:
ValueError: If no valid configuration exists for the given budget
"""
passProvides symbolic execution and constraint solving capabilities for searching valid parameter combinations.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-crosshair-toolevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10