Skip to content

Commit d7f4973

Browse files
fujimotosedsiper
authored andcommitted
tests: runtime_shell: fix GNUism in run_tests.sh
This commit makes the test script run on macOS as well as Linux. - "stat -c" is a GNU/Linux thing so does not work on BSD. - "wc -l" can contain spaces on macOS. We need trim them before comparison. Signed-off-by: Fujimoto Seiji <[email protected]>
1 parent 072a227 commit d7f4973

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tests/runtime_shell/in_tail/run_tests.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_normal_rotation() {
3535
".headers off" ".width 20" "SELECT inode FROM in_tail_files" > \
3636
$1/$2.inodes
3737

38-
rows=`cat $1/$2.inodes | wc -l`
38+
rows=`cat $1/$2.inodes | wc -l | tr -d -C '[0-9]'`
3939
if [ $rows != "1" ]; then
4040
echo "> database file $1/$2 contains $rows rows, inodes:"
4141
cat $1/$2.inodes
@@ -181,13 +181,13 @@ test_truncate() {
181181

182182
# Get the last size of the 'a.log' file and check we have the same value
183183
# in the database
184-
offset=`stat -c %s $TEST_DIR/a.log`
184+
offset=`wc -c < $TEST_DIR/a.log`
185185

186186
sqlite3 $1/$2 -batch \
187187
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset" > \
188188
$1/$2.offset
189189

190-
rows=`cat $1/$2.offset | wc -l`
190+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
191191
if [ $rows != "1" ]; then
192192
echo "> invalid database content:"
193193
cat $1/$2.offset
@@ -275,13 +275,13 @@ test_rotate_link() {
275275

276276
# Get the last size of the file pointed by 'a.log.1' and check we have the
277277
# same value in the database
278-
offset=`stat -L -c %s $TEST_DIR/a.log.1`
278+
offset=`wc -c < $TEST_DIR/a.log.1`
279279

280280
sqlite3 $1/$2 -batch \
281281
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset \
282282
AND rotated=1" > $1/$2.offset
283283

284-
rows=`cat $1/$2.offset | wc -l`
284+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
285285
if [ $rows != "1" ]; then
286286
echo "> invalid database content:"
287287
cat $1/$2.offset
@@ -298,7 +298,7 @@ test_rotate_link() {
298298
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset \
299299
AND rotated=1" > $1/$2.offset
300300

301-
rows=`cat $1/$2.offset | wc -l`
301+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
302302
if [ $rows != "0" ]; then
303303
echo "> invalid database content:"
304304
cat $1/$2.offset
@@ -342,7 +342,7 @@ test_rotate_link() {
342342
python logger_file.py -l 200 -s 200000 -b 100 -d 0 -f $TEST_DIR/a.log.1
343343

344344
# Count number of processed lines
345-
sleep 2
345+
sleep 3
346346
write_lines=300
347347
read_lines=`cat $TEST_DIR/a | wc -l`
348348

@@ -379,13 +379,13 @@ test_truncate_link() {
379379

380380
# Get the last size of the 'a.log' file and check we have the same value
381381
# in the database
382-
offset=`stat -c %s $TEST_DIR/a.log`
382+
offset=`wc -c < $TEST_DIR/a.log`
383383

384384
sqlite3 $1/$2 -batch \
385385
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset" > \
386386
$1/$2.offset
387387

388-
rows=`cat $1/$2.offset | wc -l`
388+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
389389
if [ $rows != "1" ]; then
390390
echo "> invalid database content:"
391391
cat $1/$2.offset

tests/runtime_shell/in_tail/test_rotation.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_normal_rotation() {
3535
".headers off" ".width 20" "SELECT inode FROM in_tail_files" > \
3636
$1/$2.inodes
3737

38-
rows=`cat $1/$2.inodes | wc -l`
38+
rows=`cat $1/$2.inodes | wc -l | tr -d -C '[0-9]'`
3939
if [ $rows != "1" ]; then
4040
echo "> database file $1/$2 contains $rows rows, inodes:"
4141
cat $1/$2.inodes
@@ -181,13 +181,13 @@ test_truncate() {
181181

182182
# Get the last size of the 'a.log' file and check we have the same value
183183
# in the database
184-
offset=`stat -c %s $TEST_DIR/a.log`
184+
offset=`wc -c < $TEST_DIR/a.log`
185185

186186
sqlite3 $1/$2 -batch \
187187
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset" > \
188188
$1/$2.offset
189189

190-
rows=`cat $1/$2.offset | wc -l`
190+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
191191
if [ $rows != "1" ]; then
192192
echo "> invalid database content:"
193193
cat $1/$2.offset
@@ -275,13 +275,13 @@ test_rotate_link() {
275275

276276
# Get the last size of the file pointed by 'a.log.1' and check we have the
277277
# same value in the database
278-
offset=`stat -L -c %s $TEST_DIR/a.log.1`
278+
offset=`wc -c < $TEST_DIR/a.log.1`
279279

280280
sqlite3 $1/$2 -batch \
281281
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset \
282282
AND rotated=1" > $1/$2.offset
283283

284-
rows=`cat $1/$2.offset | wc -l`
284+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
285285
if [ $rows != "1" ]; then
286286
echo "> invalid database content:"
287287
cat $1/$2.offset
@@ -298,7 +298,7 @@ test_rotate_link() {
298298
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset \
299299
AND rotated=1" > $1/$2.offset
300300

301-
rows=`cat $1/$2.offset | wc -l`
301+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
302302
if [ $rows != "0" ]; then
303303
echo "> invalid database content:"
304304
cat $1/$2.offset
@@ -342,7 +342,7 @@ test_rotate_link() {
342342
python logger_file.py -l 200 -s 200000 -b 100 -d 0 -f $TEST_DIR/a.log.1
343343

344344
# Count number of processed lines
345-
sleep 2
345+
sleep 3
346346
write_lines=300
347347
read_lines=`cat $TEST_DIR/a | wc -l`
348348

@@ -379,13 +379,13 @@ test_truncate_link() {
379379

380380
# Get the last size of the 'a.log' file and check we have the same value
381381
# in the database
382-
offset=`stat -c %s $TEST_DIR/a.log`
382+
offset=`wc -c < $TEST_DIR/a.log`
383383

384384
sqlite3 $1/$2 -batch \
385385
".headers off" "SELECT inode FROM in_tail_files WHERE offset=$offset" > \
386386
$1/$2.offset
387387

388-
rows=`cat $1/$2.offset | wc -l`
388+
rows=`cat $1/$2.offset | wc -l | tr -d -C '[0-9]'`
389389
if [ $rows != "1" ]; then
390390
echo "> invalid database content:"
391391
cat $1/$2.offset

0 commit comments

Comments
 (0)