Shell wrappers for the checkpoint interface
PATCH 1/1 Shell wrappers for the checkpoint interface
This patch provides necessary wrappers to use the checkpoint API in shell tests.
Big thanks to Cyril and Jan for their comments to the RFC versions.
---
Changes since RFC:
* Single tst_checkpoint binary instead of tst_checkpoint_{wait,wake}
* Changed the order of arguments passed to the binary
* The 'wake' command of the binary requires NR_WAKE paramater.
* Implement wrappers to all TST_CHECKPOINT_ functions
* Use TCID in LTP_IPC_PATH
* Add docs. Noted that the shell functions are compatible to C counterparts (initialized with tst_reinit).
doc/test-writing-guidelines.txt | 23 ++++++++- testcases/lib/.gitignore | 1 + testcases/lib/Makefile | 6 +- testcases/lib/test.sh | 38 +++++++++++++++ testcases/lib/tst_checkpoint.c | 101 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 testcases/lib/tst_checkpoint.c
doc/test-writing-guidelines.txt +22 -1
@@ -583,7 +583,7 @@ As LTP tests are written for Linux, most of the tests involve fork()-ing and parent-child process synchronization. LTP includes a checkpoint library that provides wait/wake futex based functions. -In order to use checkpoints the '.need_chekcpoints' flag in the 'struct +In order to use checkpoints the '.needs_checkpoints' flag in the 'struct tst_test' must be set to '1', this causes the test library to initialize checkpoints before the 'test()' function is called.
@@ -1400,6 +1400,27 @@ else fi ------------------------------------------------------------------------------- +2.3.6 Access to the checkpoint interface +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The shell library provides an implementation of the checkpoint interface +compatible with the C version. All TST_CHECKPOINT_* functions are available. + +In order to initialize checkpoints '$TST_NEEDS_CHECKPOINTS' must be set to '1' +before the inclusion of 'test.sh': + +[source,sh] +------------------------------------------------------------------------------- +#!/bin/sh + +TST_NEEDS_CHECKPOINTS=1 +. test.sh +------------------------------------------------------------------------------- + +Since both the implementations are compatible, it's also possible to start +a child binary process from a shell test and synchronize with it. This process +must have checkpoints initialized by calling tst_reinit()'. + 3. Common problems ------------------
testcases/lib/.gitignore +1 -0
@@ -1 +1,2 @@ tst_sleep +tst_checkpoint
testcases/lib/Makefile +3 -3
@@ -22,10 +22,10 @@ top_srcdir ?= ../.. -include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/testcases.mk -INSTALL_TARGETS := *.sh tst_sleep +INSTALL_TARGETS := *.sh -MAKE_TARGETS := tst_sleep +MAKE_TARGETS := tst_sleep tst_checkpoint include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/lib/test.sh +38 -0
@@ -100,6 +100,10 @@ tst_exit() $TST_CLEANUP fi + if [ -n "$LTP_IPC_PATH" -a -f "$LTP_IPC_PATH" ]; then + rm -f "$LTP_IPC_PATH" + fi + # Mask out TINFO exit $((LTP_RET_VAL & ~16)) }
@@ -383,6 +387,27 @@ tst_su() su "$usr" -c "PATH=\$PATH:$LTPROOT/testcases/bin/ $@" } +TST_CHECKPOINT_WAIT() +{ + ROD tst_checkpoint wait 10000 "$1" +} + +TST_CHECKPOINT_WAKE() +{ + ROD tst_checkpoint wake 10000 "$1" 1 +} + +TST_CHECKPOINT_WAKE2() +{ + ROD tst_checkpoint wake 10000 "$1" "$2" +} + +TST_CHECKPOINT_WAKE_AND_WAIT() +{ + TST_CHECKPOINT_WAKE + TST_CHECKPOINT_WAIT +} + # Check that test name is set if [ -z "$TCID" ]; then tst_brkm TBROK "TCID is not defined"
@@ -402,3 +427,16 @@ if [ -z "$LTPROOT" ]; then else export LTP_DATAROOT="$LTPROOT/testcases/data/$TCID" fi + +if [ "$TST_NEEDS_CHECKPOINTS" = "1" ]; then + LTP_IPC_PATH="/dev/shm/ltp_${TCID}_$$" + + LTP_IPC_SIZE=$(getconf PAGESIZE) + if [ $? -ne 0 ]; then + tst_brkm TBROK "getconf PAGESIZE failed" + fi + + ROD_SILENT dd if=/dev/zero of="$LTP_IPC_PATH" bs="$LTP_IPC_SIZE" count=1 + ROD_SILENT chmod 600 "$LTP_IPC_PATH" + export LTP_IPC_PATH +fi
testcases/lib/tst_checkpoint.c new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 1/1 Shell wrappers for the checkpoint interface
Hi!
testcases/lib/tst_checkpoint.c line 91
Quoted 4 lines
testcases/lib/tst_checkpoint.c new file +4
-0+if (!type) + ret =tst_checkpoint_wait (id, timeout); +else + ret =tst_checkpoint_wake (id, nr_wake, timeout);
I find it silly that you do negate the flag here. You could have set it the other way, or swap the wait and wake in the if and else branch...
Anyway the rest looks good to me, ackend.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 Shell wrappers for the checkpoint interface
Hi!
Quoted 8 lines · Cyril Hrubis
Hi!
testcases/lib/tst_checkpoint.c line 91
Quoted 4 lines
testcases/lib/tst_checkpoint.c new file +4
-0+if (!type) + ret =tst_checkpoint_wait (id, timeout); +else + ret =tst_checkpoint_wake (id, nr_wake, timeout);I find it silly that you do negate the flag here. You could have set it the other way, or swap the wait and wake in the if and else branch...
I swapped the wait and wake and pushed it.
Thanks!
Quoted 3 lines
Anyway the rest looks good to me, ackend.