From 5318d206478cfc5fc30bc8d50c1e7cfaf59a6560 Mon Sep 17 00:00:00 2001 From: Ravyu Sivakumaran Date: Tue, 3 Sep 2024 21:52:42 +0000 Subject: [PATCH] various CLI improvements --- .gitignore | 5 +++++ commands.md | 6 +++--- src/test_suite/test_suite.py | 28 +++++++++++++++++----------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 882a70e..c23f6ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Default paths used by test suite +readable_context/ +test_results/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -160,3 +164,4 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +scratch/ \ No newline at end of file diff --git a/commands.md b/commands.md index 62022a7..d2de9e8 100644 --- a/commands.md +++ b/commands.md @@ -39,7 +39,7 @@ $ solana-test-suite create-fixtures [OPTIONS] **Options**: -* `-i, --input-dir PATH`: Input directory containing InstrContext messages [default: corpus8] +* `-i, --input-dir PATH`: Either a file or directory containing InstrContext messages [default: corpus8] * `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: impl/lib/libsolfuzz_agave_v2.0.so] * `-t, --target PATH`: Shared object (.so) target file paths (pairs with --keep-passing). Targets must have sol_compat_instr_execute_v1 defined * `-o, --output-dir PATH`: Output directory for fixtures [default: test_fixtures] @@ -76,8 +76,8 @@ $ solana-test-suite decode-protobuf [OPTIONS] **Options**: -* `-i, --input-dir PATH`: Input directory containing InstrContext message(s) [default: raw_instruction_context] -* `-o, --output-dir PATH`: Output directory for base58-encoded, human-readable InstrContext messages [default: readable_instruction_context] +* `-i, --input PATH`: Either a InstrContext message or directory of messages [default: raw_context] +* `-o, --output-dir PATH`: Output directory for base58-encoded, human-readable InstrContext messages [default: readable_context] * `-p, --num-processes INTEGER`: Number of processes to use [default: 4] * `--help`: Show this message and exit. diff --git a/src/test_suite/test_suite.py b/src/test_suite/test_suite.py index 5942204..7b32a24 100644 --- a/src/test_suite/test_suite.py +++ b/src/test_suite/test_suite.py @@ -85,7 +85,7 @@ def exec_instr( effects = process_target(lib, context) if not effects: - print("No instruction effects returned") + print(f"No {globals.harness_ctx.effects_type.__name__} returned") continue serialized_effects = effects.SerializeToString(deterministic=True) @@ -184,11 +184,11 @@ def instr_from_fixtures( """ ) def create_fixtures( - input_dir: Path = typer.Option( + input_path: Path = typer.Option( Path("corpus8"), "--input-dir", "-i", - help=f"Input directory containing {globals.harness_ctx.context_type.__name__} messages", + help=f"Either a file or directory containing {globals.harness_ctx.context_type.__name__} messages", ), solana_shared_library: Path = typer.Option( Path("impl/lib/libsolfuzz_agave_v2.0.so"), @@ -244,7 +244,7 @@ def create_fixtures( lib.sol_compat_init() globals.target_libraries[target] = lib - test_cases = list(input_dir.iterdir()) + test_cases = [input_path] if input_path.is_file() else list(input_path.iterdir()) num_test_cases = len(test_cases) # Generate the test cases in parallel from files on disk @@ -455,14 +455,14 @@ def run_tests( help=f"Convert {globals.harness_ctx.context_type.__name__} messages to human-readable format." ) def decode_protobuf( - input_dir: Path = typer.Option( - Path("raw_instruction_context"), - "--input-dir", + input_path: Path = typer.Option( + Path("raw_context"), + "--input", "-i", - help=f"Input directory containing {globals.harness_ctx.context_type.__name__} message(s)", + help=f"Either a {globals.harness_ctx.context_type.__name__} message or directory of messages", ), output_dir: Path = typer.Option( - Path("readable_instruction_context"), + Path("readable_context"), "--output-dir", "-o", help=f"Output directory for base58-encoded, human-readable {globals.harness_ctx.context_type.__name__} messages", @@ -478,12 +478,18 @@ def decode_protobuf( shutil.rmtree(globals.output_dir) globals.output_dir.mkdir(parents=True, exist_ok=True) - num_test_cases = len(list(input_dir.iterdir())) + if not input_path.is_dir(): + ok = decode_single_test_case(input_path) + if not ok: + print(f"Error decoding {input_path}") + return + + num_test_cases = len(list(input_path.iterdir())) write_results = [] with Pool(processes=num_processes) as pool: for result in tqdm.tqdm( - pool.imap(decode_single_test_case, input_dir.iterdir()), + pool.imap(decode_single_test_case, input_path.iterdir()), total=num_test_cases, ): write_results.append(result)