.travis.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. # Environment variables
  2. env:
  3. global:
  4. - CFLAGS=-Werror
  5. - MAKEFLAGS=-j
  6. # Common test script
  7. script:
  8. # make sure example can at least compile
  9. - sed -n '/``` c/,/```/{/```/d; p;}' README.md > test.c &&
  10. make all CFLAGS+="
  11. -Duser_provided_block_device_read=NULL
  12. -Duser_provided_block_device_prog=NULL
  13. -Duser_provided_block_device_erase=NULL
  14. -Duser_provided_block_device_sync=NULL
  15. -include stdio.h"
  16. # setup a ram-backed disk to speed up reentrant tests
  17. - |
  18. mkdir disks
  19. sudo mount -t tmpfs -o size=100m tmpfs disks
  20. export TFLAGS="$TFLAGS --disk=disks/disk"
  21. # run tests
  22. - make clean test TFLAGS+="-nrk"
  23. # common real-life geometries
  24. # NOR flash: read/prog = 1 block = 4KiB
  25. - make clean test TFLAGS+="-nrk -DLFS_READ_SIZE=1 -DLFS_BLOCK_SIZE=4096"
  26. # SD card: read/prog = 512 block = 512
  27. - make clean test TFLAGS+="-nrk -DLFS_READ_SIZE=512 -DLFS_BLOCK_SIZE=512"
  28. # NAND flash: read/prog = 4KiB block = 32KiB
  29. - make clean test TFLAGS+="-nrk -DLFS_READ_SIZE=4096 -DLFS_BLOCK_SIZE=\(32*1024\)"
  30. # other extreme geometries for corner cases
  31. - make clean test TFLAGS+="-nrk -DLFS_NO_INTRINSICS"
  32. - make clean test TFLAGS+="-nrk -DLFS_INLINE_MAX=0"
  33. - make clean test TFLAGS+="-nrk -DLFS_READ_SIZE=1 -DLFS_CACHE_SIZE=1"
  34. - make clean test TFLAGS+="-nrk -DLFS_BLOCK_CYCLES=1"
  35. - make clean test TFLAGS+="-nrk -DLFS_BLOCK_COUNT=1023 -DLFS_LOOKAHEAD_SIZE=256"
  36. - make clean test TFLAGS+="-nrk -DLFS_READ_SIZE=11 -DLFS_BLOCK_SIZE=704"
  37. # compile and find the code size with the smallest configuration
  38. - make clean size
  39. OBJ="$(ls lfs*.c | sed 's/\.c/\.o/' | tr '\n' ' ')"
  40. CFLAGS+="-DLFS_NO_ASSERT -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR"
  41. | tee sizes
  42. # update status if we succeeded, compare with master if possible
  43. - |
  44. if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
  45. then
  46. CURR=$(tail -n1 sizes | awk '{print $1}')
  47. PREV=$(curl -u "$GEKY_BOT_STATUSES" https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
  48. | jq -re "select(.sha != \"$TRAVIS_COMMIT\")
  49. | .statuses[] | select(.context == \"$STAGE/$NAME\").description
  50. | capture(\"code size is (?<size>[0-9]+)\").size" \
  51. || echo 0)
  52. STATUS="Passed, code size is ${CURR}B"
  53. if [ "$PREV" -ne 0 ]
  54. then
  55. STATUS="$STATUS ($(python -c "print '%+.2f' % (100*($CURR-$PREV)/$PREV.0)")%)"
  56. fi
  57. fi
  58. # CI matrix
  59. jobs:
  60. include:
  61. # native testing
  62. - stage: test
  63. env:
  64. - STAGE=test
  65. - NAME=littlefs-x86
  66. # cross-compile with ARM (thumb mode)
  67. - stage: test
  68. env:
  69. - STAGE=test
  70. - NAME=littlefs-arm
  71. - CC="arm-linux-gnueabi-gcc --static -mthumb"
  72. - TFLAGS="-e qemu-arm"
  73. install:
  74. - sudo apt-get install
  75. gcc-arm-linux-gnueabi
  76. libc6-dev-armel-cross
  77. qemu-user
  78. - arm-linux-gnueabi-gcc --version
  79. - qemu-arm -version
  80. # cross-compile with PowerPC
  81. - stage: test
  82. env:
  83. - STAGE=test
  84. - NAME=littlefs-powerpc
  85. - CC="powerpc-linux-gnu-gcc --static"
  86. - TFLAGS="-e qemu-ppc"
  87. install:
  88. - sudo apt-get install
  89. gcc-powerpc-linux-gnu
  90. libc6-dev-powerpc-cross
  91. qemu-user
  92. - powerpc-linux-gnu-gcc --version
  93. - qemu-ppc -version
  94. # cross-compile with MIPS
  95. - stage: test
  96. env:
  97. - STAGE=test
  98. - NAME=littlefs-mips
  99. - CC="mips-linux-gnu-gcc --static"
  100. - TFLAGS="-e qemu-mips"
  101. install:
  102. - sudo apt-get install
  103. gcc-mips-linux-gnu
  104. libc6-dev-mips-cross
  105. qemu-user
  106. - mips-linux-gnu-gcc --version
  107. - qemu-mips -version
  108. # test under valgrind, checking for memory errors
  109. - stage: test
  110. env:
  111. - STAGE=test
  112. - NAME=littlefs-valgrind
  113. - TFLAGS="--valgrind"
  114. install:
  115. - sudo apt-get install valgrind
  116. - valgrind --version
  117. # self-host with littlefs-fuse for fuzz test
  118. - stage: test
  119. env:
  120. - STAGE=test
  121. - NAME=littlefs-fuse
  122. if: branch !~ -prefix$
  123. install:
  124. - sudo apt-get install libfuse-dev
  125. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2
  126. - fusermount -V
  127. - gcc --version
  128. before_script:
  129. # setup disk for littlefs-fuse
  130. - rm -rf littlefs-fuse/littlefs/*
  131. - cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
  132. - mkdir mount
  133. - sudo chmod a+rw /dev/loop0
  134. - dd if=/dev/zero bs=512 count=4096 of=disk
  135. - losetup /dev/loop0 disk
  136. script:
  137. # self-host test
  138. - make -C littlefs-fuse
  139. - littlefs-fuse/lfs --format /dev/loop0
  140. - littlefs-fuse/lfs /dev/loop0 mount
  141. - ls mount
  142. - mkdir mount/littlefs
  143. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  144. - cd mount/littlefs
  145. - stat .
  146. - ls -flh
  147. - make -B test_dirs test_files QUIET=1
  148. # self-host with littlefs-fuse for fuzz test
  149. - stage: test
  150. env:
  151. - STAGE=test
  152. - NAME=littlefs-migration
  153. if: branch !~ -prefix$
  154. install:
  155. - sudo apt-get install libfuse-dev
  156. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2 v2
  157. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v1 v1
  158. - fusermount -V
  159. - gcc --version
  160. before_script:
  161. # setup disk for littlefs-fuse
  162. - rm -rf v2/littlefs/*
  163. - cp -r $(git ls-tree --name-only HEAD) v2/littlefs
  164. - mkdir mount
  165. - sudo chmod a+rw /dev/loop0
  166. - dd if=/dev/zero bs=512 count=4096 of=disk
  167. - losetup /dev/loop0 disk
  168. script:
  169. # compile v1 and v2
  170. - make -C v1
  171. - make -C v2
  172. # run self-host test with v1
  173. - v1/lfs --format /dev/loop0
  174. - v1/lfs /dev/loop0 mount
  175. - ls mount
  176. - mkdir mount/littlefs
  177. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  178. - cd mount/littlefs
  179. - stat .
  180. - ls -flh
  181. - make -B test_dirs test_files QUIET=1
  182. # attempt to migrate
  183. - cd ../..
  184. - fusermount -u mount
  185. - v2/lfs --migrate /dev/loop0
  186. - v2/lfs /dev/loop0 mount
  187. # run self-host test with v2 right where we left off
  188. - ls mount
  189. - cd mount/littlefs
  190. - stat .
  191. - ls -flh
  192. - make -B test_dirs test_files QUIET=1
  193. # Automatically create releases
  194. - stage: deploy
  195. env:
  196. - STAGE=deploy
  197. - NAME=deploy
  198. script:
  199. - |
  200. bash << 'SCRIPT'
  201. set -ev
  202. # Find version defined in lfs.h
  203. LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
  204. LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
  205. LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
  206. # Grab latests patch from repo tags, default to 0, needs finagling
  207. # to get past github's pagination api
  208. PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
  209. PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
  210. | sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
  211. || echo $PREV_URL)
  212. LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
  213. | jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
  214. .captures[].string | tonumber) | max + 1' \
  215. || echo 0)
  216. # We have our new version
  217. LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
  218. echo "VERSION $LFS_VERSION"
  219. # Check that we're the most recent commit
  220. CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
  221. https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
  222. | jq -re '.sha')
  223. [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
  224. # Create major branch
  225. git branch v$LFS_VERSION_MAJOR HEAD
  226. # Create major prefix branch
  227. git config user.name "geky bot"
  228. git config user.email "bot@geky.net"
  229. git fetch https://github.com/$TRAVIS_REPO_SLUG.git \
  230. --depth=50 v$LFS_VERSION_MAJOR-prefix || true
  231. ./scripts/prefix.py lfs$LFS_VERSION_MAJOR
  232. git branch v$LFS_VERSION_MAJOR-prefix $( \
  233. git commit-tree $(git write-tree) \
  234. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  235. -p HEAD \
  236. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  237. git reset --hard
  238. # Update major version branches (vN and vN-prefix)
  239. git push --atomic https://$GEKY_BOT_RELEASES@github.com/$TRAVIS_REPO_SLUG.git \
  240. v$LFS_VERSION_MAJOR \
  241. v$LFS_VERSION_MAJOR-prefix
  242. # Build release notes
  243. PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
  244. if [ ! -z "$PREV" ]
  245. then
  246. echo "PREV $PREV"
  247. CHANGES=$(git log --oneline $PREV.. --grep='^Merge' --invert-grep)
  248. printf "CHANGES\n%s\n\n" "$CHANGES"
  249. fi
  250. case ${GEKY_BOT_DRAFT:-minor} in
  251. true) DRAFT=true ;;
  252. minor) DRAFT=$(jq -R 'endswith(".0")' <<< "$LFS_VERSION") ;;
  253. false) DRAFT=false ;;
  254. esac
  255. # Create the release and patch version tag (vN.N.N)
  256. curl -f -u "$GEKY_BOT_RELEASES" -X POST \
  257. https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
  258. -d "{
  259. \"tag_name\": \"$LFS_VERSION\",
  260. \"name\": \"${LFS_VERSION%.0}\",
  261. \"target_commitish\": \"$TRAVIS_COMMIT\",
  262. \"draft\": $DRAFT,
  263. \"body\": $(jq -sR '.' <<< "$CHANGES")
  264. }" #"
  265. SCRIPT
  266. # Manage statuses
  267. before_install:
  268. - |
  269. curl -u "$GEKY_BOT_STATUSES" -X POST \
  270. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  271. -d "{
  272. \"context\": \"$STAGE/$NAME\",
  273. \"state\": \"pending\",
  274. \"description\": \"${STATUS:-In progress}\",
  275. \"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
  276. }"
  277. - sudo apt-get install python3-pip
  278. - sudo pip3 install toml
  279. after_failure:
  280. - |
  281. curl -u "$GEKY_BOT_STATUSES" -X POST \
  282. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  283. -d "{
  284. \"context\": \"$STAGE/$NAME\",
  285. \"state\": \"failure\",
  286. \"description\": \"${STATUS:-Failed}\",
  287. \"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
  288. }"
  289. after_success:
  290. - |
  291. curl -u "$GEKY_BOT_STATUSES" -X POST \
  292. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  293. -d "{
  294. \"context\": \"$STAGE/$NAME\",
  295. \"state\": \"success\",
  296. \"description\": \"${STATUS:-Passed}\",
  297. \"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
  298. }"
  299. # Job control
  300. stages:
  301. - name: test
  302. - name: deploy
  303. if: branch = master AND type = push