-
Notifications
You must be signed in to change notification settings - Fork 188
Implement Unified Line Coverage Formula #898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Kartikayy007
wants to merge
6
commits into
google:main
Choose a base branch
from
Kartikayy007:unified-coverage-formula
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6a480c4
Implement unified line coverage formula
Kartikayy007 546036d
formater/linted the code and revreted the log message
Kartikayy007 33e42b3
Merge branch 'main' into unified-coverage-formula
Kartikayy007 3469348
Merge remote-tracking branch 'upstream/main' into unified-coverage-fo…
Kartikayy007 05fba99
fix: Standardize line coverage calculation formulas
Kartikayy007 ebe46e4
fix: Remove unnecessary line coverage subtraction in total coverage c…
Kartikayy007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Standard coverage calculation functions to ensure consistency.""" | ||
|
||
from experiment import textcov | ||
|
||
|
||
def calculate_coverage(cov: textcov.Textcov, linked_lines: int) -> float: | ||
"""Calculates coverage according to formula: Cov(f) / Linked(f).""" | ||
if not linked_lines: | ||
return 0.0 | ||
return cov.covered_lines / linked_lines | ||
|
||
|
||
def calculate_coverage_improvement(new_cov: textcov.Textcov, | ||
existing_cov: textcov.Textcov, | ||
union_linked_lines: int) -> float: | ||
"""Calculates coverage improvement: [Cov(f1) - Cov(f0)] / [Linked(f1 ∪ f0)].""" | ||
if not union_linked_lines: | ||
return 0.0 | ||
|
||
# Make a copy to avoid modifying the original | ||
diff_cov = new_cov.copy() | ||
diff_cov.subtract_covered_lines(existing_cov) | ||
|
||
return diff_cov.covered_lines / union_linked_lines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -31,6 +31,7 @@ | |||||||
import run_one_experiment | ||||||||
from data_prep import introspector | ||||||||
from experiment import benchmark as benchmarklib | ||||||||
from experiment import coverage as coverage_utils | ||||||||
from experiment import evaluator, oss_fuzz_checkout, textcov | ||||||||
from experiment.workdir import WorkDirs | ||||||||
from llm_toolkit import models, prompt_builder | ||||||||
|
@@ -502,23 +503,17 @@ def _process_total_coverage_gain() -> dict[str, dict[str, Any]]: | |||||||
|
||||||||
total_existing_lines = sum(lines) | ||||||||
total_cov_covered_lines_before_subtraction = total_cov.covered_lines | ||||||||
total_cov.subtract_covered_lines(existing_textcov) | ||||||||
try: | ||||||||
cov_relative_gain = (total_cov.covered_lines / | ||||||||
existing_textcov.covered_lines) | ||||||||
except ZeroDivisionError: | ||||||||
cov_relative_gain = 0.0 | ||||||||
|
||||||||
total_lines = max(total_cov.total_lines, total_existing_lines) | ||||||||
union_linked_lines = max(total_cov.total_lines, total_existing_lines) | ||||||||
|
||||||||
if total_lines: | ||||||||
coverage_gain[project] = { | ||||||||
'language': | ||||||||
oss_fuzz_checkout.get_project_language(project), | ||||||||
'coverage_diff': | ||||||||
total_cov.covered_lines / total_lines, | ||||||||
'coverage_relative_gain': | ||||||||
cov_relative_gain, | ||||||||
coverage_utils.calculate_coverage_improvement( | ||||||||
total_cov, existing_textcov, union_linked_lines), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think we have subtracted oss-fuzz-gen/run_all_experiments.py Lines 504 to 506 in 546036d
While this action should be idempotent, repeated actions add unnecessary complexity and may confuse readers. |
||||||||
'coverage_ofg_total_covered_lines': | ||||||||
total_cov_covered_lines_before_subtraction, | ||||||||
'coverage_ofg_total_new_covered_lines': | ||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the term "union" in the mathematical sense, where each line represents an element of a set. Each set can correspond to covered lines or linked lines in the project.
For example, suppose our fuzz target links lines {1,2,3,4} of the project at compile time and covers lines {1,2,3} during fuzzing, while an older fuzz target links lines {1,2,5} and covers {2,5} . Then:
Ideally, the denominator should represent "the total reachable lines" or "the total number of lines" in the project. However, they are difficult to determine accurately if certain files are not linked at compile time.
Given this is a complicate task, please feel free to prioritize on writing and refining your proposal : )
That's the most important factor for you application.
If you have a draft, I am more than happy to provide general feedback to ensure you are on the right track.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct sir I'll prioritise my proposal firstly and will surely take a look back to it and completely resolve it, Thank you !