test.yml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. name: test
  2. on: [push, pull_request]
  3. defaults:
  4. run:
  5. shell: bash -euv -o pipefail {0}
  6. env:
  7. CFLAGS: -Werror
  8. MAKEFLAGS: -j
  9. TESTFLAGS: -k
  10. BENCHFLAGS:
  11. jobs:
  12. # run tests
  13. test:
  14. runs-on: ubuntu-latest
  15. strategy:
  16. fail-fast: false
  17. matrix:
  18. arch: [x86_64, thumb, mips, powerpc]
  19. steps:
  20. - uses: actions/checkout@v4.1.7
  21. - name: install
  22. run: |
  23. # need a few things
  24. sudo apt-get update -qq
  25. sudo apt-get install -qq gcc python3 python3-pip
  26. pip3 install toml
  27. gcc --version
  28. python3 --version
  29. # cross-compile with ARM Thumb (32-bit, little-endian)
  30. - name: install-thumb
  31. if: ${{matrix.arch == 'thumb'}}
  32. run: |
  33. sudo apt-get install -qq \
  34. gcc-arm-linux-gnueabi \
  35. libc6-dev-armel-cross \
  36. qemu-user
  37. echo "CC=arm-linux-gnueabi-gcc -mthumb --static" >> $GITHUB_ENV
  38. echo "EXEC=qemu-arm" >> $GITHUB_ENV
  39. arm-linux-gnueabi-gcc --version
  40. qemu-arm -version
  41. # cross-compile with MIPS (32-bit, big-endian)
  42. - name: install-mips
  43. if: ${{matrix.arch == 'mips'}}
  44. run: |
  45. sudo apt-get install -qq \
  46. gcc-mips-linux-gnu \
  47. libc6-dev-mips-cross \
  48. qemu-user
  49. echo "CC=mips-linux-gnu-gcc --static" >> $GITHUB_ENV
  50. echo "EXEC=qemu-mips" >> $GITHUB_ENV
  51. mips-linux-gnu-gcc --version
  52. qemu-mips -version
  53. # cross-compile with PowerPC (32-bit, big-endian)
  54. - name: install-powerpc
  55. if: ${{matrix.arch == 'powerpc'}}
  56. run: |
  57. sudo apt-get install -qq \
  58. gcc-powerpc-linux-gnu \
  59. libc6-dev-powerpc-cross \
  60. qemu-user
  61. echo "CC=powerpc-linux-gnu-gcc --static" >> $GITHUB_ENV
  62. echo "EXEC=qemu-ppc" >> $GITHUB_ENV
  63. powerpc-linux-gnu-gcc --version
  64. qemu-ppc -version
  65. # does littlefs compile?
  66. - name: test-build
  67. run: |
  68. make clean
  69. make build
  70. # make sure example can at least compile
  71. - name: test-example
  72. run: |
  73. make clean
  74. sed -n '/``` c/,/```/{/```/d; p}' README.md > test.c
  75. CFLAGS="$CFLAGS \
  76. -Duser_provided_block_device_read=NULL \
  77. -Duser_provided_block_device_prog=NULL \
  78. -Duser_provided_block_device_erase=NULL \
  79. -Duser_provided_block_device_sync=NULL \
  80. -include stdio.h" \
  81. make all
  82. rm test.c
  83. # run the tests!
  84. - name: test
  85. run: |
  86. make clean
  87. make test
  88. # collect coverage info
  89. #
  90. # Note the goal is to maximize coverage in the small, easy-to-run
  91. # tests, so we intentionally exclude more aggressive powerloss testing
  92. # from coverage results
  93. - name: cov
  94. if: ${{matrix.arch == 'x86_64'}}
  95. run: |
  96. make lfs.cov.csv
  97. ./scripts/cov.py -u lfs.cov.csv
  98. mkdir -p cov
  99. cp lfs.cov.csv cov/cov.csv
  100. # find compile-time measurements
  101. - name: sizes
  102. run: |
  103. make clean
  104. CFLAGS="$CFLAGS \
  105. -DLFS_NO_ASSERT \
  106. -DLFS_NO_DEBUG \
  107. -DLFS_NO_WARN \
  108. -DLFS_NO_ERROR" \
  109. make lfs.code.csv lfs.data.csv lfs.stack.csv lfs.structs.csv
  110. ./scripts/structs.py -u lfs.structs.csv
  111. ./scripts/summary.py lfs.code.csv lfs.data.csv lfs.stack.csv \
  112. -bfunction \
  113. -fcode=code_size \
  114. -fdata=data_size \
  115. -fstack=stack_limit --max=stack_limit
  116. mkdir -p sizes
  117. cp lfs.code.csv sizes/${{matrix.arch}}.code.csv
  118. cp lfs.data.csv sizes/${{matrix.arch}}.data.csv
  119. cp lfs.stack.csv sizes/${{matrix.arch}}.stack.csv
  120. cp lfs.structs.csv sizes/${{matrix.arch}}.structs.csv
  121. - name: sizes-readonly
  122. run: |
  123. make clean
  124. CFLAGS="$CFLAGS \
  125. -DLFS_NO_ASSERT \
  126. -DLFS_NO_DEBUG \
  127. -DLFS_NO_WARN \
  128. -DLFS_NO_ERROR \
  129. -DLFS_READONLY" \
  130. make lfs.code.csv lfs.data.csv lfs.stack.csv lfs.structs.csv
  131. ./scripts/structs.py -u lfs.structs.csv
  132. ./scripts/summary.py lfs.code.csv lfs.data.csv lfs.stack.csv \
  133. -bfunction \
  134. -fcode=code_size \
  135. -fdata=data_size \
  136. -fstack=stack_limit --max=stack_limit
  137. mkdir -p sizes
  138. cp lfs.code.csv sizes/${{matrix.arch}}-readonly.code.csv
  139. cp lfs.data.csv sizes/${{matrix.arch}}-readonly.data.csv
  140. cp lfs.stack.csv sizes/${{matrix.arch}}-readonly.stack.csv
  141. cp lfs.structs.csv sizes/${{matrix.arch}}-readonly.structs.csv
  142. - name: sizes-threadsafe
  143. run: |
  144. make clean
  145. CFLAGS="$CFLAGS \
  146. -DLFS_NO_ASSERT \
  147. -DLFS_NO_DEBUG \
  148. -DLFS_NO_WARN \
  149. -DLFS_NO_ERROR \
  150. -DLFS_THREADSAFE" \
  151. make lfs.code.csv lfs.data.csv lfs.stack.csv lfs.structs.csv
  152. ./scripts/structs.py -u lfs.structs.csv
  153. ./scripts/summary.py lfs.code.csv lfs.data.csv lfs.stack.csv \
  154. -bfunction \
  155. -fcode=code_size \
  156. -fdata=data_size \
  157. -fstack=stack_limit --max=stack_limit
  158. mkdir -p sizes
  159. cp lfs.code.csv sizes/${{matrix.arch}}-threadsafe.code.csv
  160. cp lfs.data.csv sizes/${{matrix.arch}}-threadsafe.data.csv
  161. cp lfs.stack.csv sizes/${{matrix.arch}}-threadsafe.stack.csv
  162. cp lfs.structs.csv sizes/${{matrix.arch}}-threadsafe.structs.csv
  163. - name: sizes-multiversion
  164. run: |
  165. make clean
  166. CFLAGS="$CFLAGS \
  167. -DLFS_NO_ASSERT \
  168. -DLFS_NO_DEBUG \
  169. -DLFS_NO_WARN \
  170. -DLFS_NO_ERROR \
  171. -DLFS_MULTIVERSION" \
  172. make lfs.code.csv lfs.data.csv lfs.stack.csv lfs.structs.csv
  173. ./scripts/structs.py -u lfs.structs.csv
  174. ./scripts/summary.py lfs.code.csv lfs.data.csv lfs.stack.csv \
  175. -bfunction \
  176. -fcode=code_size \
  177. -fdata=data_size \
  178. -fstack=stack_limit --max=stack_limit
  179. mkdir -p sizes
  180. cp lfs.code.csv sizes/${{matrix.arch}}-multiversion.code.csv
  181. cp lfs.data.csv sizes/${{matrix.arch}}-multiversion.data.csv
  182. cp lfs.stack.csv sizes/${{matrix.arch}}-multiversion.stack.csv
  183. cp lfs.structs.csv sizes/${{matrix.arch}}-multiversion.structs.csv
  184. - name: sizes-migrate
  185. run: |
  186. make clean
  187. CFLAGS="$CFLAGS \
  188. -DLFS_NO_ASSERT \
  189. -DLFS_NO_DEBUG \
  190. -DLFS_NO_WARN \
  191. -DLFS_NO_ERROR \
  192. -DLFS_MIGRATE" \
  193. make lfs.code.csv lfs.data.csv lfs.stack.csv lfs.structs.csv
  194. ./scripts/structs.py -u lfs.structs.csv
  195. ./scripts/summary.py lfs.code.csv lfs.data.csv lfs.stack.csv \
  196. -bfunction \
  197. -fcode=code_size \
  198. -fdata=data_size \
  199. -fstack=stack_limit --max=stack_limit
  200. mkdir -p sizes
  201. cp lfs.code.csv sizes/${{matrix.arch}}-migrate.code.csv
  202. cp lfs.data.csv sizes/${{matrix.arch}}-migrate.data.csv
  203. cp lfs.stack.csv sizes/${{matrix.arch}}-migrate.stack.csv
  204. cp lfs.structs.csv sizes/${{matrix.arch}}-migrate.structs.csv
  205. - name: sizes-error-asserts
  206. run: |
  207. make clean
  208. CFLAGS="$CFLAGS \
  209. -DLFS_NO_DEBUG \
  210. -DLFS_NO_WARN \
  211. -DLFS_NO_ERROR \
  212. -D'LFS_ASSERT(test)=do {if(!(test)) {return -1;}} while(0)'" \
  213. make lfs.code.csv lfs.data.csv lfs.stack.csv lfs.structs.csv
  214. ./scripts/structs.py -u lfs.structs.csv
  215. ./scripts/summary.py lfs.code.csv lfs.data.csv lfs.stack.csv \
  216. -bfunction \
  217. -fcode=code_size \
  218. -fdata=data_size \
  219. -fstack=stack_limit --max=stack_limit
  220. mkdir -p sizes
  221. cp lfs.code.csv sizes/${{matrix.arch}}-error-asserts.code.csv
  222. cp lfs.data.csv sizes/${{matrix.arch}}-error-asserts.data.csv
  223. cp lfs.stack.csv sizes/${{matrix.arch}}-error-asserts.stack.csv
  224. cp lfs.structs.csv sizes/${{matrix.arch}}-error-asserts.structs.csv
  225. # create size statuses
  226. - name: upload-sizes
  227. uses: actions/upload-artifact@v4.4.0
  228. with:
  229. name: sizes-${{matrix.arch}}
  230. path: sizes
  231. - name: status-sizes
  232. run: |
  233. mkdir -p status
  234. for f in $(shopt -s nullglob ; echo sizes/*.csv)
  235. do
  236. # skip .data.csv as it should always be zero
  237. [[ $f == *.data.csv ]] && continue
  238. export STEP="sizes$(echo $f \
  239. | sed -n 's/[^-.]*-\([^.]*\)\..*csv/-\1/p')"
  240. export CONTEXT="sizes (${{matrix.arch}}$(echo $f \
  241. | sed -n 's/[^-.]*-\([^.]*\)\..*csv/, \1/p')) / $(echo $f \
  242. | sed -n 's/[^.]*\.\(.*\)\.csv/\1/p')"
  243. export PREV="$(curl -sS \
  244. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/master`
  245. `?per_page=100" \
  246. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]
  247. | select(.context == env.CONTEXT).description
  248. | capture("(?<prev>[0-9∞]+)").prev' \
  249. || echo 0)"
  250. export DESCRIPTION="$(./scripts/summary.py $f --max=stack_limit -Y \
  251. | awk '
  252. NR==2 {$1=0; printf "%s B",$NF}
  253. NR==2 && ENVIRON["PREV"]+0 != 0 {
  254. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  255. }')"
  256. jq -n '{
  257. state: "success",
  258. context: env.CONTEXT,
  259. description: env.DESCRIPTION,
  260. target_job: "${{github.job}} (${{matrix.arch}})",
  261. target_step: env.STEP,
  262. }' | tee status/$(basename $f .csv).json
  263. done
  264. - name: upload-status-sizes
  265. if: ${{matrix.arch == 'x86_64'}}
  266. uses: actions/upload-artifact@v4.4.0
  267. with:
  268. name: status-sizes-${{matrix.arch}}
  269. path: status
  270. retention-days: 1
  271. # create cov statuses
  272. - name: upload-cov
  273. if: ${{matrix.arch == 'x86_64'}}
  274. uses: actions/upload-artifact@v4.4.0
  275. with:
  276. name: cov
  277. path: cov
  278. - name: status-cov
  279. if: ${{matrix.arch == 'x86_64'}}
  280. run: |
  281. mkdir -p status
  282. f=cov/cov.csv
  283. for s in lines branches
  284. do
  285. export STEP="cov"
  286. export CONTEXT="cov / $s"
  287. export PREV="$(curl -sS \
  288. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/master`
  289. `?per_page=100" \
  290. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]
  291. | select(.context == env.CONTEXT).description
  292. | capture("(?<prev_a>[0-9]+)/(?<prev_b>[0-9]+)")
  293. | 100*((.prev_a|tonumber) / (.prev_b|tonumber))' \
  294. || echo 0)"
  295. export DESCRIPTION="$(./scripts/cov.py -u $f -f$s -Y \
  296. | awk -F '[ /%]+' -v s=$s '
  297. NR==2 {$1=0; printf "%d/%d %s",$2,$3,s}
  298. NR==2 && ENVIRON["PREV"]+0 != 0 {
  299. printf " (%+.1f%%)",$4-ENVIRON["PREV"]
  300. }')"
  301. jq -n '{
  302. state: "success",
  303. context: env.CONTEXT,
  304. description: env.DESCRIPTION,
  305. target_job: "${{github.job}} (${{matrix.arch}})",
  306. target_step: env.STEP,
  307. }' | tee status/$(basename $f .csv)-$s.json
  308. done
  309. - name: upload-status-cov
  310. if: ${{matrix.arch == 'x86_64'}}
  311. uses: actions/upload-artifact@v4.4.0
  312. with:
  313. name: status-cov
  314. path: status
  315. retention-days: 1
  316. # run as many exhaustive tests as fits in GitHub's time limits
  317. #
  318. # this grows exponentially, so it doesn't turn out to be that many
  319. test-pls:
  320. runs-on: ubuntu-latest
  321. strategy:
  322. fail-fast: false
  323. matrix:
  324. pls: [1, 2]
  325. steps:
  326. - uses: actions/checkout@v4.1.7
  327. - name: install
  328. run: |
  329. # need a few things
  330. sudo apt-get update -qq
  331. sudo apt-get install -qq gcc python3 python3-pip
  332. pip3 install toml
  333. gcc --version
  334. python3 --version
  335. - name: test-pls
  336. if: ${{matrix.pls <= 1}}
  337. run: |
  338. TESTFLAGS="$TESTFLAGS -P${{matrix.pls}}" make test
  339. # >=2pls takes multiple days to run fully, so we can only
  340. # run a subset of tests, these are the most important
  341. - name: test-limited-pls
  342. if: ${{matrix.pls > 1}}
  343. run: |
  344. TESTFLAGS="$TESTFLAGS -P${{matrix.pls}} test_dirs test_relocations" \
  345. make test
  346. # run with LFS_NO_INTRINSICS to make sure that works
  347. test-no-intrinsics:
  348. runs-on: ubuntu-latest
  349. steps:
  350. - uses: actions/checkout@v4.1.7
  351. - name: install
  352. run: |
  353. # need a few things
  354. sudo apt-get update -qq
  355. sudo apt-get install -qq gcc python3 python3-pip
  356. pip3 install toml
  357. gcc --version
  358. python3 --version
  359. - name: test-no-intrinsics
  360. run: |
  361. CFLAGS="$CFLAGS -DLFS_NO_INTRINSICS" make test
  362. # run LFS_MULTIVERSION tests
  363. test-multiversion:
  364. runs-on: ubuntu-latest
  365. steps:
  366. - uses: actions/checkout@v4.1.7
  367. - name: install
  368. run: |
  369. # need a few things
  370. sudo apt-get update -qq
  371. sudo apt-get install -qq gcc python3 python3-pip
  372. pip3 install toml
  373. gcc --version
  374. python3 --version
  375. - name: test-multiversion
  376. run: |
  377. CFLAGS="$CFLAGS -DLFS_MULTIVERSION" make test
  378. # run tests on the older version lfs2.0
  379. test-lfs2_0:
  380. runs-on: ubuntu-latest
  381. steps:
  382. - uses: actions/checkout@v4.1.7
  383. - name: install
  384. run: |
  385. # need a few things
  386. sudo apt-get update -qq
  387. sudo apt-get install -qq gcc python3 python3-pip
  388. pip3 install toml
  389. gcc --version
  390. python3 --version
  391. - name: test-lfs2_0
  392. run: |
  393. CFLAGS="$CFLAGS -DLFS_MULTIVERSION" \
  394. TESTFLAGS="$TESTFLAGS -DDISK_VERSION=0x00020000" \
  395. make test
  396. # run under Valgrind to check for memory errors
  397. test-valgrind:
  398. runs-on: ubuntu-latest
  399. steps:
  400. - uses: actions/checkout@v4.1.7
  401. - name: install
  402. run: |
  403. # need a few things
  404. sudo apt-get update -qq
  405. sudo apt-get install -qq gcc python3 python3-pip valgrind
  406. pip3 install toml
  407. gcc --version
  408. python3 --version
  409. valgrind --version
  410. # Valgrind takes a while with diminishing value, so only test
  411. # on one geometry
  412. - name: test-valgrind
  413. run: |
  414. TESTFLAGS="$TESTFLAGS --valgrind --context=1024 -Gdefault -Pnone" \
  415. make test
  416. # test that compilation is warning free under clang
  417. # run with Clang, mostly to check for Clang-specific warnings
  418. test-clang:
  419. runs-on: ubuntu-latest
  420. steps:
  421. - uses: actions/checkout@v4.1.7
  422. - name: install
  423. run: |
  424. # need a few things
  425. sudo apt-get install -qq clang python3 python3-pip
  426. pip3 install toml
  427. clang --version
  428. python3 --version
  429. - name: test-clang
  430. run: |
  431. # override CFLAGS since Clang does not support -fcallgraph-info
  432. # and -ftrack-macro-expansions
  433. make \
  434. CC=clang \
  435. CFLAGS="$CFLAGS -MMD -g3 -I. -std=c99 -Wall -Wextra -pedantic" \
  436. test
  437. # run benchmarks
  438. #
  439. # note there's no real benefit to running these on multiple archs
  440. bench:
  441. runs-on: ubuntu-latest
  442. steps:
  443. - uses: actions/checkout@v4.1.7
  444. - name: install
  445. run: |
  446. # need a few things
  447. sudo apt-get update -qq
  448. sudo apt-get install -qq gcc python3 python3-pip valgrind
  449. pip3 install toml
  450. gcc --version
  451. python3 --version
  452. valgrind --version
  453. - name: bench
  454. run: |
  455. make bench
  456. # find bench results
  457. make lfs.bench.csv
  458. ./scripts/summary.py lfs.bench.csv \
  459. -bsuite \
  460. -freaded=bench_readed \
  461. -fproged=bench_proged \
  462. -ferased=bench_erased
  463. mkdir -p bench
  464. cp lfs.bench.csv bench/bench.csv
  465. # find perfbd results
  466. make lfs.perfbd.csv
  467. ./scripts/perfbd.py -u lfs.perfbd.csv
  468. mkdir -p bench
  469. cp lfs.perfbd.csv bench/perfbd.csv
  470. # create bench statuses
  471. - name: upload-bench
  472. uses: actions/upload-artifact@v4.4.0
  473. with:
  474. name: bench
  475. path: bench
  476. - name: status-bench
  477. run: |
  478. mkdir -p status
  479. f=bench/bench.csv
  480. for s in readed proged erased
  481. do
  482. export STEP="bench"
  483. export CONTEXT="bench / $s"
  484. export PREV="$(curl -sS \
  485. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/master`
  486. `?per_page=100" \
  487. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]
  488. | select(.context == env.CONTEXT).description
  489. | capture("(?<prev>[0-9]+)").prev' \
  490. || echo 0)"
  491. export DESCRIPTION="$(./scripts/summary.py $f -f$s=bench_$s -Y \
  492. | awk '
  493. NR==2 {$1=0; printf "%s B",$NF}
  494. NR==2 && ENVIRON["PREV"]+0 != 0 {
  495. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  496. }')"
  497. jq -n '{
  498. state: "success",
  499. context: env.CONTEXT,
  500. description: env.DESCRIPTION,
  501. target_job: "${{github.job}}",
  502. target_step: env.STEP,
  503. }' | tee status/$(basename $f .csv)-$s.json
  504. done
  505. - name: upload-status-bench
  506. uses: actions/upload-artifact@v4.4.0
  507. with:
  508. name: status-bench
  509. path: status
  510. retention-days: 1
  511. # run compatibility tests using the current master as the previous version
  512. test-compat:
  513. runs-on: ubuntu-latest
  514. steps:
  515. - uses: actions/checkout@v4.1.7
  516. if: ${{github.event_name == 'pull_request'}}
  517. # checkout the current pr target into lfsp
  518. - uses: actions/checkout@v4.1.7
  519. if: ${{github.event_name == 'pull_request'}}
  520. with:
  521. ref: ${{github.event.pull_request.base.ref}}
  522. path: lfsp
  523. - name: install
  524. if: ${{github.event_name == 'pull_request'}}
  525. run: |
  526. # need a few things
  527. sudo apt-get update -qq
  528. sudo apt-get install -qq gcc python3 python3-pip
  529. pip3 install toml
  530. gcc --version
  531. python3 --version
  532. # adjust prefix of lfsp
  533. - name: changeprefix
  534. if: ${{github.event_name == 'pull_request'}}
  535. run: |
  536. ./scripts/changeprefix.py lfs lfsp lfsp/*.h lfsp/*.c
  537. - name: test-compat
  538. if: ${{github.event_name == 'pull_request'}}
  539. run: |
  540. TESTS=tests/test_compat.toml \
  541. SRC="$(find . lfsp -name '*.c' -maxdepth 1 \
  542. -and -not -name '*.t.*' \
  543. -and -not -name '*.b.*')" \
  544. CFLAGS="-DLFSP=lfsp/lfsp.h" \
  545. make test
  546. # self-host with littlefs-fuse for a fuzz-like test
  547. fuse:
  548. runs-on: ubuntu-latest
  549. if: ${{!endsWith(github.ref, '-prefix')}}
  550. steps:
  551. - uses: actions/checkout@v4.1.7
  552. - name: install
  553. run: |
  554. # need a few things
  555. sudo apt-get update -qq
  556. sudo apt-get install -qq gcc python3 python3-pip libfuse-dev
  557. sudo pip3 install toml
  558. gcc --version
  559. python3 --version
  560. fusermount -V
  561. - uses: actions/checkout@v4.1.7
  562. with:
  563. repository: littlefs-project/littlefs-fuse
  564. ref: v2
  565. path: littlefs-fuse
  566. - name: setup
  567. run: |
  568. # copy our new version into littlefs-fuse
  569. rm -rf littlefs-fuse/littlefs/*
  570. cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
  571. # setup disk for littlefs-fuse
  572. mkdir mount
  573. LOOP=$(sudo losetup -f)
  574. sudo chmod a+rw $LOOP
  575. dd if=/dev/zero bs=512 count=128K of=disk
  576. losetup $LOOP disk
  577. echo "LOOP=$LOOP" >> $GITHUB_ENV
  578. - name: test
  579. run: |
  580. # self-host test
  581. make -C littlefs-fuse
  582. littlefs-fuse/lfs --format $LOOP
  583. littlefs-fuse/lfs $LOOP mount
  584. ls mount
  585. mkdir mount/littlefs
  586. cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  587. cd mount/littlefs
  588. stat .
  589. ls -flh
  590. make -B test-runner
  591. make -B test
  592. # test migration using littlefs-fuse
  593. migrate:
  594. runs-on: ubuntu-latest
  595. if: ${{!endsWith(github.ref, '-prefix')}}
  596. steps:
  597. - uses: actions/checkout@v4.1.7
  598. - name: install
  599. run: |
  600. # need a few things
  601. sudo apt-get update -qq
  602. sudo apt-get install -qq gcc python3 python3-pip libfuse-dev
  603. sudo pip3 install toml
  604. gcc --version
  605. python3 --version
  606. fusermount -V
  607. - uses: actions/checkout@v4.1.7
  608. with:
  609. repository: littlefs-project/littlefs-fuse
  610. ref: v2
  611. path: v2
  612. - uses: actions/checkout@v4.1.7
  613. with:
  614. repository: littlefs-project/littlefs-fuse
  615. ref: v1
  616. path: v1
  617. - name: setup
  618. run: |
  619. # copy our new version into littlefs-fuse
  620. rm -rf v2/littlefs/*
  621. cp -r $(git ls-tree --name-only HEAD) v2/littlefs
  622. # setup disk for littlefs-fuse
  623. mkdir mount
  624. LOOP=$(sudo losetup -f)
  625. sudo chmod a+rw $LOOP
  626. dd if=/dev/zero bs=512 count=128K of=disk
  627. losetup $LOOP disk
  628. echo "LOOP=$LOOP" >> $GITHUB_ENV
  629. - name: test
  630. run: |
  631. # compile v1 and v2
  632. make -C v1
  633. make -C v2
  634. # run self-host test with v1
  635. v1/lfs --format $LOOP
  636. v1/lfs $LOOP mount
  637. ls mount
  638. mkdir mount/littlefs
  639. cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  640. cd mount/littlefs
  641. stat .
  642. ls -flh
  643. make -B test-runner
  644. make -B test
  645. # attempt to migrate
  646. cd ../..
  647. fusermount -u mount
  648. v2/lfs --migrate $LOOP
  649. v2/lfs $LOOP mount
  650. # run self-host test with v2 right where we left off
  651. ls mount
  652. cd mount/littlefs
  653. stat .
  654. ls -flh
  655. make -B test-runner
  656. make -B test
  657. # status related tasks that run after tests
  658. status:
  659. runs-on: ubuntu-latest
  660. needs: [test, bench]
  661. steps:
  662. - uses: actions/checkout@v4.1.7
  663. if: ${{github.event_name == 'pull_request'}}
  664. - name: install
  665. if: ${{github.event_name == 'pull_request'}}
  666. run: |
  667. # need a few things
  668. sudo apt-get install -qq gcc python3 python3-pip
  669. pip3 install toml
  670. gcc --version
  671. python3 --version
  672. - uses: actions/download-artifact@v4.1.8
  673. if: ${{github.event_name == 'pull_request'}}
  674. continue-on-error: true
  675. with:
  676. pattern: '{sizes,sizes-*}'
  677. merge-multiple: true
  678. path: sizes
  679. - uses: actions/download-artifact@v4.1.8
  680. if: ${{github.event_name == 'pull_request'}}
  681. continue-on-error: true
  682. with:
  683. pattern: '{cov,cov-*}'
  684. merge-multiple: true
  685. path: cov
  686. - uses: actions/download-artifact@v4.1.8
  687. if: ${{github.event_name == 'pull_request'}}
  688. continue-on-error: true
  689. with:
  690. pattern: '{bench,bench-*}'
  691. merge-multiple: true
  692. path: bench
  693. # try to find results from tests
  694. - name: create-table
  695. if: ${{github.event_name == 'pull_request'}}
  696. run: |
  697. # compare against pull-request target
  698. curl -sS \
  699. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/`
  700. `${{github.event.pull_request.base.ref}}`
  701. `?per_page=100" \
  702. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]' \
  703. >> prev-status.json \
  704. || true
  705. # build table for GitHub
  706. declare -A table
  707. # sizes table
  708. i=0
  709. j=0
  710. for c in "" readonly threadsafe multiversion migrate error-asserts
  711. do
  712. # per-config results
  713. c_or_default=${c:-default}
  714. c_camel=${c_or_default^}
  715. table[$i,$j]=$c_camel
  716. ((j+=1))
  717. for s in code stack structs
  718. do
  719. f=sizes/thumb${c:+-$c}.$s.csv
  720. [ -e $f ] && table[$i,$j]=$( \
  721. export PREV="$(jq -re '
  722. select(.context == "'"sizes (thumb${c:+, $c}) / $s"'").description
  723. | capture("(?<prev>[0-9∞]+)").prev' \
  724. prev-status.json || echo 0)"
  725. ./scripts/summary.py $f --max=stack_limit -Y \
  726. | awk '
  727. NR==2 {$1=0; printf "%s B",$NF}
  728. NR==2 && ENVIRON["PREV"]+0 != 0 {
  729. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  730. }' \
  731. | sed -e 's/ /\&nbsp;/g')
  732. ((j+=1))
  733. done
  734. ((j=0, i+=1))
  735. done
  736. # coverage table
  737. i=0
  738. j=4
  739. for s in lines branches
  740. do
  741. table[$i,$j]=${s^}
  742. ((j+=1))
  743. f=cov/cov.csv
  744. [ -e $f ] && table[$i,$j]=$( \
  745. export PREV="$(jq -re '
  746. select(.context == "'"cov / $s"'").description
  747. | capture("(?<prev_a>[0-9]+)/(?<prev_b>[0-9]+)")
  748. | 100*((.prev_a|tonumber) / (.prev_b|tonumber))' \
  749. prev-status.json || echo 0)"
  750. ./scripts/cov.py -u $f -f$s -Y \
  751. | awk -F '[ /%]+' -v s=$s '
  752. NR==2 {$1=0; printf "%d/%d %s",$2,$3,s}
  753. NR==2 && ENVIRON["PREV"]+0 != 0 {
  754. printf " (%+.1f%%)",$4-ENVIRON["PREV"]
  755. }' \
  756. | sed -e 's/ /\&nbsp;/g')
  757. ((j=4, i+=1))
  758. done
  759. # benchmark table
  760. i=3
  761. j=4
  762. for s in readed proged erased
  763. do
  764. table[$i,$j]=${s^}
  765. ((j+=1))
  766. f=bench/bench.csv
  767. [ -e $f ] && table[$i,$j]=$( \
  768. export PREV="$(jq -re '
  769. select(.context == "'"bench / $s"'").description
  770. | capture("(?<prev>[0-9]+)").prev' \
  771. prev-status.json || echo 0)"
  772. ./scripts/summary.py $f -f$s=bench_$s -Y \
  773. | awk '
  774. NR==2 {$1=0; printf "%s B",$NF}
  775. NR==2 && ENVIRON["PREV"]+0 != 0 {
  776. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  777. }' \
  778. | sed -e 's/ /\&nbsp;/g')
  779. ((j=4, i+=1))
  780. done
  781. # build the actual table
  782. echo "| | Code | Stack | Structs | | Coverage |" >> table.txt
  783. echo "|:--|-----:|------:|--------:|:--|---------:|" >> table.txt
  784. for ((i=0; i<6; i++))
  785. do
  786. echo -n "|" >> table.txt
  787. for ((j=0; j<6; j++))
  788. do
  789. echo -n " " >> table.txt
  790. [[ i -eq 2 && j -eq 5 ]] && echo -n "**Benchmarks**" >> table.txt
  791. echo -n "${table[$i,$j]:-}" >> table.txt
  792. echo -n " |" >> table.txt
  793. done
  794. echo >> table.txt
  795. done
  796. cat table.txt
  797. # create a bot comment for successful runs on pull requests
  798. - name: create-comment
  799. if: ${{github.event_name == 'pull_request'}}
  800. run: |
  801. touch comment.txt
  802. echo "<details>" >> comment.txt
  803. echo "<summary>" >> comment.txt
  804. echo "Tests passed ✓, `
  805. `Code: $(awk 'NR==3 {print $4}' table.txt || true), `
  806. `Stack: $(awk 'NR==3 {print $6}' table.txt || true), `
  807. `Structs: $(awk 'NR==3 {print $8}' table.txt || true)" \
  808. >> comment.txt
  809. echo "</summary>" >> comment.txt
  810. echo >> comment.txt
  811. [ -e table.txt ] && cat table.txt >> comment.txt
  812. echo >> comment.txt
  813. echo "</details>" >> comment.txt
  814. cat comment.txt
  815. mkdir -p comment
  816. jq -n --rawfile comment comment.txt '{
  817. number: ${{github.event.number}},
  818. body: $comment,
  819. }' | tee comment/comment.json
  820. - name: upload-comment
  821. uses: actions/upload-artifact@v4.4.0
  822. with:
  823. name: comment
  824. path: comment
  825. retention-days: 1