-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit implements a shell loader so that we don't have to write a C loader for each LTP shell test. The idea is simple, the loader parses the shell test and prepares the tst_test structure accordingly, then runs the actual shell test. The format for the metadata in the shell test was choosen to be JSON because: - I didn't want to invent an adhoc format and JSON is perfect for serializing data structures - The metadata parser for shell test will be trivial, it will just pick the JSON from the comment, no parsing will be required Signed-off-by: Cyril Hrubis <[email protected]> Reviewed-by: Richard Palethorpe <[email protected]> Reviewed-by: Li Wang <[email protected]>
- Loading branch information
Showing
18 changed files
with
738 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ | |
/tst_supported_fs | ||
/tst_timeout_kill | ||
/tst_res_ | ||
/tst_run_shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# doc | ||
# | ||
# [Description] | ||
# | ||
# This is a simple shell test loader example. | ||
# --- | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "needs_tmpdir": true | ||
# } | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TPASS "Shell loader works fine!" | ||
case "$PWD" in | ||
/tmp/*) | ||
tst_res TPASS "We are running in temp directory in $PWD";; | ||
*) | ||
tst_res TFAIL "We are not running in temp directory but $PWD";; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "needs_root": true, | ||
# "mount_device": true, | ||
# "all_filesystems": true, | ||
# "mntpoint": "ltp_mntpoint" | ||
# } | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TINFO "In shell" | ||
|
||
mntpath=$(realpath ltp_mntpoint) | ||
mounted=$(grep $mntpath /proc/mounts) | ||
|
||
if [ -n "$mounted" ]; then | ||
device=$(echo $mounted |cut -d' ' -f 1) | ||
path=$(echo $mounted |cut -d' ' -f 2) | ||
|
||
tst_res TPASS "$device mounted at $path" | ||
else | ||
tst_res TFAIL "Device not mounted!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "mount_device": true, | ||
# "mntpoint": "ltp_mntpoint", | ||
# "filesystems": [ | ||
# { | ||
# "type": "btrfs" | ||
# }, | ||
# { | ||
# "type": "xfs", | ||
# "mkfs_opts": ["-m", "reflink=1"] | ||
# } | ||
# ] | ||
# } | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TINFO "In shell" | ||
|
||
mntpoint=$(realpath ltp_mntpoint) | ||
mounted=$(grep $mntpoint /proc/mounts) | ||
|
||
if [ -n "$mounted" ]; then | ||
fs=$(echo $mounted |cut -d' ' -f 3) | ||
|
||
tst_res TPASS "Mounted device formatted with $fs" | ||
else | ||
tst_res TFAIL "Device not mounted!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# doc | ||
# | ||
# [Description] | ||
# | ||
# This is a simple shell test loader example. | ||
# --- | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "needs_tmpdir": true | ||
# } | ||
# --- | ||
# | ||
# --- | ||
# inv | ||
# | ||
# This is an invalid block that breaks the test. | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TPASS "This should pass!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
# | ||
# This test has wrong metadata and should not be run | ||
# | ||
# --- | ||
# env | ||
# { | ||
# {"needs_tmpdir": 42, | ||
# } | ||
# --- | ||
# | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TFAIL "Shell loader should TBROK the test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "needs_kconfigs": ["CONFIG_NUMA=y"] | ||
# } | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TPASS "Shell loader works fine!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
# | ||
# This test has no metadata and should not be executed | ||
# | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TFAIL "Shell loader should TBROK the test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "supported_archs": ["x86", "ppc64", "x86_64"] | ||
# } | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TPASS "We are running on supported architecture" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "tags": [ | ||
# ["linux-git", "832478cd342ab"], | ||
# ["CVE", "2099-999"] | ||
# ] | ||
# } | ||
# --- | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TFAIL "Fails the test so that tags are shown." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
# | ||
# The script should be executed tcnt times and the iteration number should be in $1 | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "tcnt": 2 | ||
# } | ||
# --- | ||
# | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TPASS "Iteration $1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
# | ||
# This test has wrong metadata and should not be run | ||
# | ||
# --- | ||
# env | ||
# { | ||
# "needs_tmpdir": 42, | ||
# } | ||
# --- | ||
# | ||
|
||
. tst_loader.sh | ||
|
||
tst_res TFAIL "Shell loader should TBROK the test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This is a loader for shell tests that use the C test library. | ||
# | ||
|
||
if [ -z "$LTP_IPC_PATH" ]; then | ||
tst_run_shell $(basename "$0") "$@" | ||
exit $? | ||
else | ||
. tst_env.sh | ||
fi |
Oops, something went wrong.