mirror of https://github.com/ARMmbed/mbed-os.git
Checking difference in thread count + review comments
parent
1dad73949c
commit
bb8ccbd373
|
@ -1,26 +1,25 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
|
/* mbed Microcontroller Library
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* Copyright (c) 2018 ARM Limited
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "mbed.h"
|
|
||||||
#include "greentea-client/test_env.h"
|
#include "greentea-client/test_env.h"
|
||||||
#include "unity/unity.h"
|
#include "unity/unity.h"
|
||||||
#include "utest/utest.h"
|
#include "utest/utest.h"
|
||||||
#include "mbed_stats.h"
|
|
||||||
#include <stdlib.h>
|
#include "mbed.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#if !defined(MBED_THREAD_STATS_ENABLED)
|
#if !defined(MBED_THREAD_STATS_ENABLED)
|
||||||
#warning [NOT_SUPPORTED] test not supported
|
#warning [NOT_SUPPORTED] test not supported
|
||||||
|
@ -53,13 +52,15 @@ void increment_with_delay()
|
||||||
|
|
||||||
void test_case_single_thread_stats()
|
void test_case_single_thread_stats()
|
||||||
{
|
{
|
||||||
|
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
|
||||||
|
int old_count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
|
|
||||||
Thread t1(osPriorityNormal, TEST_STACK_SIZE, NULL, "Th1");
|
Thread t1(osPriorityNormal, TEST_STACK_SIZE, NULL, "Th1");
|
||||||
t1.start(increment_with_delay);
|
t1.start(increment_with_delay);
|
||||||
|
|
||||||
// Read stats
|
// Read stats
|
||||||
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
|
|
||||||
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
TEST_ASSERT_EQUAL(4, count);
|
TEST_ASSERT_EQUAL(1, (count-old_count));
|
||||||
|
|
||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
if(0 == strcmp(stats[i].thread_name, "Th1")) {
|
if(0 == strcmp(stats[i].thread_name, "Th1")) {
|
||||||
|
@ -68,31 +69,34 @@ void test_case_single_thread_stats()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] stats;
|
|
||||||
t1.terminate();
|
t1.terminate();
|
||||||
|
delete[] stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SINGLE_ELEMENT 1
|
||||||
void test_case_less_count()
|
void test_case_less_count()
|
||||||
{
|
{
|
||||||
// Default Mbed OS has 3 threads
|
// Default Mbed OS has 3 threads
|
||||||
mbed_stats_thread_t *stats = new mbed_stats_thread_t[2];
|
mbed_stats_thread_t stats;
|
||||||
int count = mbed_stats_thread_get_each(stats, 2);
|
int count = mbed_stats_thread_get_each(&stats, SINGLE_ELEMENT);
|
||||||
TEST_ASSERT_EQUAL(2, count);
|
TEST_ASSERT_EQUAL(SINGLE_ELEMENT, count);
|
||||||
delete[] stats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_case_multi_threads_blocked()
|
void test_case_multi_threads_blocked()
|
||||||
{
|
{
|
||||||
|
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
|
||||||
|
int old_count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
|
|
||||||
Thread t1(osPriorityNormal, TEST_STACK_SIZE, NULL, "Th1");
|
Thread t1(osPriorityNormal, TEST_STACK_SIZE, NULL, "Th1");
|
||||||
Thread t2(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th2");
|
Thread t2(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th2");
|
||||||
t1.start(increment_with_delay);
|
t1.start(increment_with_delay);
|
||||||
t2.start(decrement_on_event);
|
t2.start(decrement_on_event);
|
||||||
|
|
||||||
// Read stats
|
// Read stats
|
||||||
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
|
|
||||||
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
|
||||||
TEST_ASSERT_EQUAL(5, count);
|
|
||||||
|
|
||||||
|
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
|
TEST_ASSERT_EQUAL(2, (count-old_count));
|
||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
if(0 == strcmp(stats[i].thread_name, "Th2")) {
|
if(0 == strcmp(stats[i].thread_name, "Th2")) {
|
||||||
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
|
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
|
||||||
|
@ -111,23 +115,26 @@ void test_case_multi_threads_blocked()
|
||||||
Thread::wait(100);
|
Thread::wait(100);
|
||||||
|
|
||||||
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
TEST_ASSERT_EQUAL(4, count);
|
TEST_ASSERT_EQUAL(1, (count-old_count));
|
||||||
|
|
||||||
delete[] stats;
|
|
||||||
t1.terminate();
|
t1.terminate();
|
||||||
|
delete[] stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_case_multi_threads_terminate()
|
void test_case_multi_threads_terminate()
|
||||||
{
|
{
|
||||||
|
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
|
||||||
|
int old_count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
|
|
||||||
Thread t1(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th1");
|
Thread t1(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th1");
|
||||||
Thread t2(osPriorityNormal2, TEST_STACK_SIZE, NULL, "Th2");
|
Thread t2(osPriorityNormal2, TEST_STACK_SIZE, NULL, "Th2");
|
||||||
t2.start(increment_with_delay);
|
t2.start(increment_with_delay);
|
||||||
t1.start(decrement_on_event);
|
t1.start(decrement_on_event);
|
||||||
|
|
||||||
// Read stats
|
// Read stats
|
||||||
mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS];
|
|
||||||
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
TEST_ASSERT_EQUAL(5, count);
|
TEST_ASSERT_EQUAL(2, (count-old_count));
|
||||||
|
|
||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
if(0 == strcmp(stats[i].thread_name, "Th2")) {
|
if(0 == strcmp(stats[i].thread_name, "Th2")) {
|
||||||
|
@ -144,10 +151,9 @@ void test_case_multi_threads_terminate()
|
||||||
t2.terminate();
|
t2.terminate();
|
||||||
|
|
||||||
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
|
||||||
TEST_ASSERT_EQUAL(3, count);
|
TEST_ASSERT_EQUAL(count, old_count);
|
||||||
|
|
||||||
delete[] stats;
|
delete[] stats;
|
||||||
t1.terminate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Case cases[] = {
|
Case cases[] = {
|
||||||
|
|
Loading…
Reference in New Issue