.travis.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. # test compilation in read-only mode
  200. - stage: test
  201. env:
  202. - NAME=littlefs-readonly
  203. - CC="arm-linux-gnueabi-gcc --static -mthumb"
  204. - CFLAGS="-Werror -DLFS_READONLY"
  205. if: branch !~ -prefix$
  206. install:
  207. - *install-common
  208. - sudo apt-get install
  209. gcc-arm-linux-gnueabi
  210. libc6-dev-armel-cross
  211. - arm-linux-gnueabi-gcc --version
  212. # report-size will compile littlefs and report the size
  213. script: [*report-size]
  214. # test compilation in thread-safe mode
  215. - stage: test
  216. env:
  217. - NAME=littlefs-threadsafe
  218. - CC="arm-linux-gnueabi-gcc --static -mthumb"
  219. - CFLAGS="-Werror -DLFS_THREADSAFE"
  220. if: branch !~ -prefix$
  221. install:
  222. - *install-common
  223. - sudo apt-get install
  224. gcc-arm-linux-gnueabi
  225. libc6-dev-armel-cross
  226. - arm-linux-gnueabi-gcc --version
  227. # report-size will compile littlefs and report the size
  228. script: [*report-size]
  229. # self-host with littlefs-fuse for fuzz test
  230. - stage: test
  231. env:
  232. - NAME=littlefs-fuse
  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
  238. - fusermount -V
  239. - gcc --version
  240. # setup disk for littlefs-fuse
  241. - rm -rf littlefs-fuse/littlefs/*
  242. - cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
  243. - mkdir mount
  244. - sudo chmod a+rw /dev/loop0
  245. - dd if=/dev/zero bs=512 count=128K of=disk
  246. - losetup /dev/loop0 disk
  247. script:
  248. # self-host test
  249. - make -C littlefs-fuse
  250. - littlefs-fuse/lfs --format /dev/loop0
  251. - littlefs-fuse/lfs /dev/loop0 mount
  252. - ls mount
  253. - mkdir mount/littlefs
  254. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  255. - cd mount/littlefs
  256. - stat .
  257. - ls -flh
  258. - make -B test
  259. # test migration using littlefs-fuse
  260. - stage: test
  261. env:
  262. - NAME=littlefs-migration
  263. if: branch !~ -prefix$
  264. install:
  265. - *install-common
  266. - sudo apt-get install libfuse-dev
  267. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2 v2
  268. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v1 v1
  269. - fusermount -V
  270. - gcc --version
  271. # setup disk for littlefs-fuse
  272. - rm -rf v2/littlefs/*
  273. - cp -r $(git ls-tree --name-only HEAD) v2/littlefs
  274. - mkdir mount
  275. - sudo chmod a+rw /dev/loop0
  276. - dd if=/dev/zero bs=512 count=128K of=disk
  277. - losetup /dev/loop0 disk
  278. script:
  279. # compile v1 and v2
  280. - make -C v1
  281. - make -C v2
  282. # run self-host test with v1
  283. - v1/lfs --format /dev/loop0
  284. - v1/lfs /dev/loop0 mount
  285. - ls mount
  286. - mkdir mount/littlefs
  287. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  288. - cd mount/littlefs
  289. - stat .
  290. - ls -flh
  291. - make -B test
  292. # attempt to migrate
  293. - cd ../..
  294. - fusermount -u mount
  295. - v2/lfs --migrate /dev/loop0
  296. - v2/lfs /dev/loop0 mount
  297. # run self-host test with v2 right where we left off
  298. - ls mount
  299. - cd mount/littlefs
  300. - stat .
  301. - ls -flh
  302. - make -B test
  303. # automatically create releases
  304. - stage: deploy
  305. env:
  306. - NAME=deploy
  307. script:
  308. - |
  309. bash << 'SCRIPT'
  310. set -ev
  311. # Find version defined in lfs.h
  312. LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
  313. LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
  314. LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
  315. # Grab latests patch from repo tags, default to 0, needs finagling
  316. # to get past github's pagination api
  317. PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
  318. PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
  319. | sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
  320. || echo $PREV_URL)
  321. LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
  322. | jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
  323. .captures[].string | tonumber) | max + 1' \
  324. || echo 0)
  325. # We have our new version
  326. LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
  327. echo "VERSION $LFS_VERSION"
  328. # Check that we're the most recent commit
  329. CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
  330. https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
  331. | jq -re '.sha')
  332. [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
  333. # Create major branch
  334. git branch v$LFS_VERSION_MAJOR HEAD
  335. # Create major prefix branch
  336. git config user.name "geky bot"
  337. git config user.email "bot@geky.net"
  338. git fetch https://github.com/$TRAVIS_REPO_SLUG.git \
  339. --depth=50 v$LFS_VERSION_MAJOR-prefix || true
  340. ./scripts/prefix.py lfs$LFS_VERSION_MAJOR
  341. git branch v$LFS_VERSION_MAJOR-prefix $( \
  342. git commit-tree $(git write-tree) \
  343. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  344. -p HEAD \
  345. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  346. git reset --hard
  347. # Update major version branches (vN and vN-prefix)
  348. git push --atomic https://$GEKY_BOT_RELEASES@github.com/$TRAVIS_REPO_SLUG.git \
  349. v$LFS_VERSION_MAJOR \
  350. v$LFS_VERSION_MAJOR-prefix
  351. # Build release notes
  352. PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
  353. if [ ! -z "$PREV" ]
  354. then
  355. echo "PREV $PREV"
  356. CHANGES=$(git log --oneline $PREV.. --grep='^Merge' --invert-grep)
  357. printf "CHANGES\n%s\n\n" "$CHANGES"
  358. fi
  359. case ${GEKY_BOT_DRAFT:-minor} in
  360. true) DRAFT=true ;;
  361. minor) DRAFT=$(jq -R 'endswith(".0")' <<< "$LFS_VERSION") ;;
  362. false) DRAFT=false ;;
  363. esac
  364. # Create the release and patch version tag (vN.N.N)
  365. curl -f -u "$GEKY_BOT_RELEASES" -X POST \
  366. https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
  367. -d "{
  368. \"tag_name\": \"$LFS_VERSION\",
  369. \"name\": \"${LFS_VERSION%.0}\",
  370. \"target_commitish\": \"$TRAVIS_COMMIT\",
  371. \"draft\": $DRAFT,
  372. \"body\": $(jq -sR '.' <<< "$CHANGES")
  373. }" #"
  374. SCRIPT
  375. # manage statuses
  376. before_install:
  377. - |
  378. # don't clobber other (not us) failures
  379. if ! curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  380. | jq -e ".statuses[] | select(
  381. .context == \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\" and
  382. .state == \"failure\" and
  383. (.target_url | endswith(\"$TRAVIS_JOB_NUMBER\") | not))"
  384. then
  385. curl -u "$GEKY_BOT_STATUSES" -X POST \
  386. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  387. -d "{
  388. \"context\": \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\",
  389. \"state\": \"pending\",
  390. \"description\": \"${STATUS:-In progress}\",
  391. \"target_url\": \"$TRAVIS_JOB_WEB_URL#$TRAVIS_JOB_NUMBER\"
  392. }"
  393. fi
  394. after_failure:
  395. - |
  396. # don't clobber other (not us) failures
  397. if ! curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  398. | jq -e ".statuses[] | select(
  399. .context == \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\" and
  400. .state == \"failure\" and
  401. (.target_url | endswith(\"$TRAVIS_JOB_NUMBER\") | not))"
  402. then
  403. curl -u "$GEKY_BOT_STATUSES" -X POST \
  404. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  405. -d "{
  406. \"context\": \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\",
  407. \"state\": \"failure\",
  408. \"description\": \"${STATUS:-Failed}\",
  409. \"target_url\": \"$TRAVIS_JOB_WEB_URL#$TRAVIS_JOB_NUMBER\"
  410. }"
  411. fi
  412. after_success:
  413. - |
  414. # don't clobber other (not us) failures
  415. # only update if we were last job to mark in progress,
  416. # this isn't perfect but is probably good enough
  417. if ! curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  418. | jq -e ".statuses[] | select(
  419. .context == \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\" and
  420. (.state == \"failure\" or .state == \"pending\") and
  421. (.target_url | endswith(\"$TRAVIS_JOB_NUMBER\") | not))"
  422. then
  423. curl -u "$GEKY_BOT_STATUSES" -X POST \
  424. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  425. -d "{
  426. \"context\": \"${TRAVIS_BUILD_STAGE_NAME,,}/$NAME\",
  427. \"state\": \"success\",
  428. \"description\": \"${STATUS:-Passed}\",
  429. \"target_url\": \"$TRAVIS_JOB_WEB_URL#$TRAVIS_JOB_NUMBER\"
  430. }"
  431. fi