[LTP] [COMMITTED] [PATCH] checkpoints: Add TST_SAFE_CHECKPOINT_WAIT2()
Cyril Hrubis
chrubis@suse.cz
Mon Feb 13 15:07:30 CET 2017
The new macro allows user to pass timeout parameter as well.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Acked-by: Jan Stancek <jstancek@redhat.com>
---
doc/test-writing-guidelines.txt | 6 ++++--
include/old/old_checkpoint.h | 7 +++++--
include/tst_checkpoint.h | 7 +++++--
include/tst_checkpoint_fn.h | 3 ++-
lib/tst_checkpoint.c | 12 +++++++++---
5 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index ee9e08e..41cee58 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -689,6 +689,8 @@ checkpoints before the 'test()' function is called.
TST_CHECKPOINT_WAIT(id)
+TST_CHECKPOINT_WAIT2(id, msec_timeout)
+
TST_CHECKPOINT_WAKE(id)
TST_CHECKPOINT_WAKE2(id, nr_wake)
@@ -701,8 +703,8 @@ unsigned integer which specifies checkpoint to wake/wait for. As a matter of
fact it's an index to an array stored in a shared memory, so it starts on
'0' and there should be enough room for at least of hundred of them.
-The 'TST_CHECKPOINT_WAIT()' suspends process execution until it's woken
-up or until timeout is reached.
+The 'TST_CHECKPOINT_WAIT()' and 'TST_CHECKPOINT_WAIT2()' suspends process
+execution until it's woken up or until timeout is reached.
The 'TST_CHECKPOINT_WAKE()' wakes one process waiting on the checkpoint.
If no process is waiting the function retries until it success or until
diff --git a/include/old/old_checkpoint.h b/include/old/old_checkpoint.h
index 37bdf92..c8ffc92 100644
--- a/include/old/old_checkpoint.h
+++ b/include/old/old_checkpoint.h
@@ -41,7 +41,10 @@
tst_checkpoint_init(__FILE__, __LINE__, cleanup_fn)
#define TST_SAFE_CHECKPOINT_WAIT(cleanup_fn, id) \
- tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id);
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0);
+
+#define TST_SAFE_CHECKPOINT_WAIT2(cleanup_fn, id, msec_timeout) \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, msec_timeout);
#define TST_SAFE_CHECKPOINT_WAKE(cleanup_fn, id) \
tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, 1);
@@ -51,6 +54,6 @@
#define TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup_fn, id) \
tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, 1); \
- tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id);
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0);
#endif /* OLD_CHECKPOINT__ */
diff --git a/include/tst_checkpoint.h b/include/tst_checkpoint.h
index ae5a68b..fdce2d6 100644
--- a/include/tst_checkpoint.h
+++ b/include/tst_checkpoint.h
@@ -21,7 +21,10 @@
#include "tst_checkpoint_fn.h"
#define TST_CHECKPOINT_WAIT(id) \
- tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id);
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
+
+#define TST_CHECKPOINT_WAIT2(id, msec_timeout) \
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, msec_timeout);
#define TST_CHECKPOINT_WAKE(id) \
tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1);
@@ -31,7 +34,7 @@
#define TST_CHECKPOINT_WAKE_AND_WAIT(id) \
tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1); \
- tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id);
+ tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
extern const char *tst_ipc_path;
extern char *const tst_ipc_envp[];
diff --git a/include/tst_checkpoint_fn.h b/include/tst_checkpoint_fn.h
index ebfd22b..0730fb0 100644
--- a/include/tst_checkpoint_fn.h
+++ b/include/tst_checkpoint_fn.h
@@ -45,7 +45,8 @@ int tst_checkpoint_wake(unsigned int id, unsigned int nr_wake,
unsigned int msec_timeout);
void tst_safe_checkpoint_wait(const char *file, const int lineno,
- void (*cleanup_fn)(void), unsigned int id);
+ void (*cleanup_fn)(void), unsigned int id,
+ unsigned int msec_timeout);
void tst_safe_checkpoint_wake(const char *file, const int lineno,
void (*cleanup_fn)(void), unsigned int id,
diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c
index 5d12ac9..a23bd02 100644
--- a/lib/tst_checkpoint.c
+++ b/lib/tst_checkpoint.c
@@ -126,14 +126,20 @@ int tst_checkpoint_wake(unsigned int id, unsigned int nr_wake,
}
void tst_safe_checkpoint_wait(const char *file, const int lineno,
- void (*cleanup_fn)(void), unsigned int id)
+ void (*cleanup_fn)(void), unsigned int id,
+ unsigned int msec_timeout)
{
- int ret = tst_checkpoint_wait(id, DEFAULT_MSEC_TIMEOUT);
+ int ret;
+
+ if (!msec_timeout)
+ msec_timeout = DEFAULT_MSEC_TIMEOUT;
+
+ ret = tst_checkpoint_wait(id, msec_timeout);
if (ret) {
tst_brkm(TBROK | TERRNO, cleanup_fn,
"%s:%d: tst_checkpoint_wait(%u, %i)",
- file, lineno, id, DEFAULT_MSEC_TIMEOUT);
+ file, lineno, id, msec_timeout);
}
}
--
2.10.2
More information about the ltp
mailing list