Checking difference in thread count + review comments

pull/6795/head
deepikabhavnani 2018-05-03 10:36:46 -05:00 committed by Deepika
parent 1dad73949c
commit bb8ccbd373
1 changed files with 43 additions and 37 deletions

View File

@ -1,26 +1,25 @@
/*
* Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest/utest.h"
#include "mbed_stats.h"
#include <stdlib.h>
#include <stdio.h>
#include "mbed.h"
#if !defined(MBED_THREAD_STATS_ENABLED)
#warning [NOT_SUPPORTED] test not supported
@ -53,52 +52,57 @@ void increment_with_delay()
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");
t1.start(increment_with_delay);
// 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(4, count);
TEST_ASSERT_EQUAL(1, (count-old_count));
for (int i = 0; i < count; i++) {
if (0 == strcmp (stats[i].thread_name, "Th1")) {
for(int i = 0; i < count; i++) {
if(0 == strcmp(stats[i].thread_name, "Th1")) {
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal, stats[i].thread_priority);
break;
}
}
delete[] stats;
t1.terminate();
delete[] stats;
}
#define SINGLE_ELEMENT 1
void test_case_less_count()
{
// Default Mbed OS has 3 threads
mbed_stats_thread_t *stats = new mbed_stats_thread_t[2];
int count = mbed_stats_thread_get_each(stats, 2);
TEST_ASSERT_EQUAL(2, count);
delete[] stats;
mbed_stats_thread_t stats;
int count = mbed_stats_thread_get_each(&stats, SINGLE_ELEMENT);
TEST_ASSERT_EQUAL(SINGLE_ELEMENT, count);
}
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 t2(osPriorityNormal1, TEST_STACK_SIZE, NULL, "Th2");
t1.start(increment_with_delay);
t2.start(decrement_on_event);
// 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);
for (int i = 0; i < count; i++) {
if (0 == strcmp (stats[i].thread_name, "Th2")) {
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++) {
if(0 == strcmp(stats[i].thread_name, "Th2")) {
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal1, stats[i].thread_priority);
TEST_ASSERT_EQUAL(osThreadBlocked, stats[i].thread_state);
} else if (0 == strcmp (stats[i].thread_name, "Th1")) {
} else if(0 == strcmp (stats[i].thread_name, "Th1")) {
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal, stats[i].thread_priority);
}
@ -111,29 +115,32 @@ void test_case_multi_threads_blocked()
Thread::wait(100);
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();
delete[] stats;
}
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 t2(osPriorityNormal2, TEST_STACK_SIZE, NULL, "Th2");
t2.start(increment_with_delay);
t1.start(decrement_on_event);
// 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);
for (int i = 0; i < count; i++) {
if (0 == strcmp (stats[i].thread_name, "Th2")) {
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++) {
if(0 == strcmp(stats[i].thread_name, "Th2")) {
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal2, stats[i].thread_priority);
} else if (0 == strcmp (stats[i].thread_name, "Th1")) {
} else if(0 == strcmp(stats[i].thread_name, "Th1")) {
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].thread_stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal1, stats[i].thread_priority);
TEST_ASSERT_EQUAL(osThreadBlocked, stats[i].thread_state);
@ -144,10 +151,9 @@ void test_case_multi_threads_terminate()
t2.terminate();
count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS);
TEST_ASSERT_EQUAL(3, count);
TEST_ASSERT_EQUAL(count, old_count);
delete[] stats;
t1.terminate();
}
Case cases[] = {