diff --git a/glibc/testcase/glibc_test.sh b/glibc/testcase/glibc_test.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e536306a839cba49f39da0ef19f60819764f68b --- /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 "$@" +###############################################################################