From aa77c85ea6879698663d4ef9e01bb63a0db1e57d Mon Sep 17 00:00:00 2001
From: jikai <jikai11@huawei.com>
Date: Wed, 3 Apr 2024 09:34:39 +0000
Subject: [PATCH 46/69] oom monitor in manual cases

Signed-off-by: jikai <jikai11@huawei.com>
---
 CI/test_cases/container_cases/inspect.sh  | 15 ------
 CI/test_cases/manual_cases/oom_monitor.sh | 59 +++++++++++++++++++++++
 2 files changed, 59 insertions(+), 15 deletions(-)
 create mode 100755 CI/test_cases/manual_cases/oom_monitor.sh

diff --git a/CI/test_cases/container_cases/inspect.sh b/CI/test_cases/container_cases/inspect.sh
index 5d976281..cde9ea1f 100755
--- a/CI/test_cases/container_cases/inspect.sh
+++ b/CI/test_cases/container_cases/inspect.sh
@@ -27,7 +27,6 @@ function test_inspect_spec()
 {
     local ret=0
     local image="busybox"
-    local ubuntu_image="ubuntu"
     local test="container inspect test => (${FUNCNAME[@]})"
 
     msg_info "${test} starting..."
@@ -38,12 +37,6 @@ function test_inspect_spec()
     isula images | grep busybox
     [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${image}" && ((ret++))
 
-    isula pull ${ubuntu_image}
-    [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${ubuntu_image}" && return ${FAILURE}
-
-    isula images | grep ubuntu
-    [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${ubuntu_image}" && ((ret++))
-
     containername=test_inspect
 
     isula create --name $containername --ipc host --pid host --uts host --restart=on-failure:10 --hook-spec ${test_data_path}/test-hookspec.json --cpu-shares 100 --memory 5MB --memory-reservation 4MB --cpu-period 1000000 --cpu-quota 200000  --cpuset-cpus 1 --cpuset-mems 0 --kernel-memory 50M --pids-limit=10000 --volume /home:/root --env a=1 $image /bin/sh ls
@@ -146,14 +139,6 @@ function test_inspect_spec()
 
     isula rm -f $containername
 
-    # use more than 10m memory limit, otherwise it might fail to run
-    isula run -it -m 10m --runtime runc --name $containername $ubuntu_image perl -e 'for ($i = 0; $i < 100000000; $i++) { $a .= " " x 1024 }'
-
-    isula inspect -f "{{json .State.OOMKilled}} {{.Name}}" $containername 2>&1 | sed -n '1p' | grep "true"
-    [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${ubuntu_image}" && ((ret++))
-
-    isula rm -f $containername
-
     msg_info "${test} finished with return ${ret}..."
     return ${ret}
 }
diff --git a/CI/test_cases/manual_cases/oom_monitor.sh b/CI/test_cases/manual_cases/oom_monitor.sh
new file mode 100755
index 00000000..a1c2503d
--- /dev/null
+++ b/CI/test_cases/manual_cases/oom_monitor.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+#
+# attributes: isulad oom monitor
+# concurrent: NA
+# spend time: 6
+
+#######################################################################
+##- Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+# - iSulad licensed under the Mulan PSL v2.
+# - You can use this software according to the terms and conditions of the Mulan PSL v2.
+# - You may obtain a copy of Mulan PSL v2 at:
+# -     http://license.coscl.org.cn/MulanPSL2
+# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# - PURPOSE.
+# - See the Mulan PSL v2 for more details.
+##- @Description:CI
+##- @Author: jikai
+##- @Create: 2024-04-03
+#######################################################################
+
+declare -r curr_path=$(dirname $(readlink -f "$0"))
+source ../helpers.sh
+test_data_path=$(realpath $curr_path/test_data)
+
+function test_oom_monitor()
+{
+    local ret=0
+    local ubuntu_image="ubuntu"
+    local test="container oom monitor test => (${FUNCNAME[@]})"
+    containername="oommonitor"
+
+    msg_info "${test} starting..."
+
+    isula pull ${ubuntu_image}
+    [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${ubuntu_image}" && return ${FAILURE}
+
+    isula images | grep ubuntu
+    [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - missing list image: ${ubuntu_image}" && ((ret++))
+
+    # use more than 10m memory limit, otherwise it might fail to run
+    # iSulad monitor cgroup file for oom event, however oom triggers cgroup files delete
+    # if cgroup files were deleted before oom event was handled for iSulad we might failed to detect oom event
+    isula run -it -m 10m --runtime runc --name $containername $ubuntu_image perl -e 'for ($i = 0; $i < 100000000; $i++) { $a .= " " x 1024 }'
+
+    isula inspect -f "{{json .State.OOMKilled}} {{.Name}}" $containername 2>&1 | sed -n '1p' | grep "true"
+    [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to check container with image: ${ubuntu_image}" && ((ret++))
+
+    isula rm -f $containername
+
+    msg_info "${test} finished with return ${ret}..."
+    return ${ret}
+}
+
+declare -i ans=0
+
+test_oom_monitor || ((ans++))
+
+show_result ${ans} "${curr_path}/${0}"
-- 
2.34.1

