Skip to content

Commit 51ea5d0

Browse files
github-actions[bot]lct1001
authored andcommitted
components:libc:cplusplus:os/utest:Some comments have been initially added.
Some comments have been initially added as a bignner task. components/libc/cplusplus/os/cxx_Semaphore.cpp components/libc/cplusplus/os/cxx_Thread.cpp components/libc/cplusplus/utest/tc_atomic.cpp components/libc/cplusplus/utest/tc_smartptr.cpp components/libc/cplusplus/utest/tc_thread.cpp Signed-off-by:Liu Chengtao<2739960959@qq.com>
1 parent eb1d86a commit 51ea5d0

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

components/libc/cplusplus/os/cxx_Semaphore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using namespace rtthread;
1313

1414
/**
15-
* @brief Semaphore class implementation.
15+
* @brief Semaphore class constructor.
1616
* @param name Semaphore name
1717
* @param count Initial semaphore count
1818
*/

components/libc/cplusplus/os/cxx_Thread.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void Thread::sleep(int32_t millisec)
101101
}
102102

103103
/**
104-
* @brief function to run the thread's entry function.
104+
* @brief Function to run the thread's entry function.
105105
*/
106106
void Thread::func(Thread *pThis)
107107
{
@@ -136,9 +136,9 @@ rt_err_t Thread::wait(int32_t millisec)
136136
}
137137

138138
/**
139-
* @brief the thread with a timeout.
139+
* @brief Join the thread with a timeout.
140140
* @param millisec Timeout in milliseconds.
141-
* @return Status code indicating the execution status.
141+
* @return RT_EOK if the thread completed within the timeout, error code otherwise.
142142
*/
143143
rt_err_t Thread::join(int32_t millisec)
144144
{
@@ -156,4 +156,4 @@ rt_err_t Thread::join(int32_t millisec)
156156
{
157157
return -RT_ENOSYS;
158158
}
159-
}
159+
}

components/libc/cplusplus/utest/tc_atomic.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
@@ -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);
@@ -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);
@@ -234,22 +234,32 @@ static void test_compare_exchange_weak(void)
234234
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-
// Test case initialization function.
242+
/**
243+
* @brief Test case initialization function.
244+
* @return RT_EOK on success.
245+
*/
242246
static rt_err_t utest_tc_init(void)
243247
{
244248
return RT_EOK;
245249
}
246250

247-
// Test case cleanup function.
251+
/**
252+
* @brief Test case cleanup function.
253+
* @return RT_EOK on success.
254+
*/
248255
static rt_err_t utest_tc_cleanup(void)
249256
{
250257
return RT_EOK;
251258
}
252259

260+
/**
261+
* @brief Main test case function that runs the test.
262+
*/
253263
static void testcase(void)
254264
{
255265
/* Test load and store operations for int32_t atomic variables in multi-threaded environment */
@@ -269,4 +279,6 @@ static void testcase(void)
269279
/* Test compare_exchange_weak operation */
270280
UTEST_UNIT_RUN(test_compare_exchange_weak);
271281
}
282+
283+
/* Export the test case with initialization and cleanup functions and a timeout of 10 ticks. */
272284
UTEST_TC_EXPORT(testcase, "components.libc.cpp.atomic_tc", utest_tc_init, utest_tc_cleanup, 10);

components/libc/cplusplus/utest/tc_smartptr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static void test_shared_ptr(void)
3737

3838
/**
3939
* @brief Test case initialization function.
40+
* @return RT_EOK on success.
4041
*/
4142
static rt_err_t utest_tc_init(void)
4243
{
@@ -45,17 +46,23 @@ static rt_err_t utest_tc_init(void)
4546

4647
/**
4748
* @brief Test case cleanup function.
49+
* @return RT_EOK on success.
4850
*/
4951
static rt_err_t utest_tc_cleanup(void)
5052
{
5153
return RT_EOK;
5254
}
5355

56+
/**
57+
* @brief Main test case function that runs the test.
58+
*/
5459
static void testcase(void)
5560
{
5661
/* Test unique_ptr basic operations */
5762
UTEST_UNIT_RUN(test_unique_ptr);
5863
/* Test shared_ptr basic operations */
5964
UTEST_UNIT_RUN(test_shared_ptr);
6065
}
66+
67+
/* Export the test case with initialization and cleanup functions and a timeout of 10 ticks. */
6168
UTEST_TC_EXPORT(testcase, "components.libc.cpp.smartptr_tc", utest_tc_init, utest_tc_cleanup, 10);

components/libc/cplusplus/utest/tc_thread.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,52 @@
1818
*/
1919
static void test_thread(void)
2020
{
21-
int count = 0;
21+
int count = 0;
2222

23-
/* Lambda function to increment the count.*/
23+
/* Lambda function to increment the count. */
2424
auto func = [&]() mutable {
2525
for (int i = 0; i < 100; ++i)
2626
{
27-
++count;
27+
++count;
2828
}
2929
};
3030

3131
/* Create and run a thread executing the lambda function. */
3232
std::thread t1(func);
33-
/* Wait for the thread to finish execution.*/
34-
t1.join();
33+
/* Wait for the thread to finish execution. */
34+
t1.join();
3535

36-
/* Verify if the count is as expected after the first thread execution.*/
36+
/* Verify if the count is as expected after the first thread execution. */
3737
if (count != 100)
3838
{
39-
uassert_false(1);
39+
uassert_false(1);
4040
}
4141

4242
/* Create and run another thread executing the same lambda function. */
4343
std::thread t2(func);
44-
t2.join();
44+
t2.join();
4545

4646
if (count != 200)
4747
{
48-
uassert_false(1);
48+
uassert_false(1);
4949
}
5050

51-
/* If both assertions passed, the test is successful.*/
51+
/* If both assertions passed, the test is successful. */
5252
uassert_true(1);
5353
}
5454

5555

5656
/**
5757
* @brief Test case initialization function.
58+
* @return RT_EOK on success.
5859
*/
59-
6060
static rt_err_t utest_tc_init(void)
6161
{
6262
return RT_EOK;
6363
}
6464
/**
6565
* @brief Test case cleanup function.
66+
* @return RT_EOK on success.
6667
*/
6768
static rt_err_t utest_tc_cleanup(void)
6869
{

0 commit comments

Comments
 (0)