test.yml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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
  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
  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. uses: actions/upload-artifact@v4
  266. with:
  267. name: status-sizes-${{matrix.arch}}
  268. path: status
  269. retention-days: 1
  270. # create cov statuses
  271. - name: upload-cov
  272. if: ${{matrix.arch == 'x86_64'}}
  273. uses: actions/upload-artifact@v4
  274. with:
  275. name: cov
  276. path: cov
  277. - name: status-cov
  278. if: ${{matrix.arch == 'x86_64'}}
  279. run: |
  280. mkdir -p status
  281. f=cov/cov.csv
  282. for s in lines branches
  283. do
  284. export STEP="cov"
  285. export CONTEXT="cov / $s"
  286. export PREV="$(curl -sS \
  287. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/master`
  288. `?per_page=100" \
  289. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]
  290. | select(.context == env.CONTEXT).description
  291. | capture("(?<prev_a>[0-9]+)/(?<prev_b>[0-9]+)")
  292. | 100*((.prev_a|tonumber) / (.prev_b|tonumber))' \
  293. || echo 0)"
  294. export DESCRIPTION="$(./scripts/cov.py -u $f -f$s -Y \
  295. | awk -F '[ /%]+' -v s=$s '
  296. NR==2 {$1=0; printf "%d/%d %s",$2,$3,s}
  297. NR==2 && ENVIRON["PREV"]+0 != 0 {
  298. printf " (%+.1f%%)",$4-ENVIRON["PREV"]
  299. }')"
  300. jq -n '{
  301. state: "success",
  302. context: env.CONTEXT,
  303. description: env.DESCRIPTION,
  304. target_job: "${{github.job}} (${{matrix.arch}})",
  305. target_step: env.STEP,
  306. }' | tee status/$(basename $f .csv)-$s.json
  307. done
  308. - name: upload-status-cov
  309. if: ${{matrix.arch == 'x86_64'}}
  310. uses: actions/upload-artifact@v4
  311. with:
  312. name: status-cov
  313. path: status
  314. retention-days: 1
  315. # run as many exhaustive tests as fits in GitHub's time limits
  316. #
  317. # this grows exponentially, so it doesn't turn out to be that many
  318. test-pls:
  319. runs-on: ubuntu-latest
  320. strategy:
  321. fail-fast: false
  322. matrix:
  323. pls: [1, 2]
  324. steps:
  325. - uses: actions/checkout@v4
  326. - name: install
  327. run: |
  328. # need a few things
  329. sudo apt-get update -qq
  330. sudo apt-get install -qq gcc python3 python3-pip
  331. pip3 install toml
  332. gcc --version
  333. python3 --version
  334. - name: test-pls
  335. if: ${{matrix.pls <= 1}}
  336. run: |
  337. TESTFLAGS="$TESTFLAGS -P${{matrix.pls}}" make test
  338. # >=2pls takes multiple days to run fully, so we can only
  339. # run a subset of tests, these are the most important
  340. - name: test-limited-pls
  341. if: ${{matrix.pls > 1}}
  342. run: |
  343. TESTFLAGS="$TESTFLAGS -P${{matrix.pls}} test_dirs test_relocations" \
  344. make test
  345. # run with LFS_NO_INTRINSICS to make sure that works
  346. test-no-intrinsics:
  347. runs-on: ubuntu-latest
  348. steps:
  349. - uses: actions/checkout@v4
  350. - name: install
  351. run: |
  352. # need a few things
  353. sudo apt-get update -qq
  354. sudo apt-get install -qq gcc python3 python3-pip
  355. pip3 install toml
  356. gcc --version
  357. python3 --version
  358. - name: test-no-intrinsics
  359. run: |
  360. CFLAGS="$CFLAGS -DLFS_NO_INTRINSICS" make test
  361. test-shrink:
  362. runs-on: ubuntu-latest
  363. steps:
  364. - uses: actions/checkout@v4
  365. - name: install
  366. run: |
  367. # need a few things
  368. sudo apt-get update -qq
  369. sudo apt-get install -qq gcc python3 python3-pip
  370. pip3 install toml
  371. gcc --version
  372. python3 --version
  373. - name: test-no-intrinsics
  374. run: |
  375. CFLAGS="$CFLAGS -DLFS_SHRINKNONRELOCATING" make test
  376. # run with all trace options enabled to at least make sure these
  377. # all compile
  378. test-yes-trace:
  379. runs-on: ubuntu-latest
  380. steps:
  381. - uses: actions/checkout@v4
  382. - name: install
  383. run: |
  384. # need a few things
  385. sudo apt-get update -qq
  386. sudo apt-get install -qq gcc python3 python3-pip
  387. pip3 install toml
  388. gcc --version
  389. python3 --version
  390. - name: test-yes-trace
  391. run: |
  392. CFLAGS="$CFLAGS \
  393. -DLFS_YES_TRACE \
  394. -DLFS_RAMBD_YES_TRACE \
  395. -DLFS_FILEBD_YES_TRACE \
  396. -DLFS_RAMBD_YES_TRACE" \
  397. make test
  398. # run LFS_MULTIVERSION tests
  399. test-multiversion:
  400. runs-on: ubuntu-latest
  401. steps:
  402. - uses: actions/checkout@v4
  403. - name: install
  404. run: |
  405. # need a few things
  406. sudo apt-get update -qq
  407. sudo apt-get install -qq gcc python3 python3-pip
  408. pip3 install toml
  409. gcc --version
  410. python3 --version
  411. - name: test-multiversion
  412. run: |
  413. CFLAGS="$CFLAGS -DLFS_MULTIVERSION" make test
  414. # run tests on the older version lfs2.0
  415. test-lfs2_0:
  416. runs-on: ubuntu-latest
  417. steps:
  418. - uses: actions/checkout@v4
  419. - name: install
  420. run: |
  421. # need a few things
  422. sudo apt-get update -qq
  423. sudo apt-get install -qq gcc python3 python3-pip
  424. pip3 install toml
  425. gcc --version
  426. python3 --version
  427. - name: test-lfs2_0
  428. run: |
  429. CFLAGS="$CFLAGS -DLFS_MULTIVERSION" \
  430. TESTFLAGS="$TESTFLAGS -DDISK_VERSION=0x00020000" \
  431. make test
  432. # run under Valgrind to check for memory errors
  433. test-valgrind:
  434. runs-on: ubuntu-latest
  435. steps:
  436. - uses: actions/checkout@v4
  437. - name: install
  438. run: |
  439. # need a few things
  440. sudo apt-get update -qq
  441. sudo apt-get install -qq gcc python3 python3-pip valgrind
  442. pip3 install toml
  443. gcc --version
  444. python3 --version
  445. valgrind --version
  446. # Valgrind takes a while with diminishing value, so only test
  447. # on one geometry
  448. - name: test-valgrind
  449. run: |
  450. TESTFLAGS="$TESTFLAGS --valgrind --context=1024 -Gdefault -Pnone" \
  451. make test
  452. # compile/run with Clang, mostly to check for Clang-specific warnings
  453. test-clang:
  454. runs-on: ubuntu-latest
  455. steps:
  456. - uses: actions/checkout@v4
  457. - name: install
  458. run: |
  459. # need a few things
  460. sudo apt-get install -qq clang python3 python3-pip
  461. pip3 install toml
  462. clang --version
  463. python3 --version
  464. - name: test-clang
  465. run: |
  466. CC=clang \
  467. make test
  468. # run benchmarks
  469. #
  470. # note there's no real benefit to running these on multiple archs
  471. bench:
  472. runs-on: ubuntu-latest
  473. steps:
  474. - uses: actions/checkout@v4
  475. - name: install
  476. run: |
  477. # need a few things
  478. sudo apt-get update -qq
  479. sudo apt-get install -qq gcc python3 python3-pip valgrind
  480. pip3 install toml
  481. gcc --version
  482. python3 --version
  483. valgrind --version
  484. - name: bench
  485. run: |
  486. make bench
  487. # find bench results
  488. make lfs.bench.csv
  489. ./scripts/summary.py lfs.bench.csv \
  490. -bsuite \
  491. -freaded=bench_readed \
  492. -fproged=bench_proged \
  493. -ferased=bench_erased
  494. mkdir -p bench
  495. cp lfs.bench.csv bench/bench.csv
  496. # find perfbd results
  497. make lfs.perfbd.csv
  498. ./scripts/perfbd.py -u lfs.perfbd.csv
  499. mkdir -p bench
  500. cp lfs.perfbd.csv bench/perfbd.csv
  501. # create bench statuses
  502. - name: upload-bench
  503. uses: actions/upload-artifact@v4
  504. with:
  505. name: bench
  506. path: bench
  507. - name: status-bench
  508. run: |
  509. mkdir -p status
  510. f=bench/bench.csv
  511. for s in readed proged erased
  512. do
  513. export STEP="bench"
  514. export CONTEXT="bench / $s"
  515. export PREV="$(curl -sS \
  516. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/master`
  517. `?per_page=100" \
  518. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]
  519. | select(.context == env.CONTEXT).description
  520. | capture("(?<prev>[0-9]+)").prev' \
  521. || echo 0)"
  522. export DESCRIPTION="$(./scripts/summary.py $f -f$s=bench_$s -Y \
  523. | awk '
  524. NR==2 {$1=0; printf "%s B",$NF}
  525. NR==2 && ENVIRON["PREV"]+0 != 0 {
  526. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  527. }')"
  528. jq -n '{
  529. state: "success",
  530. context: env.CONTEXT,
  531. description: env.DESCRIPTION,
  532. target_job: "${{github.job}}",
  533. target_step: env.STEP,
  534. }' | tee status/$(basename $f .csv)-$s.json
  535. done
  536. - name: upload-status-bench
  537. uses: actions/upload-artifact@v4
  538. with:
  539. name: status-bench
  540. path: status
  541. retention-days: 1
  542. # run compatibility tests using the current master as the previous version
  543. test-compat:
  544. runs-on: ubuntu-latest
  545. steps:
  546. - uses: actions/checkout@v4
  547. if: ${{github.event_name == 'pull_request'}}
  548. # checkout the current pr target into lfsp
  549. - uses: actions/checkout@v4
  550. if: ${{github.event_name == 'pull_request'}}
  551. with:
  552. ref: ${{github.event.pull_request.base.ref}}
  553. path: lfsp
  554. - name: install
  555. if: ${{github.event_name == 'pull_request'}}
  556. run: |
  557. # need a few things
  558. sudo apt-get update -qq
  559. sudo apt-get install -qq gcc python3 python3-pip
  560. pip3 install toml
  561. gcc --version
  562. python3 --version
  563. # adjust prefix of lfsp
  564. - name: changeprefix
  565. if: ${{github.event_name == 'pull_request'}}
  566. run: |
  567. ./scripts/changeprefix.py lfs lfsp lfsp/*.h lfsp/*.c
  568. - name: test-compat
  569. if: ${{github.event_name == 'pull_request'}}
  570. run: |
  571. TESTS=tests/test_compat.toml \
  572. SRC="$(find . lfsp -name '*.c' -maxdepth 1 \
  573. -and -not -name '*.t.*' \
  574. -and -not -name '*.b.*')" \
  575. CFLAGS="-DLFSP=lfsp/lfsp.h" \
  576. make test
  577. # self-host with littlefs-fuse for a fuzz-like test
  578. fuse:
  579. runs-on: ubuntu-latest
  580. if: ${{!endsWith(github.ref, '-prefix')}}
  581. steps:
  582. - uses: actions/checkout@v4
  583. - name: install
  584. run: |
  585. # need a few things
  586. sudo apt-get update -qq
  587. sudo apt-get install -qq gcc python3 python3-pip libfuse-dev
  588. sudo pip3 install toml
  589. gcc --version
  590. python3 --version
  591. fusermount -V
  592. - uses: actions/checkout@v4
  593. with:
  594. repository: littlefs-project/littlefs-fuse
  595. ref: v2
  596. path: littlefs-fuse
  597. - name: setup
  598. run: |
  599. # copy our new version into littlefs-fuse
  600. rm -rf littlefs-fuse/littlefs/*
  601. cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
  602. # setup disk for littlefs-fuse
  603. mkdir mount
  604. LOOP=$(sudo losetup -f)
  605. sudo chmod a+rw $LOOP
  606. dd if=/dev/zero bs=512 count=128K of=disk
  607. losetup $LOOP disk
  608. echo "LOOP=$LOOP" >> $GITHUB_ENV
  609. - name: test
  610. run: |
  611. # self-host test
  612. make -C littlefs-fuse
  613. littlefs-fuse/lfs --format $LOOP
  614. littlefs-fuse/lfs $LOOP mount
  615. ls mount
  616. mkdir mount/littlefs
  617. cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  618. cd mount/littlefs
  619. stat .
  620. ls -flh
  621. make -B test-runner
  622. make -B test
  623. # test migration using littlefs-fuse
  624. migrate:
  625. runs-on: ubuntu-latest
  626. if: ${{!endsWith(github.ref, '-prefix')}}
  627. steps:
  628. - uses: actions/checkout@v4
  629. - name: install
  630. run: |
  631. # need a few things
  632. sudo apt-get update -qq
  633. sudo apt-get install -qq gcc python3 python3-pip libfuse-dev
  634. sudo pip3 install toml
  635. gcc --version
  636. python3 --version
  637. fusermount -V
  638. - uses: actions/checkout@v4
  639. with:
  640. repository: littlefs-project/littlefs-fuse
  641. ref: v2
  642. path: v2
  643. - uses: actions/checkout@v4
  644. with:
  645. repository: littlefs-project/littlefs-fuse
  646. ref: v1
  647. path: v1
  648. - name: setup
  649. run: |
  650. # copy our new version into littlefs-fuse
  651. rm -rf v2/littlefs/*
  652. cp -r $(git ls-tree --name-only HEAD) v2/littlefs
  653. # setup disk for littlefs-fuse
  654. mkdir mount
  655. LOOP=$(sudo losetup -f)
  656. sudo chmod a+rw $LOOP
  657. dd if=/dev/zero bs=512 count=128K of=disk
  658. losetup $LOOP disk
  659. echo "LOOP=$LOOP" >> $GITHUB_ENV
  660. - name: test
  661. run: |
  662. # compile v1 and v2
  663. make -C v1
  664. make -C v2
  665. # run self-host test with v1
  666. v1/lfs --format $LOOP
  667. v1/lfs $LOOP mount
  668. ls mount
  669. mkdir mount/littlefs
  670. cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  671. cd mount/littlefs
  672. stat .
  673. ls -flh
  674. make -B test-runner
  675. make -B test
  676. # attempt to migrate
  677. cd ../..
  678. fusermount -u mount
  679. v2/lfs --migrate $LOOP
  680. v2/lfs $LOOP mount
  681. # run self-host test with v2 right where we left off
  682. ls mount
  683. cd mount/littlefs
  684. stat .
  685. ls -flh
  686. make -B test-runner
  687. make -B test
  688. # status related tasks that run after tests
  689. status:
  690. runs-on: ubuntu-latest
  691. needs: [test, bench]
  692. steps:
  693. - uses: actions/checkout@v4
  694. if: ${{github.event_name == 'pull_request'}}
  695. - name: install
  696. if: ${{github.event_name == 'pull_request'}}
  697. run: |
  698. # need a few things
  699. sudo apt-get install -qq gcc python3 python3-pip
  700. pip3 install toml
  701. gcc --version
  702. python3 --version
  703. - uses: actions/download-artifact@v4
  704. if: ${{github.event_name == 'pull_request'}}
  705. continue-on-error: true
  706. with:
  707. pattern: '{sizes,sizes-*}'
  708. merge-multiple: true
  709. path: sizes
  710. - uses: actions/download-artifact@v4
  711. if: ${{github.event_name == 'pull_request'}}
  712. continue-on-error: true
  713. with:
  714. pattern: '{cov,cov-*}'
  715. merge-multiple: true
  716. path: cov
  717. - uses: actions/download-artifact@v4
  718. if: ${{github.event_name == 'pull_request'}}
  719. continue-on-error: true
  720. with:
  721. pattern: '{bench,bench-*}'
  722. merge-multiple: true
  723. path: bench
  724. # try to find results from tests
  725. - name: create-table
  726. if: ${{github.event_name == 'pull_request'}}
  727. run: |
  728. # compare against pull-request target
  729. curl -sS \
  730. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/`
  731. `${{github.event.pull_request.base.ref}}`
  732. `?per_page=100" \
  733. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]' \
  734. >> prev-status.json \
  735. || true
  736. # build table for GitHub
  737. declare -A table
  738. # sizes table
  739. i=0
  740. j=0
  741. for c in "" readonly threadsafe multiversion migrate error-asserts
  742. do
  743. # per-config results
  744. c_or_default=${c:-default}
  745. c_camel=${c_or_default^}
  746. table[$i,$j]=$c_camel
  747. ((j+=1))
  748. for s in code stack structs
  749. do
  750. f=sizes/thumb${c:+-$c}.$s.csv
  751. [ -e $f ] && table[$i,$j]=$( \
  752. export PREV="$(jq -re '
  753. select(.context == "'"sizes (thumb${c:+, $c}) / $s"'").description
  754. | capture("(?<prev>[0-9∞]+)").prev' \
  755. prev-status.json || echo 0)"
  756. ./scripts/summary.py $f --max=stack_limit -Y \
  757. | awk '
  758. NR==2 {$1=0; printf "%s B",$NF}
  759. NR==2 && ENVIRON["PREV"]+0 != 0 {
  760. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  761. }' \
  762. | sed -e 's/ /\&nbsp;/g')
  763. ((j+=1))
  764. done
  765. ((j=0, i+=1))
  766. done
  767. # coverage table
  768. i=0
  769. j=4
  770. for s in lines branches
  771. do
  772. table[$i,$j]=${s^}
  773. ((j+=1))
  774. f=cov/cov.csv
  775. [ -e $f ] && table[$i,$j]=$( \
  776. export PREV="$(jq -re '
  777. select(.context == "'"cov / $s"'").description
  778. | capture("(?<prev_a>[0-9]+)/(?<prev_b>[0-9]+)")
  779. | 100*((.prev_a|tonumber) / (.prev_b|tonumber))' \
  780. prev-status.json || echo 0)"
  781. ./scripts/cov.py -u $f -f$s -Y \
  782. | awk -F '[ /%]+' -v s=$s '
  783. NR==2 {$1=0; printf "%d/%d %s",$2,$3,s}
  784. NR==2 && ENVIRON["PREV"]+0 != 0 {
  785. printf " (%+.1f%%)",$4-ENVIRON["PREV"]
  786. }' \
  787. | sed -e 's/ /\&nbsp;/g')
  788. ((j=4, i+=1))
  789. done
  790. # benchmark table
  791. i=3
  792. j=4
  793. for s in readed proged erased
  794. do
  795. table[$i,$j]=${s^}
  796. ((j+=1))
  797. f=bench/bench.csv
  798. [ -e $f ] && table[$i,$j]=$( \
  799. export PREV="$(jq -re '
  800. select(.context == "'"bench / $s"'").description
  801. | capture("(?<prev>[0-9]+)").prev' \
  802. prev-status.json || echo 0)"
  803. ./scripts/summary.py $f -f$s=bench_$s -Y \
  804. | awk '
  805. NR==2 {$1=0; printf "%s B",$NF}
  806. NR==2 && ENVIRON["PREV"]+0 != 0 {
  807. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  808. }' \
  809. | sed -e 's/ /\&nbsp;/g')
  810. ((j=4, i+=1))
  811. done
  812. # build the actual table
  813. echo "| | Code | Stack | Structs | | Coverage |" >> table.txt
  814. echo "|:--|-----:|------:|--------:|:--|---------:|" >> table.txt
  815. for ((i=0; i<6; i++))
  816. do
  817. echo -n "|" >> table.txt
  818. for ((j=0; j<6; j++))
  819. do
  820. echo -n " " >> table.txt
  821. [[ i -eq 2 && j -eq 5 ]] && echo -n "**Benchmarks**" >> table.txt
  822. echo -n "${table[$i,$j]:-}" >> table.txt
  823. echo -n " |" >> table.txt
  824. done
  825. echo >> table.txt
  826. done
  827. cat table.txt
  828. # create a bot comment for successful runs on pull requests
  829. - name: create-comment
  830. if: ${{github.event_name == 'pull_request'}}
  831. run: |
  832. touch comment.txt
  833. echo "<details>" >> comment.txt
  834. echo "<summary>" >> comment.txt
  835. echo "Tests passed ✓, `
  836. `Code: $(awk 'NR==3 {print $4}' table.txt || true), `
  837. `Stack: $(awk 'NR==3 {print $6}' table.txt || true), `
  838. `Structs: $(awk 'NR==3 {print $8}' table.txt || true)" \
  839. >> comment.txt
  840. echo "</summary>" >> comment.txt
  841. echo >> comment.txt
  842. [ -e table.txt ] && cat table.txt >> comment.txt
  843. echo >> comment.txt
  844. echo "</details>" >> comment.txt
  845. cat comment.txt
  846. mkdir -p comment
  847. jq -n --rawfile comment comment.txt '{
  848. number: ${{github.event.number}},
  849. body: $comment,
  850. }' | tee comment/comment.json
  851. - name: upload-comment
  852. uses: actions/upload-artifact@v4
  853. with:
  854. name: comment
  855. path: comment
  856. retention-days: 1