Re: [PATCH] perf python: Set error messages on call failure

From: Ian Rogers
Date: Wed May 03 2023 - 13:16:53 EST


On Tue, May 2, 2023 at 7:27 PM Jinli Xiao <jinli.xiao@xxxxxxx> wrote:
>
> Thanks for the prompt response!
>
> On Tue, May 2, 2023 at 4:37 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> >
> > Nice! Would it be possible to test this? We could do a shell test
>
> All my changes in this patch is just setting the error message that
> can be interpreted by Python just before the bindings return.
>
> I am not sure about shell test, but I can do something like
>
> [root@nyu-lexis linux]# export PYTHONPATH=~jinli/linux/tools/perf/python/
> [root@nyu-lexis linux]# python3
> Python 3.11.2 (main, Feb 8 2023, 00:00:00) [GCC 12.2.1 20221121 (Red
> Hat 12.2.1-4)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import perf
> >>> thread_map = perf.thread_map(9999) # a non-existent pid in /proc
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> FileNotFoundError: [Errno 2] No such file or directory
>
> whereas the original output is
>
> >>> thread_map = perf.thread_map(9999)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> SystemError: <class 'perf.thread_map'> returned NULL without setting
> an exception
>
> Upon testing I did find some of the changes unnecessary. I will submit
> a new patch to this.
>
> This is my first time contributing so please let me know if I did
> anything wrong :)

Everything is good with your patch. I'm keen that we try to make sure
we have coverage with tests. We have other shell tests that run
python:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/tests/shell/stat+json_output.sh?h=perf-tools-next
So I wonder we can start doing what you did in your example and then
just assert we get a FileNotFoundError in the python. The shell script
is really just a way to run the python and can follow the example in
the link. Sound good?

Thanks,
Ian

> Best wishes,
> Jinli