-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·160 lines (132 loc) · 4.82 KB
/
test.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
# 0.0.1
# Alexey Potehin <[email protected]>, http://www.gnuplanet.ru/doc/cv
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
APP='./bin/base64codec';
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
# run app
function run_app()
{
local RESULT=0;
local STDOUT;
if [ "${FLAG_VALGRIND}" != "1" ];
then
STDOUT=$("${APP}" "${@}");
RESULT="${?}";
else
local LOG_ID=0;
local LOG_NAME;
while true;
do
LOG_NAME=$(printf "valgrind.%03u\n" ${LOG_ID});
if [ ! -e "${LOG_NAME}" ];
then
break;
fi
(( LOG_ID++ ));
done
STDOUT=$(valgrind --tool=memcheck --leak-check=yes --leak-check=full --show-reachable=yes --log-file="${LOG_NAME}" "${APP}" "${@}");
RESULT="${?}";
fi
if [ "${STDOUT}" != "" ];
then
echo "${STDOUT}";
fi
return "${RESULT}";
}
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
# test1
function test1()
{
local TMP1;
TMP1="$(mktemp)";
if [ "${?}" != "0" ];
then
echo "can't make tmp file";
exit 1;
fi
local TMP2;
TMP2="$(mktemp)";
if [ "${?}" != "0" ];
then
echo "can't make tmp file";
exit 1;
fi
local TMP3;
TMP3="$(mktemp)";
if [ "${?}" != "0" ];
then
echo "can't make tmp file";
exit 1;
fi
echo "${MSG}" > "${TMP1}";
run_app -e "${TMP1}" > "${TMP2}" < /dev/null;
run_app -d "${TMP2}" > "${TMP3}" < /dev/null;
local HASH1="$(md5sum ${TMP1} | awk '{print $1}')";
local HASH2="$(md5sum ${TMP3} | awk '{print $1}')";
if [ "${FLAG_DEBUG}" != "" ];
then
echo "-------------------------------";
echo -n "data1(${TMP1}): "; cat "${TMP1}"; echo;
echo -n "data2(${TMP2}): "; cat "${TMP2}"; echo;
echo -n "data3(${TMP3}): "; cat "${TMP3}"; echo;
fi
if [ "${HASH1}" != "${HASH2}" ];
then
echo "ERROR: result different...";
echo -n "data1(${TMP1}): "; cat "${TMP1}"; echo;
echo -n "data2(${TMP2}): "; cat "${TMP2}"; echo;
echo -n "data3(${TMP3}): "; cat "${TMP3}"; echo;
exit 1;
fi
rm "${TMP1}";
rm "${TMP2}";
rm "${TMP3}";
}
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
# check depends
function check_prog()
{
for i in ${1};
do
if [ "$(command -v ${i})" == "" ];
then
echo "FATAL: you must install \"${i}\"...";
return 1;
fi
done
return 0;
}
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
# general function
function main()
{
if [ ! -e "${APP}" ];
then
echo "ERROR: make it";
return 1;
fi
check_prog "awk cat echo md5sum mktemp rm";
if [ "${?}" != "0" ];
then
return 1;
fi
local MSG;
MSG='hello world!';
test1;
MSG='hello world!!';
test1;
MSG='hello world!!!';
test1;
MSG='hello world!!!!';
test1;
MSG='hello world!!!!!';
test1;
echo "ok, test passed";
return 0;
}
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
main "${@}";
exit "${?}";
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#