Skip to content

Commit 147cece

Browse files
committed
Add test-root.c to avoid test timeout
1 parent 0e7746a commit 147cece

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ debian/source
2020
debian/.debhelper
2121
debian/debhelper-build-stamp
2222
debian/files
23-
tmpdir*
23+
tmpdir*
24+
test-root

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ format :
9292
shfmt -i 4 -w get-ruri.sh
9393
chmod 777 test/*.sh
9494
chmod 777 test/root/*
95+
clang-format -i test/*.c
9596
clean :
9697
$(CLEAN_LOG) $(BIN_TARGET)
9798
@rm -f $(BIN_TARGET)||true

test/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ all :
22
@echo "\033[33mWarning: This test is under sudo, do not run it on your device.\033[0m"
33
@echo "\033[33mYou have 5 seconds to press Ctrl+C to cancel.\033[0m"
44
@sleep 5
5-
@sudo bash test-root.sh
5+
@cc -o test-root test-root.c
6+
@sudo ./test-root

test/root/3-capability.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export SUBTEST_DESCRIPTION="Default capability"
1010
show_subtest_description
1111
cd ${TMPDIR}
1212
cat <<EOF >test/test.sh
13-
cat /proc/self/status | grep CapEff| awk '{print \$2}' > /cap
13+
cat /proc/self/status | grep CapBnd| awk '{print \$2}' > /cap
1414
EOF
1515
chmod 777 test/test.sh
1616
./ruri ./test /bin/sh /test.sh
@@ -55,7 +55,7 @@ export SUBTEST_DESCRIPTION="Add capability CAP_SYS_ADMIN"
5555
show_subtest_description
5656
cd ${TMPDIR}
5757
cat <<EOF >test/test.sh
58-
cat /proc/self/status | grep CapEff| awk '{print \$2}' > /cap
58+
cat /proc/self/status | grep CapBnd| awk '{print \$2}' > /cap
5959
EOF
6060
chmod 777 test/test.sh
6161
./ruri -k cap_sys_admin ./test /bin/sh /test.sh
@@ -72,7 +72,7 @@ export SUBTEST_DESCRIPTION="Drop capability CAP_CHOWN"
7272
show_subtest_description
7373
cd ${TMPDIR}
7474
cat <<EOF >test/test.sh
75-
cat /proc/self/status | grep CapEff| awk '{print \$2}' > /cap
75+
cat /proc/self/status | grep CapBnd| awk '{print \$2}' > /cap
7676
EOF
7777
chmod 777 test/test.sh
7878
./ruri -d cap_chown ./test /bin/sh /test.sh
@@ -89,7 +89,7 @@ export SUBTEST_DESCRIPTION="Drop all capabilities"
8989
show_subtest_description
9090
cd ${TMPDIR}
9191
cat <<EOF >test/test.sh
92-
cat /proc/self/status | grep CapEff| awk '{print \$2}' > /cap
92+
cat /proc/self/status | grep CapBnd| awk '{print \$2}' > /cap
9393
EOF
9494
chmod 777 test/test.sh
9595
for i in $(seq 0 40); do
@@ -109,7 +109,7 @@ export SUBTEST_DESCRIPTION="Keep all capabilities(privileged)"
109109
show_subtest_description
110110
cd ${TMPDIR}
111111
cat <<EOF >test/test.sh
112-
cat /proc/self/status | grep CapEff| awk '{print \$2}' > /cap
112+
cat /proc/self/status | grep CapBnd| awk '{print \$2}' > /cap
113113
EOF
114114
chmod 777 test/test.sh
115115
./ruri -p ./test /bin/sh /test.sh
@@ -126,7 +126,7 @@ export SUBTEST_DESCRIPTION="Drop all capabilities but keep CAP_SYS_ADMIN"
126126
show_subtest_description
127127
cd ${TMPDIR}
128128
cat <<EOF >test/test.sh
129-
cat /proc/self/status | grep CapEff| awk '{print \$2}' > /cap
129+
cat /proc/self/status | grep CapBnd| awk '{print \$2}' > /cap
130130
EOF
131131
chmod 777 test/test.sh
132132
for i in $(seq 0 40); do

test/test-root.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "../src/include/ruri.h"
2+
int main()
3+
{
4+
// Timeout: 400s
5+
// This file will ensure that the test will not stuck.
6+
pid_t pid = fork();
7+
if (pid > 0) {
8+
int status;
9+
for (int i = 0; i < 400; i++) {
10+
sleep(1);
11+
if (waitpid(pid, &status, WNOHANG) == pid) {
12+
exit(status);
13+
}
14+
}
15+
if (waitpid(pid, &status, WNOHANG) == 0) {
16+
kill(pid, SIGKILL);
17+
printf("Timeout\n");
18+
exit(114);
19+
}
20+
exit(0);
21+
}
22+
char *command[] = { "bash", "test-root.sh", NULL };
23+
execvp(command[0], command);
24+
return 0;
25+
}

0 commit comments

Comments
 (0)