All of lore.kernel.org
 help / color / mirror / Atom feed
From: mataotao <mataotao@uniontech.com>
To: ltp@lists.linux.it
Cc: mataotao <mataotao@uniontech.com>
Subject: [LTP] [PATCH] shell: add chmod command check
Date: Thu, 30 May 2024 10:33:10 +0800	[thread overview]
Message-ID: <20240530023310.4058-1-mataotao@uniontech.com> (raw)

---
 runtest/commands                        |  1 +
 testcases/commands/chmod/Makefile       | 11 ++++
 testcases/commands/chmod/chmod_tests.sh | 83 +++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 testcases/commands/chmod/Makefile
 create mode 100644 testcases/commands/chmod/chmod_tests.sh

diff --git a/runtest/commands b/runtest/commands
index 570b81262..6066d3289 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -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
diff --git a/testcases/commands/chmod/Makefile b/testcases/commands/chmod/Makefile
new file mode 100644
index 000000000..da8115d71
--- /dev/null
+++ b/testcases/commands/chmod/Makefile
@@ -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
diff --git a/testcases/commands/chmod/chmod_tests.sh b/testcases/commands/chmod/chmod_tests.sh
new file mode 100644
index 000000000..469ba70d4
--- /dev/null
+++ b/testcases/commands/chmod/chmod_tests.sh
@@ -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
-- 
2.20.1


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

             reply	other threads:[~2024-05-30  2:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-30  2:33 mataotao [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-06-24  7:05 [LTP] [PATCH] shell: add chmod command check mataotao
2024-07-10 15:36 ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240530023310.4058-1-mataotao@uniontech.com \
    --to=mataotao@uniontech.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.