.travis.yml 15 KB

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