1*49cdfc7eSAndroid Build Coastguard Worker# Configuration file for the Sphinx documentation builder. 2*49cdfc7eSAndroid Build Coastguard Worker# 3*49cdfc7eSAndroid Build Coastguard Worker# For the full list of built-in configuration values, see the documentation: 4*49cdfc7eSAndroid Build Coastguard Worker# https://www.sphinx-doc.org/en/master/usage/configuration.html 5*49cdfc7eSAndroid Build Coastguard Worker 6*49cdfc7eSAndroid Build Coastguard Workerimport os 7*49cdfc7eSAndroid Build Coastguard Workerimport re 8*49cdfc7eSAndroid Build Coastguard Workerimport sphinx 9*49cdfc7eSAndroid Build Coastguard Workerimport socket 10*49cdfc7eSAndroid Build Coastguard Workerimport urllib.request 11*49cdfc7eSAndroid Build Coastguard Worker 12*49cdfc7eSAndroid Build Coastguard Worker# -- Project information ----------------------------------------------------- 13*49cdfc7eSAndroid Build Coastguard Worker# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 14*49cdfc7eSAndroid Build Coastguard Worker 15*49cdfc7eSAndroid Build Coastguard Workerproject = 'Linux Test Project' 16*49cdfc7eSAndroid Build Coastguard Workercopyright = '2024, Linux Test Project' 17*49cdfc7eSAndroid Build Coastguard Workerauthor = 'Linux Test Project' 18*49cdfc7eSAndroid Build Coastguard Workerrelease = '1.0' 19*49cdfc7eSAndroid Build Coastguard Worker 20*49cdfc7eSAndroid Build Coastguard Worker# -- General configuration --------------------------------------------------- 21*49cdfc7eSAndroid Build Coastguard Worker# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 22*49cdfc7eSAndroid Build Coastguard Worker 23*49cdfc7eSAndroid Build Coastguard Workerextensions = [ 24*49cdfc7eSAndroid Build Coastguard Worker 'linuxdoc.rstKernelDoc', 25*49cdfc7eSAndroid Build Coastguard Worker 'sphinxcontrib.spelling', 26*49cdfc7eSAndroid Build Coastguard Worker 'sphinx.ext.extlinks' 27*49cdfc7eSAndroid Build Coastguard Worker] 28*49cdfc7eSAndroid Build Coastguard Worker 29*49cdfc7eSAndroid Build Coastguard Workerexclude_patterns = ["html*", '_static*'] 30*49cdfc7eSAndroid Build Coastguard Workerextlinks = { 31*49cdfc7eSAndroid Build Coastguard Worker 'repo': ('https://github.com/linux-test-project/ltp/%s', '%s'), 32*49cdfc7eSAndroid Build Coastguard Worker 'master': ('https://github.com/linux-test-project/ltp/blob/master/%s', '%s'), 33*49cdfc7eSAndroid Build Coastguard Worker 'git_man': ('https://git-scm.com/docs/git-%s', 'git %s'), 34*49cdfc7eSAndroid Build Coastguard Worker # TODO: allow 2nd parameter to show page description instead of plain URL 35*49cdfc7eSAndroid Build Coastguard Worker 'kernel_doc': ('https://docs.kernel.org/%s.html', 'https://docs.kernel.org/%s.html'), 36*49cdfc7eSAndroid Build Coastguard Worker 'kernel_tree': ('https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/%s', '%s'), 37*49cdfc7eSAndroid Build Coastguard Worker} 38*49cdfc7eSAndroid Build Coastguard Worker 39*49cdfc7eSAndroid Build Coastguard Workerspelling_lang = "en_US" 40*49cdfc7eSAndroid Build Coastguard Workerspelling_warning = True 41*49cdfc7eSAndroid Build Coastguard Workerspelling_exclude_patterns=['users/stats.rst'] 42*49cdfc7eSAndroid Build Coastguard Workerspelling_word_list_filename = "spelling_wordlist" 43*49cdfc7eSAndroid Build Coastguard Worker 44*49cdfc7eSAndroid Build Coastguard Worker# -- Options for HTML output ------------------------------------------------- 45*49cdfc7eSAndroid Build Coastguard Worker# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 46*49cdfc7eSAndroid Build Coastguard Worker 47*49cdfc7eSAndroid Build Coastguard Workerhtml_theme = 'sphinx_rtd_theme' 48*49cdfc7eSAndroid Build Coastguard Workerhtml_static_path = ['_static'] 49*49cdfc7eSAndroid Build Coastguard Worker 50*49cdfc7eSAndroid Build Coastguard Worker 51*49cdfc7eSAndroid Build Coastguard Workerdef generate_syscalls_stats(_): 52*49cdfc7eSAndroid Build Coastguard Worker """ 53*49cdfc7eSAndroid Build Coastguard Worker Generate statistics for syscalls. We fetch the syscalls list from the kernel 54*49cdfc7eSAndroid Build Coastguard Worker sources, then we compare it with testcases/kernel/syscalls folder and 55*49cdfc7eSAndroid Build Coastguard Worker generate a file that is included in the statistics documentation section. 56*49cdfc7eSAndroid Build Coastguard Worker """ 57*49cdfc7eSAndroid Build Coastguard Worker output = '_static/syscalls.rst' 58*49cdfc7eSAndroid Build Coastguard Worker 59*49cdfc7eSAndroid Build Coastguard Worker # sometimes checking testcases/kernel/syscalls file names are not enough, 60*49cdfc7eSAndroid Build Coastguard Worker # because in some cases (i.e. io_ring) syscalls are tested, but they are 61*49cdfc7eSAndroid Build Coastguard Worker # part of a more complex scenario. In the following list, we define syscalls 62*49cdfc7eSAndroid Build Coastguard Worker # which we know they are 100% tested already. 63*49cdfc7eSAndroid Build Coastguard Worker white_list = [ 64*49cdfc7eSAndroid Build Coastguard Worker 'rt_sigpending', 65*49cdfc7eSAndroid Build Coastguard Worker 'sethostname', 66*49cdfc7eSAndroid Build Coastguard Worker 'lsetxattr', 67*49cdfc7eSAndroid Build Coastguard Worker 'inotify_add_watch', 68*49cdfc7eSAndroid Build Coastguard Worker 'inotify_rm_watch', 69*49cdfc7eSAndroid Build Coastguard Worker 'newfstatat', 70*49cdfc7eSAndroid Build Coastguard Worker 'pselect6', 71*49cdfc7eSAndroid Build Coastguard Worker 'fanotify_init', 72*49cdfc7eSAndroid Build Coastguard Worker 'fanotify_mark', 73*49cdfc7eSAndroid Build Coastguard Worker 'prlimit64', 74*49cdfc7eSAndroid Build Coastguard Worker 'getdents64', 75*49cdfc7eSAndroid Build Coastguard Worker 'pkey_mprotect', 76*49cdfc7eSAndroid Build Coastguard Worker 'pkey_alloc', 77*49cdfc7eSAndroid Build Coastguard Worker 'pkey_free', 78*49cdfc7eSAndroid Build Coastguard Worker 'io_uring_setup', 79*49cdfc7eSAndroid Build Coastguard Worker 'io_uring_enter', 80*49cdfc7eSAndroid Build Coastguard Worker 'io_uring_register', 81*49cdfc7eSAndroid Build Coastguard Worker 'epoll_pwait2', 82*49cdfc7eSAndroid Build Coastguard Worker 'quotactl_fd', 83*49cdfc7eSAndroid Build Coastguard Worker 'pread64', 84*49cdfc7eSAndroid Build Coastguard Worker 'pwrite64', 85*49cdfc7eSAndroid Build Coastguard Worker 'fadvise64', 86*49cdfc7eSAndroid Build Coastguard Worker 'getmsg', 87*49cdfc7eSAndroid Build Coastguard Worker 'getpmsg', 88*49cdfc7eSAndroid Build Coastguard Worker 'putmsg', 89*49cdfc7eSAndroid Build Coastguard Worker 'putpmsg', 90*49cdfc7eSAndroid Build Coastguard Worker ] 91*49cdfc7eSAndroid Build Coastguard Worker 92*49cdfc7eSAndroid Build Coastguard Worker # populate with not implemented, reserved, unmaintained syscalls defined 93*49cdfc7eSAndroid Build Coastguard Worker # inside the syscalls file 94*49cdfc7eSAndroid Build Coastguard Worker black_list = [ 95*49cdfc7eSAndroid Build Coastguard Worker 'reserved177', 96*49cdfc7eSAndroid Build Coastguard Worker 'reserved193', 97*49cdfc7eSAndroid Build Coastguard Worker 'rseq', 98*49cdfc7eSAndroid Build Coastguard Worker '_newselect', 99*49cdfc7eSAndroid Build Coastguard Worker '_sysctl', 100*49cdfc7eSAndroid Build Coastguard Worker 'create_module', 101*49cdfc7eSAndroid Build Coastguard Worker 'get_kernel_syms', 102*49cdfc7eSAndroid Build Coastguard Worker 'query_module', 103*49cdfc7eSAndroid Build Coastguard Worker 'nfsservctl', 104*49cdfc7eSAndroid Build Coastguard Worker 'afs_syscall', 105*49cdfc7eSAndroid Build Coastguard Worker 'sysmips', 106*49cdfc7eSAndroid Build Coastguard Worker 'mq_getsetattr', 107*49cdfc7eSAndroid Build Coastguard Worker 'vserver', 108*49cdfc7eSAndroid Build Coastguard Worker ] 109*49cdfc7eSAndroid Build Coastguard Worker 110*49cdfc7eSAndroid Build Coastguard Worker # fetch syscalls file 111*49cdfc7eSAndroid Build Coastguard Worker error = False 112*49cdfc7eSAndroid Build Coastguard Worker try: 113*49cdfc7eSAndroid Build Coastguard Worker socket.setdefaulttimeout(3) 114*49cdfc7eSAndroid Build Coastguard Worker urllib.request.urlretrieve( 115*49cdfc7eSAndroid Build Coastguard Worker "https://raw.githubusercontent.com/torvalds/linux/master/arch/mips/kernel/syscalls/syscall_n64.tbl", 116*49cdfc7eSAndroid Build Coastguard Worker "syscalls.tbl") 117*49cdfc7eSAndroid Build Coastguard Worker except Exception as err: 118*49cdfc7eSAndroid Build Coastguard Worker error = True 119*49cdfc7eSAndroid Build Coastguard Worker logger = sphinx.util.logging.getLogger(__name__) 120*49cdfc7eSAndroid Build Coastguard Worker msg = "Can't download syscall_n64.tbl from kernel sources" 121*49cdfc7eSAndroid Build Coastguard Worker logger.warning(msg) 122*49cdfc7eSAndroid Build Coastguard Worker 123*49cdfc7eSAndroid Build Coastguard Worker with open(output, 'w+') as stats: 124*49cdfc7eSAndroid Build Coastguard Worker stats.write(f".. warning::\n\n {msg}") 125*49cdfc7eSAndroid Build Coastguard Worker 126*49cdfc7eSAndroid Build Coastguard Worker if error: 127*49cdfc7eSAndroid Build Coastguard Worker return 128*49cdfc7eSAndroid Build Coastguard Worker 129*49cdfc7eSAndroid Build Coastguard Worker text = [ 130*49cdfc7eSAndroid Build Coastguard Worker 'Syscalls\n', 131*49cdfc7eSAndroid Build Coastguard Worker '--------\n\n', 132*49cdfc7eSAndroid Build Coastguard Worker ] 133*49cdfc7eSAndroid Build Coastguard Worker 134*49cdfc7eSAndroid Build Coastguard Worker # collect all available kernel syscalls 135*49cdfc7eSAndroid Build Coastguard Worker regexp = re.compile(r'\d+\s+n64\s+(?P<syscall>\w+)\s+\w+') 136*49cdfc7eSAndroid Build Coastguard Worker ker_syscalls = [] 137*49cdfc7eSAndroid Build Coastguard Worker with open("syscalls.tbl", 'r') as data: 138*49cdfc7eSAndroid Build Coastguard Worker for line in data: 139*49cdfc7eSAndroid Build Coastguard Worker match = regexp.search(line) 140*49cdfc7eSAndroid Build Coastguard Worker if match: 141*49cdfc7eSAndroid Build Coastguard Worker ker_syscalls.append(match.group('syscall')) 142*49cdfc7eSAndroid Build Coastguard Worker 143*49cdfc7eSAndroid Build Coastguard Worker # collect all LTP tested syscalls 144*49cdfc7eSAndroid Build Coastguard Worker ltp_syscalls = [] 145*49cdfc7eSAndroid Build Coastguard Worker for root, _, files in os.walk('../testcases/kernel/syscalls'): 146*49cdfc7eSAndroid Build Coastguard Worker for myfile in files: 147*49cdfc7eSAndroid Build Coastguard Worker if myfile.endswith('.c'): 148*49cdfc7eSAndroid Build Coastguard Worker ltp_syscalls.append(myfile) 149*49cdfc7eSAndroid Build Coastguard Worker 150*49cdfc7eSAndroid Build Coastguard Worker # compare kernel syscalls with LTP tested syscalls 151*49cdfc7eSAndroid Build Coastguard Worker syscalls = {} 152*49cdfc7eSAndroid Build Coastguard Worker for kersc in ker_syscalls: 153*49cdfc7eSAndroid Build Coastguard Worker if kersc in black_list: 154*49cdfc7eSAndroid Build Coastguard Worker continue 155*49cdfc7eSAndroid Build Coastguard Worker 156*49cdfc7eSAndroid Build Coastguard Worker if kersc not in syscalls: 157*49cdfc7eSAndroid Build Coastguard Worker if kersc in white_list: 158*49cdfc7eSAndroid Build Coastguard Worker syscalls[kersc] = True 159*49cdfc7eSAndroid Build Coastguard Worker continue 160*49cdfc7eSAndroid Build Coastguard Worker 161*49cdfc7eSAndroid Build Coastguard Worker syscalls[kersc] = False 162*49cdfc7eSAndroid Build Coastguard Worker 163*49cdfc7eSAndroid Build Coastguard Worker for ltpsc in ltp_syscalls: 164*49cdfc7eSAndroid Build Coastguard Worker if ltpsc.startswith(kersc): 165*49cdfc7eSAndroid Build Coastguard Worker syscalls[kersc] = True 166*49cdfc7eSAndroid Build Coastguard Worker 167*49cdfc7eSAndroid Build Coastguard Worker # generate the statistics file 168*49cdfc7eSAndroid Build Coastguard Worker tested_syscalls = [key for key, val in syscalls.items() if val] 169*49cdfc7eSAndroid Build Coastguard Worker text.append('syscalls which are tested under :master:`testcases/kernel/syscalls`:\n\n') 170*49cdfc7eSAndroid Build Coastguard Worker text.append(f'* kernel syscalls: {len(ker_syscalls)}\n') 171*49cdfc7eSAndroid Build Coastguard Worker text.append(f'* tested syscalls: {len(tested_syscalls)}\n\n') 172*49cdfc7eSAndroid Build Coastguard Worker 173*49cdfc7eSAndroid Build Coastguard Worker # create tested/untested syscalls table 174*49cdfc7eSAndroid Build Coastguard Worker index_tested = 0 175*49cdfc7eSAndroid Build Coastguard Worker table_tested = [ 176*49cdfc7eSAndroid Build Coastguard Worker 'Tested syscalls\n', 177*49cdfc7eSAndroid Build Coastguard Worker '~~~~~~~~~~~~~~~\n\n', 178*49cdfc7eSAndroid Build Coastguard Worker '.. list-table::\n', 179*49cdfc7eSAndroid Build Coastguard Worker ' :header-rows: 0\n\n', 180*49cdfc7eSAndroid Build Coastguard Worker ] 181*49cdfc7eSAndroid Build Coastguard Worker 182*49cdfc7eSAndroid Build Coastguard Worker index_untest = 0 183*49cdfc7eSAndroid Build Coastguard Worker table_untest = [ 184*49cdfc7eSAndroid Build Coastguard Worker 'Untested syscalls\n', 185*49cdfc7eSAndroid Build Coastguard Worker '~~~~~~~~~~~~~~~~~\n\n', 186*49cdfc7eSAndroid Build Coastguard Worker '.. list-table::\n', 187*49cdfc7eSAndroid Build Coastguard Worker ' :header-rows: 0\n\n', 188*49cdfc7eSAndroid Build Coastguard Worker ] 189*49cdfc7eSAndroid Build Coastguard Worker 190*49cdfc7eSAndroid Build Coastguard Worker for sysname, tested in syscalls.items(): 191*49cdfc7eSAndroid Build Coastguard Worker if tested: 192*49cdfc7eSAndroid Build Coastguard Worker if (index_tested % 3) == 0: 193*49cdfc7eSAndroid Build Coastguard Worker table_tested.append(f' * - {sysname}\n') 194*49cdfc7eSAndroid Build Coastguard Worker else: 195*49cdfc7eSAndroid Build Coastguard Worker table_tested.append(f' - {sysname}\n') 196*49cdfc7eSAndroid Build Coastguard Worker 197*49cdfc7eSAndroid Build Coastguard Worker index_tested += 1 198*49cdfc7eSAndroid Build Coastguard Worker else: 199*49cdfc7eSAndroid Build Coastguard Worker if (index_untest % 3) == 0: 200*49cdfc7eSAndroid Build Coastguard Worker table_untest.append(f' * - {sysname}\n') 201*49cdfc7eSAndroid Build Coastguard Worker else: 202*49cdfc7eSAndroid Build Coastguard Worker table_untest.append(f' - {sysname}\n') 203*49cdfc7eSAndroid Build Coastguard Worker 204*49cdfc7eSAndroid Build Coastguard Worker index_untest += 1 205*49cdfc7eSAndroid Build Coastguard Worker 206*49cdfc7eSAndroid Build Coastguard Worker left = index_tested % 3 207*49cdfc7eSAndroid Build Coastguard Worker if left > 0: 208*49cdfc7eSAndroid Build Coastguard Worker for index in range(0, 3 - left): 209*49cdfc7eSAndroid Build Coastguard Worker table_tested.append(f' -\n') 210*49cdfc7eSAndroid Build Coastguard Worker 211*49cdfc7eSAndroid Build Coastguard Worker left = index_untest % 3 212*49cdfc7eSAndroid Build Coastguard Worker if left > 0: 213*49cdfc7eSAndroid Build Coastguard Worker for index in range(0, 3 - left): 214*49cdfc7eSAndroid Build Coastguard Worker table_untest.append(f' -\n') 215*49cdfc7eSAndroid Build Coastguard Worker 216*49cdfc7eSAndroid Build Coastguard Worker text.extend(table_tested) 217*49cdfc7eSAndroid Build Coastguard Worker text.append('\n') 218*49cdfc7eSAndroid Build Coastguard Worker text.extend(table_untest) 219*49cdfc7eSAndroid Build Coastguard Worker 220*49cdfc7eSAndroid Build Coastguard Worker # write the file 221*49cdfc7eSAndroid Build Coastguard Worker with open(output, 'w+') as stats: 222*49cdfc7eSAndroid Build Coastguard Worker stats.writelines(text) 223*49cdfc7eSAndroid Build Coastguard Worker 224*49cdfc7eSAndroid Build Coastguard Worker 225*49cdfc7eSAndroid Build Coastguard Workerdef setup(app): 226*49cdfc7eSAndroid Build Coastguard Worker app.add_css_file('custom.css') 227*49cdfc7eSAndroid Build Coastguard Worker app.connect('builder-inited', generate_syscalls_stats) 228