Skip to content

Commit da01cea

Browse files
Add GitHub Action to test FATFS support for wolfsftp client
This adds a GitHub Action workflow to test the FATFS support for the wolfsftp client. The workflow: - Installs dependencies - Clones and builds wolfSSL with appropriate flags - Compiles the FATFS library - Configures and builds wolfSSH with FATFS support - Creates a test file - Sets up an SSH server - Uses the wolfsftp client to transfer a test file - Verifies the file in the FATFS image Co-Authored-By: [email protected] <[email protected]> Co-Authored-By: [email protected] <[email protected]>
1 parent 08759f1 commit da01cea

File tree

2 files changed

+149
-2
lines changed

2 files changed

+149
-2
lines changed

.github/workflows/test-fatfs.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Test FATFS Support
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test-fatfs:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Install dependencies
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -y build-essential autoconf automake libtool pkg-config openssh-server dosfstools
21+
22+
- name: Clone wolfSSL
23+
run: |
24+
cd ..
25+
git clone https://github.com/wolfSSL/wolfssl.git
26+
cd wolfssl
27+
./autogen.sh
28+
29+
- name: Configure and build wolfSSL
30+
run: |
31+
cd ../wolfssl
32+
./configure --enable-wolfssh --enable-intelasm --disable-crl --disable-examples --disable-filesystem CFLAGS="-DNO_WOLFSSL_DIR"
33+
make
34+
sudo make install
35+
sudo ldconfig
36+
37+
- name: Compile FATFS library
38+
run: |
39+
cd ide/Linux-FATFS
40+
make
41+
42+
- name: Configure and build wolfSSH with FATFS
43+
run: |
44+
./autogen.sh
45+
export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS
46+
./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS -DSTDIN_FILENO=0 -DPRINTF=printf" LDFLAGS="-Lide/Linux-FATFS -lfatfs"
47+
make
48+
49+
50+
51+
- name: Create test file
52+
run: |
53+
dd if=/dev/urandom of=test_file.bin bs=1M count=1
54+
55+
- name: Setup SSH server
56+
run: |
57+
sudo mkdir -p /run/sshd
58+
sudo /usr/sbin/sshd
59+
mkdir -p ~/.ssh
60+
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
61+
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
62+
chmod 600 ~/.ssh/authorized_keys
63+
echo "Host localhost" > ~/.ssh/config
64+
echo " StrictHostKeyChecking no" >> ~/.ssh/config
65+
echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config
66+
chmod 600 ~/.ssh/config
67+
68+
- name: Install expect
69+
run: |
70+
sudo apt-get update
71+
sudo apt-get install -y expect
72+
73+
- name: Run wolfsftp client to get file
74+
run: |
75+
# Export the library path
76+
export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS
77+
78+
# Get the full path to the test file
79+
TEST_FILE_PATH=$(pwd)/test_file.bin
80+
81+
# Change to the sftpclient directory
82+
cd examples/sftpclient
83+
84+
# Create the FATFS image file directly in the sftpclient directory
85+
dd if=/dev/zero of=fatfs_image.img bs=1M count=32
86+
mkdosfs fatfs_image.img
87+
88+
# Create a test user with a known password and add to the same group as the runner
89+
sudo useradd -m testuser
90+
echo "testuser:password123" | sudo chpasswd
91+
sudo usermod -aG $(id -gn) testuser
92+
93+
# Make the test file accessible to testuser
94+
chmod 644 ${TEST_FILE_PATH}
95+
sudo chown testuser:$(id -gn) ${TEST_FILE_PATH}
96+
97+
# Configure SSH server to allow SFTP access
98+
sudo sed -i 's/^#Subsystem\s\+sftp.*/Subsystem sftp \/usr\/lib\/openssh\/sftp-server/' /etc/ssh/sshd_config
99+
sudo service ssh restart || sudo /etc/init.d/ssh restart || sudo /usr/sbin/sshd -t && sudo kill -HUP $(pgrep -f sshd)
100+
101+
# Create expect script to automate the wolfsftp client interaction
102+
cat > /tmp/sftp_test.exp << EOF
103+
#!/usr/bin/expect -f
104+
set timeout 60
105+
spawn ./wolfsftp -N -h localhost -p 22 -u testuser
106+
expect "Password:"
107+
send "password123\r"
108+
expect "wolfSSH sftp>"
109+
send "get ${TEST_FILE_PATH} test_file.bin\r"
110+
expect "wolfSSH sftp>"
111+
send "exit\r"
112+
expect eof
113+
EOF
114+
chmod +x /tmp/sftp_test.exp
115+
116+
# Run the expect script
117+
/tmp/sftp_test.exp
118+
119+
- name: Verify file in FATFS image
120+
run: |
121+
cd examples/sftpclient
122+
sudo mkdir -p /mnt/fatfs
123+
LOOPDEV=$(sudo losetup -f)
124+
sudo losetup $LOOPDEV fatfs_image.img
125+
sudo mount $LOOPDEV /mnt/fatfs
126+
if [ -f /mnt/fatfs/test_file.bin ]; then
127+
echo "File exists in FATFS image!"
128+
ls -la /mnt/fatfs/
129+
130+
# Verify file contents match
131+
if cmp -s ../../test_file.bin /mnt/fatfs/test_file.bin; then
132+
echo "File contents match! FATFS test PASSED."
133+
sudo umount /mnt/fatfs
134+
sudo losetup -d $LOOPDEV
135+
exit 0
136+
else
137+
echo "File contents do not match! FATFS test FAILED."
138+
sudo umount /mnt/fatfs
139+
sudo losetup -d $LOOPDEV
140+
exit 1
141+
fi
142+
else
143+
echo "File does not exist in FATFS image! FATFS test FAILED."
144+
ls -la /mnt/fatfs/
145+
sudo umount /mnt/fatfs
146+
sudo losetup -d $LOOPDEV
147+
exit 1
148+
fi

ide/Linux-FATFS/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ the library.
3030
### wolfSSH
3131

3232
```sh
33-
export LD_LIBRARY_PATH=ide/Linux-FATFS
34-
./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS -DSTDIN_FILENO=0 -DPRINTF=printf -lfatfs"
33+
./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS -DSTDIN_FILENO=0 -DPRINTF=printf" LDFLAGS="-Lide/Linux-FATFS -lfatfs"
3534
```
3635

0 commit comments

Comments
 (0)