forked from claudioscordino/jiajia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·117 lines (103 loc) · 2.57 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
ARCH=linux
MODE=test
TIMEOUT=50
CLEAN=true
ALLTEST=true
RUN=false
tests=("lu" "ep")
run_app() {
# 进入文件夹并在reports下创建对应的log文件
if [ ! -f ./reports/$ARCH/$MODE/"$1" ]; then
echo "touch reports/$ARCH/$MODE/$1 file..." >&2
touch ./reports/$ARCH/$MODE/"$1"
fi
# 运行程序
cd ./apps/"$1"/$ARCH || exit
{ time ./"$1"; } >& "../../../reports/$ARCH/$MODE/""$1""" &
local pid=$!
cd ../../..
echo "$pid"
}
listen() {
time=0
while [[ $time -lt $TIMEOUT ]]; do
# 检查进程是否存在
# echo "$time"
if ! ps -p "$1" > /dev/null; then
echo "Process with PID $1 has completed within the time limit"
return 0
fi
((time++))
sleep 1
done
echo "Terminating process with PID $1"
kill "$1"
return 1
}
# 创建reports及其子文件夹文件夹
if [ ! -d ./reports ]; then
echo "make reports dir..."
mkdir reports
fi
if [ ! -d ./reports/$ARCH ]; then
echo "make reports/$ARCH dir..."
mkdir reports/$ARCH
fi
if [ ! -d ./reports/$ARCH/$MODE ]; then
echo "make reports/$ARCH/$MODE dir..."
mkdir reports/$ARCH/$MODE
fi
# 创建libjia库
echo -e "\nmake libjia.a..."
if $CLEAN; then
rm -f ./lib/$ARCH/*.o ./lib/$ARCH/*.d ./lib/$ARCH/*.a
# make clean -C ./lib/$ARCH
fi
make all -C ./lib/$ARCH
sleep 1
# 编译app
echo -e "\nmake all apps..."
for dir in apps/*/; do
echo "compile ${dir%/}..."
if $CLEAN; then
make clean -C ./"${dir%/}"/$ARCH
fi
make all -C ./"${dir%/}"/$ARCH
done
sleep 1
# 拷贝.jiahosts到所有文件夹下(从pi出发)
echo -e "\ncopy .jiahosts..."
for dir in apps/*/ ; do
cp apps/.jiahosts "${dir%/}"/$ARCH/
done
sleep 1
# 拷贝 .jiaconf 文件到所有文件夹下
echo -e "\ncopy .jiaconf..."
for dir in apps/*/; do
cp apps/.jiaconf "${dir%/}"/$ARCH/
done
sleep 1
# 请求用户输入密码
# read -s -p "Please enter your sudo password:" password
# 运行所有app || 运行指定app
if $RUN; then
if $ALLTEST; then
for dir in apps/*/; do
echo -e "\nrunning ${dir%/}..."
# shellcheck disable=SC2046
pid=$(run_app $(basename "${dir%/}"))
listen "$pid"
# 等待5秒后继续运行下一个程序
sleep 1
done
else
for test in "${tests[@]}"; do
echo -e "\nrunning ${test}..."
pid=$(run_app "$test")
listen "$pid"
# 等待5秒后继续运行下一个程序
sleep 1
done
fi
fi