• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz
3  * Copyright (C) 2021 Xie Ziyao <xieziyao@huawei.com>
4  */
5 
6 /*
7  * These functions helps you wait till a process with given pid changes state.
8  * This is for example useful when you need to wait in parent until child blocks.
9  */
10 
11 #ifndef TST_PROCESS_STATE__
12 #define TST_PROCESS_STATE__
13 
14 #include <unistd.h>
15 
16 #ifdef TST_TEST_H__
17 
18 /*
19  * Waits for process state change.
20  *
21  * The state is one of the following:
22  *
23  * R - process is running
24  * S - process is sleeping
25  * D - process sleeping uninterruptibly
26  * Z - zombie process
27  * T - process is traced
28  */
29 #define TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) \
30 	tst_process_state_wait(__FILE__, __LINE__, NULL, \
31 			(pid), (state), (msec_timeout))
32 
33 /*
34  * Check that a given pid is present on the system
35  */
36 #define TST_PROCESS_EXIT_WAIT(pid, msec_timeout) \
37 	tst_process_exit_wait((pid), (msec_timeout))
38 
39 /*
40  * Waits for thread state change.
41  *
42  * The state is one of the following:
43  *
44  * R - running
45  * S - sleeping
46  * D - disk sleep
47  * T - stopped
48  * t - tracing stopped
49  * Z - zombie
50  * X - dead
51  */
52 #define TST_THREAD_STATE_WAIT(tid, state, msec_timeout) \
53 	tst_thread_state_wait((tid), (state), (msec_timeout))
54 
55 int tst_thread_state_wait(pid_t tid, const char state,
56 				unsigned int msec_timeout);
57 
58 #else
59 /*
60  * The same as above but does not use tst_brkm() interface.
61  *
62  * This function is intended to be used from child processes.
63  *
64  * Returns zero on success, non-zero on failure.
65  */
66 int tst_process_state_wait2(pid_t pid, const char state);
67 
68 #define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \
69 	tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \
70 			(pid), (state), 0)
71 #endif
72 
73 int tst_process_state_wait(const char *file, const int lineno,
74 			   void (*cleanup_fn)(void), pid_t pid,
75 			   const char state, unsigned int msec_timeout);
76 int tst_process_exit_wait(pid_t pid, unsigned int msec_timeout);
77 
78 #endif /* TST_PROCESS_STATE__ */
79