Skip to content

Commit

Permalink
various CLI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ravyu-jump committed Sep 3, 2024
1 parent c54888a commit 5318d20
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Default paths used by test suite
readable_context/
test_results/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -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/
6 changes: 3 additions & 3 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.

Expand Down
28 changes: 17 additions & 11 deletions src/test_suite/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down

0 comments on commit 5318d20

Please sign in to comment.