Skip to content

Commit ed1dfe9

Browse files
committed
Merge branch 'bugfix/cxx_guards_test_singlecore' into 'master'
unit tests: make static init guard test single core compatible See merge request idf/esp-idf!1615
2 parents 9ecd718 + 90ad7b4 commit ed1dfe9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

components/cxx/test/test_cxx.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,35 @@ template<> int SlowInit<2>::mInitBy = -1;
105105
template<> int SlowInit<2>::mInitCount = 0;
106106

107107
template<int obj>
108-
static void start_slow_init_task(int id, int affinity)
108+
static int start_slow_init_task(int id, int affinity)
109109
{
110-
xTaskCreatePinnedToCore(&SlowInit<obj>::task, "slow_init", 2048,
111-
reinterpret_cast<void*>(id), 3, NULL, affinity);
110+
return xTaskCreatePinnedToCore(&SlowInit<obj>::task, "slow_init", 2048,
111+
reinterpret_cast<void*>(id), 3, NULL, affinity) ? 1 : 0;
112112
}
113113

114114
TEST_CASE("static initialization guards work as expected", "[cxx]")
115115
{
116116
s_slow_init_sem = xSemaphoreCreateCounting(10, 0);
117117
TEST_ASSERT_NOT_NULL(s_slow_init_sem);
118+
int task_count = 0;
118119
// four tasks competing for static initialization of one object
119-
start_slow_init_task<1>(0, PRO_CPU_NUM);
120-
start_slow_init_task<1>(1, APP_CPU_NUM);
121-
start_slow_init_task<1>(2, PRO_CPU_NUM);
122-
start_slow_init_task<1>(3, tskNO_AFFINITY);
120+
task_count += start_slow_init_task<1>(0, PRO_CPU_NUM);
121+
#if portNUM_PROCESSORS == 2
122+
task_count += start_slow_init_task<1>(1, APP_CPU_NUM);
123+
#endif
124+
task_count += start_slow_init_task<1>(2, PRO_CPU_NUM);
125+
task_count += start_slow_init_task<1>(3, tskNO_AFFINITY);
123126

124127
// four tasks competing for static initialization of another object
125-
start_slow_init_task<2>(0, PRO_CPU_NUM);
126-
start_slow_init_task<2>(1, APP_CPU_NUM);
127-
start_slow_init_task<2>(2, PRO_CPU_NUM);
128-
start_slow_init_task<2>(3, tskNO_AFFINITY);
128+
task_count += start_slow_init_task<2>(0, PRO_CPU_NUM);
129+
#if portNUM_PROCESSORS == 2
130+
task_count += start_slow_init_task<2>(1, APP_CPU_NUM);
131+
#endif
132+
task_count += start_slow_init_task<2>(2, PRO_CPU_NUM);
133+
task_count += start_slow_init_task<2>(3, tskNO_AFFINITY);
129134

130135
// All tasks should
131-
for (int i = 0; i < 8; ++i) {
136+
for (int i = 0; i < task_count; ++i) {
132137
TEST_ASSERT_TRUE(xSemaphoreTake(s_slow_init_sem, 500/portTICK_PERIOD_MS));
133138
}
134139
vSemaphoreDelete(s_slow_init_sem);

0 commit comments

Comments
 (0)