-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Add Comments] components:libc:cplusplus:os/utest:Some comments have been initially … #10870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f585842
bfe680c
5de6ed9
e5875df
eb1d86a
41c5aa0
5983ccb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,21 @@ | |
|
|
||
| using namespace rtthread; | ||
|
|
||
| /** | ||
| * @brief Semaphore class implementation. | ||
| * @param name Semaphore name | ||
| * @param count Initial semaphore count | ||
| */ | ||
| Semaphore::Semaphore(const char *name, int32_t count) | ||
| { | ||
| rt_sem_init(&mID, name, count, RT_IPC_FLAG_FIFO); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Wait on the semaphore. | ||
| * @param millisec Timeout in milliseconds (-1 for infinite wait). | ||
| * @return true if the semaphore was successfully taken, false on timeout. | ||
| */ | ||
| bool Semaphore::wait(int32_t millisec) | ||
| { | ||
| rt_int32_t tick; | ||
|
|
@@ -28,11 +38,17 @@ bool Semaphore::wait(int32_t millisec) | |
| return rt_sem_take(&mID, tick) == RT_EOK; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Release the semaphore. | ||
| */ | ||
|
Comment on lines
+41
to
+43
|
||
| void Semaphore::release(void) | ||
| { | ||
| rt_sem_release(&mID); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Detach the semaphore when the object is destroyed. | ||
| */ | ||
| Semaphore::~Semaphore() | ||
| { | ||
| rt_sem_detach(&mID); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,13 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| using namespace rtthread; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @brief Thread class constructor with parameters for stack size, priority, tick, and name. | ||||||||||||||||||
|
||||||||||||||||||
| * @brief Thread class constructor with parameters for stack size, priority, tick, and name. | |
| * @brief Thread class constructor with parameters for stack size, priority, tick, and name. | |
| * @param stack_size Stack size in bytes | |
| * @param priority Thread priority | |
| * @param tick Time slice in ticks | |
| * @param name Thread name |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Incomplete Doxygen Comment / 不完整的 Doxygen 注释
English: The Doxygen comment should document all parameters. Add @param tags for entry, p, stack_size, priority, tick, and name parameters.
中文:Doxygen 注释应记录所有参数。为 entry、p、stack_size、priority、tick 和 name 参数添加 @param 标签。
| * @brief Thread class constructor with entry function and parameters. | |
| * @brief Thread class constructor with entry function and parameters. | |
| * @param entry The entry function pointer for the thread. | |
| * @param p The parameter to pass to the entry function. | |
| * @param stack_size The size of the thread stack in bytes. | |
| * @param priority The priority of the thread. | |
| * @param tick The time slice (tick) for the thread. | |
| * @param name The name of the thread. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void test_atomic_load_store_int32(void) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int kRound = 10000000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int kRound = 10000000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int32_t> thread_count(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int32_t> count(100); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(count.load(), 100); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,7 +56,7 @@ static void test_atomic_load_store_int32(void) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void test_atomic_load_store_int64(void) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int kRound = 10000000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int kRound = 10000000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int64_t> thread_count(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int64_t> count(100); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(count.load(), 100); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -121,9 +121,9 @@ static void test_atomic_basic_int32(void) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val.exchange(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(val.load(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int32_t x = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int32_t y = 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool exchanged = val.compare_exchange_strong(x, y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int32_t x = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int32_t y = 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool exchanged = val.compare_exchange_strong(x, y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_false(exchanged); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(val.load(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(x, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -168,9 +168,9 @@ static void test_atomic_basic_int64(void) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val.exchange(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(val.load(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t x = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t y = 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool exchanged = val.compare_exchange_strong(x, y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t x = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int64_t y = 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool exchanged = val.compare_exchange_strong(x, y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_false(exchanged); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(val.load(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(x, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -191,7 +191,7 @@ static void test_atomic_bool(void) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flag.exchange(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_false(flag.load()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool expected = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool desired = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool desired = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_true(flag.compare_exchange_strong(expected, desired)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_true(flag.load()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -201,7 +201,7 @@ static void test_atomic_bool(void) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void test_atomic_pointer(void) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int a = 1, b = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int a = 1, b = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int *> ptr(&a); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ptr.store(&b); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(*ptr.load(), 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -230,20 +230,21 @@ static void test_memory_order(void) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void test_compare_exchange_weak(void) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::atomic<int> val(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int expected = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int desired = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int expected = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int desired = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (!val.compare_exchange_weak(expected, desired)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expected = 1; // reset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uassert_int_equal(val.load(), 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test case initialization function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static rt_err_t utest_tc_init(void) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return RT_EOK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test case cleanup function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+241
to
+247
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test case initialization function. | |
| static rt_err_t utest_tc_init(void) | |
| { | |
| return RT_EOK; | |
| } | |
| // Test case cleanup function. | |
| /** | |
| * @brief Test case initialization function. | |
| * @return RT_EOK on success | |
| */ | |
| static rt_err_t utest_tc_init(void) | |
| { | |
| return RT_EOK; | |
| } | |
| /** | |
| * @brief Test case cleanup function. | |
| * @return RT_EOK on success | |
| */ |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment Style Inconsistency / 注释风格不一致
English: This comment uses // style while the file contains Doxygen-style comments elsewhere. For consistency, use the Doxygen format with /** */ and @brief tag.
中文:此注释使用 // 风格,而文件中其他地方包含 Doxygen 风格的注释。为了一致性,请使用带有 /** */ 和 @brief 标签的 Doxygen 格式。
Suggested format / 建议格式:
/**
* @brief Test case initialization function.
* @return RT_EOK on success
*/| // Test case initialization function. | |
| static rt_err_t utest_tc_init(void) | |
| { | |
| return RT_EOK; | |
| } | |
| // Test case cleanup function. | |
| /** | |
| * @brief Test case initialization function. | |
| * @return RT_EOK on success | |
| */ | |
| static rt_err_t utest_tc_init(void) | |
| { | |
| return RT_EOK; | |
| } | |
| /** | |
| * @brief Test case cleanup function. | |
| * @return RT_EOK on success | |
| */ |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,11 +35,17 @@ static void test_shared_ptr(void) | |||||||
| uassert_int_equal(p1.use_count(), 2); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * @brief Test case initialization function. | ||||||||
|
||||||||
| * @brief Test case initialization function. | |
| * @brief Test case initialization function. | |
| * @return RT_EOK on success |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,48 +12,70 @@ | |||||||
| #include "utest.h" | ||||||||
| #include <thread> | ||||||||
|
|
||||||||
|
|
||||||||
| /** | ||||||||
| * @brief Function to test thread functionality. | ||||||||
| */ | ||||||||
| static void test_thread(void) | ||||||||
| { | ||||||||
| int count = 0; | ||||||||
| auto func = [&]() mutable | ||||||||
| { | ||||||||
| int count = 0; | ||||||||
|
|
||||||||
| /* Lambda function to increment the count.*/ | ||||||||
| auto func = [&]() mutable { | ||||||||
| for (int i = 0; i < 100; ++i) | ||||||||
| { | ||||||||
| ++count; | ||||||||
| ++count; | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| /* Create and run a thread executing the lambda function. */ | ||||||||
| std::thread t1(func); | ||||||||
| t1.join(); | ||||||||
| /* Wait for the thread to finish execution.*/ | ||||||||
| t1.join(); | ||||||||
|
|
||||||||
| /* Verify if the count is as expected after the first thread execution.*/ | ||||||||
| if (count != 100) | ||||||||
| { | ||||||||
| uassert_false(1); | ||||||||
| uassert_false(1); | ||||||||
| } | ||||||||
|
|
||||||||
| /* Create and run another thread executing the same lambda function. */ | ||||||||
| std::thread t2(func); | ||||||||
| t2.join(); | ||||||||
| t2.join(); | ||||||||
|
|
||||||||
| if (count != 200) | ||||||||
| { | ||||||||
| uassert_false(1); | ||||||||
| uassert_false(1); | ||||||||
| } | ||||||||
|
|
||||||||
| /* If both assertions passed, the test is successful.*/ | ||||||||
| uassert_true(1); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| /** | ||||||||
| * @brief Test case initialization function. | ||||||||
|
||||||||
| * @brief Test case initialization function. | |
| * @brief Test case initialization function. | |
| * @return RT_EOK on success |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Incomplete Doxygen Comment / 不完整的 Doxygen 注释
English: The Doxygen comment should document the return value. Add @return RT_EOK on success for consistency and completeness.
中文:Doxygen 注释应记录返回值。添加 @return RT_EOK on success 以保持一致性和完整性。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Incomplete Doxygen Comment / 不完整的 Doxygen 注释
English: The Doxygen comment should document the constructor parameters. Add
@paramtags for name and count parameters.中文:Doxygen 注释应记录构造函数参数。为 name 和 count 参数添加
@param标签。Suggested format / 建议格式: