2020 */
2121static void test_atomic_load_store_int32 (void )
2222{
23- constexpr int kRound = 10000000 ;
23+ constexpr int kRound = 10000000 ;
2424 std::atomic<int32_t > thread_count (0 );
2525 std::atomic<int32_t > count (100 );
2626 uassert_int_equal (count.load (), 100 );
@@ -56,7 +56,7 @@ static void test_atomic_load_store_int32(void)
5656 */
5757static void test_atomic_load_store_int64 (void )
5858{
59- constexpr int kRound = 10000000 ;
59+ constexpr int kRound = 10000000 ;
6060 std::atomic<int64_t > thread_count (0 );
6161 std::atomic<int64_t > count (100 );
6262 uassert_int_equal (count.load (), 100 );
@@ -112,7 +112,7 @@ static void test_atomic_basic_int32(void)
112112 val.fetch_and (14 );
113113 uassert_int_equal (val.load (), 10 );
114114
115- val.fetch_or (11 ); // 1010
115+ val.fetch_or (11 ); /* 1010 */
116116 uassert_int_equal (val.load (), 11 );
117117
118118 val.fetch_xor (4 );
@@ -121,9 +121,9 @@ static void test_atomic_basic_int32(void)
121121 val.exchange (1 );
122122 uassert_int_equal (val.load (), 1 );
123123
124- int32_t x = 2 ;
125- int32_t y = 3 ;
126- bool exchanged = val.compare_exchange_strong (x, y);
124+ int32_t x = 2 ;
125+ int32_t y = 3 ;
126+ bool exchanged = val.compare_exchange_strong (x, y);
127127 uassert_false (exchanged);
128128 uassert_int_equal (val.load (), 1 );
129129 uassert_int_equal (x, 1 );
@@ -159,7 +159,7 @@ static void test_atomic_basic_int64(void)
159159 val.fetch_and (14 );
160160 uassert_int_equal (val.load (), 10 );
161161
162- val.fetch_or (11 ); // 1010
162+ val.fetch_or (11 ); /* 1010 */
163163 uassert_int_equal (val.load (), 11 );
164164
165165 val.fetch_xor (4 );
@@ -168,9 +168,9 @@ static void test_atomic_basic_int64(void)
168168 val.exchange (1 );
169169 uassert_int_equal (val.load (), 1 );
170170
171- int64_t x = 2 ;
172- int64_t y = 3 ;
173- bool exchanged = val.compare_exchange_strong (x, y);
171+ int64_t x = 2 ;
172+ int64_t y = 3 ;
173+ bool exchanged = val.compare_exchange_strong (x, y);
174174 uassert_false (exchanged);
175175 uassert_int_equal (val.load (), 1 );
176176 uassert_int_equal (x, 1 );
@@ -191,7 +191,7 @@ static void test_atomic_bool(void)
191191 flag.exchange (false );
192192 uassert_false (flag.load ());
193193 bool expected = false ;
194- bool desired = true ;
194+ bool desired = true ;
195195 uassert_true (flag.compare_exchange_strong (expected, desired));
196196 uassert_true (flag.load ());
197197}
@@ -201,7 +201,7 @@ static void test_atomic_bool(void)
201201 */
202202static void test_atomic_pointer (void )
203203{
204- int a = 1 , b = 2 ;
204+ int a = 1 , b = 2 ;
205205 std::atomic<int *> ptr (&a);
206206 ptr.store (&b);
207207 uassert_int_equal (*ptr.load (), 2 );
@@ -217,7 +217,7 @@ static void test_memory_order(void)
217217{
218218 std::atomic<int > x (0 );
219219 std::atomic<int > y (0 );
220- // Simple test for memory order
220+ /* Simple test for memory order */
221221 x.store (1 , std::memory_order_release);
222222 y.store (2 , std::memory_order_release);
223223 uassert_int_equal (x.load (std::memory_order_acquire), 1 );
@@ -230,25 +230,36 @@ static void test_memory_order(void)
230230static void test_compare_exchange_weak (void )
231231{
232232 std::atomic<int > val (1 );
233- int expected = 1 ;
234- int desired = 2 ;
233+ int expected = 1 ;
234+ int desired = 2 ;
235235 while (!val.compare_exchange_weak (expected, desired))
236236 {
237- expected = 1 ; // reset
237+ /* Reset */
238+ expected = 1 ;
238239 }
239240 uassert_int_equal (val.load (), 2 );
240241}
241-
242+ /* *
243+ * @brief Test case initialization function.
244+ * @return RT_EOK on success.
245+ */
242246static rt_err_t utest_tc_init (void )
243247{
244248 return RT_EOK ;
245249}
246250
251+ /* *
252+ * @brief Test case cleanup function.
253+ * @return RT_EOK on success.
254+ */
247255static rt_err_t utest_tc_cleanup (void )
248256{
249257 return RT_EOK ;
250258}
251259
260+ /* *
261+ * @brief Main test case function that runs the test.
262+ */
252263static void testcase (void )
253264{
254265 /* Test load and store operations for int32_t atomic variables in multi-threaded environment */
@@ -268,4 +279,6 @@ static void testcase(void)
268279 /* Test compare_exchange_weak operation */
269280 UTEST_UNIT_RUN (test_compare_exchange_weak);
270281}
271- UTEST_TC_EXPORT (testcase, " components.libc.cpp.atomic_tc" , utest_tc_init, utest_tc_cleanup, 10 );
282+
283+ /* Export the test case with initialization and cleanup functions and a timeout of 10 ticks. */
284+ UTEST_TC_EXPORT (testcase, " components.libc.cpp.atomic_tc" , utest_tc_init, utest_tc_cleanup, 10 );
0 commit comments