Skip to contentSkip to conversation

shell wrappers for tst_checkpoint

RFC New Stanislav Kholmanskikh 3 participants 9 messages Jun 1, 2016 – Jun 6, 2016

lore
Share & tools
lore
#0 lore raw

Hi!

There is a need to use the tst_checkpoint interface from shell, but we don't have wrappers for it (yet).

Patch 1 of the series contains one possible implementation for that, patch 2 - an example of usage in the context of the memcg_functional test case.

I'd like to get some feedback from LTP users.

My primary concern is about two issues:

1. The new test API for C is cool and takes the responsibility on maintaining the infrastructure for tst_checkpoint. However, I couldn't find a way to implement something similar in shell, so I switched back to using two separate functions for that - TST_CHECKPOINT_SETUP, TST_CHECKPOINT_CLEANUP.

There may be a better way...

2. What is the best location for the new supplemental binaries (tst_checkpoint_wait, tst_checkpoint_wake)? tools/apicmds/ltpapicmd.c or separate source files in testcases/lib/ (similar to tst_sleep)?

Thanks.

#1 lore raw

RFC PATCH 1/2 a draft for tst_checkpoint shell wrappers

---
 testcases/lib/test.sh     |   33 ++++++++++++++++++++++++++++++++
 tools/apicmds/.gitignore  |    2 +
 tools/apicmds/Makefile    |    3 +-
 tools/apicmds/ltpapicmd.c |   46 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 1 deletions(-)
testcases/lib/test.sh +33 -0
index 70345e5..33af37d 100644
@@ -374,6 +374,39 @@ tst_module_exists()
 	tst_brkm TCONF "Failed to find module '$mod_name'"
 }
 
+TST_CHECKPOINT_SETUP()
+{
+	local size
+
+	LTP_IPC_PATH="/dev/shm/ltp_$$"
+
+	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="$size" count=1
+	ROD_SILENT chmod 600 "$LTP_IPC_PATH"
+	export LTP_IPC_PATH
+}
+
+TST_CHECKPOINT_CLEANUP()
+{
+	if [ -n "$LTP_IPC_PATH" -a -f "$LTP_IPC_PATH" ]; then
+		rm -f "$LTP_IPC_PATH"
+	fi
+}
+
+TST_CHECKPOINT_WAIT()
+{
+	ROD tst_checkpoint_wait "$1" 10000
+}
+
+TST_CHECKPOINT_WAKE()
+{
+	ROD tst_checkpoint_wake "$1" 10000
+}
+
 # Check that test name is set
 if [ -z "$TCID" ]; then
 	tst_brkm TBROK "TCID is not defined"
tools/apicmds/.gitignore +2 -0
index b4f7922..de5fd4f 100644
@@ -11,3 +11,5 @@ tst_ncpus_max
 tst_res
 tst_resm
 tst_fs_has_free
+tst_checkpoint_wait
+tst_checkpoint_wake
tools/apicmds/Makefile +2 -1
index 9c9472d..90e776a 100644
@@ -28,7 +28,8 @@ CPPFLAGS		+= -D_GNU_SOURCE
 
 MAKE_TARGETS		:= $(addprefix tst_,brk brkm exit flush kvercmp \
 			     kvercmp2 res resm ncpus ncpus_conf ncpus_max \
-			     get_unused_port fs_has_free)
+			     get_unused_port fs_has_free \
+			     checkpoint_wait checkpoint_wake)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
 
tools/apicmds/ltpapicmd.c +46 -0

70 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

RFC PATCH 2/2 An example of usage of tst_checkpoint shell wrappers

In reply to Stanislav Kholmanskikh
---
 .../memcg/functional/memcg_function_test.sh        |   27 +++++++++++---------
 .../controllers/memcg/functional/memcg_lib.sh      |   16 +++++------
 .../controllers/memcg/functional/memcg_process.c   |    6 ++++
 3 files changed, 28 insertions(+), 21 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +15 -12
index 2c2f32a..efafad5 100755
@@ -25,12 +25,19 @@
 ##                                                                            ##
 ################################################################################
 
-export TCID="memcg_function_test"
-export TST_TOTAL=38
-export TST_COUNT=0
-
+TCID="memcg_function_test"
+TST_TOTAL=38
+. test.sh
 . memcg_lib.sh || exit 1
 
+my_cleanup()
+{
+	TST_CHECKPOINT_CLEANUP
+}
+
+TST_CLEANUP=my_cleanup
+TST_CHECKPOINT_SETUP
+
 # Case 1 - 10: Test the management and counting of memory
 testcase_1()
 {
@@ -207,7 +214,7 @@ testcase_29()
 {
 	$TEST_PATH/memcg_process --mmap-anon -s $PAGESIZE &
 	pid=$!
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	echo $pid > tasks
 	kill -s USR1 $pid 2> /dev/null
 	sleep 1
@@ -228,7 +235,7 @@ testcase_30()
 {
 	$TEST_PATH/memcg_process --mmap-lock2 -s $PAGESIZE &
 	pid=$!
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	echo $pid > tasks
 	kill -s USR1 $pid 2> /dev/null
 	sleep 1
@@ -299,7 +306,6 @@ fi
 # Run all the test cases
 for i in $(seq 1 $TST_TOTAL)
 do
-	export TST_COUNT=$(( $TST_COUNT + 1 ))
 	cur_id=$i
 
 	do_mount
@@ -325,8 +331,5 @@ done
 
 echo $shmmax > /proc/sys/kernel/shmmax
 
-if [ $failed -ne 0 ]; then
-	exit $failed
-else
-	exit 0
-fi
+tst_exit
+
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +7 -9
index 9b9b0fd..b3e6157 100755
@@ -41,7 +41,6 @@ FAIL=1
 orig_memory_use_hierarchy=""
 
 cur_id=0
-failed=0
 
 # Record the test result of a test case
 # $1 - The result of the test case, $PASS or $FAIL
@@ -55,7 +54,6 @@ result()
 		tst_resm TPASS "$info"
 	else
 		tst_resm TFAIL "$info"
-		: $(( failed += 1 ))
 	fi
 }
 
@@ -111,7 +109,7 @@ test_mem_stat()
 {
 	echo "Running $TEST_PATH/memcg_process $1 -s $2"
 	$TEST_PATH/memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	warmup $!
 	if [ $? -ne 0 ]; then
@@ -144,7 +142,7 @@ test_max_usage_in_bytes()
 {
 	echo "Running $TEST_PATH/memcg_process $1 -s $2"
 	$TEST_PATH/memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	warmup $!
 	if [ $? -ne 0 ]; then
@@ -175,7 +173,7 @@ malloc_free_memory()
 {
 	echo "Running $TEST_PATH/memcg_process $1 -s $2"
 	$TEST_PATH/memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	echo $! > tasks
 	kill -s USR1 $! 2> /dev/null
@@ -220,7 +218,7 @@ test_proc_kill()
 
 	$TEST_PATH/memcg_process $2 -s $3 &
 	pid=$!
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	echo $pid > tasks
 
 	kill -s USR1 $pid 2> /dev/null
@@ -284,7 +282,7 @@ test_hugepage()
 	echo $1 > /proc/sys/vm/nr_hugepages
 
 	$TEST_PATH/memcg_process $2 --hugepage -s $3 > $TMP_FILE 2>&1 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	kill -s USR1 $! 2> /dev/null
 	sleep 1
@@ -332,7 +330,7 @@ test_subgroup()
 
 	echo "Running $TEST_PATH/memcg_process --mmap-anon -s $PAGESIZE"
 	$TEST_PATH/memcg_process --mmap-anon -s $PAGESIZE &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 
 	warmup $!
 	if [ $? -ne 0 ]; then
@@ -367,7 +365,7 @@ test_move_charge()
 	mkdir subgroup_a
 
 	$TEST_PATH/memcg_process $1 -s $2 &
-	sleep 1
+	TST_CHECKPOINT_WAIT 0
 	warmup $!
 	if [ $? -ne 0 ]; then
 		rmdir subgroup_a
testcases/kernel/controllers/memcg/functional/memcg_process.c +6 -0
index 3d34394..95e947f 100644
@@ -34,6 +34,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
 
 int fd;
 
@@ -310,6 +312,10 @@ int main(int argc, char *argv[])
 
 	process_options(argc, argv);
 
+	tst_reinit();
+
+	TST_CHECKPOINT_WAKE(0);
+
 	while (!flag_exit)
 		sleep(1);
 
Signature · 1 line
1.7.1
#3 lore raw

RFC PATCH 2/2 An example of usage of tst_checkpoint shell wrappers

Hi!
I really like how we can mix the checkpoints between the C and shell source now ;).

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw
In reply to Stanislav Kholmanskikh

Hi!

Quoted 8 lines

There is a need to use the tst_checkpoint interface from shell, but we don't have wrappers for it (yet).

Patch 1 of the series contains one possible implementation for that, patch 2 - an example of usage in the context of the memcg_functional test case.

I'd like to get some feedback from LTP users.

Quoted 8 lines

My primary concern is about two issues:

1. The new test API for C is cool and takes the responsibility on maintaining the infrastructure for tst_checkpoint. However, I couldn't find a way to implement something similar in shell, so I switched back to using two separate functions for that - TST_CHECKPOINT_SETUP, TST_CHECKPOINT_CLEANUP.

There may be a better way...

Well we can always put the cleanup into the tst_exit() which is executed both on clean and unclean exit (tst_brkm). And the setup could be done right after the checks for TCID and TST_TOTAL. Both supposedly if something as TST_NEEDS_CHECKPOINTS=1 has been set before sourcing test.sh.

Also nothing stops us from bringing the shell API closer to what we have for C :).

We would have to source the test library script after we had defined all the setup() cleanup() and test() functions and after setting the corresponding TST_ID=foo, TST_NEEDS_CHECKPOINTS=1, etc. But as far as I can tell it seems doable.

And it would be really cool if we managed to use the shared memory for test results as well so that result from child processes (subshells) would be propagated automatically as well.

Quoted 3 lines

2. What is the best location for the new supplemental binaries (tst_checkpoint_wait, tst_checkpoint_wake)? tools/apicmds/ltpapicmd.c or separate source files in testcases/lib/ (similar to tst_sleep)?

I would go for separate binary in testcases/lib/ rather than adding to the ltpapicmd.c which should really be removed at some point in future, once there are no users for the binary tst_resm.

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

Hi!

Quoted 24 lines · Cyril Hrubis

Hi!

Quoted 8 lines

There is a need to use the tst_checkpoint interface from shell, but we don't have wrappers for it (yet).

Patch 1 of the series contains one possible implementation for that, patch 2 - an example of usage in the context of the memcg_functional test case.

I'd like to get some feedback from LTP users.

Quoted 8 lines

My primary concern is about two issues:

1. The new test API for C is cool and takes the responsibility on maintaining the infrastructure for tst_checkpoint. However, I couldn't find a way to implement something similar in shell, so I switched back to using two separate functions for that - TST_CHECKPOINT_SETUP, TST_CHECKPOINT_CLEANUP.

There may be a better way...

Well we can always put the cleanup into the tst_exit() which is executed both on clean and unclean exit (tst_brkm). And the setup could be done right after the checks for TCID and TST_TOTAL. Both supposedly if something as TST_NEEDS_CHECKPOINTS=1 has been set before sourcing test.sh.

Quoted 7 lines

Also nothing stops us from bringing the shell API closer to what we have for C :).

We would have to source the test library script after we had defined all the setup() cleanup() and test() functions and after setting the corresponding TST_ID=foo, TST_NEEDS_CHECKPOINTS=1, etc. But as far as I can tell it seems doable.

Could, you, please, have a look at the attached series. I suppose it addresses your proposal. In particular, the changes are:
* tst_checkpoint_* binaries were moved to testcases/lib/
* logic from TST_CHECKPOINT_CLEANUP was moved to tst_exit()
* logic from TST_CHECKPOINT_SETUP was moved right into tst_test.sh
(now it depends on TST_NEEDS_CHECKPOINTS flag)

Existent test cases should not be affected by this change.

If checkpoints are needed, TST_NEEDS_CHECKPOINTS must be defined before '.test.sh'. I think this fact could be documented.

Quoted 4 lines

And it would be really cool if we managed to use the shared memory for test results as well so that result from child processes (subshells) would be propagated automatically as well.

Yes, but may this be addressed sometimes later :)

Quoted 9 lines
Quoted 4 lines

2. What is the best location for the new supplemental binaries (tst_checkpoint_wait, tst_checkpoint_wake)? tools/apicmds/ltpapicmd.c or separate source files in testcases/lib/ (similar to tst_sleep)?

I would go for separate binary in testcases/lib/ rather than adding to the ltpapicmd.c which should really be removed at some point in future, once there are no users for the binary tst_resm.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-shell-wrapper-for-tst_checkpoint.patch
Type: text/x-patch
Size: 4897 bytes
Desc: not available
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160602/7b15e917/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-an-example-of-usage.patch
Type: text/x-patch
Size: 4677 bytes
Desc: not available
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160602/7b15e917/attachment-0001.bin>

#6 lore raw

Hi!

Quoted 19 lines

include $(top_srcdir)/include/mk/generic_leaf_target.mk

testcases/lib/test.sh +4 -0
index 70345e5..00eeeae 100644
@@ -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))
 }
@@ -374,6 +378,16 @@ tst_module_exists()
 	tst_brkm TCONF "Failed to find module '$mod_name'"
 }

testcases/lib/test.sh tst_module_exists() · line 389

Quoted 10 lines
testcases/lib/test.sh +9 -0
 
+TST_CHECKPOINT_WAIT()
+{
+	ROD tst_checkpoint_wait "$1" 10000
+}
+
+TST_CHECKPOINT_WAKE()
+{
+	ROD tst_checkpoint_wake "$1" 10000
+}

Given that we have wrappers for the checkpoint programs anyway, we can build just one binary called tst_checkpoint and pass the wait/wake as first parameter. That way we can spare us the special rules in Makefile and ifdefs in the checkpoint C source.

testcases/lib/test.sh if [ -z "$LTPROOT" ]; then · line 412

Quoted 10 lines
testcases/lib/test.sh +3 -0
 # Check that test name is set
 if [ -z "$TCID" ]; then
 	tst_brkm TBROK "TCID is not defined"
@@ -393,3 +407,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_$$"

We may also include the $TCID in the filename, since that would make identifying which tests possibly failed to cleanup easier...

testcases/lib/test.sh if [ -z "$LTPROOT" ]; then · line 421

Quoted 9 lines
testcases/lib/test.sh +9 -0
+	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

Otherwise this looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
#7 lore raw
In reply to Stanislav Kholmanskikh

----- Original Message -----

Quoted 8 lines

From: "Stanislav Kholmanskikh" <[email protected]>
To: [email protected]
Cc: "vasily isaenko" <[email protected]>
Sent: Wednesday, 1 June, 2016 4:34:51 PM
Subject: [LTP] [RFC] shell wrappers for tst_checkpoint

Hi!

Quoted 8 lines

There is a need to use the tst_checkpoint interface from shell, but we don't have wrappers for it (yet).

Patch 1 of the series contains one possible implementation for that, patch 2 - an example of usage in the context of the memcg_functional test case.

I'd like to get some feedback from LTP users.

If we don't plan to support oldlib, we should document that shell checkpoints will work only with newlib C testcases, since oldlib currently doesn't use LTP_IPC_PATH and file has different layout (there is no results struct).

Quoted 23 lines

My primary concern is about two issues:

1. The new test API for C is cool and takes the responsibility on maintaining the infrastructure for tst_checkpoint. However, I couldn't find
a way to implement something similar in shell, so I switched back to using two separate functions for that - TST_CHECKPOINT_SETUP, TST_CHECKPOINT_CLEANUP.

There may be a better way...

2. What is the best location for the new supplemental binaries (tst_checkpoint_wait,
tst_checkpoint_wake)? tools/apicmds/ltpapicmd.c or separate source files in testcases/lib/ (similar to tst_sleep)?

Thanks.

--
Mailing list info: https://lists.linux.it/listinfo/ltp

#8 lore raw
Quoted 20 lines · Jan Stancek

----- Original Message -----

Quoted 15 lines

From: "Stanislav Kholmanskikh" <[email protected]>
To: [email protected]
Cc: "vasily isaenko" <[email protected]>
Sent: Wednesday, 1 June, 2016 4:34:51 PM
Subject: [LTP] [RFC] shell wrappers for tst_checkpoint

Hi!

There is a need to use the tst_checkpoint interface from shell, but we don't have wrappers for it (yet).

Patch 1 of the series contains one possible implementation for that, patch 2 - an example of usage in the context of the memcg_functional test case.

Quoted 6 lines
Quoted 1 line

I'd like to get some feedback from LTP users.

If we don't plan to support oldlib, we should document that shell checkpoints will work only with newlib C testcases, since oldlib currently doesn't use LTP_IPC_PATH and file has different layout (there is no results struct).

I'd better remove the old checkpoint api from LTP. There are ~20 C test cases using TST_CHECKPOINT_INIT(). It should be doable to convert them to using the new api, since it's likely that they are not "legacy" and don't require additional cleanup. :)

Per my understanding, all new C test cases are expected to be written with the new api, so the only downside of this approach is that removing TST_CHECKPOINT_INIT() may require more time.

Quoted 24 lines
Quoted 24 lines

My primary concern is about two issues:

1. The new test API for C is cool and takes the responsibility on maintaining the infrastructure for tst_checkpoint. However, I couldn't find
a way to implement something similar in shell, so I switched back to using two separate functions for that - TST_CHECKPOINT_SETUP, TST_CHECKPOINT_CLEANUP.

There may be a better way...

2. What is the best location for the new supplemental binaries (tst_checkpoint_wait,
tst_checkpoint_wake)? tools/apicmds/ltpapicmd.c or separate source files in testcases/lib/ (similar to tst_sleep)?

Thanks.

--
Mailing list info: https://lists.linux.it/listinfo/ltp