|
| 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 | + get-fatfs: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Set up cache key |
| 15 | + id: cache-key |
| 16 | + run: echo "CACHE_KEY=ff15a-cache" >> $GITHUB_ENV |
| 17 | + |
| 18 | + - name: Download FF15a.zip |
| 19 | + id: download |
| 20 | + run: | |
| 21 | + wget http://elm-chan.org/fsw/ff/arc/ff15a.zip -O ff15a.zip |
| 22 | +
|
| 23 | + - name: Cache the downloaded ZIP file |
| 24 | + uses: actions/cache@v4 |
| 25 | + with: |
| 26 | + path: ./ff15a.zip |
| 27 | + key: ${{ env.CACHE_KEY }} |
| 28 | + restore-keys: | |
| 29 | + ${{ env.CACHE_KEY }} |
| 30 | +
|
| 31 | + test-fatfs: |
| 32 | + needs: get-fatfs |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Checkout code |
| 36 | + uses: actions/checkout@v3 |
| 37 | + |
| 38 | + - name: Checking cache for FATFS |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ./ff15a.zip |
| 42 | + key: ff15a-cache |
| 43 | + fail-on-cache-miss: true |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + run: | |
| 47 | + sudo apt-get update |
| 48 | + sudo apt-get install -y build-essential autoconf automake libtool pkg-config openssh-server dosfstools |
| 49 | +
|
| 50 | + - name: Clone wolfSSL |
| 51 | + run: | |
| 52 | + cd .. |
| 53 | + git clone https://github.com/wolfSSL/wolfssl.git |
| 54 | + cd wolfssl |
| 55 | + ./autogen.sh |
| 56 | +
|
| 57 | + - name: Configure and build wolfSSL |
| 58 | + run: | |
| 59 | + cd ../wolfssl |
| 60 | + ./configure --enable-wolfssh --enable-intelasm --disable-crl --disable-examples --disable-filesystem CFLAGS="-DNO_WOLFSSL_DIR" |
| 61 | + make |
| 62 | + sudo make install |
| 63 | + sudo ldconfig |
| 64 | +
|
| 65 | + - name: Compile FATFS library |
| 66 | + run: | |
| 67 | + cd ide/Linux-FATFS |
| 68 | + unzip ../../ff15a.zip |
| 69 | + cp ffconf.h source/ |
| 70 | + make |
| 71 | +
|
| 72 | + - name: Configure and build wolfSSH with FATFS |
| 73 | + run: | |
| 74 | + ./autogen.sh |
| 75 | + export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS |
| 76 | + ./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS/source -DSTDIN_FILENO=0 -DPRINTF=printf" LDFLAGS="-Lide/Linux-FATFS -lfatfs" |
| 77 | + make |
| 78 | +
|
| 79 | +
|
| 80 | +
|
| 81 | + - name: Create test file |
| 82 | + run: | |
| 83 | + dd if=/dev/urandom of=test_file.bin bs=1M count=1 |
| 84 | +
|
| 85 | + - name: Setup SSH server |
| 86 | + run: | |
| 87 | + sudo mkdir -p /run/sshd |
| 88 | + sudo /usr/sbin/sshd |
| 89 | + mkdir -p ~/.ssh |
| 90 | + ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" |
| 91 | + cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
| 92 | + chmod 600 ~/.ssh/authorized_keys |
| 93 | + echo "Host localhost" > ~/.ssh/config |
| 94 | + echo " StrictHostKeyChecking no" >> ~/.ssh/config |
| 95 | + echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config |
| 96 | + chmod 600 ~/.ssh/config |
| 97 | +
|
| 98 | + - name: Install expect |
| 99 | + run: | |
| 100 | + sudo apt-get update |
| 101 | + sudo apt-get install -y expect |
| 102 | +
|
| 103 | + - name: Run wolfsftp client to get file |
| 104 | + run: | |
| 105 | + # Export the library path |
| 106 | + export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS |
| 107 | + |
| 108 | + # Get the full path to the test file |
| 109 | + TEST_FILE_PATH=$(pwd)/test_file.bin |
| 110 | + |
| 111 | + # Change to the sftpclient directory |
| 112 | + cd examples/sftpclient |
| 113 | + |
| 114 | + # Create the FATFS image file directly in the sftpclient directory |
| 115 | + dd if=/dev/zero of=fatfs_image.img bs=1M count=32 |
| 116 | + mkdosfs fatfs_image.img |
| 117 | + |
| 118 | + # Create a test user with a known password and add to the same group as the runner |
| 119 | + sudo useradd -m testuser |
| 120 | + echo "testuser:password123" | sudo chpasswd |
| 121 | + sudo usermod -aG $(id -gn) testuser |
| 122 | + |
| 123 | + # Make the test file accessible to testuser |
| 124 | + chmod 644 ${TEST_FILE_PATH} |
| 125 | + sudo chown testuser:$(id -gn) ${TEST_FILE_PATH} |
| 126 | + |
| 127 | + # Configure SSH server to allow SFTP access |
| 128 | + sudo sed -i 's/^#Subsystem\s\+sftp.*/Subsystem sftp \/usr\/lib\/openssh\/sftp-server/' /etc/ssh/sshd_config |
| 129 | + sudo service ssh restart || sudo /etc/init.d/ssh restart || sudo /usr/sbin/sshd -t && sudo kill -HUP $(pgrep -f sshd) |
| 130 | + |
| 131 | + # Create expect script to automate the wolfsftp client interaction |
| 132 | + cat > /tmp/sftp_test.exp << EOF |
| 133 | + #!/usr/bin/expect -f |
| 134 | + set timeout 60 |
| 135 | + spawn ./wolfsftp -N -h localhost -p 22 -u testuser |
| 136 | + expect "Password:" |
| 137 | + send "password123\r" |
| 138 | + expect "wolfSSH sftp>" |
| 139 | + send "get ${TEST_FILE_PATH} test_file.bin\r" |
| 140 | + expect "wolfSSH sftp>" |
| 141 | + send "exit\r" |
| 142 | + expect eof |
| 143 | + EOF |
| 144 | + chmod +x /tmp/sftp_test.exp |
| 145 | + |
| 146 | + # Run the expect script |
| 147 | + /tmp/sftp_test.exp |
| 148 | +
|
| 149 | + - name: Verify file in FATFS image |
| 150 | + run: | |
| 151 | + cd examples/sftpclient |
| 152 | + sudo mkdir -p /mnt/fatfs |
| 153 | + LOOPDEV=$(sudo losetup -f) |
| 154 | + sudo losetup $LOOPDEV fatfs_image.img |
| 155 | + sudo mount $LOOPDEV /mnt/fatfs |
| 156 | + if [ -f /mnt/fatfs/test_file.bin ]; then |
| 157 | + echo "File exists in FATFS image!" |
| 158 | + ls -la /mnt/fatfs/ |
| 159 | + |
| 160 | + # Verify file contents match |
| 161 | + if cmp -s ../../test_file.bin /mnt/fatfs/test_file.bin; then |
| 162 | + echo "File contents match! FATFS test PASSED." |
| 163 | + sudo umount /mnt/fatfs |
| 164 | + sudo losetup -d $LOOPDEV |
| 165 | + exit 0 |
| 166 | + else |
| 167 | + echo "File contents do not match! FATFS test FAILED." |
| 168 | + sudo umount /mnt/fatfs |
| 169 | + sudo losetup -d $LOOPDEV |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | + else |
| 173 | + echo "File does not exist in FATFS image! FATFS test FAILED." |
| 174 | + ls -la /mnt/fatfs/ |
| 175 | + sudo umount /mnt/fatfs |
| 176 | + sudo losetup -d $LOOPDEV |
| 177 | + exit 1 |
| 178 | + fi |
0 commit comments