Skip to content

Commit 61d1b26

Browse files
committed
feat: add ns_last_pid extension test and enhance test framework
- Add comprehensive test for ns_last_pid extension - Improve test script JSON merging capabilities - Update existing tests and CMake configuration Signed-off-by: ComixHe <ComixHe1895@outlook.com>
1 parent 53883d5 commit 61d1b26

4 files changed

Lines changed: 49 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ if(NOT linyaps-box_MAKE_RELEASE)
195195
COMMAND git rev-parse --short=7 HEAD
196196
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
197197
OUTPUT_VARIABLE GIT_COMMIT_HASH
198-
OUTPUT_STRIP_TRAILING_WHITESPACE
199-
)
198+
OUTPUT_STRIP_TRAILING_WHITESPACE)
200199

201200
set(LINYAPS_BOX_VERSION "${LINYAPS_BOX_VERSION}-dev-${GIT_COMMIT_HASH}")
202201
endif()
@@ -438,7 +437,8 @@ function(setup_linyaps_box_smoke_tests)
438437
./tests/ll-box-st/09-check-rlimit.json
439438
./tests/ll-box-st/10-check-oom.json
440439
./tests/ll-box-st/11-output-to-null.json
441-
./tests/ll-box-st/12-bind-host-dev.json)
440+
./tests/ll-box-st/12-bind-host-dev.json
441+
./tests/ll-box-st/13-pid-extension.json)
442442

443443
foreach(test ${linyaps-box_SMOKE_TESTS})
444444
add_test(

tests/ll-box-st/12-bind-host-dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"uid": 0,
66
"gid": 0
77
},
8-
"args": ["/bin/env", "bash", "-c", "pwd"],
8+
"args": ["true"],
99
"env": [
1010
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
1111
"TERM=xterm",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "Set ns_last_pid",
3+
"process": {
4+
"user": {
5+
"uid": 0,
6+
"gid": 0
7+
},
8+
"args": ["/bin/env", "bash", "-c", "cat /proc/sys/kernel/ns_last_pid"],
9+
"env": [
10+
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
11+
"TERM=xterm",
12+
"HOME=/root"
13+
],
14+
"cwd": "/"
15+
},
16+
"annotations": {
17+
"cn.org.linyaps.runtime.ns_last_pid": "100"
18+
},
19+
"linux": {
20+
"readonlyPaths": [
21+
"/proc/asound",
22+
"/proc/bus",
23+
"/proc/fs",
24+
"/proc/irq",
25+
"/proc/sysrq-trigger"
26+
]
27+
},
28+
"expected": "100"
29+
}

tests/ll-box-st/ll-box-st

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,22 @@ function run_test() {
175175
mkdir -p -- "${TEST_DIR}"
176176

177177
local TEST_CONFIG="${TEST_DIR}/test_config.json"
178-
# patch process from test file
179-
"${JQ}" >"${TEST_CONFIG}" \
180-
".process |= $("${JQ}" -r '.process' "${TEST_FILE}" || true)" \
181-
"${BUNDLE_DIR}/config.json"
182-
183-
# patch mount from test file if test file has mount field
184-
if "${JQ}" -e '.mounts' "${TEST_FILE}" &>/dev/null; then
185-
"${JQ}" >"${TEST_CONFIG}" \
186-
".mounts |= $("${JQ}" -r '.mounts' "${TEST_FILE}" || true)" \
187-
"${BUNDLE_DIR}/config.json"
188-
fi
178+
179+
# Create a copy of the original config and apply all patches at once
180+
"${JQ}" -s '
181+
.[0] as $base |
182+
.[1] as $patch |
183+
$base * {
184+
process: ($patch.process // $base.process),
185+
mounts: ($patch.mounts // $base.mounts),
186+
annotations: ($patch.annotations // $base.annotations),
187+
linux: (if $patch.linux then
188+
$base.linux * $patch.linux
189+
else
190+
$base.linux
191+
end)
192+
}
193+
' "${BUNDLE_DIR}/config.json" "${TEST_FILE}" > "${TEST_CONFIG}"
189194

190195
local CONTAINER_NAME
191196
CONTAINER_NAME="$(basename -- "${TEST_FILE_NAME}" .json)"

0 commit comments

Comments
 (0)