.travis.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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 --exec=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. # it just takes way to long to run byte-level writes in qemu,
  127. # note this is still tested in the native tests
  128. #- {<<: *arm, script: [*test-byte-writes, *report-size]}
  129. - {<<: *arm, script: [*test-block-cycles, *report-size]}
  130. - {<<: *arm, script: [*test-odd-block-count, *report-size]}
  131. - {<<: *arm, script: [*test-odd-block-size, *report-size]}
  132. # cross-compile with MIPS
  133. - &mips
  134. stage: test
  135. env:
  136. - NAME=littlefs-mips
  137. - CC="mips-linux-gnu-gcc --static"
  138. - TFLAGS="$TFLAGS --exec=qemu-mips"
  139. install:
  140. - *install-common
  141. - sudo apt-get install
  142. gcc-mips-linux-gnu
  143. libc6-dev-mips-cross
  144. qemu-user
  145. - mips-linux-gnu-gcc --version
  146. - qemu-mips -version
  147. script: [*test-example, *report-size]
  148. - {<<: *mips, script: [*test-default, *report-size]}
  149. - {<<: *mips, script: [*test-nor, *report-size]}
  150. - {<<: *mips, script: [*test-emmc, *report-size]}
  151. - {<<: *mips, script: [*test-nand, *report-size]}
  152. - {<<: *mips, script: [*test-no-intrinsics, *report-size]}
  153. - {<<: *mips, script: [*test-no-inline, *report-size]}
  154. # it just takes way to long to run byte-level writes in qemu,
  155. # note this is still tested in the native tests
  156. #- {<<: *mips, script: [*test-byte-writes, *report-size]}
  157. - {<<: *mips, script: [*test-block-cycles, *report-size]}
  158. - {<<: *mips, script: [*test-odd-block-count, *report-size]}
  159. - {<<: *mips, script: [*test-odd-block-size, *report-size]}
  160. # cross-compile with PowerPC
  161. - &powerpc
  162. stage: test
  163. env:
  164. - NAME=littlefs-powerpc
  165. - CC="powerpc-linux-gnu-gcc --static"
  166. - TFLAGS="$TFLAGS --exec=qemu-ppc"
  167. install:
  168. - *install-common
  169. - sudo apt-get install
  170. gcc-powerpc-linux-gnu
  171. libc6-dev-powerpc-cross
  172. qemu-user
  173. - powerpc-linux-gnu-gcc --version
  174. - qemu-ppc -version
  175. script: [*test-example, *report-size]
  176. - {<<: *powerpc, script: [*test-default, *report-size]}
  177. - {<<: *powerpc, script: [*test-nor, *report-size]}
  178. - {<<: *powerpc, script: [*test-emmc, *report-size]}
  179. - {<<: *powerpc, script: [*test-nand, *report-size]}
  180. - {<<: *powerpc, script: [*test-no-intrinsics, *report-size]}
  181. - {<<: *powerpc, script: [*test-no-inline, *report-size]}
  182. # it just takes way to long to run byte-level writes in qemu,
  183. # note this is still tested in the native tests
  184. #- {<<: *powerpc, script: [*test-byte-writes, *report-size]}
  185. - {<<: *powerpc, script: [*test-block-cycles, *report-size]}
  186. - {<<: *powerpc, script: [*test-odd-block-count, *report-size]}
  187. - {<<: *powerpc, script: [*test-odd-block-size, *report-size]}
  188. # test under valgrind, checking for memory errors
  189. - &valgrind
  190. stage: test
  191. env:
  192. - NAME=littlefs-valgrind
  193. install:
  194. - *install-common
  195. - sudo apt-get install valgrind
  196. - valgrind --version
  197. script:
  198. - make test TFLAGS+="-k --valgrind"
  199. # self-host with littlefs-fuse for fuzz test
  200. - stage: test
  201. env:
  202. - NAME=littlefs-fuse
  203. if: branch !~ -prefix$
  204. install:
  205. - *install-common
  206. - sudo apt-get install libfuse-dev
  207. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2
  208. - fusermount -V
  209. - gcc --version
  210. # setup disk for littlefs-fuse
  211. - rm -rf littlefs-fuse/littlefs/*
  212. - cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
  213. - mkdir mount
  214. - sudo chmod a+rw /dev/loop0
  215. - dd if=/dev/zero bs=512 count=128K of=disk
  216. - losetup /dev/loop0 disk
  217. script:
  218. # self-host test
  219. - make -C littlefs-fuse
  220. - littlefs-fuse/lfs --format /dev/loop0
  221. - littlefs-fuse/lfs /dev/loop0 mount
  222. - ls mount
  223. - mkdir mount/littlefs
  224. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  225. - cd mount/littlefs
  226. - stat .
  227. - ls -flh
  228. - make -B test
  229. # test migration using littlefs-fuse
  230. - stage: test
  231. env:
  232. - NAME=littlefs-migration
  233. if: branch !~ -prefix$
  234. install:
  235. - *install-common
  236. - sudo apt-get install libfuse-dev
  237. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2 v2
  238. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v1 v1
  239. - fusermount -V
  240. - gcc --version
  241. # setup disk for littlefs-fuse
  242. - rm -rf v2/littlefs/*
  243. - cp -r $(git ls-tree --name-only HEAD) v2/littlefs
  244. - mkdir mount
  245. - sudo chmod a+rw /dev/loop0
  246. - dd if=/dev/zero bs=512 count=128K of=disk
  247. - losetup /dev/loop0 disk
  248. script:
  249. # compile v1 and v2
  250. - make -C v1
  251. - make -C v2
  252. # run self-host test with v1
  253. - v1/lfs --format /dev/loop0
  254. - v1/lfs /dev/loop0 mount
  255. - ls mount
  256. - mkdir mount/littlefs
  257. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  258. - cd mount/littlefs
  259. - stat .
  260. - ls -flh
  261. - make -B test
  262. # attempt to migrate
  263. - cd ../..
  264. - fusermount -u mount
  265. - v2/lfs --migrate /dev/loop0
  266. - v2/lfs /dev/loop0 mount
  267. # run self-host test with v2 right where we left off
  268. - ls mount
  269. - cd mount/littlefs
  270. - stat .
  271. - ls -flh
  272. - make -B test
  273. # automatically create releases
  274. - stage: deploy
  275. env:
  276. - NAME=deploy
  277. script:
  278. - |
  279. bash << 'SCRIPT'
  280. set -ev
  281. # Find version defined in lfs.h
  282. LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
  283. LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
  284. LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
  285. # Grab latests patch from repo tags, default to 0, needs finagling
  286. # to get past github's pagination api
  287. PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
  288. PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
  289. | sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
  290. || echo $PREV_URL)
  291. LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
  292. | jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
  293. .captures[].string | tonumber) | max + 1' \
  294. || echo 0)
  295. # We have our new version
  296. LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
  297. echo "VERSION $LFS_VERSION"
  298. # Check that we're the most recent commit
  299. CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
  300. https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
  301. | jq -re '.sha')
  302. [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
  303. # Create major branch
  304. git branch v$LFS_VERSION_MAJOR HEAD
  305. # Create major prefix branch
  306. git config user.name "geky bot"
  307. git config user.email "bot@geky.net"
  308. git fetch https://github.com/$TRAVIS_REPO_SLUG.git \
  309. --depth=50 v$LFS_VERSION_MAJOR-prefix || true
  310. ./scripts/prefix.py lfs$LFS_VERSION_MAJOR
  311. git branch v$LFS_VERSION_MAJOR-prefix $( \
  312. git commit-tree $(git write-tree) \
  313. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  314. -p HEAD \
  315. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  316. git reset --hard
  317. # Update major version branches (vN and vN-prefix)
  318. git push --atomic https://$GEKY_BOT_RELEASES@github.com/$TRAVIS_REPO_SLUG.git \
  319. v$LFS_VERSION_MAJOR \
  320. v$LFS_VERSION_MAJOR-prefix
  321. # Build release notes
  322. PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
  323. if [ ! -z "$PREV" ]
  324. then
  325. echo "PREV $PREV"
  326. CHANGES=$(git log --oneline $PREV.. --grep='^Merge' --invert-grep)
  327. printf "CHANGES\n%s\n\n" "$CHANGES"
  328. fi
  329. case ${GEKY_BOT_DRAFT:-minor} in
  330. true) DRAFT=true ;;
  331. minor) DRAFT=$(jq -R 'endswith(".0")' <<< "$LFS_VERSION") ;;
  332. false) DRAFT=false ;;
  333. esac
  334. # Create the release and patch version tag (vN.N.N)
  335. curl -f -u "$GEKY_BOT_RELEASES" -X POST \
  336. https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
  337. -d "{
  338. \"tag_name\": \"$LFS_VERSION\",
  339. \"name\": \"${LFS_VERSION%.0}\",
  340. \"target_commitish\": \"$TRAVIS_COMMIT\",
  341. \"draft\": $DRAFT,
  342. \"body\": $(jq -sR '.' <<< "$CHANGES")
  343. }" #"
  344. SCRIPT
  345. # manage statuses
  346. before_install:
  347. - |
  348. # don't clobber other (not us) failures
  349. if ! curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  350. | jq -e ".statuses[] | select(
  351. .context == \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\" and
  352. .state == \"failure\" and
  353. (.target_url | endswith(\"$TRAVIS_JOB_NUMBER\") | not))"
  354. then
  355. curl -u "$GEKY_BOT_STATUSES" -X POST \
  356. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  357. -d "{
  358. \"context\": \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\",
  359. \"state\": \"pending\",
  360. \"description\": \"${STATUS:-In progress}\",
  361. \"target_url\": \"$TRAVIS_JOB_WEB_URL#$TRAVIS_JOB_NUMBER\"
  362. }"
  363. fi
  364. after_failure:
  365. - |
  366. # don't clobber other (not us) failures
  367. if ! curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  368. | jq -e ".statuses[] | select(
  369. .context == \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\" and
  370. .state == \"failure\" and
  371. (.target_url | endswith(\"$TRAVIS_JOB_NUMBER\") | not))"
  372. then
  373. curl -u "$GEKY_BOT_STATUSES" -X POST \
  374. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  375. -d "{
  376. \"context\": \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\",
  377. \"state\": \"failure\",
  378. \"description\": \"${STATUS:-Failed}\",
  379. \"target_url\": \"$TRAVIS_JOB_WEB_URL#$TRAVIS_JOB_NUMBER\"
  380. }"
  381. fi
  382. after_success:
  383. - |
  384. # don't clobber other (not us) failures
  385. # only update if we were last job to mark in progress,
  386. # this isn't perfect but is probably good enough
  387. if ! curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  388. | jq -e ".statuses[] | select(
  389. .context == \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\" and
  390. (.state == \"failure\" or .state == \"pending\") and
  391. (.target_url | endswith(\"$TRAVIS_JOB_NUMBER\") | not))"
  392. then
  393. curl -u "$GEKY_BOT_STATUSES" -X POST \
  394. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  395. -d "{
  396. \"context\": \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\",
  397. \"state\": \"success\",
  398. \"description\": \"${STATUS:-Passed}\",
  399. \"target_url\": \"$TRAVIS_JOB_WEB_URL#$TRAVIS_JOB_NUMBER\"
  400. }"
  401. fi