.travis.yml 17 KB

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