refactor(core): reformat newlib and pthread with astyle

This commit is contained in:
Marius Vikhammer
2024-02-27 10:00:06 +08:00
parent b39f13d685
commit f2fe408b99
39 changed files with 442 additions and 460 deletions
@@ -11,7 +11,6 @@
#include "unity_test_runner.h"
#include "esp_heap_caps.h"
// Some resources are lazy allocated (e.g. newlib locks), the threshold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (-200)
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -24,10 +24,13 @@ static void waits(int idx, int timeout_ms)
std::unique_lock<std::mutex> lk(cv_m);
auto now = std::chrono::system_clock::now();
if(cv.wait_until(lk, now + std::chrono::milliseconds(timeout_ms), [](){return i == 1;}))
std::cout << "Thread " << idx << " finished waiting. i == " << i << '\n';
else
if (cv.wait_until(lk, now + std::chrono::milliseconds(timeout_ms), []() {
return i == 1;
}))
std::cout << "Thread " << idx << " finished waiting. i == " << i << '\n';
else {
std::cout << "Thread " << idx << " timed out. i == " << i << '\n';
}
}
static void signals(int signal_ms)
@@ -53,7 +56,6 @@ TEST_CASE("C++ condition_variable", "[std::condition_variable]")
std::cout << "All threads joined\n";
}
TEST_CASE("cxx: condition_variable can timeout", "[cxx]")
{
std::condition_variable cv;
@@ -76,19 +78,20 @@ TEST_CASE("cxx: condition_variable timeout never before deadline", "[cxx]")
std::unique_lock<std::mutex> lock(mutex);
for (int i = 0; i < 25; ++i) {
auto timeout = std::chrono::milliseconds(portTICK_PERIOD_MS * (i+1));
auto timeout = std::chrono::milliseconds(portTICK_PERIOD_MS * (i + 1));
auto deadline = SysClock::now() + timeout;
auto secs = std::chrono::time_point_cast<std::chrono::seconds>(deadline);
auto nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>
(deadline - secs);
(deadline - secs);
struct timespec ts = {
.tv_sec = static_cast<time_t>(secs.time_since_epoch().count()),
.tv_nsec = static_cast<long>(nsecs.count())};
.tv_sec = static_cast<time_t>(secs.time_since_epoch().count()),
.tv_nsec = static_cast<long>(nsecs.count())
};
int rc = ::pthread_cond_timedwait(cond.native_handle(),
lock.mutex()->native_handle(), &ts);
auto status = (rc == ETIMEDOUT) ? std::cv_status::timeout :
std::cv_status::no_timeout;
std::cv_status::no_timeout;
auto end = SysClock::now();
auto extra = end - deadline;
auto extra_us = extra / std::chrono::microseconds(1);
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -12,17 +12,17 @@
TEST_CASE("C++ future", "[std::future]")
{
// future from a packaged_task
std::packaged_task<int()> task([]{ return 7; }); // wrap the function
std::packaged_task<int()> task([] { return 7; }); // wrap the function
std::future<int> f1 = task.get_future(); // get a future
std::thread t(std::move(task)); // launch on a thread
// future from an async()
std::future<int> f2 = std::async(std::launch::async, []{ return 8; });
std::future<int> f2 = std::async(std::launch::async, [] { return 8; });
// future from a promise
std::promise<int> p;
std::future<int> f3 = p.get_future();
std::thread( [&p]{ p.set_value_at_thread_exit(9); }).detach();
std::thread([&p] { p.set_value_at_thread_exit(9); }).detach();
std::cout << "Waiting..." << std::flush;
f1.wait();
@@ -232,7 +232,7 @@ static void test_mutex_lock_unlock(int mutex_type)
res = pthread_mutex_lock(&mutex);
if(mutex_type == PTHREAD_MUTEX_ERRORCHECK) {
if (mutex_type == PTHREAD_MUTEX_ERRORCHECK) {
TEST_ASSERT_EQUAL_INT(EDEADLK, res);
} else {
TEST_ASSERT_EQUAL_INT(0, res);
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -114,7 +114,7 @@ TEST_CASE("pthread local storage destructor in FreeRTOS task", "[thread-specific
TEST_ASSERT_EQUAL(0, pthread_key_create(&key, test_pthread_destructor));
xTaskCreate(task_test_pthread_destructor,
"ptdest", 8192, (void *)key, UNITY_FREERTOS_PRIORITY+1,
"ptdest", 8192, (void *)key, UNITY_FREERTOS_PRIORITY + 1,
NULL);
// Above task has higher priority to us, so should run immediately
@@ -146,14 +146,13 @@ static void *thread_stress_test(void *v_key)
pthread_setspecific(key, tls_value);
for(int i = 0; i < STRESS_NUMITER; i++) {
for (int i = 0; i < STRESS_NUMITER; i++) {
TEST_ASSERT_EQUAL_HEX32(pthread_getspecific(key), tls_value);
}
return NULL;
}
// This test case added to reproduce issues with unpinned tasks and TLS
TEST_CASE("pthread local storage stress test", "[thread-specific]")
{
@@ -169,7 +168,6 @@ TEST_CASE("pthread local storage stress test", "[thread-specific]")
}
}
#define NUM_KEYS 4 // number of keys used in repeat destructor test
#define NUM_REPEATS 17 // number of times we re-set a key to a non-NULL value to re-trigger destructor
@@ -179,7 +177,6 @@ typedef struct {
int last_idx; // index of last key where destructor was called
} destr_test_state_t;
static void s_test_repeat_destructor(void *vp_state);
static void *s_test_repeat_destructor_thread(void *vp_state);
@@ -202,7 +199,7 @@ TEST_CASE("pthread local storage 'repeat' destructor test", "[thread-specific]")
TEST_ASSERT_EQUAL(0, r);
r = pthread_join(thread, NULL);
TEST_ASSERT_EQUAL(0 ,r);
TEST_ASSERT_EQUAL(0, r);
// Cheating here to make sure compiler reads the value of 'count' from memory not from a register
//