From 6f88767ad0ee732260253e88075b1369ce55c947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E9=9C=B2?= <16062016+ganlufan@user.noreply.gitee.com> Date: Sat, 25 Apr 2026 17:52:53 +0800 Subject: [PATCH 1/5] Initial commit: local files --- .gitmodules | 90 +++++++++++++++++++++++++++++++ NetworkManager/.gitignore | 17 ++++++ NetworkManager/Makefile | 27 ++++++++++ NetworkManager/Makefile.common | 3 ++ NetworkManager/cmd/Makefile | 20 +++++++ NetworkManager/cmd/hello.c | 6 +++ NetworkManager/kmod/Makefile | 33 ++++++++++++ NetworkManager/lib/Makefile | 20 +++++++ NetworkManager/lib/ts_common.c | 14 +++++ NetworkManager/lib/ts_common.h | 6 +++ NetworkManager/lib/ts_common.py | 35 ++++++++++++ NetworkManager/lib/ts_common.sh | 16 ++++++ NetworkManager/lib/ts_setup | 13 +++++ NetworkManager/lib/ts_teardown | 13 +++++ NetworkManager/testcase/Makefile | 21 ++++++++ NetworkManager/tsuite | 21 ++++++++ README.en.md | 36 +++++++++++++ README.md | 91 ++++++++++++++++++++++++++++++++ ant-condition-fail-build.sh | 84 +++++++++++++++++++++++++++++ bash/.gitignore | 17 ++++++ bash/Makefile | 27 ++++++++++ bash/Makefile.common | 3 ++ bash/cmd/Makefile | 20 +++++++ bash/cmd/hello.c | 6 +++ bash/kmod/Makefile | 33 ++++++++++++ bash/lib/Makefile | 20 +++++++ bash/lib/ts_common.c | 14 +++++ bash/lib/ts_common.h | 6 +++ bash/lib/ts_common.py | 35 ++++++++++++ bash/lib/ts_common.sh | 16 ++++++ bash/lib/ts_setup | 13 +++++ bash/lib/ts_teardown | 13 +++++ bash/testcase/Makefile | 21 ++++++++ bash/tsuite | 21 ++++++++ bind/.gitignore | 17 ++++++ bind/Makefile | 27 ++++++++++ bind/Makefile.common | 3 ++ bind/cmd/Makefile | 20 +++++++ bind/cmd/hello.c | 6 +++ bind/kmod/Makefile | 33 ++++++++++++ bind/lib/Makefile | 20 +++++++ bind/lib/ts_common.c | 14 +++++ bind/lib/ts_common.h | 6 +++ bind/lib/ts_common.py | 35 ++++++++++++ bind/lib/ts_common.sh | 16 ++++++ bind/lib/ts_setup | 13 +++++ bind/lib/ts_teardown | 13 +++++ bind/testcase/Makefile | 21 ++++++++ bind/tsuite | 21 ++++++++ binutils/.gitignore | 17 ++++++ binutils/Makefile | 27 ++++++++++ binutils/Makefile.common | 3 ++ binutils/cmd/Makefile | 20 +++++++ binutils/cmd/hello.c | 6 +++ binutils/kmod/Makefile | 33 ++++++++++++ binutils/lib/Makefile | 20 +++++++ binutils/lib/ts_common.c | 14 +++++ binutils/lib/ts_common.h | 6 +++ binutils/lib/ts_common.py | 35 ++++++++++++ binutils/lib/ts_common.sh | 16 ++++++ binutils/lib/ts_setup | 13 +++++ binutils/lib/ts_teardown | 13 +++++ binutils/testcase/Makefile | 21 ++++++++ binutils/tsuite | 21 ++++++++ coreutils/.gitignore | 17 ++++++ coreutils/Makefile | 27 ++++++++++ coreutils/Makefile.common | 3 ++ coreutils/cmd/Makefile | 20 +++++++ coreutils/cmd/hello.c | 6 +++ coreutils/kmod/Makefile | 33 ++++++++++++ coreutils/lib/Makefile | 20 +++++++ coreutils/lib/ts_common.c | 14 +++++ coreutils/lib/ts_common.h | 6 +++ coreutils/lib/ts_common.py | 35 ++++++++++++ coreutils/lib/ts_common.sh | 16 ++++++ coreutils/lib/ts_setup | 13 +++++ coreutils/lib/ts_teardown | 13 +++++ coreutils/testcase/Makefile | 21 ++++++++ coreutils/tsuite | 21 ++++++++ curl/.gitignore | 17 ++++++ curl/Makefile | 27 ++++++++++ curl/Makefile.common | 3 ++ curl/cmd/Makefile | 20 +++++++ curl/cmd/hello.c | 6 +++ curl/kmod/Makefile | 33 ++++++++++++ curl/lib/Makefile | 20 +++++++ curl/lib/ts_common.c | 14 +++++ curl/lib/ts_common.h | 6 +++ curl/lib/ts_common.py | 35 ++++++++++++ curl/lib/ts_common.sh | 16 ++++++ curl/lib/ts_setup | 13 +++++ curl/lib/ts_teardown | 13 +++++ curl/testcase/Makefile | 21 ++++++++ curl/tsuite | 21 ++++++++ dnf/.gitignore | 17 ++++++ dnf/Makefile | 27 ++++++++++ dnf/Makefile.common | 3 ++ dnf/cmd/Makefile | 20 +++++++ dnf/cmd/hello.c | 6 +++ dnf/kmod/Makefile | 33 ++++++++++++ dnf/lib/Makefile | 20 +++++++ dnf/lib/ts_common.c | 14 +++++ dnf/lib/ts_common.h | 6 +++ dnf/lib/ts_common.py | 35 ++++++++++++ dnf/lib/ts_common.sh | 16 ++++++ dnf/lib/ts_setup | 13 +++++ dnf/lib/ts_teardown | 13 +++++ dnf/testcase/Makefile | 21 ++++++++ dnf/tsuite | 21 ++++++++ findutils/.gitignore | 17 ++++++ findutils/Makefile | 27 ++++++++++ findutils/Makefile.common | 3 ++ findutils/cmd/Makefile | 20 +++++++ findutils/cmd/hello.c | 6 +++ findutils/kmod/Makefile | 33 ++++++++++++ findutils/lib/Makefile | 20 +++++++ findutils/lib/ts_common.c | 14 +++++ findutils/lib/ts_common.h | 6 +++ findutils/lib/ts_common.py | 35 ++++++++++++ findutils/lib/ts_common.sh | 16 ++++++ findutils/lib/ts_setup | 13 +++++ findutils/lib/ts_teardown | 13 +++++ findutils/testcase/Makefile | 21 ++++++++ findutils/tsuite | 21 ++++++++ gawk/.gitignore | 17 ++++++ gawk/Makefile | 27 ++++++++++ gawk/Makefile.common | 3 ++ gawk/cmd/Makefile | 20 +++++++ gawk/cmd/hello.c | 6 +++ gawk/kmod/Makefile | 33 ++++++++++++ gawk/lib/Makefile | 20 +++++++ gawk/lib/ts_common.c | 14 +++++ gawk/lib/ts_common.h | 6 +++ gawk/lib/ts_common.py | 35 ++++++++++++ gawk/lib/ts_common.sh | 16 ++++++ gawk/lib/ts_setup | 13 +++++ gawk/lib/ts_teardown | 13 +++++ gawk/testcase/Makefile | 21 ++++++++ gawk/tsuite | 21 ++++++++ git/.gitignore | 17 ++++++ git/Makefile | 27 ++++++++++ git/Makefile.common | 3 ++ git/cmd/Makefile | 20 +++++++ git/cmd/hello.c | 6 +++ git/kmod/Makefile | 33 ++++++++++++ git/lib/Makefile | 20 +++++++ git/lib/ts_common.c | 14 +++++ git/lib/ts_common.h | 6 +++ git/lib/ts_common.py | 35 ++++++++++++ git/lib/ts_common.sh | 16 ++++++ git/lib/ts_setup | 13 +++++ git/lib/ts_teardown | 13 +++++ git/testcase/Makefile | 21 ++++++++ git/tsuite | 21 ++++++++ grep/.gitignore | 17 ++++++ grep/Makefile | 27 ++++++++++ grep/Makefile.common | 3 ++ grep/cmd/Makefile | 20 +++++++ grep/cmd/hello.c | 6 +++ grep/kmod/Makefile | 33 ++++++++++++ grep/lib/Makefile | 20 +++++++ grep/lib/ts_common.c | 14 +++++ grep/lib/ts_common.h | 6 +++ grep/lib/ts_common.py | 35 ++++++++++++ grep/lib/ts_common.sh | 16 ++++++ grep/lib/ts_setup | 13 +++++ grep/lib/ts_teardown | 13 +++++ grep/testcase/Makefile | 21 ++++++++ grep/tsuite | 21 ++++++++ gzip/.gitignore | 17 ++++++ gzip/Makefile | 27 ++++++++++ gzip/Makefile.common | 3 ++ gzip/cmd/Makefile | 20 +++++++ gzip/cmd/hello.c | 6 +++ gzip/kmod/Makefile | 33 ++++++++++++ gzip/lib/Makefile | 20 +++++++ gzip/lib/ts_common.c | 14 +++++ gzip/lib/ts_common.h | 6 +++ gzip/lib/ts_common.py | 35 ++++++++++++ gzip/lib/ts_common.sh | 16 ++++++ gzip/lib/ts_setup | 13 +++++ gzip/lib/ts_teardown | 13 +++++ gzip/testcase/Makefile | 21 ++++++++ gzip/tsuite | 21 ++++++++ iproute/.gitignore | 17 ++++++ iproute/Makefile | 27 ++++++++++ iproute/Makefile.common | 3 ++ iproute/cmd/Makefile | 20 +++++++ iproute/cmd/hello.c | 6 +++ iproute/kmod/Makefile | 33 ++++++++++++ iproute/lib/Makefile | 20 +++++++ iproute/lib/ts_common.c | 14 +++++ iproute/lib/ts_common.h | 6 +++ iproute/lib/ts_common.py | 35 ++++++++++++ iproute/lib/ts_common.sh | 16 ++++++ iproute/lib/ts_setup | 13 +++++ iproute/lib/ts_teardown | 13 +++++ iproute/testcase/Makefile | 21 ++++++++ iproute/tsuite | 21 ++++++++ iputils/.gitignore | 17 ++++++ iputils/Makefile | 27 ++++++++++ iputils/Makefile.common | 3 ++ iputils/cmd/Makefile | 20 +++++++ iputils/cmd/hello.c | 6 +++ iputils/kmod/Makefile | 33 ++++++++++++ iputils/lib/Makefile | 20 +++++++ iputils/lib/ts_common.c | 14 +++++ iputils/lib/ts_common.h | 6 +++ iputils/lib/ts_common.py | 35 ++++++++++++ iputils/lib/ts_common.sh | 16 ++++++ iputils/lib/ts_setup | 13 +++++ iputils/lib/ts_teardown | 13 +++++ iputils/testcase/Makefile | 21 ++++++++ iputils/tsuite | 21 ++++++++ make/.gitignore | 17 ++++++ make/Makefile | 27 ++++++++++ make/Makefile.common | 3 ++ make/cmd/Makefile | 20 +++++++ make/cmd/hello.c | 6 +++ make/kmod/Makefile | 33 ++++++++++++ make/lib/Makefile | 20 +++++++ make/lib/ts_common.c | 14 +++++ make/lib/ts_common.h | 6 +++ make/lib/ts_common.py | 35 ++++++++++++ make/lib/ts_common.sh | 16 ++++++ make/lib/ts_setup | 13 +++++ make/lib/ts_teardown | 13 +++++ make/testcase/Makefile | 21 ++++++++ make/tsuite | 21 ++++++++ net-tools/.gitignore | 17 ++++++ net-tools/Makefile | 27 ++++++++++ net-tools/Makefile.common | 3 ++ net-tools/cmd/Makefile | 20 +++++++ net-tools/cmd/hello.c | 6 +++ net-tools/kmod/Makefile | 33 ++++++++++++ net-tools/lib/Makefile | 20 +++++++ net-tools/lib/ts_common.c | 14 +++++ net-tools/lib/ts_common.h | 6 +++ net-tools/lib/ts_common.py | 35 ++++++++++++ net-tools/lib/ts_common.sh | 16 ++++++ net-tools/lib/ts_setup | 13 +++++ net-tools/lib/ts_teardown | 13 +++++ net-tools/testcase/Makefile | 21 ++++++++ net-tools/tsuite | 21 ++++++++ nmap/.gitignore | 17 ++++++ nmap/Makefile | 27 ++++++++++ nmap/Makefile.common | 3 ++ nmap/cmd/Makefile | 20 +++++++ nmap/cmd/hello.c | 6 +++ nmap/kmod/Makefile | 33 ++++++++++++ nmap/lib/Makefile | 20 +++++++ nmap/lib/ts_common.c | 14 +++++ nmap/lib/ts_common.h | 6 +++ nmap/lib/ts_common.py | 35 ++++++++++++ nmap/lib/ts_common.sh | 16 ++++++ nmap/lib/ts_setup | 13 +++++ nmap/lib/ts_teardown | 13 +++++ nmap/testcase/Makefile | 21 ++++++++ nmap/tsuite | 21 ++++++++ openssh/.gitignore | 17 ++++++ openssh/Makefile | 27 ++++++++++ openssh/Makefile.common | 3 ++ openssh/cmd/Makefile | 20 +++++++ openssh/cmd/hello.c | 6 +++ openssh/kmod/Makefile | 33 ++++++++++++ openssh/lib/Makefile | 20 +++++++ openssh/lib/ts_common.c | 14 +++++ openssh/lib/ts_common.h | 6 +++ openssh/lib/ts_common.py | 35 ++++++++++++ openssh/lib/ts_common.sh | 16 ++++++ openssh/lib/ts_setup | 13 +++++ openssh/lib/ts_teardown | 13 +++++ openssh/testcase/Makefile | 21 ++++++++ openssh/tsuite | 21 ++++++++ openssl/.gitignore | 17 ++++++ openssl/Makefile | 27 ++++++++++ openssl/Makefile.common | 3 ++ openssl/cmd/Makefile | 20 +++++++ openssl/cmd/hello.c | 6 +++ openssl/kmod/Makefile | 33 ++++++++++++ openssl/lib/Makefile | 20 +++++++ openssl/lib/ts_common.c | 14 +++++ openssl/lib/ts_common.h | 6 +++ openssl/lib/ts_common.py | 35 ++++++++++++ openssl/lib/ts_common.sh | 16 ++++++ openssl/lib/ts_setup | 13 +++++ openssl/lib/ts_teardown | 13 +++++ openssl/testcase/Makefile | 21 ++++++++ openssl/tsuite | 21 ++++++++ perl/.gitignore | 17 ++++++ perl/Makefile | 27 ++++++++++ perl/Makefile.common | 3 ++ perl/cmd/Makefile | 20 +++++++ perl/cmd/hello.c | 6 +++ perl/kmod/Makefile | 33 ++++++++++++ perl/lib/Makefile | 20 +++++++ perl/lib/ts_common.c | 14 +++++ perl/lib/ts_common.h | 6 +++ perl/lib/ts_common.py | 35 ++++++++++++ perl/lib/ts_common.sh | 16 ++++++ perl/lib/ts_setup | 13 +++++ perl/lib/ts_teardown | 13 +++++ perl/testcase/Makefile | 21 ++++++++ perl/tsuite | 21 ++++++++ procps-ng/.gitignore | 17 ++++++ procps-ng/Makefile | 27 ++++++++++ procps-ng/Makefile.common | 3 ++ procps-ng/cmd/Makefile | 20 +++++++ procps-ng/cmd/hello.c | 6 +++ procps-ng/kmod/Makefile | 33 ++++++++++++ procps-ng/lib/Makefile | 20 +++++++ procps-ng/lib/ts_common.c | 14 +++++ procps-ng/lib/ts_common.h | 6 +++ procps-ng/lib/ts_common.py | 35 ++++++++++++ procps-ng/lib/ts_common.sh | 16 ++++++ procps-ng/lib/ts_setup | 13 +++++ procps-ng/lib/ts_teardown | 13 +++++ procps-ng/testcase/Makefile | 21 ++++++++ procps-ng/tsuite | 21 ++++++++ python3/.gitignore | 17 ++++++ python3/Makefile | 27 ++++++++++ python3/Makefile.common | 3 ++ python3/cmd/Makefile | 20 +++++++ python3/cmd/hello.c | 6 +++ python3/kmod/Makefile | 33 ++++++++++++ python3/lib/Makefile | 20 +++++++ python3/lib/ts_common.c | 14 +++++ python3/lib/ts_common.h | 6 +++ python3/lib/ts_common.py | 35 ++++++++++++ python3/lib/ts_common.sh | 16 ++++++ python3/lib/ts_setup | 13 +++++ python3/lib/ts_teardown | 13 +++++ python3/testcase/Makefile | 21 ++++++++ python3/tsuite | 21 ++++++++ rpm/.gitignore | 17 ++++++ rpm/Makefile | 27 ++++++++++ rpm/Makefile.common | 3 ++ rpm/cmd/Makefile | 20 +++++++ rpm/cmd/hello.c | 6 +++ rpm/kmod/Makefile | 33 ++++++++++++ rpm/lib/Makefile | 20 +++++++ rpm/lib/ts_common.c | 14 +++++ rpm/lib/ts_common.h | 6 +++ rpm/lib/ts_common.py | 35 ++++++++++++ rpm/lib/ts_common.sh | 16 ++++++ rpm/lib/ts_setup | 13 +++++ rpm/lib/ts_teardown | 13 +++++ rpm/testcase/Makefile | 21 ++++++++ rpm/tsuite | 21 ++++++++ sed/.gitignore | 17 ++++++ sed/Makefile | 27 ++++++++++ sed/Makefile.common | 3 ++ sed/cmd/Makefile | 20 +++++++ sed/cmd/hello.c | 6 +++ sed/kmod/Makefile | 33 ++++++++++++ sed/lib/Makefile | 20 +++++++ sed/lib/ts_common.c | 14 +++++ sed/lib/ts_common.h | 6 +++ sed/lib/ts_common.py | 35 ++++++++++++ sed/lib/ts_common.sh | 16 ++++++ sed/lib/ts_setup | 13 +++++ sed/lib/ts_teardown | 13 +++++ sed/testcase/Makefile | 21 ++++++++ sed/tsuite | 21 ++++++++ systemd/.gitignore | 17 ++++++ systemd/Makefile | 27 ++++++++++ systemd/Makefile.common | 3 ++ systemd/cmd/Makefile | 20 +++++++ systemd/cmd/hello.c | 6 +++ systemd/kmod/Makefile | 33 ++++++++++++ systemd/lib/Makefile | 20 +++++++ systemd/lib/ts_common.c | 14 +++++ systemd/lib/ts_common.h | 6 +++ systemd/lib/ts_common.py | 35 ++++++++++++ systemd/lib/ts_common.sh | 16 ++++++ systemd/lib/ts_setup | 13 +++++ systemd/lib/ts_teardown | 13 +++++ systemd/testcase/Makefile | 21 ++++++++ systemd/tsuite | 21 ++++++++ tar/.gitignore | 17 ++++++ tar/Makefile | 27 ++++++++++ tar/Makefile.common | 3 ++ tar/cmd/Makefile | 20 +++++++ tar/cmd/hello.c | 6 +++ tar/kmod/Makefile | 33 ++++++++++++ tar/lib/Makefile | 20 +++++++ tar/lib/ts_common.c | 14 +++++ tar/lib/ts_common.h | 6 +++ tar/lib/ts_common.py | 35 ++++++++++++ tar/lib/ts_common.sh | 16 ++++++ tar/lib/ts_setup | 13 +++++ tar/lib/ts_teardown | 13 +++++ tar/testcase/Makefile | 21 ++++++++ tar/tsuite | 21 ++++++++ tcpdump/.gitignore | 17 ++++++ tcpdump/Makefile | 27 ++++++++++ tcpdump/Makefile.common | 3 ++ tcpdump/cmd/Makefile | 20 +++++++ tcpdump/cmd/hello.c | 6 +++ tcpdump/kmod/Makefile | 33 ++++++++++++ tcpdump/lib/Makefile | 20 +++++++ tcpdump/lib/ts_common.c | 14 +++++ tcpdump/lib/ts_common.h | 6 +++ tcpdump/lib/ts_common.py | 35 ++++++++++++ tcpdump/lib/ts_common.sh | 16 ++++++ tcpdump/lib/ts_setup | 13 +++++ tcpdump/lib/ts_teardown | 13 +++++ tcpdump/testcase/Makefile | 21 ++++++++ tcpdump/tsuite | 21 ++++++++ util-linux/.gitignore | 17 ++++++ util-linux/Makefile | 27 ++++++++++ util-linux/Makefile.common | 3 ++ util-linux/cmd/Makefile | 20 +++++++ util-linux/cmd/hello.c | 6 +++ util-linux/kmod/Makefile | 33 ++++++++++++ util-linux/lib/Makefile | 20 +++++++ util-linux/lib/ts_common.c | 14 +++++ util-linux/lib/ts_common.h | 6 +++ util-linux/lib/ts_common.py | 35 ++++++++++++ util-linux/lib/ts_common.sh | 16 ++++++ util-linux/lib/ts_setup | 13 +++++ util-linux/lib/ts_teardown | 13 +++++ util-linux/testcase/Makefile | 21 ++++++++ util-linux/tsuite | 21 ++++++++ wget/.gitignore | 17 ++++++ wget/Makefile | 27 ++++++++++ wget/Makefile.common | 3 ++ wget/cmd/Makefile | 20 +++++++ wget/cmd/hello.c | 6 +++ wget/kmod/Makefile | 33 ++++++++++++ wget/lib/Makefile | 20 +++++++ wget/lib/ts_common.c | 14 +++++ wget/lib/ts_common.h | 6 +++ wget/lib/ts_common.py | 35 ++++++++++++ wget/lib/ts_common.sh | 16 ++++++ wget/lib/ts_setup | 13 +++++ wget/lib/ts_teardown | 13 +++++ wget/testcase/Makefile | 21 ++++++++ wget/tsuite | 21 ++++++++ xz/.gitignore | 17 ++++++ xz/Makefile | 27 ++++++++++ xz/Makefile.common | 3 ++ xz/cmd/Makefile | 20 +++++++ xz/cmd/hello.c | 6 +++ xz/kmod/Makefile | 33 ++++++++++++ xz/lib/Makefile | 20 +++++++ xz/lib/ts_common.c | 14 +++++ xz/lib/ts_common.h | 6 +++ xz/lib/ts_common.py | 35 ++++++++++++ xz/lib/ts_common.sh | 16 ++++++ xz/lib/ts_setup | 13 +++++ xz/lib/ts_teardown | 13 +++++ xz/testcase/Makefile | 21 ++++++++ xz/tsuite | 21 ++++++++ 454 files changed, 8251 insertions(+) create mode 100644 .gitmodules create mode 100644 NetworkManager/.gitignore create mode 100644 NetworkManager/Makefile create mode 100644 NetworkManager/Makefile.common create mode 100644 NetworkManager/cmd/Makefile create mode 100644 NetworkManager/cmd/hello.c create mode 100644 NetworkManager/kmod/Makefile create mode 100644 NetworkManager/lib/Makefile create mode 100644 NetworkManager/lib/ts_common.c create mode 100644 NetworkManager/lib/ts_common.h create mode 100644 NetworkManager/lib/ts_common.py create mode 100644 NetworkManager/lib/ts_common.sh create mode 100644 NetworkManager/lib/ts_setup create mode 100644 NetworkManager/lib/ts_teardown create mode 100644 NetworkManager/testcase/Makefile create mode 100644 NetworkManager/tsuite create mode 100644 README.en.md create mode 100644 README.md create mode 100644 ant-condition-fail-build.sh create mode 100644 bash/.gitignore create mode 100644 bash/Makefile create mode 100644 bash/Makefile.common create mode 100644 bash/cmd/Makefile create mode 100644 bash/cmd/hello.c create mode 100644 bash/kmod/Makefile create mode 100644 bash/lib/Makefile create mode 100644 bash/lib/ts_common.c create mode 100644 bash/lib/ts_common.h create mode 100644 bash/lib/ts_common.py create mode 100644 bash/lib/ts_common.sh create mode 100644 bash/lib/ts_setup create mode 100644 bash/lib/ts_teardown create mode 100644 bash/testcase/Makefile create mode 100644 bash/tsuite create mode 100644 bind/.gitignore create mode 100644 bind/Makefile create mode 100644 bind/Makefile.common create mode 100644 bind/cmd/Makefile create mode 100644 bind/cmd/hello.c create mode 100644 bind/kmod/Makefile create mode 100644 bind/lib/Makefile create mode 100644 bind/lib/ts_common.c create mode 100644 bind/lib/ts_common.h create mode 100644 bind/lib/ts_common.py create mode 100644 bind/lib/ts_common.sh create mode 100644 bind/lib/ts_setup create mode 100644 bind/lib/ts_teardown create mode 100644 bind/testcase/Makefile create mode 100644 bind/tsuite create mode 100644 binutils/.gitignore create mode 100644 binutils/Makefile create mode 100644 binutils/Makefile.common create mode 100644 binutils/cmd/Makefile create mode 100644 binutils/cmd/hello.c create mode 100644 binutils/kmod/Makefile create mode 100644 binutils/lib/Makefile create mode 100644 binutils/lib/ts_common.c create mode 100644 binutils/lib/ts_common.h create mode 100644 binutils/lib/ts_common.py create mode 100644 binutils/lib/ts_common.sh create mode 100644 binutils/lib/ts_setup create mode 100644 binutils/lib/ts_teardown create mode 100644 binutils/testcase/Makefile create mode 100644 binutils/tsuite create mode 100644 coreutils/.gitignore create mode 100644 coreutils/Makefile create mode 100644 coreutils/Makefile.common create mode 100644 coreutils/cmd/Makefile create mode 100644 coreutils/cmd/hello.c create mode 100644 coreutils/kmod/Makefile create mode 100644 coreutils/lib/Makefile create mode 100644 coreutils/lib/ts_common.c create mode 100644 coreutils/lib/ts_common.h create mode 100644 coreutils/lib/ts_common.py create mode 100644 coreutils/lib/ts_common.sh create mode 100644 coreutils/lib/ts_setup create mode 100644 coreutils/lib/ts_teardown create mode 100644 coreutils/testcase/Makefile create mode 100644 coreutils/tsuite create mode 100644 curl/.gitignore create mode 100644 curl/Makefile create mode 100644 curl/Makefile.common create mode 100644 curl/cmd/Makefile create mode 100644 curl/cmd/hello.c create mode 100644 curl/kmod/Makefile create mode 100644 curl/lib/Makefile create mode 100644 curl/lib/ts_common.c create mode 100644 curl/lib/ts_common.h create mode 100644 curl/lib/ts_common.py create mode 100644 curl/lib/ts_common.sh create mode 100644 curl/lib/ts_setup create mode 100644 curl/lib/ts_teardown create mode 100644 curl/testcase/Makefile create mode 100644 curl/tsuite create mode 100644 dnf/.gitignore create mode 100644 dnf/Makefile create mode 100644 dnf/Makefile.common create mode 100644 dnf/cmd/Makefile create mode 100644 dnf/cmd/hello.c create mode 100644 dnf/kmod/Makefile create mode 100644 dnf/lib/Makefile create mode 100644 dnf/lib/ts_common.c create mode 100644 dnf/lib/ts_common.h create mode 100644 dnf/lib/ts_common.py create mode 100644 dnf/lib/ts_common.sh create mode 100644 dnf/lib/ts_setup create mode 100644 dnf/lib/ts_teardown create mode 100644 dnf/testcase/Makefile create mode 100644 dnf/tsuite create mode 100644 findutils/.gitignore create mode 100644 findutils/Makefile create mode 100644 findutils/Makefile.common create mode 100644 findutils/cmd/Makefile create mode 100644 findutils/cmd/hello.c create mode 100644 findutils/kmod/Makefile create mode 100644 findutils/lib/Makefile create mode 100644 findutils/lib/ts_common.c create mode 100644 findutils/lib/ts_common.h create mode 100644 findutils/lib/ts_common.py create mode 100644 findutils/lib/ts_common.sh create mode 100644 findutils/lib/ts_setup create mode 100644 findutils/lib/ts_teardown create mode 100644 findutils/testcase/Makefile create mode 100644 findutils/tsuite create mode 100644 gawk/.gitignore create mode 100644 gawk/Makefile create mode 100644 gawk/Makefile.common create mode 100644 gawk/cmd/Makefile create mode 100644 gawk/cmd/hello.c create mode 100644 gawk/kmod/Makefile create mode 100644 gawk/lib/Makefile create mode 100644 gawk/lib/ts_common.c create mode 100644 gawk/lib/ts_common.h create mode 100644 gawk/lib/ts_common.py create mode 100644 gawk/lib/ts_common.sh create mode 100644 gawk/lib/ts_setup create mode 100644 gawk/lib/ts_teardown create mode 100644 gawk/testcase/Makefile create mode 100644 gawk/tsuite create mode 100644 git/.gitignore create mode 100644 git/Makefile create mode 100644 git/Makefile.common create mode 100644 git/cmd/Makefile create mode 100644 git/cmd/hello.c create mode 100644 git/kmod/Makefile create mode 100644 git/lib/Makefile create mode 100644 git/lib/ts_common.c create mode 100644 git/lib/ts_common.h create mode 100644 git/lib/ts_common.py create mode 100644 git/lib/ts_common.sh create mode 100644 git/lib/ts_setup create mode 100644 git/lib/ts_teardown create mode 100644 git/testcase/Makefile create mode 100644 git/tsuite create mode 100644 grep/.gitignore create mode 100644 grep/Makefile create mode 100644 grep/Makefile.common create mode 100644 grep/cmd/Makefile create mode 100644 grep/cmd/hello.c create mode 100644 grep/kmod/Makefile create mode 100644 grep/lib/Makefile create mode 100644 grep/lib/ts_common.c create mode 100644 grep/lib/ts_common.h create mode 100644 grep/lib/ts_common.py create mode 100644 grep/lib/ts_common.sh create mode 100644 grep/lib/ts_setup create mode 100644 grep/lib/ts_teardown create mode 100644 grep/testcase/Makefile create mode 100644 grep/tsuite create mode 100644 gzip/.gitignore create mode 100644 gzip/Makefile create mode 100644 gzip/Makefile.common create mode 100644 gzip/cmd/Makefile create mode 100644 gzip/cmd/hello.c create mode 100644 gzip/kmod/Makefile create mode 100644 gzip/lib/Makefile create mode 100644 gzip/lib/ts_common.c create mode 100644 gzip/lib/ts_common.h create mode 100644 gzip/lib/ts_common.py create mode 100644 gzip/lib/ts_common.sh create mode 100644 gzip/lib/ts_setup create mode 100644 gzip/lib/ts_teardown create mode 100644 gzip/testcase/Makefile create mode 100644 gzip/tsuite create mode 100644 iproute/.gitignore create mode 100644 iproute/Makefile create mode 100644 iproute/Makefile.common create mode 100644 iproute/cmd/Makefile create mode 100644 iproute/cmd/hello.c create mode 100644 iproute/kmod/Makefile create mode 100644 iproute/lib/Makefile create mode 100644 iproute/lib/ts_common.c create mode 100644 iproute/lib/ts_common.h create mode 100644 iproute/lib/ts_common.py create mode 100644 iproute/lib/ts_common.sh create mode 100644 iproute/lib/ts_setup create mode 100644 iproute/lib/ts_teardown create mode 100644 iproute/testcase/Makefile create mode 100644 iproute/tsuite create mode 100644 iputils/.gitignore create mode 100644 iputils/Makefile create mode 100644 iputils/Makefile.common create mode 100644 iputils/cmd/Makefile create mode 100644 iputils/cmd/hello.c create mode 100644 iputils/kmod/Makefile create mode 100644 iputils/lib/Makefile create mode 100644 iputils/lib/ts_common.c create mode 100644 iputils/lib/ts_common.h create mode 100644 iputils/lib/ts_common.py create mode 100644 iputils/lib/ts_common.sh create mode 100644 iputils/lib/ts_setup create mode 100644 iputils/lib/ts_teardown create mode 100644 iputils/testcase/Makefile create mode 100644 iputils/tsuite create mode 100644 make/.gitignore create mode 100644 make/Makefile create mode 100644 make/Makefile.common create mode 100644 make/cmd/Makefile create mode 100644 make/cmd/hello.c create mode 100644 make/kmod/Makefile create mode 100644 make/lib/Makefile create mode 100644 make/lib/ts_common.c create mode 100644 make/lib/ts_common.h create mode 100644 make/lib/ts_common.py create mode 100644 make/lib/ts_common.sh create mode 100644 make/lib/ts_setup create mode 100644 make/lib/ts_teardown create mode 100644 make/testcase/Makefile create mode 100644 make/tsuite create mode 100644 net-tools/.gitignore create mode 100644 net-tools/Makefile create mode 100644 net-tools/Makefile.common create mode 100644 net-tools/cmd/Makefile create mode 100644 net-tools/cmd/hello.c create mode 100644 net-tools/kmod/Makefile create mode 100644 net-tools/lib/Makefile create mode 100644 net-tools/lib/ts_common.c create mode 100644 net-tools/lib/ts_common.h create mode 100644 net-tools/lib/ts_common.py create mode 100644 net-tools/lib/ts_common.sh create mode 100644 net-tools/lib/ts_setup create mode 100644 net-tools/lib/ts_teardown create mode 100644 net-tools/testcase/Makefile create mode 100644 net-tools/tsuite create mode 100644 nmap/.gitignore create mode 100644 nmap/Makefile create mode 100644 nmap/Makefile.common create mode 100644 nmap/cmd/Makefile create mode 100644 nmap/cmd/hello.c create mode 100644 nmap/kmod/Makefile create mode 100644 nmap/lib/Makefile create mode 100644 nmap/lib/ts_common.c create mode 100644 nmap/lib/ts_common.h create mode 100644 nmap/lib/ts_common.py create mode 100644 nmap/lib/ts_common.sh create mode 100644 nmap/lib/ts_setup create mode 100644 nmap/lib/ts_teardown create mode 100644 nmap/testcase/Makefile create mode 100644 nmap/tsuite create mode 100644 openssh/.gitignore create mode 100644 openssh/Makefile create mode 100644 openssh/Makefile.common create mode 100644 openssh/cmd/Makefile create mode 100644 openssh/cmd/hello.c create mode 100644 openssh/kmod/Makefile create mode 100644 openssh/lib/Makefile create mode 100644 openssh/lib/ts_common.c create mode 100644 openssh/lib/ts_common.h create mode 100644 openssh/lib/ts_common.py create mode 100644 openssh/lib/ts_common.sh create mode 100644 openssh/lib/ts_setup create mode 100644 openssh/lib/ts_teardown create mode 100644 openssh/testcase/Makefile create mode 100644 openssh/tsuite create mode 100644 openssl/.gitignore create mode 100644 openssl/Makefile create mode 100644 openssl/Makefile.common create mode 100644 openssl/cmd/Makefile create mode 100644 openssl/cmd/hello.c create mode 100644 openssl/kmod/Makefile create mode 100644 openssl/lib/Makefile create mode 100644 openssl/lib/ts_common.c create mode 100644 openssl/lib/ts_common.h create mode 100644 openssl/lib/ts_common.py create mode 100644 openssl/lib/ts_common.sh create mode 100644 openssl/lib/ts_setup create mode 100644 openssl/lib/ts_teardown create mode 100644 openssl/testcase/Makefile create mode 100644 openssl/tsuite create mode 100644 perl/.gitignore create mode 100644 perl/Makefile create mode 100644 perl/Makefile.common create mode 100644 perl/cmd/Makefile create mode 100644 perl/cmd/hello.c create mode 100644 perl/kmod/Makefile create mode 100644 perl/lib/Makefile create mode 100644 perl/lib/ts_common.c create mode 100644 perl/lib/ts_common.h create mode 100644 perl/lib/ts_common.py create mode 100644 perl/lib/ts_common.sh create mode 100644 perl/lib/ts_setup create mode 100644 perl/lib/ts_teardown create mode 100644 perl/testcase/Makefile create mode 100644 perl/tsuite create mode 100644 procps-ng/.gitignore create mode 100644 procps-ng/Makefile create mode 100644 procps-ng/Makefile.common create mode 100644 procps-ng/cmd/Makefile create mode 100644 procps-ng/cmd/hello.c create mode 100644 procps-ng/kmod/Makefile create mode 100644 procps-ng/lib/Makefile create mode 100644 procps-ng/lib/ts_common.c create mode 100644 procps-ng/lib/ts_common.h create mode 100644 procps-ng/lib/ts_common.py create mode 100644 procps-ng/lib/ts_common.sh create mode 100644 procps-ng/lib/ts_setup create mode 100644 procps-ng/lib/ts_teardown create mode 100644 procps-ng/testcase/Makefile create mode 100644 procps-ng/tsuite create mode 100644 python3/.gitignore create mode 100644 python3/Makefile create mode 100644 python3/Makefile.common create mode 100644 python3/cmd/Makefile create mode 100644 python3/cmd/hello.c create mode 100644 python3/kmod/Makefile create mode 100644 python3/lib/Makefile create mode 100644 python3/lib/ts_common.c create mode 100644 python3/lib/ts_common.h create mode 100644 python3/lib/ts_common.py create mode 100644 python3/lib/ts_common.sh create mode 100644 python3/lib/ts_setup create mode 100644 python3/lib/ts_teardown create mode 100644 python3/testcase/Makefile create mode 100644 python3/tsuite create mode 100644 rpm/.gitignore create mode 100644 rpm/Makefile create mode 100644 rpm/Makefile.common create mode 100644 rpm/cmd/Makefile create mode 100644 rpm/cmd/hello.c create mode 100644 rpm/kmod/Makefile create mode 100644 rpm/lib/Makefile create mode 100644 rpm/lib/ts_common.c create mode 100644 rpm/lib/ts_common.h create mode 100644 rpm/lib/ts_common.py create mode 100644 rpm/lib/ts_common.sh create mode 100644 rpm/lib/ts_setup create mode 100644 rpm/lib/ts_teardown create mode 100644 rpm/testcase/Makefile create mode 100644 rpm/tsuite create mode 100644 sed/.gitignore create mode 100644 sed/Makefile create mode 100644 sed/Makefile.common create mode 100644 sed/cmd/Makefile create mode 100644 sed/cmd/hello.c create mode 100644 sed/kmod/Makefile create mode 100644 sed/lib/Makefile create mode 100644 sed/lib/ts_common.c create mode 100644 sed/lib/ts_common.h create mode 100644 sed/lib/ts_common.py create mode 100644 sed/lib/ts_common.sh create mode 100644 sed/lib/ts_setup create mode 100644 sed/lib/ts_teardown create mode 100644 sed/testcase/Makefile create mode 100644 sed/tsuite create mode 100644 systemd/.gitignore create mode 100644 systemd/Makefile create mode 100644 systemd/Makefile.common create mode 100644 systemd/cmd/Makefile create mode 100644 systemd/cmd/hello.c create mode 100644 systemd/kmod/Makefile create mode 100644 systemd/lib/Makefile create mode 100644 systemd/lib/ts_common.c create mode 100644 systemd/lib/ts_common.h create mode 100644 systemd/lib/ts_common.py create mode 100644 systemd/lib/ts_common.sh create mode 100644 systemd/lib/ts_setup create mode 100644 systemd/lib/ts_teardown create mode 100644 systemd/testcase/Makefile create mode 100644 systemd/tsuite create mode 100644 tar/.gitignore create mode 100644 tar/Makefile create mode 100644 tar/Makefile.common create mode 100644 tar/cmd/Makefile create mode 100644 tar/cmd/hello.c create mode 100644 tar/kmod/Makefile create mode 100644 tar/lib/Makefile create mode 100644 tar/lib/ts_common.c create mode 100644 tar/lib/ts_common.h create mode 100644 tar/lib/ts_common.py create mode 100644 tar/lib/ts_common.sh create mode 100644 tar/lib/ts_setup create mode 100644 tar/lib/ts_teardown create mode 100644 tar/testcase/Makefile create mode 100644 tar/tsuite create mode 100644 tcpdump/.gitignore create mode 100644 tcpdump/Makefile create mode 100644 tcpdump/Makefile.common create mode 100644 tcpdump/cmd/Makefile create mode 100644 tcpdump/cmd/hello.c create mode 100644 tcpdump/kmod/Makefile create mode 100644 tcpdump/lib/Makefile create mode 100644 tcpdump/lib/ts_common.c create mode 100644 tcpdump/lib/ts_common.h create mode 100644 tcpdump/lib/ts_common.py create mode 100644 tcpdump/lib/ts_common.sh create mode 100644 tcpdump/lib/ts_setup create mode 100644 tcpdump/lib/ts_teardown create mode 100644 tcpdump/testcase/Makefile create mode 100644 tcpdump/tsuite create mode 100644 util-linux/.gitignore create mode 100644 util-linux/Makefile create mode 100644 util-linux/Makefile.common create mode 100644 util-linux/cmd/Makefile create mode 100644 util-linux/cmd/hello.c create mode 100644 util-linux/kmod/Makefile create mode 100644 util-linux/lib/Makefile create mode 100644 util-linux/lib/ts_common.c create mode 100644 util-linux/lib/ts_common.h create mode 100644 util-linux/lib/ts_common.py create mode 100644 util-linux/lib/ts_common.sh create mode 100644 util-linux/lib/ts_setup create mode 100644 util-linux/lib/ts_teardown create mode 100644 util-linux/testcase/Makefile create mode 100644 util-linux/tsuite create mode 100644 wget/.gitignore create mode 100644 wget/Makefile create mode 100644 wget/Makefile.common create mode 100644 wget/cmd/Makefile create mode 100644 wget/cmd/hello.c create mode 100644 wget/kmod/Makefile create mode 100644 wget/lib/Makefile create mode 100644 wget/lib/ts_common.c create mode 100644 wget/lib/ts_common.h create mode 100644 wget/lib/ts_common.py create mode 100644 wget/lib/ts_common.sh create mode 100644 wget/lib/ts_setup create mode 100644 wget/lib/ts_teardown create mode 100644 wget/testcase/Makefile create mode 100644 wget/tsuite create mode 100644 xz/.gitignore create mode 100644 xz/Makefile create mode 100644 xz/Makefile.common create mode 100644 xz/cmd/Makefile create mode 100644 xz/cmd/hello.c create mode 100644 xz/kmod/Makefile create mode 100644 xz/lib/Makefile create mode 100644 xz/lib/ts_common.c create mode 100644 xz/lib/ts_common.h create mode 100644 xz/lib/ts_common.py create mode 100644 xz/lib/ts_common.sh create mode 100644 xz/lib/ts_setup create mode 100644 xz/lib/ts_teardown create mode 100644 xz/testcase/Makefile create mode 100644 xz/tsuite diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..844c7b7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,90 @@ +[submodule "systemd/common"] + path = systemd/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "bash/common"] + path = bash/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "coreutils/common"] + path = coreutils/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "util-linux/common"] + path = util-linux/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "rpm/common"] + path = rpm/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "dnf/common"] + path = dnf/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "procps-ng/common"] + path = procps-ng/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "findutils/common"] + path = findutils/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "openssh/common"] + path = openssh/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "iproute/common"] + path = iproute/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "iputils/common"] + path = iputils/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "net-tools/common"] + path = net-tools/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "curl/common"] + path = curl/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "wget/common"] + path = wget/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "bind/common"] + path = bind/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "tcpdump/common"] + path = tcpdump/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "nmap/common"] + path = nmap/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "NetworkManager/common"] + path = NetworkManager/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "grep/common"] + path = grep/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "sed/common"] + path = sed/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "gawk/common"] + path = gawk/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "tar/common"] + path = tar/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "gzip/common"] + path = gzip/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "xz/common"] + path = xz/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "make/common"] + path = make/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "git/common"] + path = git/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "python3/common"] + path = python3/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "perl/common"] + path = perl/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "openssl/common"] + path = openssl/common + url = https://gitee.com/opencloudos-testing/tsuite.git +[submodule "binutils/common"] + path = binutils/common + url = https://gitee.com/opencloudos-testing/tsuite.git diff --git a/NetworkManager/.gitignore b/NetworkManager/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/NetworkManager/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/NetworkManager/Makefile b/NetworkManager/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/NetworkManager/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/NetworkManager/Makefile.common b/NetworkManager/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/NetworkManager/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/NetworkManager/cmd/Makefile b/NetworkManager/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/NetworkManager/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/NetworkManager/cmd/hello.c b/NetworkManager/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/NetworkManager/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/NetworkManager/kmod/Makefile b/NetworkManager/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/NetworkManager/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/NetworkManager/lib/Makefile b/NetworkManager/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/NetworkManager/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/NetworkManager/lib/ts_common.c b/NetworkManager/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/NetworkManager/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/NetworkManager/lib/ts_common.h b/NetworkManager/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/NetworkManager/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/NetworkManager/lib/ts_common.py b/NetworkManager/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/NetworkManager/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/NetworkManager/lib/ts_common.sh b/NetworkManager/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/NetworkManager/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/NetworkManager/lib/ts_setup b/NetworkManager/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/NetworkManager/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/NetworkManager/lib/ts_teardown b/NetworkManager/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/NetworkManager/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/NetworkManager/testcase/Makefile b/NetworkManager/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/NetworkManager/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/NetworkManager/tsuite b/NetworkManager/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/NetworkManager/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..590f5dc --- /dev/null +++ b/README.en.md @@ -0,0 +1,36 @@ +# OpenCloudOS-Agent-Issue + +#### Description +agent 相关问题、需求收集 + +#### Software Architecture +Software architecture description + +#### Installation + +1. xxxx +2. xxxx +3. xxxx + +#### Instructions + +1. xxxx +2. xxxx +3. xxxx + +#### Contribution + +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request + + +#### Gitee Feature + +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e436a2e --- /dev/null +++ b/README.md @@ -0,0 +1,91 @@ + + +# OpenCloudOS-Agent-Issue + +## 介绍 + +OpenCloudOS-Agent-Issue 是一个专门用于收集和管理 OpenCloudOS Agent 相关问题与需求的开源项目仓库。 + +本仓库旨在为用户提供一个便捷的平台,用于报告 OpenCloudOS Agent 在使用过程中遇到的各类问题,以及提出功能改进建议和需求。 + +## 软件架构 + +作为问题收集仓库,本项目不涉及具体的代码实现,主要包含: + +- **问题跟踪**:收集各类 Agent 使用问题 +- **需求收集**:汇总用户功能需求和改进建议 +- **文档记录**:记录已知问题和解决方案 + +## 安装教程 + +本仓库为问题跟踪仓库,无需安装。您可以直接在 Gitee 上浏览和提交问题。 + +### 访问仓库 + +1. 访问仓库地址:https://gitee.com/OpenCloudOS/opencloudos-agent-issue +2. 点击 "Star" 关注项目更新 +3. 点击 "Watch" 订阅项目动态 + +## 使用说明 + +### 提交问题 + +1. **搜索现有问题**:在提交新问题前,请先搜索是否已存在相同或类似问题 +2. **创建 Issue**:点击 "新建 Issue" 按钮 +3. **填写问题信息**: + - 标题:简明扼要描述问题 + - 标签:选择适当的问题类型标签 + - 详细内容:描述问题现象、复现步骤、环境信息等 + - 附件:如有需要,可上传日志、截图等 + +### 问题分类 + +请根据问题类型选择合适的标签: + +- **Bug**:程序错误或异常行为 +- **Feature Request**:新功能请求 +- **Enhancement**:现有功能改进 +- **Question**:问题咨询 +- **Documentation**:文档相关 + +### 参与贡献 + +1. **Fork 本仓库**:点击右上角 Fork 按钮 +2. **新建分支**:创建 Feat_xxx 分支用于提交修改 +3. **提交 Pull Request**:提交您的修改并等待审核 + +## 问题反馈模板 + +建议按以下格式提交问题: + +```markdown +## 问题描述 +[详细描述遇到的问题] + +## 环境信息 +- 操作系统: +- Agent 版本: + +## 复现步骤 +1. 第一步 +2. 第二步 +3. 第三步 + +## 预期行为 +[描述您期望的行为] + +## 实际行为 +[描述实际发生的行为] + +## 相关日志 +[如有日志,请粘贴在此] +``` + +## 联系方式 + +- 项目主页:https://gitee.com/OpenCloudOS/opencloudos-agent-issue +- 问题反馈:欢迎通过 Issue 提交问题和建议 + +## 开源协议 + +本项目遵循开源社区惯例,欢迎社区成员积极参与贡献。 \ No newline at end of file diff --git a/ant-condition-fail-build.sh b/ant-condition-fail-build.sh new file mode 100644 index 0000000..0885435 --- /dev/null +++ b/ant-condition-fail-build.sh @@ -0,0 +1,84 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260405-232654-173528830 +# @用例名称: ant-condition-fail-build +# @用例级别: 3 +# @用例标签: ant +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 ant 构建脚本中的 fail 条件触发后命令返回失败 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" +g_buildfile="$g_tmpdir/build.xml" +g_marker_file="$g_tmpdir/should_not_exist.txt" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装软件包 + msg "CHECK: 安装 ant 软件包的命令即将执行, 实际值=ant" + assert_true yum install -y ant + + # @预置条件: 创建包含条件 fail 逻辑的 Ant 构建文件 + cat > "$g_buildfile" < + + + + + + unexpected success + + +EOF + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 执行包含 fail 条件的 verify 目标 + # @预期结果: ant 命令执行失败,退出码非 0 + ant -f "$g_buildfile" verify > "$g_tmpdir/ant.out" 2>&1 + ret=$? + msg "CHECK: 执行 ant verify 的退出码, 实际值=$ret" + assert_false [ $ret -eq 0 ] + + # @测试步骤: 检查 fail 触发后后续 echo 是否未执行 + # @预期结果: 标记文件不存在 + msg "CHECK: 标记文件是否不存在, 实际值=$([ -f "$g_marker_file" ] && echo 存在 || echo 不存在)" + assert_true test ! -f "$g_marker_file" + + # @测试步骤: 检查输出中不应出现 BUILD SUCCESSFUL + # @预期结果: 输出不包含 BUILD SUCCESSFUL + grep -q -i "BUILD SUCCESSFUL" "$g_tmpdir/ant.out" + ret=$? + msg "CHECK: ant 输出不应包含 BUILD SUCCESSFUL, 实际值=$ret" + assert_true [ $ret -ne 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/bash/.gitignore b/bash/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/bash/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/bash/Makefile b/bash/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/bash/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/bash/Makefile.common b/bash/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/bash/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/bash/cmd/Makefile b/bash/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/bash/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/bash/cmd/hello.c b/bash/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/bash/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/bash/kmod/Makefile b/bash/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/bash/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/bash/lib/Makefile b/bash/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/bash/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/bash/lib/ts_common.c b/bash/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/bash/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/bash/lib/ts_common.h b/bash/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/bash/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/bash/lib/ts_common.py b/bash/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/bash/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/bash/lib/ts_common.sh b/bash/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/bash/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/bash/lib/ts_setup b/bash/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/bash/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/bash/lib/ts_teardown b/bash/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/bash/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/bash/testcase/Makefile b/bash/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/bash/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/bash/tsuite b/bash/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/bash/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/bind/.gitignore b/bind/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/bind/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/bind/Makefile b/bind/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/bind/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/bind/Makefile.common b/bind/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/bind/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/bind/cmd/Makefile b/bind/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/bind/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/bind/cmd/hello.c b/bind/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/bind/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/bind/kmod/Makefile b/bind/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/bind/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/bind/lib/Makefile b/bind/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/bind/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/bind/lib/ts_common.c b/bind/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/bind/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/bind/lib/ts_common.h b/bind/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/bind/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/bind/lib/ts_common.py b/bind/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/bind/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/bind/lib/ts_common.sh b/bind/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/bind/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/bind/lib/ts_setup b/bind/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/bind/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/bind/lib/ts_teardown b/bind/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/bind/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/bind/testcase/Makefile b/bind/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/bind/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/bind/tsuite b/bind/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/bind/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/binutils/.gitignore b/binutils/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/binutils/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/binutils/Makefile b/binutils/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/binutils/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/binutils/Makefile.common b/binutils/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/binutils/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/binutils/cmd/Makefile b/binutils/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/binutils/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/binutils/cmd/hello.c b/binutils/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/binutils/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/binutils/kmod/Makefile b/binutils/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/binutils/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/binutils/lib/Makefile b/binutils/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/binutils/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/binutils/lib/ts_common.c b/binutils/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/binutils/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/binutils/lib/ts_common.h b/binutils/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/binutils/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/binutils/lib/ts_common.py b/binutils/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/binutils/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/binutils/lib/ts_common.sh b/binutils/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/binutils/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/binutils/lib/ts_setup b/binutils/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/binutils/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/binutils/lib/ts_teardown b/binutils/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/binutils/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/binutils/testcase/Makefile b/binutils/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/binutils/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/binutils/tsuite b/binutils/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/binutils/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/coreutils/.gitignore b/coreutils/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/coreutils/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/coreutils/Makefile b/coreutils/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/coreutils/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/coreutils/Makefile.common b/coreutils/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/coreutils/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/coreutils/cmd/Makefile b/coreutils/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/coreutils/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/coreutils/cmd/hello.c b/coreutils/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/coreutils/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/coreutils/kmod/Makefile b/coreutils/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/coreutils/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/coreutils/lib/Makefile b/coreutils/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/coreutils/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/coreutils/lib/ts_common.c b/coreutils/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/coreutils/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/coreutils/lib/ts_common.h b/coreutils/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/coreutils/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/coreutils/lib/ts_common.py b/coreutils/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/coreutils/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/coreutils/lib/ts_common.sh b/coreutils/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/coreutils/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/coreutils/lib/ts_setup b/coreutils/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/coreutils/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/coreutils/lib/ts_teardown b/coreutils/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/coreutils/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/coreutils/testcase/Makefile b/coreutils/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/coreutils/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/coreutils/tsuite b/coreutils/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/coreutils/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/curl/.gitignore b/curl/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/curl/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/curl/Makefile b/curl/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/curl/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/curl/Makefile.common b/curl/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/curl/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/curl/cmd/Makefile b/curl/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/curl/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/curl/cmd/hello.c b/curl/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/curl/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/curl/kmod/Makefile b/curl/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/curl/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/curl/lib/Makefile b/curl/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/curl/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/curl/lib/ts_common.c b/curl/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/curl/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/curl/lib/ts_common.h b/curl/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/curl/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/curl/lib/ts_common.py b/curl/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/curl/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/curl/lib/ts_common.sh b/curl/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/curl/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/curl/lib/ts_setup b/curl/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/curl/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/curl/lib/ts_teardown b/curl/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/curl/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/curl/testcase/Makefile b/curl/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/curl/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/curl/tsuite b/curl/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/curl/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/dnf/.gitignore b/dnf/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/dnf/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/dnf/Makefile b/dnf/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/dnf/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/dnf/Makefile.common b/dnf/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/dnf/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/dnf/cmd/Makefile b/dnf/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/dnf/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/dnf/cmd/hello.c b/dnf/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/dnf/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/dnf/kmod/Makefile b/dnf/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/dnf/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/dnf/lib/Makefile b/dnf/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/dnf/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/dnf/lib/ts_common.c b/dnf/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/dnf/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/dnf/lib/ts_common.h b/dnf/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/dnf/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/dnf/lib/ts_common.py b/dnf/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/dnf/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/dnf/lib/ts_common.sh b/dnf/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/dnf/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/dnf/lib/ts_setup b/dnf/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/dnf/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/dnf/lib/ts_teardown b/dnf/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/dnf/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/dnf/testcase/Makefile b/dnf/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/dnf/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/dnf/tsuite b/dnf/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/dnf/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/findutils/.gitignore b/findutils/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/findutils/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/findutils/Makefile b/findutils/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/findutils/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/findutils/Makefile.common b/findutils/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/findutils/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/findutils/cmd/Makefile b/findutils/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/findutils/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/findutils/cmd/hello.c b/findutils/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/findutils/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/findutils/kmod/Makefile b/findutils/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/findutils/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/findutils/lib/Makefile b/findutils/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/findutils/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/findutils/lib/ts_common.c b/findutils/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/findutils/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/findutils/lib/ts_common.h b/findutils/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/findutils/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/findutils/lib/ts_common.py b/findutils/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/findutils/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/findutils/lib/ts_common.sh b/findutils/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/findutils/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/findutils/lib/ts_setup b/findutils/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/findutils/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/findutils/lib/ts_teardown b/findutils/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/findutils/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/findutils/testcase/Makefile b/findutils/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/findutils/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/findutils/tsuite b/findutils/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/findutils/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/gawk/.gitignore b/gawk/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/gawk/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/gawk/Makefile b/gawk/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/gawk/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/gawk/Makefile.common b/gawk/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/gawk/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/gawk/cmd/Makefile b/gawk/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/gawk/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/gawk/cmd/hello.c b/gawk/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/gawk/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/gawk/kmod/Makefile b/gawk/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/gawk/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/gawk/lib/Makefile b/gawk/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/gawk/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/gawk/lib/ts_common.c b/gawk/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/gawk/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/gawk/lib/ts_common.h b/gawk/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/gawk/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/gawk/lib/ts_common.py b/gawk/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/gawk/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/gawk/lib/ts_common.sh b/gawk/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/gawk/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/gawk/lib/ts_setup b/gawk/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/gawk/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/gawk/lib/ts_teardown b/gawk/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/gawk/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/gawk/testcase/Makefile b/gawk/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/gawk/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/gawk/tsuite b/gawk/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/gawk/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/git/.gitignore b/git/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/git/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/git/Makefile b/git/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/git/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/git/Makefile.common b/git/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/git/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/git/cmd/Makefile b/git/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/git/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/git/cmd/hello.c b/git/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/git/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/git/kmod/Makefile b/git/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/git/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/git/lib/Makefile b/git/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/git/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/git/lib/ts_common.c b/git/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/git/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/git/lib/ts_common.h b/git/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/git/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/git/lib/ts_common.py b/git/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/git/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/git/lib/ts_common.sh b/git/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/git/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/git/lib/ts_setup b/git/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/git/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/git/lib/ts_teardown b/git/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/git/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/git/testcase/Makefile b/git/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/git/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/git/tsuite b/git/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/git/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/grep/.gitignore b/grep/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/grep/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/grep/Makefile b/grep/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/grep/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/grep/Makefile.common b/grep/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/grep/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/grep/cmd/Makefile b/grep/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/grep/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/grep/cmd/hello.c b/grep/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/grep/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/grep/kmod/Makefile b/grep/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/grep/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/grep/lib/Makefile b/grep/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/grep/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/grep/lib/ts_common.c b/grep/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/grep/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/grep/lib/ts_common.h b/grep/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/grep/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/grep/lib/ts_common.py b/grep/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/grep/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/grep/lib/ts_common.sh b/grep/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/grep/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/grep/lib/ts_setup b/grep/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/grep/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/grep/lib/ts_teardown b/grep/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/grep/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/grep/testcase/Makefile b/grep/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/grep/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/grep/tsuite b/grep/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/grep/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/gzip/.gitignore b/gzip/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/gzip/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/gzip/Makefile b/gzip/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/gzip/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/gzip/Makefile.common b/gzip/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/gzip/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/gzip/cmd/Makefile b/gzip/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/gzip/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/gzip/cmd/hello.c b/gzip/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/gzip/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/gzip/kmod/Makefile b/gzip/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/gzip/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/gzip/lib/Makefile b/gzip/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/gzip/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/gzip/lib/ts_common.c b/gzip/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/gzip/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/gzip/lib/ts_common.h b/gzip/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/gzip/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/gzip/lib/ts_common.py b/gzip/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/gzip/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/gzip/lib/ts_common.sh b/gzip/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/gzip/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/gzip/lib/ts_setup b/gzip/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/gzip/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/gzip/lib/ts_teardown b/gzip/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/gzip/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/gzip/testcase/Makefile b/gzip/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/gzip/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/gzip/tsuite b/gzip/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/gzip/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/iproute/.gitignore b/iproute/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/iproute/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/iproute/Makefile b/iproute/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/iproute/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/iproute/Makefile.common b/iproute/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/iproute/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/iproute/cmd/Makefile b/iproute/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/iproute/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/iproute/cmd/hello.c b/iproute/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/iproute/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/iproute/kmod/Makefile b/iproute/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/iproute/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/iproute/lib/Makefile b/iproute/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/iproute/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/iproute/lib/ts_common.c b/iproute/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/iproute/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/iproute/lib/ts_common.h b/iproute/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/iproute/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/iproute/lib/ts_common.py b/iproute/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/iproute/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/iproute/lib/ts_common.sh b/iproute/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/iproute/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/iproute/lib/ts_setup b/iproute/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/iproute/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/iproute/lib/ts_teardown b/iproute/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/iproute/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/iproute/testcase/Makefile b/iproute/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/iproute/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/iproute/tsuite b/iproute/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/iproute/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/iputils/.gitignore b/iputils/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/iputils/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/iputils/Makefile b/iputils/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/iputils/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/iputils/Makefile.common b/iputils/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/iputils/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/iputils/cmd/Makefile b/iputils/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/iputils/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/iputils/cmd/hello.c b/iputils/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/iputils/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/iputils/kmod/Makefile b/iputils/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/iputils/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/iputils/lib/Makefile b/iputils/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/iputils/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/iputils/lib/ts_common.c b/iputils/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/iputils/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/iputils/lib/ts_common.h b/iputils/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/iputils/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/iputils/lib/ts_common.py b/iputils/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/iputils/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/iputils/lib/ts_common.sh b/iputils/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/iputils/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/iputils/lib/ts_setup b/iputils/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/iputils/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/iputils/lib/ts_teardown b/iputils/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/iputils/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/iputils/testcase/Makefile b/iputils/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/iputils/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/iputils/tsuite b/iputils/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/iputils/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/make/.gitignore b/make/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/make/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/make/Makefile b/make/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/make/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/make/Makefile.common b/make/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/make/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/make/cmd/Makefile b/make/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/make/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/make/cmd/hello.c b/make/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/make/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/make/kmod/Makefile b/make/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/make/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/make/lib/Makefile b/make/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/make/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/make/lib/ts_common.c b/make/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/make/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/make/lib/ts_common.h b/make/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/make/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/make/lib/ts_common.py b/make/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/make/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/make/lib/ts_common.sh b/make/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/make/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/make/lib/ts_setup b/make/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/make/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/make/lib/ts_teardown b/make/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/make/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/make/testcase/Makefile b/make/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/make/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/make/tsuite b/make/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/make/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/net-tools/.gitignore b/net-tools/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/net-tools/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/net-tools/Makefile b/net-tools/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/net-tools/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/net-tools/Makefile.common b/net-tools/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/net-tools/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/net-tools/cmd/Makefile b/net-tools/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/net-tools/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/net-tools/cmd/hello.c b/net-tools/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/net-tools/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/net-tools/kmod/Makefile b/net-tools/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/net-tools/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/net-tools/lib/Makefile b/net-tools/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/net-tools/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/net-tools/lib/ts_common.c b/net-tools/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/net-tools/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/net-tools/lib/ts_common.h b/net-tools/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/net-tools/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/net-tools/lib/ts_common.py b/net-tools/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/net-tools/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/net-tools/lib/ts_common.sh b/net-tools/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/net-tools/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/net-tools/lib/ts_setup b/net-tools/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/net-tools/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/net-tools/lib/ts_teardown b/net-tools/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/net-tools/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/net-tools/testcase/Makefile b/net-tools/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/net-tools/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/net-tools/tsuite b/net-tools/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/net-tools/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/nmap/.gitignore b/nmap/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/nmap/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/nmap/Makefile b/nmap/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/nmap/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/nmap/Makefile.common b/nmap/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/nmap/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/nmap/cmd/Makefile b/nmap/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/nmap/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/nmap/cmd/hello.c b/nmap/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/nmap/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/nmap/kmod/Makefile b/nmap/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/nmap/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/nmap/lib/Makefile b/nmap/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/nmap/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/nmap/lib/ts_common.c b/nmap/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/nmap/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/nmap/lib/ts_common.h b/nmap/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/nmap/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/nmap/lib/ts_common.py b/nmap/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/nmap/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/nmap/lib/ts_common.sh b/nmap/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/nmap/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/nmap/lib/ts_setup b/nmap/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/nmap/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/nmap/lib/ts_teardown b/nmap/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/nmap/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/nmap/testcase/Makefile b/nmap/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/nmap/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/nmap/tsuite b/nmap/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/nmap/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/openssh/.gitignore b/openssh/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/openssh/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/openssh/Makefile b/openssh/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/openssh/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/openssh/Makefile.common b/openssh/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/openssh/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/openssh/cmd/Makefile b/openssh/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/openssh/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/openssh/cmd/hello.c b/openssh/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/openssh/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/openssh/kmod/Makefile b/openssh/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/openssh/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/openssh/lib/Makefile b/openssh/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/openssh/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/openssh/lib/ts_common.c b/openssh/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/openssh/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/openssh/lib/ts_common.h b/openssh/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/openssh/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/openssh/lib/ts_common.py b/openssh/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/openssh/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/openssh/lib/ts_common.sh b/openssh/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/openssh/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/openssh/lib/ts_setup b/openssh/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/openssh/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/openssh/lib/ts_teardown b/openssh/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/openssh/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/openssh/testcase/Makefile b/openssh/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/openssh/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/openssh/tsuite b/openssh/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/openssh/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/openssl/.gitignore b/openssl/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/openssl/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/openssl/Makefile b/openssl/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/openssl/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/openssl/Makefile.common b/openssl/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/openssl/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/openssl/cmd/Makefile b/openssl/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/openssl/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/openssl/cmd/hello.c b/openssl/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/openssl/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/openssl/kmod/Makefile b/openssl/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/openssl/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/openssl/lib/Makefile b/openssl/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/openssl/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/openssl/lib/ts_common.c b/openssl/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/openssl/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/openssl/lib/ts_common.h b/openssl/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/openssl/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/openssl/lib/ts_common.py b/openssl/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/openssl/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/openssl/lib/ts_common.sh b/openssl/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/openssl/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/openssl/lib/ts_setup b/openssl/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/openssl/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/openssl/lib/ts_teardown b/openssl/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/openssl/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/openssl/testcase/Makefile b/openssl/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/openssl/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/openssl/tsuite b/openssl/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/openssl/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/perl/.gitignore b/perl/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/perl/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/perl/Makefile b/perl/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/perl/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/perl/Makefile.common b/perl/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/perl/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/perl/cmd/Makefile b/perl/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/perl/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/perl/cmd/hello.c b/perl/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/perl/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/perl/kmod/Makefile b/perl/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/perl/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/perl/lib/Makefile b/perl/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/perl/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/perl/lib/ts_common.c b/perl/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/perl/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/perl/lib/ts_common.h b/perl/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/perl/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/perl/lib/ts_common.py b/perl/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/perl/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/perl/lib/ts_common.sh b/perl/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/perl/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/perl/lib/ts_setup b/perl/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/perl/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/perl/lib/ts_teardown b/perl/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/perl/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/perl/testcase/Makefile b/perl/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/perl/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/perl/tsuite b/perl/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/perl/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/procps-ng/.gitignore b/procps-ng/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/procps-ng/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/procps-ng/Makefile b/procps-ng/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/procps-ng/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/procps-ng/Makefile.common b/procps-ng/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/procps-ng/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/procps-ng/cmd/Makefile b/procps-ng/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/procps-ng/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/procps-ng/cmd/hello.c b/procps-ng/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/procps-ng/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/procps-ng/kmod/Makefile b/procps-ng/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/procps-ng/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/procps-ng/lib/Makefile b/procps-ng/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/procps-ng/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/procps-ng/lib/ts_common.c b/procps-ng/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/procps-ng/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/procps-ng/lib/ts_common.h b/procps-ng/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/procps-ng/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/procps-ng/lib/ts_common.py b/procps-ng/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/procps-ng/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/procps-ng/lib/ts_common.sh b/procps-ng/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/procps-ng/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/procps-ng/lib/ts_setup b/procps-ng/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/procps-ng/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/procps-ng/lib/ts_teardown b/procps-ng/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/procps-ng/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/procps-ng/testcase/Makefile b/procps-ng/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/procps-ng/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/procps-ng/tsuite b/procps-ng/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/procps-ng/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/python3/.gitignore b/python3/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/python3/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/python3/Makefile b/python3/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/python3/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/python3/Makefile.common b/python3/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/python3/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/python3/cmd/Makefile b/python3/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/python3/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/python3/cmd/hello.c b/python3/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/python3/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/python3/kmod/Makefile b/python3/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/python3/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/python3/lib/Makefile b/python3/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/python3/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/python3/lib/ts_common.c b/python3/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/python3/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/python3/lib/ts_common.h b/python3/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/python3/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/python3/lib/ts_common.py b/python3/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/python3/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/python3/lib/ts_common.sh b/python3/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/python3/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/python3/lib/ts_setup b/python3/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/python3/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/python3/lib/ts_teardown b/python3/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/python3/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/python3/testcase/Makefile b/python3/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/python3/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/python3/tsuite b/python3/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/python3/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/rpm/.gitignore b/rpm/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/rpm/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/rpm/Makefile b/rpm/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/rpm/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/rpm/Makefile.common b/rpm/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/rpm/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/rpm/cmd/Makefile b/rpm/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/rpm/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/rpm/cmd/hello.c b/rpm/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/rpm/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/rpm/kmod/Makefile b/rpm/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/rpm/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/rpm/lib/Makefile b/rpm/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/rpm/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/rpm/lib/ts_common.c b/rpm/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/rpm/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/rpm/lib/ts_common.h b/rpm/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/rpm/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/rpm/lib/ts_common.py b/rpm/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/rpm/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/rpm/lib/ts_common.sh b/rpm/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/rpm/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/rpm/lib/ts_setup b/rpm/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/rpm/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/rpm/lib/ts_teardown b/rpm/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/rpm/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/rpm/testcase/Makefile b/rpm/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/rpm/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/rpm/tsuite b/rpm/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/rpm/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/sed/.gitignore b/sed/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/sed/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/sed/Makefile b/sed/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/sed/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/sed/Makefile.common b/sed/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/sed/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/sed/cmd/Makefile b/sed/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/sed/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/sed/cmd/hello.c b/sed/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/sed/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/sed/kmod/Makefile b/sed/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/sed/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/sed/lib/Makefile b/sed/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/sed/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/sed/lib/ts_common.c b/sed/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/sed/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/sed/lib/ts_common.h b/sed/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/sed/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/sed/lib/ts_common.py b/sed/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/sed/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/sed/lib/ts_common.sh b/sed/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/sed/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/sed/lib/ts_setup b/sed/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/sed/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/sed/lib/ts_teardown b/sed/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/sed/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/sed/testcase/Makefile b/sed/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/sed/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/sed/tsuite b/sed/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/sed/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/systemd/.gitignore b/systemd/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/systemd/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/systemd/Makefile b/systemd/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/systemd/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/systemd/Makefile.common b/systemd/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/systemd/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/systemd/cmd/Makefile b/systemd/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/systemd/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/systemd/cmd/hello.c b/systemd/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/systemd/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/systemd/kmod/Makefile b/systemd/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/systemd/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/systemd/lib/Makefile b/systemd/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/systemd/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/systemd/lib/ts_common.c b/systemd/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/systemd/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/systemd/lib/ts_common.h b/systemd/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/systemd/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/systemd/lib/ts_common.py b/systemd/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/systemd/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/systemd/lib/ts_common.sh b/systemd/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/systemd/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/systemd/lib/ts_setup b/systemd/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/systemd/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/systemd/lib/ts_teardown b/systemd/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/systemd/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/systemd/testcase/Makefile b/systemd/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/systemd/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/systemd/tsuite b/systemd/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/systemd/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/tar/.gitignore b/tar/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/tar/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/tar/Makefile b/tar/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/tar/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/tar/Makefile.common b/tar/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/tar/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/tar/cmd/Makefile b/tar/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/tar/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/tar/cmd/hello.c b/tar/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/tar/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/tar/kmod/Makefile b/tar/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/tar/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/tar/lib/Makefile b/tar/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/tar/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/tar/lib/ts_common.c b/tar/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/tar/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/tar/lib/ts_common.h b/tar/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/tar/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/tar/lib/ts_common.py b/tar/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/tar/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/tar/lib/ts_common.sh b/tar/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/tar/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/tar/lib/ts_setup b/tar/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/tar/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/tar/lib/ts_teardown b/tar/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/tar/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/tar/testcase/Makefile b/tar/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/tar/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/tar/tsuite b/tar/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/tar/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/tcpdump/.gitignore b/tcpdump/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/tcpdump/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/tcpdump/Makefile b/tcpdump/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/tcpdump/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/tcpdump/Makefile.common b/tcpdump/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/tcpdump/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/tcpdump/cmd/Makefile b/tcpdump/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/tcpdump/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/tcpdump/cmd/hello.c b/tcpdump/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/tcpdump/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/tcpdump/kmod/Makefile b/tcpdump/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/tcpdump/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/tcpdump/lib/Makefile b/tcpdump/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/tcpdump/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/tcpdump/lib/ts_common.c b/tcpdump/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/tcpdump/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/tcpdump/lib/ts_common.h b/tcpdump/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/tcpdump/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/tcpdump/lib/ts_common.py b/tcpdump/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/tcpdump/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/tcpdump/lib/ts_common.sh b/tcpdump/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/tcpdump/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/tcpdump/lib/ts_setup b/tcpdump/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/tcpdump/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/tcpdump/lib/ts_teardown b/tcpdump/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/tcpdump/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/tcpdump/testcase/Makefile b/tcpdump/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/tcpdump/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/tcpdump/tsuite b/tcpdump/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/tcpdump/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/util-linux/.gitignore b/util-linux/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/util-linux/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/util-linux/Makefile b/util-linux/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/util-linux/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/util-linux/Makefile.common b/util-linux/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/util-linux/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/util-linux/cmd/Makefile b/util-linux/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/util-linux/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/util-linux/cmd/hello.c b/util-linux/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/util-linux/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/util-linux/kmod/Makefile b/util-linux/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/util-linux/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/util-linux/lib/Makefile b/util-linux/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/util-linux/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/util-linux/lib/ts_common.c b/util-linux/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/util-linux/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/util-linux/lib/ts_common.h b/util-linux/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/util-linux/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/util-linux/lib/ts_common.py b/util-linux/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/util-linux/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/util-linux/lib/ts_common.sh b/util-linux/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/util-linux/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/util-linux/lib/ts_setup b/util-linux/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/util-linux/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/util-linux/lib/ts_teardown b/util-linux/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/util-linux/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/util-linux/testcase/Makefile b/util-linux/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/util-linux/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/util-linux/tsuite b/util-linux/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/util-linux/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/wget/.gitignore b/wget/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/wget/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/wget/Makefile b/wget/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/wget/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/wget/Makefile.common b/wget/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/wget/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/wget/cmd/Makefile b/wget/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/wget/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/wget/cmd/hello.c b/wget/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/wget/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/wget/kmod/Makefile b/wget/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/wget/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/wget/lib/Makefile b/wget/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/wget/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/wget/lib/ts_common.c b/wget/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/wget/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/wget/lib/ts_common.h b/wget/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/wget/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/wget/lib/ts_common.py b/wget/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/wget/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/wget/lib/ts_common.sh b/wget/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/wget/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/wget/lib/ts_setup b/wget/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/wget/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/wget/lib/ts_teardown b/wget/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/wget/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/wget/testcase/Makefile b/wget/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/wget/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/wget/tsuite b/wget/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/wget/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" diff --git a/xz/.gitignore b/xz/.gitignore new file mode 100644 index 0000000..f634975 --- /dev/null +++ b/xz/.gitignore @@ -0,0 +1,17 @@ +.idea/ +logs/ +__pycache__/ +*.o +*.a +*.d +*.cmd +*.test +*.ko +*.mod +*.mod.c +Module.symvers +modules.order +compile_commands.json +/*.json +/*.xlsx + diff --git a/xz/Makefile b/xz/Makefile new file mode 100644 index 0000000..2606fa9 --- /dev/null +++ b/xz/Makefile @@ -0,0 +1,27 @@ +export TST_TS_TOPDIR := $(shell pwd) +DIRS := cmd kmod testcase +LIBS := common lib + +all: libs + @for d in $(DIRS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +libs: + @for d in $(LIBS); do \ + echo try make $$d; \ + make -C $$d all; \ + done + +clean: + @for d in $(DIRS) $(LIBS); do \ + echo try clean $$d; \ + make -C $$d clean; \ + done + +cleanall: + @for d in $(DIRS) $(LIBS); do \ + echo try cleanall $$d; \ + make -C $$d cleanall; \ + done diff --git a/xz/Makefile.common b/xz/Makefile.common new file mode 100644 index 0000000..812f9dc --- /dev/null +++ b/xz/Makefile.common @@ -0,0 +1,3 @@ +CFLAGS += -Wall -g -I$(TST_TS_TOPDIR)/common/lib -I$(TST_TS_TOPDIR)/lib +LDFLAGS += -L$(TST_TS_TOPDIR)/common/lib -L$(TST_TS_TOPDIR)/lib +LDFLAGS += -lm -lrt -lpthread -Wl,--whole-archive -lcommon -ltscommon -Wl,--no-whole-archive diff --git a/xz/cmd/Makefile b/xz/cmd/Makefile new file mode 100644 index 0000000..133158c --- /dev/null +++ b/xz/cmd/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.cmd,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.cmd:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/xz/cmd/hello.c b/xz/cmd/hello.c new file mode 100644 index 0000000..c70b442 --- /dev/null +++ b/xz/cmd/hello.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + printf("hello world\n"); + return 0; +} diff --git a/xz/kmod/Makefile b/xz/kmod/Makefile new file mode 100644 index 0000000..5f4ff1a --- /dev/null +++ b/xz/kmod/Makefile @@ -0,0 +1,33 @@ +# General Purpose Makefile for Linux Kernel module +# 以下编译适合于在内核代码树之外编译内核模块。 +# 整个过程会导致本Makefile文件被加载执行两遍。 +# 第一遍执行时,由于`KERNELRELEASE`没有被定义,所以先执行`else`下的逻辑。 +# `-C $(KERNEL_DIR)`指明跳转到内核源码目录下读取那里的Makefile; +# `M=$(CURDIR)`表明然后返回到当前目录继续读入当前的Makefile并执行之。此为第二遍执行。 +# 第二遍执行时,此时从内核源码目录返回时,KERNELRELEASE已被被定义, +# kbuild也被启动去解析kbuild语法的语句,make将继续读取else之前的内容。 +# else之前的内容为kbuild语法的语句, 指明模块源码中各文件的依赖关系,以及要生成的目标模块名。 + +CURDIR ?= $(shell pwd) +KERNEL_VER := $(shell uname -r) +KERNEL_DIR ?= /usr/src/kernels/$(KERNEL_VER) +export ALL_SRC ?= $(filter-out %.mod.c, $(wildcard *.c)) +export ALL_OBJ ?= $(patsubst %.c,%.o,$(ALL_SRC)) +export ALL_MOD ?= $(patsubst %.o,%.ko,$(ALL_OBJ)) + +ifneq ($(KERNELRELEASE),) + obj-m += $(ALL_OBJ) +else +all: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) modules + ../tsuite sign $(ALL_MOD) +endif +endif + +clean: +ifneq ($(ALL_OBJ),) + $(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean +endif + +cleanall: clean diff --git a/xz/lib/Makefile b/xz/lib/Makefile new file mode 100644 index 0000000..171b10b --- /dev/null +++ b/xz/lib/Makefile @@ -0,0 +1,20 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(wildcard *.c) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +LIB_STATIC := libtscommon.a +CFLAGS += + +all: $(LIB_STATIC) + +$(LIB_STATIC): $(ALL_OBJ) + ar -rc $(LIB_STATIC) $(ALL_OBJ) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(LIB_STATIC) $(ALL_OBJ) + +cleanall: clean + rm -rfv __pycache__ diff --git a/xz/lib/ts_common.c b/xz/lib/ts_common.c new file mode 100644 index 0000000..b449430 --- /dev/null +++ b/xz/lib/ts_common.c @@ -0,0 +1,14 @@ +// 测试套自定义公共函数库 +#include "common.h" +#include "ts_common.h" + +int tc_setup_common(int argc, char **argv) { + msg("this is tc_setup_common"); + return 0; +} + +int tc_teardown_common(int argc, char **argv) { + msg("this is tc_teardown_common"); + return 0; +} + diff --git a/xz/lib/ts_common.h b/xz/lib/ts_common.h new file mode 100644 index 0000000..9ed2c5f --- /dev/null +++ b/xz/lib/ts_common.h @@ -0,0 +1,6 @@ +#ifndef __TS_COMMON_H__ +#define __TS_COMMON_H__ + +// 测试套自定义头文件内容 + +#endif // __TS_COMMON_H__ diff --git a/xz/lib/ts_common.py b/xz/lib/ts_common.py new file mode 100644 index 0000000..51ca901 --- /dev/null +++ b/xz/lib/ts_common.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# coding: utf-8 +# Desc: 测试套公共模块 +import abc +import os.path +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) +from common.lib.common import TestCase + + +class MyTestCase(TestCase): + """ + 本测试套内的Python用例需要继承此类 + """ + + def tc_setup_common(self, *args): + """ + 所有Python用例执行tc_setup函数前会先执行本函数 + :param args: + :return: + """ + self.msg("this is tc_setup_common") + + @abc.abstractmethod + def do_test(self, *args): + pass + + def tc_teardown_common(self, *args): + """ + 所有Python用例执行tc_teardown函数后会执行本函数 + :param args: + :return: + """ + self.msg("this is tc_teardown_common") diff --git a/xz/lib/ts_common.sh b/xz/lib/ts_common.sh new file mode 100644 index 0000000..6ef4aa8 --- /dev/null +++ b/xz/lib/ts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# 测试套公共函数 +# 约定: +# 1、以下划线"_"开头的函数和变量用例不能直接调用 +# 2、环境变量全大写,全局变量加上"g_"前置,局部变量统一加"local"修饰 + +tc_setup_common() { + msg "this is tc_setup_common" + return 0 +} + +tc_teardown_common() { + msg "this is tc_teardown_common" + return 0 +} + diff --git a/xz/lib/ts_setup b/xz/lib/ts_setup new file mode 100644 index 0000000..3aaab92 --- /dev/null +++ b/xz/lib/ts_setup @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_setup +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_setup() { + # 测试套setup脚本,在这里增加setup操作 + msg "this is ts_setup" + return 0 +} + +ts_setup diff --git a/xz/lib/ts_teardown b/xz/lib/ts_teardown new file mode 100644 index 0000000..8616195 --- /dev/null +++ b/xz/lib/ts_teardown @@ -0,0 +1,13 @@ +#!/bin/bash +# Time: 2022-04-19 22:44:25 +# Desc: ts_teardown +[ -z "$TST_TS_TOPDIR" ] && export TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" +source "${TST_TS_TOPDIR}/common/lib/common.sh" + +ts_teardown() { + # 测试套teardown脚本,在这里增加teardown操作 + msg "this is ts_teardown" + return 0 +} + +ts_teardown diff --git a/xz/testcase/Makefile b/xz/testcase/Makefile new file mode 100644 index 0000000..1b4db5b --- /dev/null +++ b/xz/testcase/Makefile @@ -0,0 +1,21 @@ +export TST_TS_TOPDIR ?= $(shell pwd)/.. +include $(TST_TS_TOPDIR)/Makefile.common +ALL_SRC := $(filter-out %.mod.c, $(wildcard *.c)) +ALL_OBJ := $(patsubst %.c,%.o,$(ALL_SRC)) +ALL_BIN := $(patsubst %.o,%.test,$(ALL_OBJ)) +CFLAGS += +LDFLAGS += +LDFLAGS += + +all: $(ALL_BIN) + +$(ALL_BIN):%.test:%.o + $(CC) $^ -o $@ $(LDFLAGS) + +$(ALL_OBJ):%.o:%.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -rfv $(ALL_OBJ) $(ALL_BIN) + +cleanall: clean diff --git a/xz/tsuite b/xz/tsuite new file mode 100644 index 0000000..5fa0542 --- /dev/null +++ b/xz/tsuite @@ -0,0 +1,21 @@ +#!/bin/bash + +TST_TS_TOPDIR=$(realpath "$(dirname "$0")") +export TST_TS_TOPDIR +TST_TS_SYSDIR="$TST_TS_TOPDIR/logs/.ts.sysdir" +export TST_TS_SYSDIR +TST_RUN_DATATIME=$(date '+%Y%m%d%H%M%S') +export TST_RUN_DATATIME +TST_TS_ORI_CWD="$(pwd)" +export TST_TS_ORI_CWD + +_tsuite_main() { + if [ ! -x "${TST_TS_TOPDIR}/common/tsuite" ]; then + echo "tsuite common in submodule not checkout, please run command:" + echo " git submodule init && git submodule update" + return 1 + fi + "${TST_TS_TOPDIR}/common/tsuite" "$@" +} + +_tsuite_main "$@" -- Gitee From b9dc2411517c18e331e4b1f354434d6c99184424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E9=9C=B2?= <16062016+ganlufan@user.noreply.gitee.com> Date: Sat, 25 Apr 2026 18:23:09 +0800 Subject: [PATCH 2/5] Add 12 curl test case scripts --- curl/testcase/curl-basic-http-get.sh | 90 +++++++++++++++ curl/testcase/curl-cookie-handling.sh | 108 ++++++++++++++++++ curl/testcase/curl-custom-headers.sh | 111 ++++++++++++++++++ curl/testcase/curl-download-file.sh | 94 ++++++++++++++++ curl/testcase/curl-follow-redirect.sh | 96 ++++++++++++++++ curl/testcase/curl-form-upload.sh | 118 ++++++++++++++++++++ curl/testcase/curl-http-post-data.sh | 112 +++++++++++++++++++ curl/testcase/curl-response-headers-only.sh | 111 ++++++++++++++++++ curl/testcase/curl-silent-mode.sh | 105 +++++++++++++++++ curl/testcase/curl-timeout-setting.sh | 99 ++++++++++++++++ curl/testcase/curl-user-agent.sh | 113 +++++++++++++++++++ curl/testcase/curl-verbose-output.sh | 114 +++++++++++++++++++ 12 files changed, 1271 insertions(+) create mode 100644 curl/testcase/curl-basic-http-get.sh create mode 100644 curl/testcase/curl-cookie-handling.sh create mode 100644 curl/testcase/curl-custom-headers.sh create mode 100644 curl/testcase/curl-download-file.sh create mode 100644 curl/testcase/curl-follow-redirect.sh create mode 100644 curl/testcase/curl-form-upload.sh create mode 100644 curl/testcase/curl-http-post-data.sh create mode 100644 curl/testcase/curl-response-headers-only.sh create mode 100644 curl/testcase/curl-silent-mode.sh create mode 100644 curl/testcase/curl-timeout-setting.sh create mode 100644 curl/testcase/curl-user-agent.sh create mode 100644 curl/testcase/curl-verbose-output.sh diff --git a/curl/testcase/curl-basic-http-get.sh b/curl/testcase/curl-basic-http-get.sh new file mode 100644 index 0000000..11cb581 --- /dev/null +++ b/curl/testcase/curl-basic-http-get.sh @@ -0,0 +1,90 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180001-000000001 +# @用例名称: curl-basic-http-get +# @用例级别: 3 +# @用例标签: curl,http,get +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 基本的 HTTP GET 请求功能,包括获取网页内容、返回码和输出保存 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" +g_output_file="$g_tmpdir/response.txt" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 curl 发起基本 HTTP GET 请求并保存响应 + # @预期结果: 命令执行成功,返回码为 0 + curl -s "http://httpbin.org/get" -o "$g_output_file" + ret=$? + msg "CHECK: curl GET 请求返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证下载的响应文件存在且非空 + # @预期结果: 文件存在且大小大于 0 + msg "CHECK: 响应文件是否存在且非空" + assert_true test -s "$g_output_file" + + # @测试步骤: 验证响应内容包含 JSON 格式的 url 字段 + # @预期结果: 响应内容包含 url 字段 + grep -q "\"url\"" "$g_output_file" + ret=$? + msg "CHECK: 响应包含 url 字段, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应内容包含请求的 URL + # @预期结果: 响应中包含 httpbin.org/get + grep -q "httpbin.org/get" "$g_output_file" + ret=$? + msg "CHECK: 响应包含请求 URL, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 curl 直接输出到 stdout 并检查返回码 + # @预期结果: 命令执行成功,返回码为 0 + curl -s "http://httpbin.org/get" > /dev/null + ret=$? + msg "CHECK: curl GET 请求输出到 stdout 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 curl -w 获取 HTTP 状态码 + # @预期结果: HTTP 状态码为 200 + http_code=$(curl -s -o /dev/null -w "%{http_code}" "http://httpbin.org/get") + msg "CHECK: HTTP 状态码, 实际值=$http_code" + assert_true [ "$http_code" = "200" ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-cookie-handling.sh b/curl/testcase/curl-cookie-handling.sh new file mode 100644 index 0000000..6624b2d --- /dev/null +++ b/curl/testcase/curl-cookie-handling.sh @@ -0,0 +1,108 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180008-000000008 +# @用例名称: curl-cookie-handling +# @用例级别: 3 +# @用例标签: curl,http,cookie,-b,-c +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl Cookie 处理功能,包括 -c 保存 Cookie、-b 发送 Cookie 和 Cookie 持久化 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" +g_cookie_jar="$g_tmpdir/cookies.txt" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -c 保存服务器返回的 Cookie 到文件 + # @预期结果: Cookie 文件创建成功且非空 + curl -s -c "$g_cookie_jar" "http://httpbin.org/cookies/set?testcookie=testvalue" -o /dev/null + ret=$? + msg "CHECK: curl -c 保存 Cookie 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_cookie_jar" + + # @测试步骤: 验证 Cookie 文件包含设置的 Cookie + # @预期结果: Cookie 文件包含 testcookie + grep -q "testcookie" "$g_cookie_jar" + ret=$? + msg "CHECK: Cookie 文件包含 testcookie, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -b 从 Cookie 文件发送 Cookie + # @预期结果: 请求成功,服务器收到 Cookie + curl -s -b "$g_cookie_jar" "http://httpbin.org/cookies" -o "$g_tmpdir/cookie_response.txt" + ret=$? + msg "CHECK: curl -b 发送 Cookie 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证服务器收到了 Cookie + # @预期结果: 响应中包含 testcookie + grep -q "testcookie" "$g_tmpdir/cookie_response.txt" + ret=$? + msg "CHECK: 服务器收到 Cookie, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -b 直接指定 Cookie 字符串 + # @预期结果: 请求成功,服务器收到指定的 Cookie + curl -s -b "mycookie=myvalue" "http://httpbin.org/cookies" -o "$g_tmpdir/cookie_str_response.txt" + ret=$? + msg "CHECK: curl -b 字符串发送 Cookie 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证服务器收到了字符串指定的 Cookie + # @预期结果: 响应中包含 mycookie + grep -q "mycookie" "$g_tmpdir/cookie_str_response.txt" + ret=$? + msg "CHECK: 服务器收到字符串 Cookie, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 同时使用 -b 和 -c,发送并保存 Cookie + # @预期结果: Cookie 文件更新成功 + curl -s -b "$g_cookie_jar" -c "$g_cookie_jar" "http://httpbin.org/cookies/set?newcookie=newvalue" -o /dev/null + ret=$? + msg "CHECK: curl -b -c 同时使用返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 Cookie 文件包含新 Cookie + # @预期结果: Cookie 文件包含 newcookie + grep -q "newcookie" "$g_cookie_jar" + ret=$? + msg "CHECK: Cookie 文件包含新 Cookie, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-custom-headers.sh b/curl/testcase/curl-custom-headers.sh new file mode 100644 index 0000000..2766ba2 --- /dev/null +++ b/curl/testcase/curl-custom-headers.sh @@ -0,0 +1,111 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180004-000000004 +# @用例名称: curl-custom-headers +# @用例级别: 3 +# @用例标签: curl,http,headers,-H +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 自定义请求头功能,包括 -H 添加单个和多个自定义请求头 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -H 添加单个自定义请求头 X-Custom-Header + # @预期结果: 请求成功,响应中包含自定义头信息 + curl -s -H "X-Custom-Header: TestValue" "http://httpbin.org/headers" -o "$g_tmpdir/headers1.txt" + ret=$? + msg "CHECK: curl -H 单个请求头返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含自定义头 + # @预期结果: 响应中包含 X-Custom-Header 和 TestValue + grep -q "TestValue" "$g_tmpdir/headers1.txt" + ret=$? + msg "CHECK: 响应包含自定义头值, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用多个 -H 添加多个自定义请求头 + # @预期结果: 请求成功,响应中包含所有自定义头 + curl -s -H "X-First-Header: FirstValue" -H "X-Second-Header: SecondValue" "http://httpbin.org/headers" -o "$g_tmpdir/headers2.txt" + ret=$? + msg "CHECK: curl 多个 -H 请求头返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含第一个自定义头 + # @预期结果: 响应中包含 FirstValue + grep -q "FirstValue" "$g_tmpdir/headers2.txt" + ret=$? + msg "CHECK: 响应包含第一个自定义头值, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含第二个自定义头 + # @预期结果: 响应中包含 SecondValue + grep -q "SecondValue" "$g_tmpdir/headers2.txt" + ret=$? + msg "CHECK: 响应包含第二个自定义头值, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -H 修改 Content-Type 请求头 + # @预期结果: 请求成功,Content-Type 被修改 + curl -s -H "Content-Type: application/json" "http://httpbin.org/headers" -o "$g_tmpdir/headers3.txt" + ret=$? + msg "CHECK: curl -H 修改 Content-Type 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含修改后的 Content-Type + # @预期结果: 响应中包含 application/json + grep -q "application/json" "$g_tmpdir/headers3.txt" + ret=$? + msg "CHECK: 响应包含修改后的 Content-Type, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -H 添加 Accept 请求头 + # @预期结果: 请求成功,响应中包含 Accept 头 + curl -s -H "Accept: text/html" "http://httpbin.org/headers" -o "$g_tmpdir/headers4.txt" + ret=$? + msg "CHECK: curl -H Accept 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + grep -q "text/html" "$g_tmpdir/headers4.txt" + ret=$? + msg "CHECK: 响应包含 Accept 头, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-download-file.sh b/curl/testcase/curl-download-file.sh new file mode 100644 index 0000000..c671f2b --- /dev/null +++ b/curl/testcase/curl-download-file.sh @@ -0,0 +1,94 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180002-000000002 +# @用例名称: curl-download-file +# @用例级别: 3 +# @用例标签: curl,download,-O,-o +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 下载文件功能,包括 -o 指定文件名下载和 -O 保留远程文件名下载 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -o 选项指定文件名下载文件 + # @预期结果: 文件下载成功,指定文件名的文件存在且非空 + curl -s -o "$g_tmpdir/custom_name.json" "http://httpbin.org/json" + ret=$? + msg "CHECK: curl -o 下载返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_tmpdir/custom_name.json" + + # @测试步骤: 验证下载的 JSON 文件内容包含 slideshow 字段 + # @预期结果: 文件内容包含 slideshow 字段 + grep -q "slideshow" "$g_tmpdir/custom_name.json" + ret=$? + msg "CHECK: 下载文件包含 slideshow 字段, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -O 选项保留远程文件名下载 + # @预期结果: 文件下载成功,文件名为远程文件名 + cd "$g_tmpdir" + curl -s -O "http://httpbin.org/json" + ret=$? + msg "CHECK: curl -O 下载返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_tmpdir/json" + + # @测试步骤: 使用 -o 下载二进制内容(如图片)并验证文件大小 + # @预期结果: 下载成功且文件非空 + curl -s -o "$g_tmpdir/image.png" "http://httpbin.org/image/png" + ret=$? + msg "CHECK: curl 下载 PNG 图片返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_tmpdir/image.png" + + # @测试步骤: 验证下载的 PNG 文件大小大于 0 字节 + # @预期结果: 文件大小大于 100 字节(有效 PNG 图片) + file_size=$(stat -c%s "$g_tmpdir/image.png" 2>/dev/null || stat -f%z "$g_tmpdir/image.png" 2>/dev/null) + msg "CHECK: PNG 文件大小, 实际值=$file_size" + assert_true [ "$file_size" -gt 100 ] + + # @测试步骤: 使用 -w 获取下载的 HTTP 状态码 + # @预期结果: HTTP 状态码为 200 + http_code=$(curl -s -o /dev/null -w "%{http_code}" "http://httpbin.org/json") + msg "CHECK: 下载 HTTP 状态码, 实际值=$http_code" + assert_true [ "$http_code" = "200" ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-follow-redirect.sh b/curl/testcase/curl-follow-redirect.sh new file mode 100644 index 0000000..7bc927e --- /dev/null +++ b/curl/testcase/curl-follow-redirect.sh @@ -0,0 +1,96 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180005-000000005 +# @用例名称: curl-follow-redirect +# @用例级别: 3 +# @用例标签: curl,http,redirect,-L +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 跟随重定向功能,包括 -L 自动跟随重定向和不使用 -L 时的行为差异 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 不使用 -L 访问重定向 URL,获取 HTTP 状态码 + # @预期结果: 返回 302 重定向状态码 + http_code=$(curl -s -o /dev/null -w "%{http_code}" "http://httpbin.org/redirect/2") + msg "CHECK: 不使用 -L 的 HTTP 状态码, 实际值=$http_code" + assert_true [ "$http_code" = "302" ] + + # @测试步骤: 使用 -L 跟随重定向访问同一 URL + # @预期结果: 返回 200 状态码,表示成功跟随重定向 + http_code=$(curl -s -L -o /dev/null -w "%{http_code}" "http://httpbin.org/redirect/2") + msg "CHECK: 使用 -L 的 HTTP 状态码, 实际值=$http_code" + assert_true [ "$http_code" = "200" ] + + # @测试步骤: 使用 -L 跟随重定向并保存响应内容 + # @预期结果: 响应文件非空且包含最终页面内容 + curl -s -L "http://httpbin.org/redirect/1" -o "$g_tmpdir/redirect_response.txt" + ret=$? + msg "CHECK: curl -L 跟随重定向返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_tmpdir/redirect_response.txt" + + # @测试步骤: 验证跟随重定向后的响应包含最终页面内容 + # @预期结果: 响应中包含 url 字段(httpbin.org/get 的响应) + grep -q "\"url\"" "$g_tmpdir/redirect_response.txt" + ret=$? + msg "CHECK: 重定向响应包含 url 字段, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 --max-redirs 限制最大重定向次数 + # @预期结果: 限制重定向次数后请求成功或返回适当错误码 + curl -s -L --max-redirs 1 "http://httpbin.org/redirect/1" -o "$g_tmpdir/max_redirect.txt" + ret=$? + msg "CHECK: curl --max-redirs 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -L 访问绝对路径重定向 + # @预期结果: 跟随绝对路径重定向成功 + http_code=$(curl -s -L -o /dev/null -w "%{http_code}" "http://httpbin.org/absolute-redirect/1") + msg "CHECK: 绝对路径重定向 HTTP 状态码, 实际值=$http_code" + assert_true [ "$http_code" = "200" ] + + # @测试步骤: 使用 -L 访问相对路径重定向 + # @预期结果: 跟随相对路径重定向成功 + http_code=$(curl -s -L -o /dev/null -w "%{http_code}" "http://httpbin.org/relative-redirect/1") + msg "CHECK: 相对路径重定向 HTTP 状态码, 实际值=$http_code" + assert_true [ "$http_code" = "200" ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-form-upload.sh b/curl/testcase/curl-form-upload.sh new file mode 100644 index 0000000..1d80e49 --- /dev/null +++ b/curl/testcase/curl-form-upload.sh @@ -0,0 +1,118 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180012-000000012 +# @用例名称: curl-form-upload +# @用例级别: 3 +# @用例标签: curl,http,form,-F,upload +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 表单上传功能,包括 -F 提交表单数据和文件上传 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" +g_upload_file="$g_tmpdir/upload_test.txt" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + # @预置条件: 创建用于上传的测试文件 + echo "This is a test file for curl upload." > "$g_upload_file" + echo "Line 2 of test file." >> "$g_upload_file" + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -F 提交简单表单字段 + # @预期结果: 表单提交成功,响应中包含提交的数据 + curl -s -F "username=testuser" -F "email=test@example.com" "http://httpbin.org/post" -o "$g_tmpdir/form_response.txt" + ret=$? + msg "CHECK: curl -F 提交表单返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含表单字段 + # @预期结果: 响应中包含 testuser + grep -q "testuser" "$g_tmpdir/form_response.txt" + ret=$? + msg "CHECK: 响应包含表单字段 username, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含 email 字段 + # @预期结果: 响应中包含 test@example.com + grep -q "test@example.com" "$g_tmpdir/form_response.txt" + ret=$? + msg "CHECK: 响应包含表单字段 email, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -F 上传文件 + # @预期结果: 文件上传成功,返回码为 0 + curl -s -F "file=@$g_upload_file" "http://httpbin.org/post" -o "$g_tmpdir/upload_response.txt" + ret=$? + msg "CHECK: curl -F 上传文件返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证上传响应中包含文件内容 + # @预期结果: 响应中包含上传文件的内容 + grep -q "This is a test file" "$g_tmpdir/upload_response.txt" + ret=$? + msg "CHECK: 上传响应包含文件内容, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -F 指定文件类型上传 + # @预期结果: 文件上传成功,Content-Type 被正确设置 + curl -s -F "file=@$g_upload_file;type=text/plain" "http://httpbin.org/post" -o "$g_tmpdir/typed_upload.txt" + ret=$? + msg "CHECK: curl -F 指定文件类型上传返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证上传响应中包含 text/plain 类型 + # @预期结果: 响应中包含 text/plain + grep -q "text/plain" "$g_tmpdir/typed_upload.txt" + ret=$? + msg "CHECK: 上传响应包含 text/plain 类型, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 同时提交表单字段和文件 + # @预期结果: 请求成功,响应中包含字段和文件 + curl -s -F "description=test upload" -F "file=@$g_upload_file" "http://httpbin.org/post" -o "$g_tmpdir/mixed_response.txt" + ret=$? + msg "CHECK: curl -F 同时提交字段和文件返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证混合提交响应中包含描述字段 + # @预期结果: 响应中包含 test upload + grep -q "test upload" "$g_tmpdir/mixed_response.txt" + ret=$? + msg "CHECK: 混合提交响应包含描述字段, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-http-post-data.sh b/curl/testcase/curl-http-post-data.sh new file mode 100644 index 0000000..a138ed6 --- /dev/null +++ b/curl/testcase/curl-http-post-data.sh @@ -0,0 +1,112 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180003-000000003 +# @用例名称: curl-http-post-data +# @用例级别: 3 +# @用例标签: curl,http,post,-X,-d +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 发送 HTTP POST 请求功能,包括 -X POST 指定方法、-d 发送表单数据和 JSON 数据 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" +g_output_file="$g_tmpdir/response.txt" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -X POST 发送 POST 请求 + # @预期结果: 请求成功,返回码为 0 + curl -s -X POST "http://httpbin.org/post" -o "$g_output_file" + ret=$? + msg "CHECK: curl POST 请求返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应中包含 POST 方法标识 + # @预期结果: 响应 JSON 中 method 字段为 POST + grep -q "\"method\": \"POST\"" "$g_output_file" + ret=$? + msg "CHECK: 响应中 method 为 POST, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -d 发送表单数据 + # @预期结果: 表单数据成功发送,响应中包含提交的数据 + curl -s -X POST -d "name=testuser&age=25" "http://httpbin.org/post" -o "$g_tmpdir/form_response.txt" + ret=$? + msg "CHECK: curl -d 发送表单数据返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证表单数据在响应中 + # @预期结果: 响应中包含提交的 name 和 age 字段 + grep -q "testuser" "$g_tmpdir/form_response.txt" + ret=$? + msg "CHECK: 响应包含 name 字段值, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + grep -q "25" "$g_tmpdir/form_response.txt" + ret=$? + msg "CHECK: 响应包含 age 字段值, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -H Content-Type 发送 JSON 数据 + # @预期结果: JSON 数据成功发送,返回码为 0 + curl -s -X POST -H "Content-Type: application/json" -d '{"key":"value"}' "http://httpbin.org/post" -o "$g_tmpdir/json_response.txt" + ret=$? + msg "CHECK: curl 发送 JSON 数据返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 JSON 数据在响应中 + # @预期结果: 响应中包含提交的 key 和 value + grep -q "\"key\"" "$g_tmpdir/json_response.txt" + ret=$? + msg "CHECK: 响应包含 JSON key 字段, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 --data-urlencode 发送 URL 编码数据 + # @预期结果: 编码数据成功发送,返回码为 0 + curl -s -X POST --data-urlencode "message=hello world" "http://httpbin.org/post" -o "$g_tmpdir/encode_response.txt" + ret=$? + msg "CHECK: curl --data-urlencode 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证编码数据在响应中 + # @预期结果: 响应中包含 hello world + grep -q "hello" "$g_tmpdir/encode_response.txt" + ret=$? + msg "CHECK: 响应包含编码数据, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-response-headers-only.sh b/curl/testcase/curl-response-headers-only.sh new file mode 100644 index 0000000..9df2d23 --- /dev/null +++ b/curl/testcase/curl-response-headers-only.sh @@ -0,0 +1,111 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180007-000000007 +# @用例名称: curl-response-headers-only +# @用例级别: 3 +# @用例标签: curl,http,headers,-I,HEAD +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 仅获取响应头功能,包括 -I 发送 HEAD 请求获取响应头信息 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -I 选项发送 HEAD 请求获取响应头 + # @预期结果: 命令执行成功,返回码为 0 + curl -s -I "http://httpbin.org/get" -o "$g_tmpdir/headers.txt" + ret=$? + msg "CHECK: curl -I 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应头包含 HTTP 状态行 + # @预期结果: 响应头包含 HTTP/200 + grep -q "HTTP/" "$g_tmpdir/headers.txt" + ret=$? + msg "CHECK: 响应头包含 HTTP 状态行, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应头包含 Content-Type + # @预期结果: 响应头包含 Content-Type 字段 + grep -q "Content-Type" "$g_tmpdir/headers.txt" + ret=$? + msg "CHECK: 响应头包含 Content-Type, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证响应头包含 Date 字段 + # @预期结果: 响应头包含 Date 字段 + grep -q "Date" "$g_tmpdir/headers.txt" + ret=$? + msg "CHECK: 响应头包含 Date, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -I 响应不包含响应体内容 + # @预期结果: 响应头文件中不包含 JSON 数据字段 + grep -q "\"url\"" "$g_tmpdir/headers.txt" + ret=$? + msg "CHECK: -I 响应不包含响应体, 实际值=$ret" + assert_true [ $ret -ne 0 ] + + # @测试步骤: 使用 -I 获取不同资源类型的响应头 + # @预期结果: 不同资源返回不同的 Content-Type + curl -s -I "http://httpbin.org/image/png" -o "$g_tmpdir/img_headers.txt" + ret=$? + msg "CHECK: curl -I 获取图片响应头返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证图片资源的 Content-Type 为 image/png + # @预期结果: Content-Type 包含 image/png + grep -q "image/png" "$g_tmpdir/img_headers.txt" + ret=$? + msg "CHECK: 图片 Content-Type 为 image/png, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -I 获取 HTML 页面的响应头 + # @预期结果: HTML 页面返回正确的 Content-Type + curl -s -I "http://httpbin.org/html" -o "$g_tmpdir/html_headers.txt" + ret=$? + msg "CHECK: curl -I 获取 HTML 响应头返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + grep -q "text/html" "$g_tmpdir/html_headers.txt" + ret=$? + msg "CHECK: HTML Content-Type 为 text/html, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-silent-mode.sh b/curl/testcase/curl-silent-mode.sh new file mode 100644 index 0000000..7f2742e --- /dev/null +++ b/curl/testcase/curl-silent-mode.sh @@ -0,0 +1,105 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180010-000000010 +# @用例名称: curl-silent-mode +# @用例级别: 3 +# @用例标签: curl,silent,-s,-S +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 静默模式功能,包括 -s 静默模式和 -S 显示错误,以及进度条控制 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -s 静默模式下载文件 + # @预期结果: 下载成功,无进度条输出到 stderr + curl -s "http://httpbin.org/get" -o "$g_tmpdir/silent_out.txt" 2> "$g_tmpdir/silent_err.txt" + ret=$? + msg "CHECK: curl -s 静默下载返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -s 模式下 stderr 无进度条输出 + # @预期结果: stderr 输出为空 + err_size=$(stat -c%s "$g_tmpdir/silent_err.txt" 2>/dev/null || stat -f%z "$g_tmpdir/silent_err.txt" 2>/dev/null) + msg "CHECK: -s 模式 stderr 大小, 实际值=$err_size" + assert_true [ "$err_size" -eq 0 ] + + # @测试步骤: 验证 -s 模式下响应文件非空 + # @预期结果: 响应文件存在且非空 + assert_true test -s "$g_tmpdir/silent_out.txt" + + # @测试步骤: 不使用 -s 下载文件,检查是否有进度条输出 + # @预期结果: 下载成功,stderr 包含进度信息 + curl "http://httpbin.org/get" -o "$g_tmpdir/normal_out.txt" 2> "$g_tmpdir/normal_err.txt" + ret=$? + msg "CHECK: curl 不使用 -s 下载返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证非静默模式下 stderr 有输出 + # @预期结果: stderr 输出非空 + assert_true test -s "$g_tmpdir/normal_err.txt" + + # @测试步骤: 使用 -sS 静默但显示错误 + # @预期结果: 正常请求成功,错误时仍显示错误信息 + curl -sS "http://httpbin.org/get" -o "$g_tmpdir/sS_out.txt" 2> "$g_tmpdir/sS_err.txt" + ret=$? + msg "CHECK: curl -sS 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -sS 模式下正常请求 stderr 无进度条 + # @预期结果: 正常请求时 stderr 为空 + err_size=$(stat -c%s "$g_tmpdir/sS_err.txt" 2>/dev/null || stat -f%z "$g_tmpdir/sS_err.txt" 2>/dev/null) + msg "CHECK: -sS 正常请求 stderr 大小, 实际值=$err_size" + assert_true [ "$err_size" -eq 0 ] + + # @测试步骤: 使用 -sS 访问不存在的 URL,验证错误信息显示 + # @预期结果: 请求失败,stderr 包含错误信息 + curl -sS "http://httpbin.org/status/404" -o /dev/null 2> "$g_tmpdir/sS_error.txt" + ret=$? + msg "CHECK: curl -sS 访问 404 返回码, 实际值=$ret" + + # @测试步骤: 使用 --progress-bar 显示进度条 + # @预期结果: 下载成功 + curl -s --progress-bar "http://httpbin.org/get" -o "$g_tmpdir/progress_out.txt" 2> "$g_tmpdir/progress_err.txt" + ret=$? + msg "CHECK: curl --progress-bar 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_tmpdir/progress_out.txt" + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-timeout-setting.sh b/curl/testcase/curl-timeout-setting.sh new file mode 100644 index 0000000..3abc877 --- /dev/null +++ b/curl/testcase/curl-timeout-setting.sh @@ -0,0 +1,99 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180009-000000009 +# @用例名称: curl-timeout-setting +# @用例级别: 3 +# @用例标签: curl,timeout,--connect-timeout,-m +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 超时设置功能,包括 --connect-timeout 连接超时和 -m 最大传输时间 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 --connect-timeout 设置连接超时为 10 秒,访问正常 URL + # @预期结果: 在超时时间内连接成功,返回码为 0 + curl -s --connect-timeout 10 "http://httpbin.org/get" -o /dev/null + ret=$? + msg "CHECK: --connect-timeout 10 访问正常 URL 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 --connect-timeout 设置极短超时(1秒),访问延迟 URL + # @预期结果: 连接超时,返回码非 0 + curl -s --connect-timeout 1 "http://httpbin.org/delay/5" -o /dev/null + ret=$? + msg "CHECK: --connect-timeout 1 访问延迟 URL 返回码, 实际值=$ret" + assert_true [ $ret -ne 0 ] + + # @测试步骤: 使用 -m 设置最大传输时间为 10 秒,访问正常 URL + # @预期结果: 在最大时间内完成,返回码为 0 + curl -s -m 10 "http://httpbin.org/get" -o /dev/null + ret=$? + msg "CHECK: -m 10 访问正常 URL 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -m 设置极短最大传输时间(1秒),访问延迟 URL + # @预期结果: 传输超时,返回码非 0 + curl -s -m 1 "http://httpbin.org/delay/5" -o /dev/null + ret=$? + msg "CHECK: -m 1 访问延迟 URL 返回码, 实际值=$ret" + assert_true [ $ret -ne 0 ] + + # @测试步骤: 同时设置 --connect-timeout 和 -m,访问正常 URL + # @预期结果: 请求成功完成,返回码为 0 + curl -s --connect-timeout 5 -m 10 "http://httpbin.org/get" -o /dev/null + ret=$? + msg "CHECK: 同时设置超时访问正常 URL 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 --connect-timeout 访问不可达地址 + # @预期结果: 连接超时,返回码非 0 + curl -s --connect-timeout 2 "http://192.0.2.1" -o /dev/null 2>&1 + ret=$? + msg "CHECK: --connect-timeout 访问不可达地址返回码, 实际值=$ret" + assert_true [ $ret -ne 0 ] + + # @测试步骤: 使用 --max-time 访问延迟 2 秒的 URL,设置超时 5 秒 + # @预期结果: 在超时前完成,返回码为 0 + curl -s --max-time 5 "http://httpbin.org/delay/2" -o /dev/null + ret=$? + msg "CHECK: --max-time 5 访问 delay/2 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-user-agent.sh b/curl/testcase/curl-user-agent.sh new file mode 100644 index 0000000..d3b6669 --- /dev/null +++ b/curl/testcase/curl-user-agent.sh @@ -0,0 +1,113 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180011-000000011 +# @用例名称: curl-user-agent +# @用例级别: 3 +# @用例标签: curl,http,user-agent,-A +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 自定义 User-Agent 功能,包括 -A 设置 User-Agent 和默认 User-Agent +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 不设置 User-Agent 发送请求,查看默认值 + # @预期结果: 请求成功,响应中包含默认 curl User-Agent + curl -s "http://httpbin.org/user-agent" -o "$g_tmpdir/default_ua.txt" + ret=$? + msg "CHECK: curl 默认 User-Agent 请求返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证默认 User-Agent 包含 curl + # @预期结果: 响应中包含 curl 字样 + grep -q "curl" "$g_tmpdir/default_ua.txt" + ret=$? + msg "CHECK: 默认 User-Agent 包含 curl, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -A 设置自定义 User-Agent + # @预期结果: 请求成功,响应中显示自定义 User-Agent + curl -s -A "MyTestAgent/1.0" "http://httpbin.org/user-agent" -o "$g_tmpdir/custom_ua.txt" + ret=$? + msg "CHECK: curl -A 自定义 User-Agent 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证自定义 User-Agent 被正确设置 + # @预期结果: 响应中包含 MyTestAgent/1.0 + grep -q "MyTestAgent" "$g_tmpdir/custom_ua.txt" + ret=$? + msg "CHECK: 自定义 User-Agent 被设置, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -H 设置 User-Agent 头 + # @预期结果: 请求成功,响应中显示通过 -H 设置的 User-Agent + curl -s -H "User-Agent: HeaderAgent/2.0" "http://httpbin.org/user-agent" -o "$g_tmpdir/header_ua.txt" + ret=$? + msg "CHECK: curl -H 设置 User-Agent 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -H 设置的 User-Agent 被正确设置 + # @预期结果: 响应中包含 HeaderAgent/2.0 + grep -q "HeaderAgent" "$g_tmpdir/header_ua.txt" + ret=$? + msg "CHECK: -H 设置的 User-Agent 被设置, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -A 设置浏览器 User-Agent 模拟浏览器访问 + # @预期结果: 请求成功,响应中显示浏览器 User-Agent + curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" "http://httpbin.org/user-agent" -o "$g_tmpdir/browser_ua.txt" + ret=$? + msg "CHECK: curl -A 模拟浏览器返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证浏览器 User-Agent 被正确设置 + # @预期结果: 响应中包含 Mozilla + grep -q "Mozilla" "$g_tmpdir/browser_ua.txt" + ret=$? + msg "CHECK: 浏览器 User-Agent 被设置, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用空字符串 -A "" 清除 User-Agent + # @预期结果: 请求成功 + curl -s -A "" "http://httpbin.org/user-agent" -o "$g_tmpdir/empty_ua.txt" + ret=$? + msg "CHECK: curl -A 空字符串返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### diff --git a/curl/testcase/curl-verbose-output.sh b/curl/testcase/curl-verbose-output.sh new file mode 100644 index 0000000..1cad376 --- /dev/null +++ b/curl/testcase/curl-verbose-output.sh @@ -0,0 +1,114 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20260425-180006-000000006 +# @用例名称: curl-verbose-output +# @用例级别: 3 +# @用例标签: curl,verbose,-v,-i +# @扩展属性: +# @用例类型: 功能测试 +# @自动化: 1 +# @超时时间: 0 +# @用例描述: 验证 curl 详细输出模式功能,包括 -v 显示通信过程和 -i 显示响应头 +############################################################################### +if [ -z "$TST_TS_TOPDIR" ]; then + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + while [ "$TST_TS_TOPDIR" != "/" ]; do + [ -f "${TST_TS_TOPDIR}/tsuite" ] && break + TST_TS_TOPDIR="$(dirname "$TST_TS_TOPDIR")" + done + export TST_TS_TOPDIR +fi +source "${TST_TS_TOPDIR}/common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + # @预置条件: 安装 curl 软件包 + msg "CHECK: 安装 curl 软件包" + assert_true yum install -y curl + + return 0 +} + +do_test() { + msg "this is do_test" + + # @测试步骤: 使用 -v 选项显示详细通信过程 + # @预期结果: 输出包含请求和响应的详细信息 + curl -s -v "http://httpbin.org/get" > "$g_tmpdir/verbose.txt" 2>&1 + ret=$? + msg "CHECK: curl -v 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -v 输出包含请求头信息 + # @预期结果: 输出中包含 > GET 请求行 + grep -q "> GET" "$g_tmpdir/verbose.txt" + ret=$? + msg "CHECK: -v 输出包含请求行, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -v 输出包含响应头信息 + # @预期结果: 输出中包含 < 响应头标记 + grep -q "< " "$g_tmpdir/verbose.txt" + ret=$? + msg "CHECK: -v 输出包含响应头标记, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -v 输出包含 HTTP 响应状态行 + # @预期结果: 输出中包含 HTTP/ 状态行 + grep -q "HTTP/" "$g_tmpdir/verbose.txt" + ret=$? + msg "CHECK: -v 输出包含 HTTP 状态行, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 -i 选项在输出中包含响应头 + # @预期结果: 输出包含 HTTP 响应头和响应体 + curl -s -i "http://httpbin.org/get" -o "$g_tmpdir/with_headers.txt" + ret=$? + msg "CHECK: curl -i 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -i 输出包含 Content-Type 响应头 + # @预期结果: 输出中包含 Content-Type 头 + grep -q "Content-Type" "$g_tmpdir/with_headers.txt" + ret=$? + msg "CHECK: -i 输出包含 Content-Type, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 验证 -i 输出包含响应体内容 + # @预期结果: 输出中包含 url 字段(响应体内容) + grep -q "\"url\"" "$g_tmpdir/with_headers.txt" + ret=$? + msg "CHECK: -i 输出包含响应体, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + # @测试步骤: 使用 --trace 选项记录完整通信过程到文件 + # @预期结果: trace 文件创建成功且非空 + curl -s --trace "$g_tmpdir/trace.log" "http://httpbin.org/get" -o /dev/null + ret=$? + msg "CHECK: curl --trace 返回码, 实际值=$ret" + assert_true [ $ret -eq 0 ] + assert_true test -s "$g_tmpdir/trace.log" + + # @测试步骤: 验证 trace 日志包含通信记录 + # @预期结果: trace 文件包含发送和接收的数据记录 + grep -q "Recv" "$g_tmpdir/trace.log" + ret=$? + msg "CHECK: trace 日志包含接收记录, 实际值=$ret" + assert_true [ $ret -eq 0 ] + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### -- Gitee From d8e2f0b122acb6c2b03b1e22930429c18a37d50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E9=9C=B2?= <16062016+ganlufan@user.noreply.gitee.com> Date: Sat, 25 Apr 2026 18:36:56 +0800 Subject: [PATCH 3/5] Fix 3 failing curl test cases - curl-form-upload: use -v to capture Content-Type in request headers - curl-http-post-data: use HTTPS to avoid redirect, flexible grep - curl-timeout-setting: use -m for delay URL, --connect-timeout for unreachable IP --- curl/testcase/curl-form-upload.sh | 20 ++++++++++---------- curl/testcase/curl-http-post-data.sh | 10 +++++----- curl/testcase/curl-timeout-setting.sh | 20 ++++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/curl/testcase/curl-form-upload.sh b/curl/testcase/curl-form-upload.sh index 1d80e49..14234b3 100644 --- a/curl/testcase/curl-form-upload.sh +++ b/curl/testcase/curl-form-upload.sh @@ -43,7 +43,7 @@ do_test() { # @测试步骤: 使用 -F 提交简单表单字段 # @预期结果: 表单提交成功,响应中包含提交的数据 - curl -s -F "username=testuser" -F "email=test@example.com" "http://httpbin.org/post" -o "$g_tmpdir/form_response.txt" + curl -s -F "username=testuser" -F "email=test@example.com" "https://httpbin.org/post" -o "$g_tmpdir/form_response.txt" ret=$? msg "CHECK: curl -F 提交表单返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] @@ -64,7 +64,7 @@ do_test() { # @测试步骤: 使用 -F 上传文件 # @预期结果: 文件上传成功,返回码为 0 - curl -s -F "file=@$g_upload_file" "http://httpbin.org/post" -o "$g_tmpdir/upload_response.txt" + curl -s -F "file=@$g_upload_file" "https://httpbin.org/post" -o "$g_tmpdir/upload_response.txt" ret=$? msg "CHECK: curl -F 上传文件返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] @@ -76,23 +76,23 @@ do_test() { msg "CHECK: 上传响应包含文件内容, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 使用 -F 指定文件类型上传 - # @预期结果: 文件上传成功,Content-Type 被正确设置 - curl -s -F "file=@$g_upload_file;type=text/plain" "http://httpbin.org/post" -o "$g_tmpdir/typed_upload.txt" + # @测试步骤: 使用 -F 指定文件类型上传,通过 -v 捕获请求头 + # @预期结果: 文件上传成功,请求中 Content-Type 被正确设置为 text/plain + curl -s -v -F "file=@$g_upload_file;type=text/plain" "https://httpbin.org/post" -o "$g_tmpdir/typed_upload.txt" 2>"$g_tmpdir/typed_upload_verbose.txt" ret=$? msg "CHECK: curl -F 指定文件类型上传返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 验证上传响应中包含 text/plain 类型 - # @预期结果: 响应中包含 text/plain - grep -q "text/plain" "$g_tmpdir/typed_upload.txt" + # @测试步骤: 验证请求头中包含 text/plain 类型 + # @预期结果: verbose 输出中包含 text/plain(curl 在 multipart 请求中设置了该 Content-Type) + grep -q "text/plain" "$g_tmpdir/typed_upload_verbose.txt" ret=$? - msg "CHECK: 上传响应包含 text/plain 类型, 实际值=$ret" + msg "CHECK: 请求头包含 text/plain 类型, 实际值=$ret" assert_true [ $ret -eq 0 ] # @测试步骤: 同时提交表单字段和文件 # @预期结果: 请求成功,响应中包含字段和文件 - curl -s -F "description=test upload" -F "file=@$g_upload_file" "http://httpbin.org/post" -o "$g_tmpdir/mixed_response.txt" + curl -s -F "description=test upload" -F "file=@$g_upload_file" "https://httpbin.org/post" -o "$g_tmpdir/mixed_response.txt" ret=$? msg "CHECK: curl -F 同时提交字段和文件返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] diff --git a/curl/testcase/curl-http-post-data.sh b/curl/testcase/curl-http-post-data.sh index a138ed6..4894e20 100644 --- a/curl/testcase/curl-http-post-data.sh +++ b/curl/testcase/curl-http-post-data.sh @@ -39,21 +39,21 @@ do_test() { # @测试步骤: 使用 -X POST 发送 POST 请求 # @预期结果: 请求成功,返回码为 0 - curl -s -X POST "http://httpbin.org/post" -o "$g_output_file" + curl -s -X POST "https://httpbin.org/post" -o "$g_output_file" ret=$? msg "CHECK: curl POST 请求返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] # @测试步骤: 验证响应中包含 POST 方法标识 # @预期结果: 响应 JSON 中 method 字段为 POST - grep -q "\"method\": \"POST\"" "$g_output_file" + grep -qi '"method".*"POST"' "$g_output_file" ret=$? msg "CHECK: 响应中 method 为 POST, 实际值=$ret" assert_true [ $ret -eq 0 ] # @测试步骤: 使用 -d 发送表单数据 # @预期结果: 表单数据成功发送,响应中包含提交的数据 - curl -s -X POST -d "name=testuser&age=25" "http://httpbin.org/post" -o "$g_tmpdir/form_response.txt" + curl -s -X POST -d "name=testuser&age=25" "https://httpbin.org/post" -o "$g_tmpdir/form_response.txt" ret=$? msg "CHECK: curl -d 发送表单数据返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] @@ -72,7 +72,7 @@ do_test() { # @测试步骤: 使用 -H Content-Type 发送 JSON 数据 # @预期结果: JSON 数据成功发送,返回码为 0 - curl -s -X POST -H "Content-Type: application/json" -d '{"key":"value"}' "http://httpbin.org/post" -o "$g_tmpdir/json_response.txt" + curl -s -X POST -H "Content-Type: application/json" -d '{"key":"value"}' "https://httpbin.org/post" -o "$g_tmpdir/json_response.txt" ret=$? msg "CHECK: curl 发送 JSON 数据返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] @@ -86,7 +86,7 @@ do_test() { # @测试步骤: 使用 --data-urlencode 发送 URL 编码数据 # @预期结果: 编码数据成功发送,返回码为 0 - curl -s -X POST --data-urlencode "message=hello world" "http://httpbin.org/post" -o "$g_tmpdir/encode_response.txt" + curl -s -X POST --data-urlencode "message=hello world" "https://httpbin.org/post" -o "$g_tmpdir/encode_response.txt" ret=$? msg "CHECK: curl --data-urlencode 返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] diff --git a/curl/testcase/curl-timeout-setting.sh b/curl/testcase/curl-timeout-setting.sh index 3abc877..479e305 100644 --- a/curl/testcase/curl-timeout-setting.sh +++ b/curl/testcase/curl-timeout-setting.sh @@ -38,21 +38,21 @@ do_test() { # @测试步骤: 使用 --connect-timeout 设置连接超时为 10 秒,访问正常 URL # @预期结果: 在超时时间内连接成功,返回码为 0 - curl -s --connect-timeout 10 "http://httpbin.org/get" -o /dev/null + curl -s --connect-timeout 10 "https://httpbin.org/get" -o /dev/null ret=$? msg "CHECK: --connect-timeout 10 访问正常 URL 返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 使用 --connect-timeout 设置极短超时(1秒),访问延迟 URL - # @预期结果: 连接超时,返回码非 0 - curl -s --connect-timeout 1 "http://httpbin.org/delay/5" -o /dev/null + # @测试步骤: 使用 -m 设置极短最大传输时间(2秒),访问延迟 URL + # @预期结果: 传输超时,返回码非 0(-m 限制整个操作时间,包括传输) + curl -s -m 2 "http://httpbin.org/delay/5" -o /dev/null ret=$? - msg "CHECK: --connect-timeout 1 访问延迟 URL 返回码, 实际值=$ret" + msg "CHECK: -m 2 访问延迟 URL 返回码, 实际值=$ret" assert_true [ $ret -ne 0 ] # @测试步骤: 使用 -m 设置最大传输时间为 10 秒,访问正常 URL # @预期结果: 在最大时间内完成,返回码为 0 - curl -s -m 10 "http://httpbin.org/get" -o /dev/null + curl -s -m 10 "https://httpbin.org/get" -o /dev/null ret=$? msg "CHECK: -m 10 访问正常 URL 返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] @@ -66,21 +66,21 @@ do_test() { # @测试步骤: 同时设置 --connect-timeout 和 -m,访问正常 URL # @预期结果: 请求成功完成,返回码为 0 - curl -s --connect-timeout 5 -m 10 "http://httpbin.org/get" -o /dev/null + curl -s --connect-timeout 5 -m 10 "https://httpbin.org/get" -o /dev/null ret=$? msg "CHECK: 同时设置超时访问正常 URL 返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 使用 --connect-timeout 访问不可达地址 + # @测试步骤: 使用 --connect-timeout 访问不可达地址(较长超时) # @预期结果: 连接超时,返回码非 0 curl -s --connect-timeout 2 "http://192.0.2.1" -o /dev/null 2>&1 ret=$? - msg "CHECK: --connect-timeout 访问不可达地址返回码, 实际值=$ret" + msg "CHECK: --connect-timeout 2 访问不可达地址返回码, 实际值=$ret" assert_true [ $ret -ne 0 ] # @测试步骤: 使用 --max-time 访问延迟 2 秒的 URL,设置超时 5 秒 # @预期结果: 在超时前完成,返回码为 0 - curl -s --max-time 5 "http://httpbin.org/delay/2" -o /dev/null + curl -s --max-time 5 "https://httpbin.org/delay/2" -o /dev/null ret=$? msg "CHECK: --max-time 5 访问 delay/2 返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] -- Gitee From d8569c241594cf858121769e6732620dac9cdbc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E9=9C=B2?= <16062016+ganlufan@user.noreply.gitee.com> Date: Sat, 25 Apr 2026 18:39:48 +0800 Subject: [PATCH 4/5] Fix form-upload: use --trace-ascii for text/plain check; Fix post-data: check url field instead of method --- curl/testcase/curl-form-upload.sh | 12 ++++++------ curl/testcase/curl-http-post-data.sh | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/curl/testcase/curl-form-upload.sh b/curl/testcase/curl-form-upload.sh index 14234b3..4fffde4 100644 --- a/curl/testcase/curl-form-upload.sh +++ b/curl/testcase/curl-form-upload.sh @@ -76,18 +76,18 @@ do_test() { msg "CHECK: 上传响应包含文件内容, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 使用 -F 指定文件类型上传,通过 -v 捕获请求头 + # @测试步骤: 使用 -F 指定文件类型上传,通过 --trace-ascii 捕获完整请求 # @预期结果: 文件上传成功,请求中 Content-Type 被正确设置为 text/plain - curl -s -v -F "file=@$g_upload_file;type=text/plain" "https://httpbin.org/post" -o "$g_tmpdir/typed_upload.txt" 2>"$g_tmpdir/typed_upload_verbose.txt" + curl -s --trace-ascii "$g_tmpdir/typed_upload_trace.txt" -F "file=@$g_upload_file;type=text/plain" "https://httpbin.org/post" -o "$g_tmpdir/typed_upload.txt" ret=$? msg "CHECK: curl -F 指定文件类型上传返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 验证请求头中包含 text/plain 类型 - # @预期结果: verbose 输出中包含 text/plain(curl 在 multipart 请求中设置了该 Content-Type) - grep -q "text/plain" "$g_tmpdir/typed_upload_verbose.txt" + # @测试步骤: 验证请求中包含 text/plain 类型 + # @预期结果: trace 输出中包含 text/plain(curl 在 multipart part 中设置了该 Content-Type) + grep -q "text/plain" "$g_tmpdir/typed_upload_trace.txt" ret=$? - msg "CHECK: 请求头包含 text/plain 类型, 实际值=$ret" + msg "CHECK: 请求中包含 text/plain 类型, 实际值=$ret" assert_true [ $ret -eq 0 ] # @测试步骤: 同时提交表单字段和文件 diff --git a/curl/testcase/curl-http-post-data.sh b/curl/testcase/curl-http-post-data.sh index 4894e20..1d1760a 100644 --- a/curl/testcase/curl-http-post-data.sh +++ b/curl/testcase/curl-http-post-data.sh @@ -44,11 +44,11 @@ do_test() { msg "CHECK: curl POST 请求返回码, 实际值=$ret" assert_true [ $ret -eq 0 ] - # @测试步骤: 验证响应中包含 POST 方法标识 - # @预期结果: 响应 JSON 中 method 字段为 POST - grep -qi '"method".*"POST"' "$g_output_file" + # @测试步骤: 验证响应来自 POST 端点 + # @预期结果: 响应 JSON 中 url 字段包含 /post 路径 + grep -q '"/post"' "$g_output_file" ret=$? - msg "CHECK: 响应中 method 为 POST, 实际值=$ret" + msg "CHECK: 响应 url 包含 /post, 实际值=$ret" assert_true [ $ret -eq 0 ] # @测试步骤: 使用 -d 发送表单数据 -- Gitee From 096221687501a261c1ff4ef6cbe12d0aab4330bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E9=9C=B2?= <16062016+ganlufan@user.noreply.gitee.com> Date: Sat, 25 Apr 2026 18:42:57 +0800 Subject: [PATCH 5/5] Fix post-data: grep /post without surrounding quotes --- curl/testcase/curl-http-post-data.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curl/testcase/curl-http-post-data.sh b/curl/testcase/curl-http-post-data.sh index 1d1760a..c2d11f8 100644 --- a/curl/testcase/curl-http-post-data.sh +++ b/curl/testcase/curl-http-post-data.sh @@ -46,7 +46,7 @@ do_test() { # @测试步骤: 验证响应来自 POST 端点 # @预期结果: 响应 JSON 中 url 字段包含 /post 路径 - grep -q '"/post"' "$g_output_file" + grep -q '/post' "$g_output_file" ret=$? msg "CHECK: 响应 url 包含 /post, 实际值=$ret" assert_true [ $ret -eq 0 ] -- Gitee