File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7878 run : ctest --test-dir build -C Release
7979 - name : CTest - Unit testing Release With Debug Info configuration
8080 run : ctest --test-dir build -C RelWithDebInfo
81- - name : CTest - Unit testing Minimal Size With Debug Info configuration
81+ - name : CTest - Unit testing Minimal Size configuration
8282 run : ctest --test-dir build -C MinSizeRel
8383
8484 deploy :
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ add_library(util)
22
33# Tests
44add_executable (hello_test )
5+ add_executable (crc16_test )
6+ add_executable (crc32_test )
57add_executable (bm_search_test )
68add_executable (linear_search_test )
79
@@ -13,12 +15,20 @@ target_include_directories(util PUBLIC
1315# Sources: library
1416target_sources (util PRIVATE
1517 bm_search.c
18+ crc16.c
19+ crc32.c
1620 linear_search.c
1721)
1822# Sources: unit tests
1923target_sources (hello_test PRIVATE
2024 hello_test.c
2125)
26+ target_sources (crc16_test PRIVATE
27+ crc16_test.c
28+ )
29+ target_sources (crc32_test PRIVATE
30+ crc32_test.c
31+ )
2232target_sources (bm_search_test PRIVATE
2333 bm_search_test.c
2434)
@@ -30,20 +40,24 @@ target_sources(linear_search_test PRIVATE
3040set_target_properties (
3141 util
3242 PROPERTIES
33- COMPILE_OPTIONS "--cpu=cortex-m4;--dlib_config=full;-e"
43+ COMPILE_OPTIONS "--cpu=cortex-m4;--dlib_config=full;-e;--no_wrap_diagnostics "
3444)
3545# Properties: unit testing
3646set_target_properties (
3747 bm_search_test
48+ crc16_test
49+ crc32_test
3850 linear_search_test
3951 hello_test
4052 PROPERTIES
41- COMPILE_OPTIONS "--cpu=cortex-m4;--dlib_config=full;-e"
53+ COMPILE_OPTIONS "--cpu=cortex-m4;--dlib_config=full;-e;--no_wrap_diagnostics "
4254 LINK_LIBRARIES util
4355 LINK_OPTIONS "--cpu=cortex-m4;--semihosting;--redirect=_Printf=_PrintfFullNoMb"
4456)
4557
4658# Register unit tests
4759iar_cspysim (hello_test )
60+ iar_cspysim (crc16_test )
61+ iar_cspysim (crc32_test )
4862iar_cspysim (bm_search_test )
4963iar_cspysim (linear_search_test )
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright (c) 2020-2025, IAR Systems AB.
3+ SPDX-License-Identifier: MIT
4+ */
5+
6+ /*!
7+ \file crc16.c
8+ \brief Software implementation for CRC16
9+ \version 20250929
10+ */
11+
12+ #include <stddef.h>
13+ #include <stdint.h>
14+
15+ #define CRC16_POLY 0x1021
16+
17+ uint16_t crc16 (const char * data )
18+ {
19+ uint16_t crc = 0xFFFF ;
20+
21+ while (* data )
22+ {
23+ crc ^= ((uint8_t )(* data ++ ) << 8 );
24+ for (int i = 0 ; i < 8 ; i ++ )
25+ {
26+ if (crc & 0x8000 )
27+ crc = (crc << 1 ) ^ CRC16_POLY ;
28+ else
29+ crc <<= 1 ;
30+ }
31+ }
32+ return crc ;
33+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright (c) 2020-2025, IAR Systems AB.
3+ SPDX-License-Identifier: MIT
4+ */
5+
6+ /*!
7+ \file crc16_test.c
8+ \brief CRC16 test module
9+ \version 20250929
10+ */
11+
12+ #include <errno.h>
13+ #include "acutest.h"
14+ #include "util.h"
15+
16+
17+ void crc16_test ()
18+ {
19+ TEST_CASE ("The quick brown fox" );
20+ char * message = "The quick brown fox jumps over the lazy dog" ;
21+ uint16_t result = crc16 (message );
22+ TEST_CHECK (0x8FDD == result );
23+ }
24+
25+ TEST_LIST = {
26+ {"CRC16" , crc16_test },
27+
28+ {NULL , NULL }
29+ };
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright (c) 2020-2025, IAR Systems AB.
3+ SPDX-License-Identifier: MIT
4+ */
5+
6+ /*!
7+ \file crc32.c
8+ \brief Software implementation for CRC32
9+ \version 20250929
10+ */
11+
12+ #include <stddef.h>
13+ #include <stdint.h>
14+
15+ #define CRC32_POLY 0xEDB88320
16+
17+ uint32_t crc32 (const char * data )
18+ {
19+ uint32_t crc = 0xFFFFFFFF ;
20+
21+ while (* data )
22+ {
23+ crc ^= (uint8_t )(* data ++ );
24+ for (int i = 0 ; i < 8 ; i ++ )
25+ {
26+ if (crc & 1 )
27+ crc = (crc >> 1 ) ^ CRC32_POLY ;
28+ else
29+ crc >>= 1 ;
30+ }
31+ }
32+ return ~crc ;
33+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright (c) 2020-2025, IAR Systems AB.
3+ SPDX-License-Identifier: MIT
4+ */
5+
6+ /*!
7+ \file crc32_test.c
8+ \brief CRC32 test module
9+ \version 20250929
10+ */
11+
12+ #include <errno.h>
13+ #include "acutest.h"
14+ #include "util.h"
15+
16+ void crc32_test ()
17+ {
18+ TEST_CASE ("The quick brown fox" );
19+ char * message = "The quick brown fox jumps over the lazy dog" ;
20+ int32_t result = crc32 (message );
21+ TEST_CHECK (0x414fa339 == result );
22+ }
23+
24+ TEST_LIST = {
25+ {"CRC32" , crc32_test },
26+
27+ {NULL , NULL }
28+ };
Original file line number Diff line number Diff line change @@ -18,5 +18,7 @@ typedef struct data_s {
1818
1919const uint8_t * bm_search (const uint8_t * text , const uint8_t * pattern );
2020uint32_t linear_search (uint32_t x , const data_t * data );
21+ uint16_t crc16 (const char * data );
22+ uint32_t crc32 (const char * data );
2123
22- #endif /* __TEST_CONFIG__ */
24+ #endif /* __UTIL_H__ */
You can’t perform that action at this time.
0 commit comments