configuration.xml 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <SPC5-Config version="1.0.0">
  3. <application name="ChibiOS/HAL MFS Test Suite" version="1.0.0" standalone="true" locked="false">
  4. <description>Test Specification for ChibiOS/HAL MFS Complex Driver.</description>
  5. <component id="org.chibios.spc5.components.portable.generic_startup">
  6. <component id="org.chibios.spc5.components.portable.chibios_unitary_tests_engine" />
  7. </component>
  8. <instances>
  9. <instance locked="false" id="org.chibios.spc5.components.portable.generic_startup" />
  10. <instance locked="false" id="org.chibios.spc5.components.portable.chibios_unitary_tests_engine">
  11. <description>
  12. <brief>
  13. <value>ChibiOS/HAL MFS Test Suite.</value>
  14. </brief>
  15. <copyright>
  16. <value><![CDATA[/*
  17. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  18. Licensed under the Apache License, Version 2.0 (the "License");
  19. you may not use this file except in compliance with the License.
  20. You may obtain a copy of the License at
  21. http://www.apache.org/licenses/LICENSE-2.0
  22. Unless required by applicable law or agreed to in writing, software
  23. distributed under the License is distributed on an "AS IS" BASIS,
  24. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. See the License for the specific language governing permissions and
  26. limitations under the License.
  27. */]]></value>
  28. </copyright>
  29. <introduction>
  30. <value>Test suite for ChibiOS/HAL MFS. The purpose of this suite is to perform unit tests on the MFS module and to converge to 100% code coverage through successive improvements.</value>
  31. </introduction>
  32. </description>
  33. <global_data_and_code>
  34. <code_prefix>
  35. <value>mfs_</value>
  36. </code_prefix>
  37. <global_definitions>
  38. <value><![CDATA[#include "hal_mfs.h"
  39. #define TEST_SUITE_NAME "ChibiOS/HAL MFS Test Suite"
  40. #define TEST_REPORT_HOOK_HEADER test_print_mfs_info();
  41. extern const MFSConfig mfscfg1;
  42. extern MFSDriver mfs1;
  43. extern uint8_t mfs_buffer[512];
  44. flash_error_t bank_erase(mfs_bank_t bank);
  45. flash_error_t bank_verify_erased(mfs_bank_t bank);
  46. void test_print_mfs_info(void);]]></value>
  47. </global_definitions>
  48. <global_code>
  49. <value><![CDATA[#include "hal_mfs.h"
  50. MFSDriver mfs1;
  51. uint8_t mfs_buffer[512];
  52. void test_print_mfs_info(void) {
  53. }
  54. flash_error_t bank_erase(mfs_bank_t bank) {
  55. flash_sector_t sector, n;
  56. if (bank == MFS_BANK_0) {
  57. sector = mfscfg1.bank0_start;
  58. n = mfscfg1.bank0_sectors;
  59. }
  60. else {
  61. sector = mfscfg1.bank1_start;
  62. n = mfscfg1.bank1_sectors;
  63. }
  64. while (n--) {
  65. flash_error_t ferr;
  66. ferr = flashStartEraseSector(mfscfg1.flashp, sector);
  67. if (ferr != FLASH_NO_ERROR)
  68. return ferr;
  69. ferr = flashWaitErase(mfscfg1.flashp);
  70. if (ferr != FLASH_NO_ERROR)
  71. return ferr;
  72. sector++;
  73. }
  74. return FLASH_NO_ERROR;
  75. }
  76. flash_error_t bank_verify_erased(mfs_bank_t bank) {
  77. flash_sector_t sector, n;
  78. if (bank == MFS_BANK_0) {
  79. sector = mfscfg1.bank0_start;
  80. n = mfscfg1.bank0_sectors;
  81. }
  82. else {
  83. sector = mfscfg1.bank1_start;
  84. n = mfscfg1.bank1_sectors;
  85. }
  86. while (n--) {
  87. flash_error_t ferr;
  88. ferr = flashVerifyErase(mfscfg1.flashp, sector);
  89. if (ferr != FLASH_NO_ERROR)
  90. return ferr;
  91. sector++;
  92. }
  93. return FLASH_NO_ERROR;
  94. }]]></value>
  95. </global_code>
  96. </global_data_and_code>
  97. <sequences>
  98. <sequence>
  99. <type index="0">
  100. <value>Internal Tests</value>
  101. </type>
  102. <brief>
  103. <value>Functional tests.</value>
  104. </brief>
  105. <description>
  106. <value>The APIs are tested for functionality, correct cases and expected error cases are tested.</value>
  107. </description>
  108. <condition>
  109. <value />
  110. </condition>
  111. <shared_code>
  112. <value><![CDATA[#include <string.h>
  113. #include "hal_mfs.h"
  114. static const uint8_t pattern1[] = {
  115. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  116. };
  117. static const uint8_t pattern2[] = {
  118. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  119. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
  120. };
  121. static const uint8_t pattern3[] = {
  122. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57
  123. };
  124. static const uint8_t pattern512[] = {
  125. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  126. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  127. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  128. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  129. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  130. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  131. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  132. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  133. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  134. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  135. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  136. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  137. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  138. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  139. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  140. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  141. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  142. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  143. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  144. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  145. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  146. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  147. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  148. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  149. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  150. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  151. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  152. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  153. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  154. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  155. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  156. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
  157. };]]></value>
  158. </shared_code>
  159. <cases>
  160. <case>
  161. <brief>
  162. <value>Testing mfsStart() behavior.</value>
  163. </brief>
  164. <description>
  165. <value>The initialization function is tested. This function can fail only in case of Flash Array failures or in case of unexpected internal errors.</value>
  166. </description>
  167. <condition>
  168. <value />
  169. </condition>
  170. <various_code>
  171. <setup_code>
  172. <value><![CDATA[mfsObjectInit(&mfs1);]]></value>
  173. </setup_code>
  174. <teardown_code>
  175. <value><![CDATA[mfsStop(&mfs1);]]></value>
  176. </teardown_code>
  177. <local_variables>
  178. <value />
  179. </local_variables>
  180. </various_code>
  181. <steps>
  182. <step>
  183. <description>
  184. <value>Erasing the flash array using a low level function.</value>
  185. </description>
  186. <tags>
  187. <value />
  188. </tags>
  189. <code>
  190. <value><![CDATA[flash_error_t ferr;
  191. ferr = bank_erase(MFS_BANK_0);
  192. test_assert(ferr == FLASH_NO_ERROR, "Bank 0 erase failure");
  193. ferr = bank_erase(MFS_BANK_1);
  194. test_assert(ferr == FLASH_NO_ERROR, "Bank 1 erase failure");]]></value>
  195. </code>
  196. </step>
  197. <step>
  198. <description>
  199. <value>Calling mfsStart() on an uninitialized flash array, MFS_NO_ERROR is expected.</value>
  200. </description>
  201. <tags>
  202. <value />
  203. </tags>
  204. <code>
  205. <value><![CDATA[mfs_error_t err;
  206. err = mfsStart(&mfs1, &mfscfg1);
  207. test_assert(err == MFS_NO_ERROR, "initialization error with erased flash");]]></value>
  208. </code>
  209. </step>
  210. <step>
  211. <description>
  212. <value>Calling mfsStart() on a newly initialized flash array, MFS_NO_ERROR is expected.</value>
  213. </description>
  214. <tags>
  215. <value />
  216. </tags>
  217. <code>
  218. <value><![CDATA[mfs_error_t err;
  219. err = mfsStart(&mfs1, &mfscfg1);
  220. test_assert(err == MFS_NO_ERROR, "initialization error with initialized flash");]]></value>
  221. </code>
  222. </step>
  223. </steps>
  224. </case>
  225. <case>
  226. <brief>
  227. <value>Checking for non existing record.</value>
  228. </brief>
  229. <description>
  230. <value>The records space is explored with an initialized but empty managed storage, no record should exist.</value>
  231. </description>
  232. <condition>
  233. <value />
  234. </condition>
  235. <various_code>
  236. <setup_code>
  237. <value><![CDATA[mfsStart(&mfs1, &mfscfg1);]]></value>
  238. </setup_code>
  239. <teardown_code>
  240. <value><![CDATA[mfsStop(&mfs1);]]></value>
  241. </teardown_code>
  242. <local_variables>
  243. <value />
  244. </local_variables>
  245. </various_code>
  246. <steps>
  247. <step>
  248. <description>
  249. <value>Exploring the records space, MFS_ERR_NOT_FOUND is expected for each index.</value>
  250. </description>
  251. <tags>
  252. <value />
  253. </tags>
  254. <code>
  255. <value><![CDATA[mfs_error_t err;
  256. mfs_id_t id;
  257. size_t size;
  258. for (id = 1; id <= MFS_CFG_MAX_RECORDS; id++) {
  259. size = sizeof mfs_buffer;
  260. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  261. test_assert(err == MFS_ERR_NOT_FOUND,
  262. "found a record that should not exists");
  263. }]]></value>
  264. </code>
  265. </step>
  266. </steps>
  267. </case>
  268. <case>
  269. <brief>
  270. <value>Creating, updating and erasing a record.</value>
  271. </brief>
  272. <description>
  273. <value>A record is created, updated several times with different payloads and finally erased.</value>
  274. </description>
  275. <condition>
  276. <value />
  277. </condition>
  278. <various_code>
  279. <setup_code>
  280. <value><![CDATA[mfsStart(&mfs1, &mfscfg1);]]></value>
  281. </setup_code>
  282. <teardown_code>
  283. <value><![CDATA[mfsStop(&mfs1);]]></value>
  284. </teardown_code>
  285. <local_variables>
  286. <value><![CDATA[size_t size;]]></value>
  287. </local_variables>
  288. </various_code>
  289. <steps>
  290. <step>
  291. <description>
  292. <value>The record must not already exists, MFS_ERR_NOT_FOUND is expected.</value>
  293. </description>
  294. <tags>
  295. <value />
  296. </tags>
  297. <code>
  298. <value><![CDATA[size = sizeof mfs_buffer;
  299. mfs_error_t err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  300. test_assert(err == MFS_ERR_NOT_FOUND , "record was already present");]]></value>
  301. </code>
  302. </step>
  303. <step>
  304. <description>
  305. <value>Creating the record then retrieving it again, MFS_NO_ERROR is expected, record content and size are compared with the original.</value>
  306. </description>
  307. <tags>
  308. <value />
  309. </tags>
  310. <code>
  311. <value><![CDATA[mfs_error_t err;
  312. err = mfsWriteRecord(&mfs1, 1, sizeof pattern1, pattern1);
  313. test_assert(err == MFS_NO_ERROR, "error creating the record");
  314. size = sizeof mfs_buffer;
  315. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  316. test_assert(err == MFS_NO_ERROR, "record not found");
  317. test_assert(size == sizeof pattern1, "unexpected record length");
  318. test_assert(memcmp(pattern1, mfs_buffer, size) == 0, "wrong record content");]]></value>
  319. </code>
  320. </step>
  321. <step>
  322. <description>
  323. <value>Updating the record then retrieving it again, MFS_NO_ERROR is expected, record content and size are compared with the original.</value>
  324. </description>
  325. <tags>
  326. <value />
  327. </tags>
  328. <code>
  329. <value><![CDATA[mfs_error_t err;
  330. err = mfsWriteRecord(&mfs1, 1, sizeof pattern2, pattern2);
  331. test_assert(err == MFS_NO_ERROR, "error updating the record");
  332. size = sizeof mfs_buffer;
  333. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  334. test_assert(err == MFS_NO_ERROR, "record not found");
  335. test_assert(size == sizeof pattern2, "unexpected record length");
  336. test_assert(memcmp(pattern2, mfs_buffer, size) == 0, "wrong record content");]]></value>
  337. </code>
  338. </step>
  339. <step>
  340. <description>
  341. <value>Erasing the record then trying to retrieve it again, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is expected on retrieve.</value>
  342. </description>
  343. <tags>
  344. <value />
  345. </tags>
  346. <code>
  347. <value><![CDATA[mfs_error_t err;
  348. err = mfsEraseRecord(&mfs1, 1);
  349. test_assert(err == MFS_NO_ERROR, "error erasing the record");
  350. size = sizeof mfs_buffer;
  351. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  352. test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");]]></value>
  353. </code>
  354. </step>
  355. </steps>
  356. </case>
  357. <case>
  358. <brief>
  359. <value>Erasing the whole storage and re-initialization.</value>
  360. </brief>
  361. <description>
  362. <value>The managed storage is erased, initialized and re-mounted.</value>
  363. </description>
  364. <condition>
  365. <value />
  366. </condition>
  367. <various_code>
  368. <setup_code>
  369. <value><![CDATA[bank_erase(MFS_BANK_0);
  370. bank_erase(MFS_BANK_1);
  371. mfsStart(&mfs1, &mfscfg1);]]></value>
  372. </setup_code>
  373. <teardown_code>
  374. <value><![CDATA[mfsStop(&mfs1);]]></value>
  375. </teardown_code>
  376. <local_variables>
  377. <value />
  378. </local_variables>
  379. </various_code>
  380. <steps>
  381. <step>
  382. <description>
  383. <value>Creating records 1, 2 and 3, MFS_NO_ERROR is expected.</value>
  384. </description>
  385. <tags>
  386. <value />
  387. </tags>
  388. <code>
  389. <value><![CDATA[mfs_error_t err;
  390. err = mfsWriteRecord(&mfs1, 1, sizeof pattern1, pattern1);
  391. test_assert(err == MFS_NO_ERROR, "error creating record 1");
  392. err = mfsWriteRecord(&mfs1, 2, sizeof pattern2, pattern2);
  393. test_assert(err == MFS_NO_ERROR, "error creating record 2");
  394. err = mfsWriteRecord(&mfs1, 3, sizeof pattern3, pattern3);
  395. test_assert(err == MFS_NO_ERROR, "error creating record 3");]]></value>
  396. </code>
  397. </step>
  398. <step>
  399. <description>
  400. <value>Records must exist.</value>
  401. </description>
  402. <tags>
  403. <value />
  404. </tags>
  405. <code>
  406. <value><![CDATA[mfs_error_t err;
  407. size_t size;
  408. size = sizeof mfs_buffer;
  409. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  410. test_assert(err == MFS_NO_ERROR, "record 0 not present");
  411. size = sizeof mfs_buffer;
  412. err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
  413. test_assert(err == MFS_NO_ERROR, "record 1 not present");
  414. size = sizeof mfs_buffer;
  415. err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
  416. test_assert(err == MFS_NO_ERROR, "record 2 not present");]]></value>
  417. </code>
  418. </step>
  419. <step>
  420. <description>
  421. <value>Re-mounting, records must still exist.</value>
  422. </description>
  423. <tags>
  424. <value />
  425. </tags>
  426. <code>
  427. <value><![CDATA[mfs_error_t err;
  428. size_t size;
  429. err = mfsStart(&mfs1, &mfscfg1);
  430. test_assert(err == MFS_NO_ERROR, "re-mount failed");
  431. size = sizeof mfs_buffer;
  432. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  433. test_assert(err == MFS_NO_ERROR, "record 0 not present");
  434. size = sizeof mfs_buffer;
  435. err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
  436. test_assert(err == MFS_NO_ERROR, "record 1 not present");
  437. size = sizeof mfs_buffer;
  438. err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
  439. test_assert(err == MFS_NO_ERROR, "record 2 not present");]]></value>
  440. </code>
  441. </step>
  442. <step>
  443. <description>
  444. <value>Erasing storage and verify that the records have been removed, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is expected on retrieve.</value>
  445. </description>
  446. <tags>
  447. <value />
  448. </tags>
  449. <code>
  450. <value><![CDATA[mfs_error_t err;
  451. size_t size;
  452. err = mfsErase(&mfs1);
  453. test_assert(err == MFS_NO_ERROR, "storage erase error");
  454. size = sizeof mfs_buffer;
  455. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  456. test_assert(err == MFS_ERR_NOT_FOUND, "record 0 still present");
  457. size = sizeof mfs_buffer;
  458. err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer);
  459. test_assert(err == MFS_ERR_NOT_FOUND, "record 1 still present");
  460. size = sizeof mfs_buffer;
  461. err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer);
  462. test_assert(err == MFS_ERR_NOT_FOUND, "record 2 still present");]]></value>
  463. </code>
  464. </step>
  465. </steps>
  466. </case>
  467. <case>
  468. <brief>
  469. <value>Testing storage size limit.</value>
  470. </brief>
  471. <description>
  472. <value>The storage is entirely filled with different records and the final error is tested.</value>
  473. </description>
  474. <condition>
  475. <value />
  476. </condition>
  477. <various_code>
  478. <setup_code>
  479. <value><![CDATA[mfsStart(&mfs1, &mfscfg1);
  480. mfsErase(&mfs1);]]></value>
  481. </setup_code>
  482. <teardown_code>
  483. <value><![CDATA[mfsStop(&mfs1);]]></value>
  484. </teardown_code>
  485. <local_variables>
  486. <value />
  487. </local_variables>
  488. </various_code>
  489. <steps>
  490. <step>
  491. <description>
  492. <value>Filling up the storage by writing records with increasing IDs, MFS_NO_ERROR is expected.</value>
  493. </description>
  494. <tags>
  495. <value />
  496. </tags>
  497. <code>
  498. <value><![CDATA[mfs_id_t id;
  499. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  500. (sizeof (mfs_data_header_t) + sizeof pattern512);
  501. for (id = 1; id <= id_max; id++) {
  502. mfs_error_t err;
  503. size_t size;
  504. err = mfsWriteRecord(&mfs1, id, sizeof pattern512, pattern512);
  505. test_assert(err == MFS_NO_ERROR, "error creating the record");
  506. size = sizeof mfs_buffer;
  507. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  508. test_assert(err == MFS_NO_ERROR,
  509. "record not found");
  510. test_assert(size == sizeof pattern512,
  511. "unexpected record length");
  512. test_assert(memcmp(pattern512, mfs_buffer, size) == 0,
  513. "wrong record content");
  514. }]]></value>
  515. </code>
  516. </step>
  517. <step>
  518. <description>
  519. <value>Creating one more record, should fail, MFS_ERR_OUT_OF_MEM is expected.</value>
  520. </description>
  521. <tags>
  522. <value />
  523. </tags>
  524. <code>
  525. <value><![CDATA[mfs_error_t err;
  526. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  527. (sizeof (mfs_data_header_t) + sizeof pattern512);
  528. err = mfsWriteRecord(&mfs1, id_max, sizeof pattern512 , pattern512);
  529. test_assert(err == MFS_ERR_OUT_OF_MEM, "creation didn't fail");]]></value>
  530. </code>
  531. </step>
  532. <step>
  533. <description>
  534. <value>Adding a smaller record to fill the final gap. A reinitialization is performed and MFS_NO_ERROR is expected.</value>
  535. </description>
  536. <tags>
  537. <value />
  538. </tags>
  539. <code>
  540. <value><![CDATA[mfs_error_t err;
  541. size_t remaining;
  542. remaining = (size_t)flashGetSectorOffset(mfscfg1.flashp, mfscfg1.bank0_start) +
  543. (size_t)mfscfg1.bank_size - (size_t)mfs1.next_offset;
  544. test_assert(remaining >= sizeof (mfs_data_header_t), "not enough space");
  545. if (remaining > sizeof (mfs_data_header_t) * 2) {
  546. err = mfsWriteRecord(&mfs1, MFS_CFG_MAX_RECORDS,
  547. remaining - (sizeof (mfs_data_header_t) * 2),
  548. pattern512);
  549. test_assert(err == MFS_NO_ERROR, "error filling remaining space");
  550. err = mfsEraseRecord(&mfs1, MFS_CFG_MAX_RECORDS);
  551. test_assert(err == MFS_NO_ERROR, "error filling remaining space");
  552. }
  553. else {
  554. if (remaining == sizeof (mfs_data_header_t) * 2) {
  555. err = mfsEraseRecord(&mfs1, 2);
  556. test_assert(err == MFS_NO_ERROR, "error filling remaining space");
  557. }
  558. err = mfsEraseRecord(&mfs1, 1);
  559. test_assert(err == MFS_NO_ERROR, "error filling remaining space");
  560. }
  561. remaining = (size_t)flashGetSectorOffset(mfscfg1.flashp, mfscfg1.bank0_start) +
  562. (size_t)mfscfg1.bank_size - (size_t)mfs1.next_offset;
  563. test_assert(remaining == 0U, "remaining space not zero");
  564. mfsStop(&mfs1);
  565. err = mfsStart(&mfs1, &mfscfg1);
  566. test_assert(err == MFS_NO_ERROR, "initialization error");]]></value>
  567. </code>
  568. </step>
  569. </steps>
  570. </case>
  571. <case>
  572. <brief>
  573. <value>Testing garbage collection by writing.</value>
  574. </brief>
  575. <description>
  576. <value>The garbage collection procedure is triggeredby a write operation and the state of both banks is checked.</value>
  577. </description>
  578. <condition>
  579. <value />
  580. </condition>
  581. <various_code>
  582. <setup_code>
  583. <value><![CDATA[mfsStart(&mfs1, &mfscfg1);
  584. mfsErase(&mfs1);]]></value>
  585. </setup_code>
  586. <teardown_code>
  587. <value><![CDATA[mfsStop(&mfs1);]]></value>
  588. </teardown_code>
  589. <local_variables>
  590. <value />
  591. </local_variables>
  592. </various_code>
  593. <steps>
  594. <step>
  595. <description>
  596. <value>Filling up the storage by writing records with increasing IDs, MFS_NO_ERROR is expected.</value>
  597. </description>
  598. <tags>
  599. <value />
  600. </tags>
  601. <code>
  602. <value><![CDATA[mfs_id_t id;
  603. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  604. (sizeof (mfs_data_header_t) + sizeof pattern512);
  605. for (id = 1; id <= id_max; id++) {
  606. mfs_error_t err;
  607. size_t size;
  608. err = mfsWriteRecord(&mfs1, id, sizeof pattern512, pattern512);
  609. test_assert(err == MFS_NO_ERROR, "error creating the record");
  610. size = sizeof mfs_buffer;
  611. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  612. test_assert(err == MFS_NO_ERROR,
  613. "record not found");
  614. test_assert(size == sizeof pattern512,
  615. "unexpected record length");
  616. test_assert(memcmp(pattern512, mfs_buffer, size) == 0,
  617. "wrong record content");
  618. }]]></value>
  619. </code>
  620. </step>
  621. <step>
  622. <description>
  623. <value>Erasing one record, MFS_NO_ERROR is expected.</value>
  624. </description>
  625. <tags>
  626. <value />
  627. </tags>
  628. <code>
  629. <value><![CDATA[mfs_error_t err;
  630. size_t size;
  631. err = mfsEraseRecord(&mfs1, 1);
  632. test_assert(err == MFS_NO_ERROR, "error erasing the record");
  633. size = sizeof mfs_buffer;
  634. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  635. test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");]]></value>
  636. </code>
  637. </step>
  638. <step>
  639. <description>
  640. <value>Writing one more record triggers garbage collection, MFS_WARN_GC is expected, KS state is checked for correctness after the operation.</value>
  641. </description>
  642. <tags>
  643. <value />
  644. </tags>
  645. <code>
  646. <value><![CDATA[mfs_error_t err;
  647. size_t size;
  648. test_assert(mfs1.current_counter == 1, "not first instance");
  649. err = mfsWriteRecord(&mfs1, 1, sizeof pattern512, pattern512);
  650. test_assert(err == MFS_WARN_GC, "error creating the record");
  651. test_assert(mfs1.current_counter == 2, "not second instance");
  652. size = sizeof mfs_buffer;
  653. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  654. test_assert(err == MFS_NO_ERROR, "record not found");
  655. test_assert(size == sizeof pattern512, "unexpected record length");
  656. test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content");
  657. test_assert(mfs1.current_bank == MFS_BANK_1, "unexpected bank");
  658. test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased");]]></value>
  659. </code>
  660. </step>
  661. <step>
  662. <description>
  663. <value>Checking for all records in the new bank, MFS_NOERROR is expected for each record.</value>
  664. </description>
  665. <tags>
  666. <value />
  667. </tags>
  668. <code>
  669. <value><![CDATA[mfs_id_t id;
  670. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  671. (sizeof (mfs_data_header_t) + sizeof pattern512);
  672. for (id = 1; id <= MFS_CFG_MAX_RECORDS; id++) {
  673. mfs_error_t err;
  674. size_t size;
  675. if (id <= id_max) {
  676. size = sizeof mfs_buffer;
  677. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  678. test_assert(err == MFS_NO_ERROR, "record not found");
  679. test_assert(size == sizeof pattern512, "unexpected record length");
  680. test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content");
  681. }
  682. else {
  683. size = sizeof mfs_buffer;
  684. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  685. test_assert(err == MFS_ERR_NOT_FOUND, "found unexpected record");
  686. }
  687. }]]></value>
  688. </code>
  689. </step>
  690. <step>
  691. <description>
  692. <value>Erasing one record, MFS_NO_ERROR is expected.</value>
  693. </description>
  694. <tags>
  695. <value />
  696. </tags>
  697. <code>
  698. <value><![CDATA[mfs_error_t err;
  699. size_t size;
  700. err = mfsEraseRecord(&mfs1, 1);
  701. test_assert(err == MFS_NO_ERROR, "error erasing the record");
  702. size = sizeof mfs_buffer;
  703. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  704. test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");]]></value>
  705. </code>
  706. </step>
  707. <step>
  708. <description>
  709. <value>Writing one more record triggers garbage collection, MFS_WARN_GC is expected, MFS object state is checked for correctness after the operation.</value>
  710. </description>
  711. <tags>
  712. <value />
  713. </tags>
  714. <code>
  715. <value><![CDATA[mfs_error_t err;
  716. size_t size;
  717. test_assert(mfs1.current_counter == 2, "not second instance");
  718. err = mfsWriteRecord(&mfs1, 1, sizeof pattern512, pattern512);
  719. test_assert(err == MFS_WARN_GC, "error creating the record");
  720. test_assert(mfs1.current_counter == 3, "not third instance");
  721. size = sizeof mfs_buffer;
  722. err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  723. test_assert(err == MFS_NO_ERROR, "record not found");
  724. test_assert(size == sizeof pattern512, "unexpected record length");
  725. test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content");
  726. test_assert(mfs1.current_bank == MFS_BANK_0, "unexpected bank");
  727. test_assert(bank_verify_erased(MFS_BANK_1) == FLASH_NO_ERROR, "bank 1 not erased");]]></value>
  728. </code>
  729. </step>
  730. <step>
  731. <description>
  732. <value>Checking for all records in the new bank, MFS_NO_ERROR is expected for each record.</value>
  733. </description>
  734. <tags>
  735. <value />
  736. </tags>
  737. <code>
  738. <value><![CDATA[mfs_id_t id;
  739. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  740. (sizeof (mfs_data_header_t) + sizeof pattern512);
  741. for (id = 1; id <= MFS_CFG_MAX_RECORDS; id++) {
  742. mfs_error_t err;
  743. size_t size;
  744. if (id <= id_max) {
  745. size = sizeof mfs_buffer;
  746. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  747. test_assert(err == MFS_NO_ERROR, "record not found");
  748. test_assert(size == sizeof pattern512, "unexpected record length");
  749. test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content");
  750. }
  751. else {
  752. size = sizeof mfs_buffer;
  753. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  754. test_assert(err == MFS_ERR_NOT_FOUND, "found unexpected record");
  755. }
  756. }]]></value>
  757. </code>
  758. </step>
  759. </steps>
  760. </case>
  761. <case>
  762. <brief>
  763. <value>Testing garbage collection by erasing</value>
  764. </brief>
  765. <description>
  766. <value>The garbage collection procedure is triggered by an erase operation and the state of both banks is checked.</value>
  767. </description>
  768. <condition>
  769. <value />
  770. </condition>
  771. <various_code>
  772. <setup_code>
  773. <value><![CDATA[mfsStart(&mfs1, &mfscfg1);
  774. mfsErase(&mfs1);]]></value>
  775. </setup_code>
  776. <teardown_code>
  777. <value><![CDATA[mfsStop(&mfs1);]]></value>
  778. </teardown_code>
  779. <local_variables>
  780. <value />
  781. </local_variables>
  782. </various_code>
  783. <steps>
  784. <step>
  785. <description>
  786. <value>Filling up the storage by writing records with increasing IDs, MFS_NO_ERROR is expected.</value>
  787. </description>
  788. <tags>
  789. <value />
  790. </tags>
  791. <code>
  792. <value><![CDATA[mfs_id_t id;
  793. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  794. (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2));
  795. for (id = 1; id <= id_max; id++) {
  796. mfs_error_t err;
  797. size_t size;
  798. err = mfsWriteRecord(&mfs1, id, (sizeof pattern512 / 2), pattern512);
  799. test_assert(err == MFS_NO_ERROR, "error creating the record");
  800. size = sizeof mfs_buffer;
  801. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  802. test_assert(err == MFS_NO_ERROR, "record not found");
  803. test_assert(size == (sizeof pattern512 / 2), "unexpected record length");
  804. test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content");
  805. }]]></value>
  806. </code>
  807. </step>
  808. <step>
  809. <description>
  810. <value>Erase records until the flash bank is filled entirely.</value>
  811. </description>
  812. <tags>
  813. <value />
  814. </tags>
  815. <code>
  816. <value><![CDATA[mfs_error_t err;
  817. size_t size;
  818. mfs_id_t id;
  819. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  820. (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2));
  821. mfs_id_t n = ((mfscfg1.bank_size - sizeof (mfs_bank_header_t)) -
  822. (id_max * (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)))) /
  823. sizeof (mfs_data_header_t);
  824. for (id = 1; id <= n; id++) {
  825. err = mfsEraseRecord(&mfs1, id);
  826. test_assert(err == MFS_NO_ERROR, "error erasing the record");
  827. size = sizeof mfs_buffer;
  828. err = mfsReadRecord(&mfs1, id, &size, mfs_buffer);
  829. test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");
  830. }]]></value>
  831. </code>
  832. </step>
  833. <step>
  834. <description>
  835. <value>Erasing one more record triggers garbage collection, MFS_WARN_GC is expected, KS state is checked for correctness after the operation.</value>
  836. </description>
  837. <tags>
  838. <value />
  839. </tags>
  840. <code>
  841. <value><![CDATA[mfs_error_t err;
  842. size_t size;
  843. mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) /
  844. (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2));
  845. test_assert(mfs1.current_counter == 1, "not first instance");
  846. err = mfsEraseRecord(&mfs1, id_max);
  847. test_assert(err == MFS_WARN_GC, "error erasing the record");
  848. test_assert(mfs1.current_counter == 2, "not second instance");
  849. size = sizeof mfs_buffer;
  850. err = mfsReadRecord(&mfs1, id_max, &size, mfs_buffer);
  851. test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");
  852. test_assert(mfs1.current_bank == MFS_BANK_1, "unexpected bank");
  853. test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased");]]></value>
  854. </code>
  855. </step>
  856. </steps>
  857. </case>
  858. </cases>
  859. </sequence>
  860. <sequence>
  861. <type index="0">
  862. <value>Internal Tests</value>
  863. </type>
  864. <brief>
  865. <value>API Invalid Cases tests.</value>
  866. </brief>
  867. <description>
  868. <value>This test sequence tests the error coded returned by the various APIs when called when the system is not initialized.</value>
  869. </description>
  870. <condition>
  871. <value />
  872. </condition>
  873. <shared_code>
  874. <value><![CDATA[#include "hal_mfs.h"]]></value>
  875. </shared_code>
  876. <cases>
  877. <case>
  878. <brief>
  879. <value>Initialization error from APIs.</value>
  880. </brief>
  881. <description>
  882. <value>The API functions are invoked without prior initialization.</value>
  883. </description>
  884. <condition>
  885. <value />
  886. </condition>
  887. <various_code>
  888. <setup_code>
  889. <value />
  890. </setup_code>
  891. <teardown_code>
  892. <value />
  893. </teardown_code>
  894. <local_variables>
  895. <value />
  896. </local_variables>
  897. </various_code>
  898. <steps>
  899. <step>
  900. <description>
  901. <value>The function mfsErase() is called, MFS_ERR_INV_STATE is expected.</value>
  902. </description>
  903. <tags>
  904. <value />
  905. </tags>
  906. <code>
  907. <value><![CDATA[mfs_error_t err = mfsErase(&mfs1);
  908. test_assert(err == MFS_ERR_INV_STATE, "mfsErase() returned wrong status");]]></value>
  909. </code>
  910. </step>
  911. <step>
  912. <description>
  913. <value>The function mfsWriteRecord() is called, MFS_ERR_INV_STATE is expected.</value>
  914. </description>
  915. <tags>
  916. <value />
  917. </tags>
  918. <code>
  919. <value><![CDATA[mfs_error_t err = mfsWriteRecord(&mfs1, 1, 16, mfs_buffer);
  920. test_assert(err == MFS_ERR_INV_STATE, "mfsWriteRecord() returned wrong status");]]></value>
  921. </code>
  922. </step>
  923. <step>
  924. <description>
  925. <value>The function mfsEraseRecord() is called, MFS_ERR_INV_STATE is expected.</value>
  926. </description>
  927. <tags>
  928. <value />
  929. </tags>
  930. <code>
  931. <value><![CDATA[mfs_error_t err = mfsEraseRecord(&mfs1, 1);
  932. test_assert(err == MFS_ERR_INV_STATE, "mfsEraseRecord() returned wrong status");]]></value>
  933. </code>
  934. </step>
  935. <step>
  936. <description>
  937. <value>The function mfsReadRecord() is called, MFS_ERR_INV_STATE is expected.</value>
  938. </description>
  939. <tags>
  940. <value />
  941. </tags>
  942. <code>
  943. <value><![CDATA[size_t size = sizeof mfs_buffer;
  944. mfs_error_t err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer);
  945. test_assert(err == MFS_ERR_INV_STATE, "mfsReadRecord() returned wrong status");]]></value>
  946. </code>
  947. </step>
  948. <step>
  949. <description>
  950. <value>The function mfsPerformGarbageCollection() is called, MFS_ERR_INV_STATE is expected.</value>
  951. </description>
  952. <tags>
  953. <value />
  954. </tags>
  955. <code>
  956. <value><![CDATA[mfs_error_t err = mfsPerformGarbageCollection(&mfs1);
  957. test_assert(err == MFS_ERR_INV_STATE, "mfsPerformGarbageCollection() returned wrong status");]]></value>
  958. </code>
  959. </step>
  960. </steps>
  961. </case>
  962. <case>
  963. <brief>
  964. <value>Erasing non existing record.</value>
  965. </brief>
  966. <description>
  967. <value>An erase operation is attempted on an non-existing record.</value>
  968. </description>
  969. <condition>
  970. <value />
  971. </condition>
  972. <various_code>
  973. <setup_code>
  974. <value><![CDATA[mfsStart(&mfs1, &mfscfg1);
  975. mfsErase(&mfs1);]]></value>
  976. </setup_code>
  977. <teardown_code>
  978. <value><![CDATA[mfsStop(&mfs1);]]></value>
  979. </teardown_code>
  980. <local_variables>
  981. <value />
  982. </local_variables>
  983. </various_code>
  984. <steps>
  985. <step>
  986. <description>
  987. <value>Record one is erased, the error MFS_ERR_NOT_FOUND is expected.</value>
  988. </description>
  989. <tags>
  990. <value />
  991. </tags>
  992. <code>
  993. <value><![CDATA[mfs_error_t err;
  994. err = mfsEraseRecord(&mfs1, 1);
  995. test_assert(err != MFS_NO_ERROR, "record was present");
  996. test_assert(err == MFS_ERR_NOT_FOUND, "invalid error code");]]></value>
  997. </code>
  998. </step>
  999. </steps>
  1000. </case>
  1001. </cases>
  1002. </sequence>
  1003. </sequences>
  1004. </instance>
  1005. </instances>
  1006. <exportedFeatures />
  1007. </application>
  1008. </SPC5-Config>