From ebe5777c88e0d8a2168a574c8ce67f0122da052c Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Thu, 25 Jun 2026 12:39:33 +0200 Subject: [PATCH] test: generate report after the test command --- .gitignore | 2 + tools/storage-test/README.md | 6 ++ tools/storage-test/storage-test.sh | 105 ++++++++++++++++++++++++++--- 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f689aee1..f7917e13 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,8 @@ data/ tests/cbindings/data-dir tests/cbindings/downloaded_hello.txt +report-*.md + nimbledeps CLAUDE.local.md .claude/settings.local.json diff --git a/tools/storage-test/README.md b/tools/storage-test/README.md index 21b1e26b..cd8dd3d3 100644 --- a/tools/storage-test/README.md +++ b/tools/storage-test/README.md @@ -240,6 +240,12 @@ tools/storage-test/storage-test.sh lib test The scenario uploads random files to the remote Linode node, downloads them using the selected local target, validates SHA-256 hashes, and deletes involved CIDs from both sides. The default file sizes are `4K 1M 10M`; override with `TEST_FILE_SIZES`. +The scenario prints a detailed progress summary and writes a Markdown report in the current directory: + +```text +./report-YYYY-MM-DD_HH-MM-SS.md +``` + ## Useful API Endpoints | Operation | Endpoint | diff --git a/tools/storage-test/storage-test.sh b/tools/storage-test/storage-test.sh index acb8ea57..fa61e17e 100755 --- a/tools/storage-test/storage-test.sh +++ b/tools/storage-test/storage-test.sh @@ -490,28 +490,101 @@ target_test() { need sha256sum local max_bytes=$((10 * 1024 * 1024)) - local workspace + local workspace report_ts report_path start_time start_epoch cleanup_done=0 cleanup_failures=0 workspace="$(mktemp -d "${TMPDIR:-/tmp}/logos-storage-test.XXXXXX")" + report_ts="$(date +%Y-%m-%d_%H-%M-%S)" + report_path="./report-${report_ts}.md" + start_time="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + start_epoch="$(date +%s)" local -a cids=() local -a local_cids=() + local -a result_sizes=() + local -a result_bytes=() + local -a result_sources=() + local -a result_downloads=() + local -a result_cids=() + local -a result_hashes=() + local -a cleanup_messages=() cleanup() { + if [[ "$cleanup_done" == '1' ]]; then + return 0 + fi + cleanup_done=1 local cid for cid in "${local_cids[@]:-}"; do - target_delete_cid "$target" "$cid" >/dev/null 2>&1 || true + if target_delete_cid "$target" "$cid" >/dev/null 2>&1; then + cleanup_messages+=("deleted $cid from $target") + else + cleanup_messages+=("failed to delete $cid from $target") + cleanup_failures=$((cleanup_failures + 1)) + fi done for cid in "${cids[@]:-}"; do - target_delete_cid remote "$cid" >/dev/null 2>&1 || true + if target_delete_cid remote "$cid" >/dev/null 2>&1; then + cleanup_messages+=("deleted $cid from remote") + else + cleanup_messages+=("failed to delete $cid from remote") + cleanup_failures=$((cleanup_failures + 1)) + fi done if [[ "$TEST_KEEP_FILES" != '1' ]]; then rm -rf "$workspace" + cleanup_messages+=("removed workspace $workspace") else printf 'kept test workspace: %s\n' "$workspace" >&2 + cleanup_messages+=("kept workspace $workspace") fi } trap cleanup RETURN - printf 'test workspace: %s\n' "$workspace" >&2 + write_report() { + local end_time end_epoch duration i + end_time="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + end_epoch="$(date +%s)" + duration=$((end_epoch - start_epoch)) + + { + printf '# Logos Storage Test Report\n\n' + printf '- **Status:** PASS\n' + printf '- **Started:** `%s`\n' "$start_time" + printf '- **Finished:** `%s`\n' "$end_time" + printf '- **Duration:** `%ss`\n' "$duration" + printf '- **Target:** `%s`\n' "$target" + printf '- **Remote source:** `remote`\n' + printf '- **File sizes:** `%s`\n' "$TEST_FILE_SIZES" + printf '- **Workspace:** `%s`\n' "$workspace" + printf '- **Cleanup failures:** `%s`\n\n' "$cleanup_failures" + + printf '## Files\n\n' + printf '| # | Size | Bytes | CID | SHA-256 | Source | Download |\n' + printf '|---:|---:|---:|---|---|---|---|\n' + for i in "${!result_cids[@]}"; do + printf '| %d | `%s` | `%s` | `%s` | `%s` | `%s` | `%s` |\n' \ + "$((i + 1))" \ + "${result_sizes[$i]}" \ + "${result_bytes[$i]}" \ + "${result_cids[$i]}" \ + "${result_hashes[$i]}" \ + "${result_sources[$i]}" \ + "${result_downloads[$i]}" + done + + printf '\n## Cleanup\n\n' + if [[ ${#cleanup_messages[@]} -eq 0 ]]; then + printf '- No cleanup actions recorded.\n' + else + for i in "${!cleanup_messages[@]}"; do + printf '- %s\n' "${cleanup_messages[$i]}" + done + fi + } > "$report_path" + } + + printf 'Starting Logos Storage remote-to-%s test\n' "$target" + printf ' workspace: %s\n' "$workspace" + printf ' report: %s\n' "$report_path" + printf ' sizes: %s\n' "$TEST_FILE_SIZES" local size index=0 for size in $TEST_FILE_SIZES; do @@ -525,11 +598,12 @@ target_test() { dd if=/dev/urandom of="$src" bs="$size" count=1 status=none src_hash="$(sha256sum "$src" | awk '{ print $1 }')" - printf '[%d] upload remote %s\n' "$index" "$size" >&2 + printf '\n[%d] Generate %s random file (%s bytes)\n' "$index" "$size" "$bytes" + printf '[%d] Upload to remote\n' "$index" cid="$(target_upload_file remote "$src")" cids+=("$cid") - printf '[%d] download via %s cid=%s\n' "$index" "$target" "$cid" >&2 + printf '[%d] Download via %s: %s\n' "$index" "$target" "$cid" if [[ "$target" == 'local' ]]; then target_fetch_cid local "$cid" --wait >/dev/null local_cids+=("$cid") @@ -541,10 +615,25 @@ target_test() { out_hash="$(sha256sum "$out" | awk '{ print $1 }')" [[ "$src_hash" == "$out_hash" ]] || die "hash mismatch for cid $cid" - printf '[%d] ok cid=%s sha256=%s\n' "$index" "$cid" "$src_hash" + result_sizes+=("$size") + result_bytes+=("$bytes") + result_sources+=("$src") + result_downloads+=("$out") + result_cids+=("$cid") + result_hashes+=("$src_hash") + printf '[%d] OK sha256=%s\n' "$index" "$src_hash" done - printf 'test passed target=%s files=%d\n' "$target" "$index" + printf '\nCleaning up remote and %s CIDs...\n' "$target" + cleanup + trap - RETURN + write_report + + printf '\nTest passed\n' + printf ' target: %s\n' "$target" + printf ' files validated: %d\n' "$index" + printf ' cleanup failures: %d\n' "$cleanup_failures" + printf ' report: %s\n' "$report_path" } target_command() {