From 10c9d954f6bfadf2724d4a74b5991eeea1126870 Mon Sep 17 00:00:00 2001 From: hou Date: Sun, 28 May 2023 03:00:26 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eglibc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hou --- glibc/testcase/glibc_test.sh | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 glibc/testcase/glibc_test.sh diff --git a/glibc/testcase/glibc_test.sh b/glibc/testcase/glibc_test.sh new file mode 100644 index 0000000..2e53630 --- /dev/null +++ b/glibc/testcase/glibc_test.sh @@ -0,0 +1,76 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20230525-154056-556766079 +# @用例名称: glibc-test +# @用例级别: 3 +# @用例标签: +# @用例类型: 功能 +############################################################################### +[ -z "$TST_TS_TOPDIR" ] && { + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + export TST_TS_TOPDIR +} +source "${TST_TS_TOPDIR}/tst_common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + # @预置条件:glibc已提前安装 + + assert_true command -v gcc + return 0 +} + +do_test() { + msg "this is do_test" + + # 编写测试程序文件 + cat >test.c < +#include + +int main() { + // 使用 printf 打印 Hello, World! + printf("Hello, World!\\n"); + + // 使用 malloc 分配内存 + int* arr = malloc(5 * sizeof(int)); + if (arr == NULL) { + printf("Failed to allocate memory\\n"); + return 1; + } + + // 释放内存 + free(arr); + + return 0; +} +EOF + + # 编译测试程序 + assert_true gcc -o test test.c + + # 执行测试程序 + assert_true ./test + + return 0 +} + +tc_teardown() { + msg "this is tc_teardown" + + # 删除 test.c 文件 + rm -f test.c + + # 删除 test 文件 + rm -f test + + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + +############################################################################### +tst_main "$@" +############################################################################### -- Gitee