Skip to content

Commit 33203c3

Browse files
committed
Add contention testing
Simulate netowrk latency using netem and use it to test the non-blocking mode of SFTP. This helps find issues which would affect running an SFTP server on a microcontroller. It helped find the bug fixed in #876.
1 parent e60aafe commit 33203c3

File tree

2 files changed

+188
-3
lines changed

2 files changed

+188
-3
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: wolfSSH Network Contention Test
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
create_matrix:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
versions: ${{ steps.json.outputs.versions }}
19+
steps:
20+
- name: Create wolfSSL version matrix
21+
id: json
22+
run: |
23+
current=`curl -s https://api.github.com/repos/wolfssl/wolfssl/releases | grep tag_name | cut -d : -f 2,3 | tr -d \" | tr -d , | tr -d ' ' | head -1`
24+
last=`curl -s https://api.github.com/repos/wolfssl/wolfssl/releases | grep tag_name | cut -d : -f 2,3 | tr -d \" | tr -d , | tr -d ' ' | head -2 | tail -1`
25+
VERSIONS=$(echo "[ \"master\", \"$current\", \"$last\" ]")
26+
echo "wolfSSL versions found: $VERSIONS"
27+
echo "versions=$VERSIONS" >> $GITHUB_OUTPUT
28+
29+
build_wolfssl:
30+
needs: create_matrix
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
os: [ ubuntu-latest ]
35+
wolfssl: ${{ fromJson(needs.create_matrix.outputs['versions']) }}
36+
name: Build wolfssl
37+
runs-on: ${{ matrix.os }}
38+
timeout-minutes: 4
39+
steps:
40+
- name: Checking cache for wolfssl
41+
uses: actions/cache@v4
42+
id: cache-wolfssl
43+
with:
44+
path: build-dir/
45+
key: wolfssh-contention-wolfssl-${{ matrix.wolfssl }}-${{ matrix.os }}
46+
lookup-only: true
47+
48+
- name: Checkout, build, and install wolfssl
49+
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
50+
uses: wolfSSL/actions-build-autotools-project@v1
51+
with:
52+
repository: wolfssl/wolfssl
53+
ref: ${{ matrix.wolfssl }}
54+
path: wolfssl
55+
configure: --enable-ssh
56+
check: false
57+
install: true
58+
59+
test_sftp_contention:
60+
needs:
61+
- build_wolfssl
62+
- create_matrix
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
os: [ ubuntu-latest ]
67+
wolfssl: ${{ fromJson(needs.create_matrix.outputs['versions']) }}
68+
block_prob: [ 30, 50, 70 ]
69+
name: SFTP contention test (prob=${{ matrix.block_prob }}%)
70+
runs-on: ${{ matrix.os }}
71+
timeout-minutes: 15
72+
steps:
73+
- name: Checking cache for wolfssl
74+
uses: actions/cache@v4
75+
with:
76+
path: build-dir/
77+
key: wolfssh-contention-wolfssl-${{ matrix.wolfssl }}-${{ matrix.os }}
78+
fail-on-cache-miss: true
79+
80+
- uses: actions/checkout@v4
81+
with:
82+
path: wolfssh/
83+
84+
- name: autogen
85+
working-directory: ./wolfssh/
86+
run: ./autogen.sh
87+
88+
- name: configure with TEST_BLOCK
89+
working-directory: ./wolfssh/
90+
run: |
91+
./configure --enable-sftp \
92+
LDFLAGS="-L${{ github.workspace }}/build-dir/lib" \
93+
CPPFLAGS="-I${{ github.workspace }}/build-dir/include -DWOLFSSH_TEST_BLOCK -DWOLFSSH_BLOCK_PROB=${{ matrix.block_prob }} -DWOLFSSH_NO_FPKI"
94+
95+
- name: make
96+
working-directory: ./wolfssh/
97+
run: make
98+
99+
- name: Setup network delay with tc/netem
100+
run: |
101+
sudo tc qdisc add dev lo root netem delay 10ms 5ms loss 0.1%
102+
echo "Network delay configured:"
103+
tc qdisc show dev lo
104+
105+
- name: Run SFTP contention tests
106+
working-directory: ./wolfssh/
107+
timeout-minutes: 10
108+
run: ./scripts/sftp.test
109+
110+
- name: Install expect for extended tests
111+
run: sudo apt-get update && sudo apt-get install -y expect
112+
113+
- name: Create large test files
114+
run: |
115+
dd if=/dev/urandom of=/tmp/test_1kb.dat bs=1K count=1
116+
dd if=/dev/urandom of=/tmp/test_2mb.dat bs=1M count=2
117+
dd if=/dev/urandom of=/tmp/test_10mb.dat bs=1M count=10
118+
md5sum /tmp/test_*.dat > /tmp/test_checksums.md5
119+
echo "Test files created:"
120+
ls -la /tmp/test_*.dat
121+
122+
- name: Run extended SFTP file transfer tests
123+
working-directory: ./wolfssh/
124+
timeout-minutes: 10
125+
run: |
126+
# Start echoserver in non-blocking mode
127+
./examples/echoserver/echoserver -N -f &
128+
SERVER_PID=$!
129+
sleep 2
130+
131+
# Create expect script for file transfers
132+
cat > /tmp/sftp_test.exp << 'EXPECTEOF'
133+
#!/usr/bin/expect -f
134+
set timeout 120
135+
set testfile [lindex $argv 0]
136+
set outfile [lindex $argv 1]
137+
138+
spawn ./examples/sftpclient/wolfsftp -N -h 127.0.0.1 -p 22222 -u jill
139+
expect "Password:"
140+
send "upthehill\r"
141+
expect "wolfSSH sftp>"
142+
send "get $testfile $outfile\r"
143+
expect "wolfSSH sftp>"
144+
send "exit\r"
145+
expect eof
146+
EXPECTEOF
147+
chmod +x /tmp/sftp_test.exp
148+
149+
# Test 1KB file transfer
150+
echo "Testing 1KB file transfer..."
151+
/tmp/sftp_test.exp /tmp/test_1kb.dat /tmp/recv_1kb.dat
152+
if ! cmp -s /tmp/test_1kb.dat /tmp/recv_1kb.dat; then
153+
echo "FAILED: 1KB file integrity check"
154+
kill $SERVER_PID 2>/dev/null || true
155+
exit 1
156+
fi
157+
echo "1KB file transfer: PASSED"
158+
159+
# Test 2MB file transfer
160+
echo "Testing 2MB file transfer..."
161+
/tmp/sftp_test.exp /tmp/test_2mb.dat /tmp/recv_2mb.dat
162+
if ! cmp -s /tmp/test_2mb.dat /tmp/recv_2mb.dat; then
163+
echo "FAILED: 2MB file integrity check"
164+
kill $SERVER_PID 2>/dev/null || true
165+
exit 1
166+
fi
167+
echo "2MB file transfer: PASSED"
168+
169+
# Test 10MB file transfer
170+
echo "Testing 10MB file transfer..."
171+
/tmp/sftp_test.exp /tmp/test_10mb.dat /tmp/recv_10mb.dat
172+
if ! cmp -s /tmp/test_10mb.dat /tmp/recv_10mb.dat; then
173+
echo "FAILED: 10MB file integrity check"
174+
kill $SERVER_PID 2>/dev/null || true
175+
exit 1
176+
fi
177+
echo "10MB file transfer: PASSED"
178+
179+
kill $SERVER_PID 2>/dev/null || true
180+
echo "All extended SFTP tests PASSED"
181+
182+
- name: Cleanup network delay
183+
if: always()
184+
run: sudo tc qdisc del dev lo root netem || true

scripts/scp.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ counter=0
99

1010
[ ! -x ./examples/scpclient/wolfscp ] && echo -e "\n\nwolfscp client doesn't exist" && exit 1
1111

12-
# test for nonblocking only
12+
# test for nonblocking only - wolfscp does not support -N flag for non-blocking
13+
# mode, so we must skip when TEST_BLOCK is enabled
1314
./examples/client/client -h | grep WOLFSSH_TEST_BLOCK
1415
if [ $? -eq 0 ]
1516
then
16-
echo "macro NO_WOLFSSH_CLIENT was used"
17-
echo "skipping for now"
17+
echo "WOLFSSH_TEST_BLOCK detected"
18+
echo "wolfscp client does not support non-blocking mode, skipping test"
1819
exit 77
1920
fi
2021

0 commit comments

Comments
 (0)