Thread: Script for determining code coverage of functions listed in pg_proc.dat
Script for determining code coverage of functions listed in pg_proc.dat
From
Aleksander Alekseev
Date:
Hi, I would like to share a script that determines code coverage of functions that are directly accessible from SQL. To use the script you have to build a code coverage report first, as usual: ``` git clean -dfx meson setup --buildtype debug -DPG_TEST_EXTRA="kerberos ldap ssl" -Db_coverage=true -Dldap=disabled -Dssl=openssl -Dcassert=true -Dtap_tests=enabled -Dprefix=/home/eax/pginstall build ninja -C build PG_TEST_EXTRA=1 meson test -C build ninja -C build coverage-html ``` Note that this will only work in the Linux environment, to my knowledge at least. Then execute: ``` ./coverage-analyze.py > coverage.csv ``` This will give you functions listed in pg_proc.dat and where to find them in the source code, sorted by code coverage. These functions are easy to cover with tests, see for instance [1] and similar patches in `git log`. I believe this can be useful to newcomers looking for an idea of the first patch. You can also modify the script to check the coverage of particular functions you are interested in. Just modify this part accordingly: ``` functions = set() with open("src/include/catalog/pg_proc.dat") as f: proc_data = f.read() re_str = """prosrc[ ]+=>[ ]+['"](.*?)['"]""" for m in re.finditer(re_str, proc_data): func_name = m.group(1) functions.add(func_name) ``` If you want to know coverage of *all* functions, just comment this part: ``` if current_func_name not in functions: current_func_name = None continue ``` Please find attached the script and the compressed report. I also uploaded a copy of the report to Google Drive [2]. As always, your thoughts and feedback are most welcomed. [1]: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=4f071349 [2]: https://docs.google.com/spreadsheets/d/1i3_tfBjMO3QbnVVnWb1uwhp5R_gdmjdx1Q9eXmjoUUA/edit?usp=sharing -- Best regards, Aleksander Alekseev