Skip to content
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

Introspector not showing coverage on Python Decorators #1003

Open
sg3-141-592 opened this issue Apr 21, 2023 · 7 comments · Fixed by #1005
Open

Introspector not showing coverage on Python Decorators #1003

sg3-141-592 opened this issue Apr 21, 2023 · 7 comments · Fixed by #1005

Comments

@sg3-141-592
Copy link
Contributor

sg3-141-592 commented Apr 21, 2023

I recently integrated the cachetools library into OSS-Fuzz recently. This library uses a @cached decorator to indicate a function output to cache, e.g.

@cachetools.cached(cache=fdp.PickValueInList(CACHE_TYPES), lock=cache_lock, info=fdp.ConsumeBool()) 
def fib(n):
     return n if n < 2 else fib(n - 1) + fib(n - 2)

I can't get the introspector to recognise that we're hitting the cached decorator. I can see the coverage here cachetools/__init__py.html:632 but I can't get it in the call graph.

image

Some other data points, if you see fuzzerLogFile-fuzz_cached.data.yaml this method is on line 629

    functionLinenumber: 629
    functionName: cachetools.cached.decorator
    functionSourceFile: cachetools

CallTree File fuzzerLogFile-fuzz_cached.data

Call tree
...fuzz_cached.TestOneInput / -1
  cachetools.cached.decorator ...fuzz_cached -1
    <builtin>.isinstance cachetools 633

And Coverage File all_cov.json

        "/pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cachetools/__init__.py": {
            "executed_lines": [
...
                629,
                630,
                631,
                633,
...

Any idea if this is an introspector issue, or if it's likely something else?

@sg3-141-592 sg3-141-592 changed the title Is the Introspector able to see Python Decorators Introspector not show coverage on Python Decorators Apr 21, 2023
@DavidKorczynski
Copy link
Contributor

Do I get this right, that the decorator is recognised in the calltree and the coverage is recorded in all_cov.json but it isn't showing up as green in the calltree?

@sg3-141-592 sg3-141-592 changed the title Introspector not show coverage on Python Decorators Introspector not showing coverage on Python Decorators Apr 22, 2023
@sg3-141-592
Copy link
Contributor Author

That's correct yes. It's not turning up in the Functions coverage either.

image

@DavidKorczynski
Copy link
Contributor

Ah thanks, I will see if I can go over this Monday!

@DavidKorczynski
Copy link
Contributor

Should be fixed in #1005

Screenshot 2023-04-24 114156

Thanks for reporting!

@DavidKorczynski
Copy link
Contributor

DavidKorczynski commented Apr 24, 2023

leaving open until we've bumped oss-fuzz

@sg3-141-592
Copy link
Contributor Author

Thanks for the quick fix. Did a bit of local testing with the latest fuzz-introspector repo and results look good.

import function_inspector

function_inspector.print_function_details(
    "cachetools",
    [
        "cachetools.cached.decorator",
        "cachetools.Cache.__init__",
        "cachetools.LFUCache.__init__",
    ],
)

## Outputs
cachetools.cached.decorator
  Reached by 1 fuzzers [['fuzz_cached']]
  Code coverage: 75.000000
cachetools.Cache.__init__
  Reached by 1 fuzzers [['fuzz_cached']]
  Code coverage: 100.000000
cachetools.LFUCache.__init__
  Reached by 1 fuzzers [['fuzz_cached']]
  Code coverage: 100.000000

@sg3-141-592
Copy link
Contributor Author

Hey @DavidKorczynski , some observations from the latest introspector report for cachetools https://storage.googleapis.com/oss-fuzz-introspector/cachetools/inspector-report/20230501/fuzz_report.html .

The calltree looks good, and __init__ methods are showing as covered. And the overall coverage number has increased from 9% to 69%.

However the overall "functions statically reachable" and "cyclomatic complexity statically reachable" overview numbers haven't changed. Is there a secondary fix needed on the introspector get the __init__ methods included in these statistics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants