Debian Codegraph @

dirsrvtests/tests/suites/threads/thread_naming_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2026 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import logging
10 import os
11 import platform
12 import pytest
13
14 from lib389 import pid_from_file
15 from test389.topologies import topology_st
16
17 pytestmark = pytest.mark.tier1
18
19 logging.getLogger(__name__).setLevel(logging.INFO)
20 log = logging.getLogger(__name__)
21
22
23 def _get_thread_names(pid):
24 """Read thread names from /proc/<pid>/task/*/comm"""
25 names = []
26 task_dir = f"/proc/{pid}/task"
27 if not os.path.isdir(task_dir):
28 pytest.skip(f"{task_dir} not available")
29 for tid in os.listdir(task_dir):
30 comm_path = os.path.join(task_dir, tid, "comm")
31 try:
32 with open(comm_path, "r") as f:
33 names.append(f.read().strip())
34 except (FileNotFoundError, PermissionError):
35 pass
36 return names
37
38
39 def test_thread_names_present(topology_st):
40 """Test that key threads have been named via pthread_setname_np
41
42 :id: a95b4eca-e806-48dc-8c91-debbc3ef4053
43 :setup: Standalone instance
44 :steps:
45 1. Get the server PID
46 2. Read thread names from /proc/{pid}/task/{tid}/comm
47 3. Verify expected thread names are present
48 :expectedresults:
49 1. PID is obtained
50 2. Thread names are readable
51 3. Core thread names (listener, worker, ct-list, event-q,
52 housekeep) are found
53 """
54 inst = topology_st.standalone
55 pid = str(pid_from_file(inst.ds_paths.pid_file))
56 log.info(f"Server PID: {pid}")
57
58 thread_names = _get_thread_names(pid)
59 log.info(f"Found {len(thread_names)} threads: {sorted(set(thread_names))}")
60
61 # Verify the listener thread
62 assert "listener" in thread_names, \
63 f"'listener' thread not found in {thread_names}"
64
65 # Verify at least one worker thread
66 worker_threads = [n for n in thread_names if n.startswith("worker-")]
67 assert len(worker_threads) > 0, \
68 f"No 'worker-*' threads found in {thread_names}"
69
70 # Verify at least one connection table list thread
71 ct_threads = [n for n in thread_names if n.startswith("ct-list-")]
72 assert len(ct_threads) > 0, \
73 f"No 'ct-list-*' threads found in {thread_names}"
74
75 # Verify event queue thread
76 assert "event-q" in thread_names, \
77 f"'event-q' thread not found in {thread_names}"
78
79 # Verify housekeeping thread
80 assert "housekeep" in thread_names, \
81 f"'housekeep' thread not found in {thread_names}"