xref: /aosp_15_r20/external/ltp/include/tst_checkpoint.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2016 Cyril Hrubis <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /**
7*49cdfc7eSAndroid Build Coastguard Worker  * DOC: Checkpoints introduction
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * Checkpoints implements a futex based synchronization primitive for threads
10*49cdfc7eSAndroid Build Coastguard Worker  * and processes. When a process calls wait function its execution is suspended
11*49cdfc7eSAndroid Build Coastguard Worker  * until wake is called for a corresponding checkpoint. Checkpoints are
12*49cdfc7eSAndroid Build Coastguard Worker  * numbered from 0 and process can use at least hundred of them.
13*49cdfc7eSAndroid Build Coastguard Worker  *
14*49cdfc7eSAndroid Build Coastguard Worker  * In order to use checkpoints the test must set the tst_test.needs_checkpoints
15*49cdfc7eSAndroid Build Coastguard Worker  * flag.
16*49cdfc7eSAndroid Build Coastguard Worker  */
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_CHECKPOINT__
19*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT__
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker #include "tst_checkpoint_fn.h"
22*49cdfc7eSAndroid Build Coastguard Worker 
23*49cdfc7eSAndroid Build Coastguard Worker /**
24*49cdfc7eSAndroid Build Coastguard Worker  * TST_CHECKPOINT_WAIT() - Waits for a checkpoint.
25*49cdfc7eSAndroid Build Coastguard Worker  *
26*49cdfc7eSAndroid Build Coastguard Worker  * @id: A checkpoint id a positive integer.
27*49cdfc7eSAndroid Build Coastguard Worker  *
28*49cdfc7eSAndroid Build Coastguard Worker  * Suspends thread/process execution until it's woken up with a wake. The call
29*49cdfc7eSAndroid Build Coastguard Worker  * does not wait indefinitely it gives up after 10 seconds. If an error
30*49cdfc7eSAndroid Build Coastguard Worker  * happened or timeout was reached the function calls tst_brk(TBROK, ...) which
31*49cdfc7eSAndroid Build Coastguard Worker  * exits the test.
32*49cdfc7eSAndroid Build Coastguard Worker  */
33*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT_WAIT(id) \
34*49cdfc7eSAndroid Build Coastguard Worker         tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0)
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker /**
37*49cdfc7eSAndroid Build Coastguard Worker  * TST_CHECKPOINT_WAIT2() - Waits for a checkpoint.
38*49cdfc7eSAndroid Build Coastguard Worker  *
39*49cdfc7eSAndroid Build Coastguard Worker  * @id: A checkpoint id a positive integer.
40*49cdfc7eSAndroid Build Coastguard Worker  * @msec_timeout: A timeout.
41*49cdfc7eSAndroid Build Coastguard Worker  *
42*49cdfc7eSAndroid Build Coastguard Worker  * Suspends thread/process execution until it's woken up with a wake. If an
43*49cdfc7eSAndroid Build Coastguard Worker  * error happened or timeout was reached the function calls tst_brk(TBROK, ...)
44*49cdfc7eSAndroid Build Coastguard Worker  * which exits the test.
45*49cdfc7eSAndroid Build Coastguard Worker  */
46*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT_WAIT2(id, msec_timeout) \
47*49cdfc7eSAndroid Build Coastguard Worker         tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, msec_timeout)
48*49cdfc7eSAndroid Build Coastguard Worker 
49*49cdfc7eSAndroid Build Coastguard Worker /**
50*49cdfc7eSAndroid Build Coastguard Worker  * TST_CHECKPOINT_WAKE() - Wakes up a checkpoint.
51*49cdfc7eSAndroid Build Coastguard Worker  *
52*49cdfc7eSAndroid Build Coastguard Worker  * @id: A checkpoint id a positive integer.
53*49cdfc7eSAndroid Build Coastguard Worker  *
54*49cdfc7eSAndroid Build Coastguard Worker  * Wakes up a process suspended on a checkpoint and retries if there is no
55*49cdfc7eSAndroid Build Coastguard Worker  * process suspended on the checkpoint yet. The call does not retry
56*49cdfc7eSAndroid Build Coastguard Worker  * indefinitely but gives up after 10 seconds. If an error happened or timeout
57*49cdfc7eSAndroid Build Coastguard Worker  * was reached the function calls tst_brk(TBROK, ...) which exits the test.
58*49cdfc7eSAndroid Build Coastguard Worker  */
59*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT_WAKE(id) \
60*49cdfc7eSAndroid Build Coastguard Worker         tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1)
61*49cdfc7eSAndroid Build Coastguard Worker 
62*49cdfc7eSAndroid Build Coastguard Worker /**
63*49cdfc7eSAndroid Build Coastguard Worker  * TST_CHECKPOINT_WAKE2() - Wakes up several checkpoints.
64*49cdfc7eSAndroid Build Coastguard Worker  *
65*49cdfc7eSAndroid Build Coastguard Worker  * @id: A checkpoint id a positive integer.
66*49cdfc7eSAndroid Build Coastguard Worker  * @nr_wake: A number of processes to wake.
67*49cdfc7eSAndroid Build Coastguard Worker  *
68*49cdfc7eSAndroid Build Coastguard Worker  * Wakes up nr_wake processes suspended on a checkpoint and retries if there
69*49cdfc7eSAndroid Build Coastguard Worker  * wasn't enough process suspended on the checkpoint yet. The call does not
70*49cdfc7eSAndroid Build Coastguard Worker  * retry indefinitely but gives up if it does not wake nr_wake processes after
71*49cdfc7eSAndroid Build Coastguard Worker  * 10 seconds. If an error happened or timeout was reached the function calls
72*49cdfc7eSAndroid Build Coastguard Worker  * tst_brk(TBROK, ...) which exits the test.
73*49cdfc7eSAndroid Build Coastguard Worker  */
74*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT_WAKE2(id, nr_wake) \
75*49cdfc7eSAndroid Build Coastguard Worker         tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, nr_wake)
76*49cdfc7eSAndroid Build Coastguard Worker 
77*49cdfc7eSAndroid Build Coastguard Worker /**
78*49cdfc7eSAndroid Build Coastguard Worker  * TST_CHECKPOINT_WAKE_AND_WAIT() - Wakes up a checkpoint and immediately waits on it.
79*49cdfc7eSAndroid Build Coastguard Worker  *
80*49cdfc7eSAndroid Build Coastguard Worker  * @id: A checkpoint id a positive integer.
81*49cdfc7eSAndroid Build Coastguard Worker  *
82*49cdfc7eSAndroid Build Coastguard Worker  * This is a combination of TST_CHECKPOINT_WAKE() and TST_CHECKPOINT_WAIT().
83*49cdfc7eSAndroid Build Coastguard Worker  */
84*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT_WAKE_AND_WAIT(id) do { \
85*49cdfc7eSAndroid Build Coastguard Worker         tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1); \
86*49cdfc7eSAndroid Build Coastguard Worker         tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0); \
87*49cdfc7eSAndroid Build Coastguard Worker } while (0)
88*49cdfc7eSAndroid Build Coastguard Worker 
89*49cdfc7eSAndroid Build Coastguard Worker extern const char *tst_ipc_path;
90*49cdfc7eSAndroid Build Coastguard Worker 
91*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_CHECKPOINT__ */
92