Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi



, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Add script to generate fuzz coverage by Prabhat1308 · Pull Request #3718 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,9 @@ jobs:
# Will anyone be impressed by your amazing coverage? No
# Maybe if codecov wasn't broken we wouldn't need to do this...
bash <(curl -s https://codecov.io/bash) -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
- name: Run fuzz coverage generation
run: |
./ci/ci-fuzz.sh

benchmark:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ci/ci-fuzz.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, we now have a fuzz/ci-fuzz.sh and a ci/ci-fuzz.sh, that's confusing :)

set -eox pipefail

echo -e "\n\nGenerating fuzz coverage report"
# In CI, store coverage in target directory for consistency with other artifacts
COVERAGE_DIR="target/coverage-report"
echo "Installing cargo-llvm-cov..."
# Install cargo-llvm-cov if not already installed
cargo install cargo-llvm-cov --locked

echo "Cleaning up to save disk space..."
rm -rf target/*
echo "Disk cleanup completed"
Comment thread
Prabhat1308 marked this conversation as resolved.


echo "Running fuzz coverage generation..."
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo "Coverage generation completed. Checking results..."

# Upload fuzz coverage to codecov if the file exists (CI only)
if [ -f "target/fuzz-codecov.json" ]; then
echo "Uploading fuzz coverage to codecov..."
bash <(curl -s https://codecov.io/bash) -f "target/fuzz-codecov.json" -F fuzz -t "f421b687-4dc2-4387-ac3d-dc3b2528af57"
fi
88 changes: 88 additions & 0 deletions contrib/generate_fuzz_coverage.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
set -x

# Parse command line arguments
OUTPUT_DIR="coverage-report"
while [[ $# -gt 0 ]]; do
case $1 in
--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
exit 1
;;
esac
done

# Check if we're in the root directory, if so change to fuzz
if [ -d "fuzz" ]; then
cd fuzz
elif [ ! -f "Cargo.toml" ] || ! grep -q "fuzz" Cargo.toml 2>/dev/null; then
echo "Error: Please run this script from the rust-lightning root directory or fuzz directory"
exit 1
fi

# Check if test_cases directory exists and has content
show_corpus_message=false
if [ ! -d "test_cases" ]; then
show_corpus_message=true
elif [ -z "$(find test_cases -name '*' -type f 2>/dev/null | head -1)" ]; then
show_corpus_message=true
fi
Comment thread
Prabhat1308 marked this conversation as resolved.

if [ "$show_corpus_message" = true ]; then
echo "Warning: No corpus found in test_cases directory."
echo "Generating coverage report without fuzzing corpus."
echo ""
echo "To include fuzzing corpus coverage, create test_cases directories with your corpus:"
echo " mkdir -p test_cases/{target_name}"
echo " cp your_corpus_directory/* test_cases/{target_name}/"
echo ""
echo "Example:"
echo " mkdir -p test_cases/base32"
echo " cp /path/to/your/base32_corpus/* test_cases/base32/"
Comment thread
Prabhat1308 marked this conversation as resolved.
echo ""
Comment thread
Prabhat1308 marked this conversation as resolved.
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"

# dont run this command when running in CI
if [ "$CI" != "true" ] && [ "$GITHUB_ACTIONS" != "true" ]; then
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

# Check if coverage report was generated successfully
# The report is generated in $OUTPUT_DIR/html/index.html when using --html --output-dir
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
echo "Contents of $OUTPUT_DIR:"
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
if [ -d "$OUTPUT_DIR/html" ]; then
echo "Contents of $OUTPUT_DIR/html:"
ls -la "$OUTPUT_DIR/html"
fi
exit 1
fi
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
fi

# Generate codecov JSON format if running in CI environment
if [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
echo "CI environment detected, generating codecov JSON format..."
cargo llvm-cov --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"

if [ -f "$OUTPUT_DIR/fuzz-codecov.json" ] && [[ "$OUTPUT_DIR" == *"target/"* ]]; then
TARGET_DIR="../target"
cp "$OUTPUT_DIR/fuzz-codecov.json" "$TARGET_DIR/fuzz-codecov.json"
echo "Fuzz codecov report copied to $TARGET_DIR/fuzz-codecov.json"
fi
Comment thread
Prabhat1308 marked this conversation as resolved.
fi