@@ -13,6 +13,7 @@ cp01_sh cp_tests.sh
ln01_sh ln_tests.sh
mkdir01_sh mkdir_tests.sh
echo_tests_sh echo_tests.sh
+chmod_tests_sh chmod_tests.sh
mv01_sh mv_tests.sh
du01_sh du01.sh
df01_sh df01.sh
new file mode 100644
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2024 UnionTech Ltd.
+# Author: Taotao Ma <mataotao@uniontech.com>
+
+top_srcdir ?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+INSTALL_TARGETS := chmod_tests.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
new file mode 100644
@@ -0,0 +1,83 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2024
+# Copyright (c) 2024 UnionTech Ltd.
+# Author: Taotao Ma <mataotao@uniontech.com>
+#
+# Test basic functionality of chmod command.
+
+TST_CNT=7
+TST_TESTFUNC=do_test
+TST_SETUP=setup
+TST_NEEDS_TMPDIR=1
+
+create_tree()
+{
+ local dirname=$1
+ local dircnt=$2
+ local filecnt=$3
+
+ tst_res TINFO "Creating $dircnt directories."
+ tst_res TINFO "Filling each dir with $filecnt files".
+ while [ $dircnt -gt 0 ]; do
+ dirname=$dirname/dir$dircnt
+ ROD mkdir -p $dirname
+
+ local fcnt=0
+ while [ $fcnt -lt $filecnt ]; do
+ ROD touch $dirname/file$fcnt
+ fcnt=$((fcnt+1))
+ done
+ dircnt=$((dircnt-1))
+ done
+}
+
+setup()
+{
+ create_tree "dir" 3 3
+ ROD echo LTP > file
+}
+
+compare()
+{
+ local act_auth="$1"
+ local exp_auth="$2"
+
+ act="$(stat -c "%a" "$act_auth")"
+ tst_res TINFO "$act"
+ if [ "$act" = "$exp_auth" ]; then
+ tst_res TPASS "Files $act_auth authority Modified successfully"
+ else
+ tst_res TFAIL "Files $act_auth authority Modified failed"
+ fi
+}
+
+chmod_test()
+{
+ local args="$1"
+ local auth="$2"
+ local src="$3"
+ local check="$4"
+ if [[ -n $auth ]]; then
+ EXPECT_PASS chmod $args $auth $src
+ compare "$src" "$check"
+ else
+ compare "$src" "$check"
+ fi
+}
+
+do_test()
+{
+ case $1 in
+ 1) chmod_test "-R" "775" "dir/dir3/dir2/dir1" "775";;
+ 2) chmod_test "" "" "dir/dir3/dir2/dir1/file0" "775";;
+ 3) chmod_test "" "" "dir/dir3/dir2/dir1/file1" "775";;
+ 4) chmod_test "" "go+rwx" "dir/dir3/file0" "677";;
+ 5) chmod_test "" "777" "dir/dir3/file1" "777";;
+ 6) chmod_test "" "g-r" "dir/dir3/dir2/file0" "604";;
+ 7) chmod_test "" "g-r" "dir/dir3/file0" "637";;
+ esac
+}
+
+. tst_test.sh
+tst_run