diff mbox series

[1/1] lib: Add ROD shell API test

Message ID 20220727151657.2242-1-pvorel@suse.cz
State Changes Requested
Headers show
Series [1/1] lib: Add ROD shell API test | expand

Commit Message

Petr Vorel July 27, 2022, 3:16 p.m. UTC
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/newlib_tests/runtest.sh   |  2 +-
 lib/newlib_tests/shell/rod.sh | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100755 lib/newlib_tests/shell/rod.sh

Comments

Richard Palethorpe Sept. 2, 2022, 9:57 a.m. UTC | #1
Hello,

Petr Vorel <pvorel@suse.cz> writes:

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  lib/newlib_tests/runtest.sh   |  2 +-
>  lib/newlib_tests/shell/rod.sh | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 31 insertions(+), 1 deletion(-)
>  create mode 100755 lib/newlib_tests/shell/rod.sh
>
> diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
> index f136bcb88..5b75fe2c7 100755
> --- a/lib/newlib_tests/runtest.sh
> +++ b/lib/newlib_tests/runtest.sh
> @@ -8,7 +8,7 @@ tst_fuzzy_sync03 test_zero_hugepage.sh test_kconfig.sh
>  test_children_cleanup.sh}"
>  
>  LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
> -shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
> +shell/tst_check_kconfig0[1-5].sh shell/rod.sh shell/net/*.sh}"
>  
>  cd $(dirname $0)
>  PATH="$PWD/../../testcases/lib/:$PATH"
> diff --git a/lib/newlib_tests/shell/rod.sh b/lib/newlib_tests/shell/rod.sh
> new file mode 100755
> index 000000000..e05516d0b
> --- /dev/null
> +++ b/lib/newlib_tests/shell/rod.sh
> @@ -0,0 +1,30 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
> +
> +TST_TESTFUNC="test"
> +TST_NEEDS_TMPDIR=1
> +TST_CNT=3
> +
> +test1()
> +{
> +	ROD cd /
> +	EXPECT_PASS [ "$PWD" != "/" ]
> +}
> +
> +test2()
> +{
> +	ROD echo foo > /nonexisting-file

If we are running as root then this will succeed?

I suppose we don't usually run the lib tests as root, but wouldn't it be
better to create a file and write protect it, then try redirecting to it?

> +	tst_res TPASS "ROD redirecting without qoting continue on failure. NOTE: proper syntax needs to escape '>': ROD echo foo \> /nonexisting-file"
> +	EXPECT_FAIL 'cat /nonexisting-file'
> +}
> +
> +test3()
> +{
> +	ROD echo foo \> file
> +	tst_res TPASS "ROD redirect quoting syntax works"
> +	EXPECT_PASS '[ $(cat file) = foo ]'
> +}
> +
> +. tst_test.sh
> +tst_run
> -- 
> 2.37.1
Richard Palethorpe Oct. 11, 2022, 9:26 a.m. UTC | #2
Hello,

Richard Palethorpe <rpalethorpe@suse.de> writes:

> Hello,
>
> Petr Vorel <pvorel@suse.cz> writes:
>
>> Signed-off-by: Petr Vorel <pvorel@suse.cz>
>> ---
>>  lib/newlib_tests/runtest.sh   |  2 +-
>>  lib/newlib_tests/shell/rod.sh | 30 ++++++++++++++++++++++++++++++
>>  2 files changed, 31 insertions(+), 1 deletion(-)
>>  create mode 100755 lib/newlib_tests/shell/rod.sh
>>
>> diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
>> index f136bcb88..5b75fe2c7 100755
>> --- a/lib/newlib_tests/runtest.sh
>> +++ b/lib/newlib_tests/runtest.sh
>> @@ -8,7 +8,7 @@ tst_fuzzy_sync03 test_zero_hugepage.sh test_kconfig.sh
>>  test_children_cleanup.sh}"
>>  
>>  LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
>> -shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
>> +shell/tst_check_kconfig0[1-5].sh shell/rod.sh shell/net/*.sh}"
>>  
>>  cd $(dirname $0)
>>  PATH="$PWD/../../testcases/lib/:$PATH"
>> diff --git a/lib/newlib_tests/shell/rod.sh b/lib/newlib_tests/shell/rod.sh
>> new file mode 100755
>> index 000000000..e05516d0b
>> --- /dev/null
>> +++ b/lib/newlib_tests/shell/rod.sh
>> @@ -0,0 +1,30 @@
>> +#!/bin/sh
>> +# SPDX-License-Identifier: GPL-2.0-or-later
>> +# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
>> +
>> +TST_TESTFUNC="test"
>> +TST_NEEDS_TMPDIR=1
>> +TST_CNT=3
>> +
>> +test1()
>> +{
>> +	ROD cd /
>> +	EXPECT_PASS [ "$PWD" != "/" ]
>> +}
>> +
>> +test2()
>> +{
>> +	ROD echo foo > /nonexisting-file
>
> If we are running as root then this will succeed?
>
> I suppose we don't usually run the lib tests as root, but wouldn't it be
> better to create a file and write protect it, then try redirecting to
> it?

Marking as "changes requested", to remove it from the queue.
diff mbox series

Patch

diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index f136bcb88..5b75fe2c7 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -8,7 +8,7 @@  tst_fuzzy_sync03 test_zero_hugepage.sh test_kconfig.sh
 test_children_cleanup.sh}"
 
 LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
-shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
+shell/tst_check_kconfig0[1-5].sh shell/rod.sh shell/net/*.sh}"
 
 cd $(dirname $0)
 PATH="$PWD/../../testcases/lib/:$PATH"
diff --git a/lib/newlib_tests/shell/rod.sh b/lib/newlib_tests/shell/rod.sh
new file mode 100755
index 000000000..e05516d0b
--- /dev/null
+++ b/lib/newlib_tests/shell/rod.sh
@@ -0,0 +1,30 @@ 
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_TESTFUNC="test"
+TST_NEEDS_TMPDIR=1
+TST_CNT=3
+
+test1()
+{
+	ROD cd /
+	EXPECT_PASS [ "$PWD" != "/" ]
+}
+
+test2()
+{
+	ROD echo foo > /nonexisting-file
+	tst_res TPASS "ROD redirecting without qoting continue on failure. NOTE: proper syntax needs to escape '>': ROD echo foo \> /nonexisting-file"
+	EXPECT_FAIL 'cat /nonexisting-file'
+}
+
+test3()
+{
+	ROD echo foo \> file
+	tst_res TPASS "ROD redirect quoting syntax works"
+	EXPECT_PASS '[ $(cat file) = foo ]'
+}
+
+. tst_test.sh
+tst_run