.travis.yml 16 KB

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