Greentea: Add required header file and namespace element instead add all

1. RTOS is needed only for Stack stats

Move+Add all required header files for RTOS into MBED_STACK_STATS_ENABLED
define. Also added 'using namespace'

2.  Add heap stats only when MBED_HEAP_STATS_ENABLED
pull/8008/head
deepikabhavnani 2018-10-08 12:55:48 -05:00 committed by Deepika
parent f58e103758
commit e95d08e471
1 changed files with 22 additions and 4 deletions

View File

@ -15,12 +15,10 @@
* limitations under the License.
*/
#include "mbed_stats.h"
#include "cmsis_os2.h"
#include "greentea-client/test_env.h"
#include "greentea-client/greentea_metrics.h"
#include "SingletonPtr.h"
#include "CircularBuffer.h"
#include "platform/mbed_stats.h"
#include <stdint.h>
#define THREAD_BUF_COUNT 16
@ -31,6 +29,20 @@ typedef struct {
} thread_info_t;
#if defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED
#if !defined(MBED_CONF_RTOS_PRESENT) || !(MBED_CONF_RTOS_PRESENT)
#error "RTOS required for Stack stats"
#endif
#include "rtos/Mutex.h"
#include "rtos/Thread.h"
#include "mbed_stats.h"
#include "cmsis_os2.h"
#include "platform/SingletonPtr.h"
#include "platform/CircularBuffer.h"
using namespace mbed;
using namespace rtos;
// Mutex to protect "buf"
static SingletonPtr<Mutex> mutex;
static char buf[128];
@ -41,7 +53,9 @@ static SingletonPtr<CircularBuffer<thread_info_t, THREAD_BUF_COUNT> > queue;
static void send_CPU_info(void);
#endif
#if defined(MBED_HEAP_STATS_ENABLED ) && MBED_HEAP_STATS_ENABLED
static void send_heap_info(void);
#endif
#if defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED
static void send_stack_info(void);
static void on_thread_terminate(osThreadId_t id);
@ -62,7 +76,9 @@ void greentea_metrics_setup()
void greentea_metrics_report()
{
#if defined(MBED_HEAP_STATS_ENABLED ) && MBED_HEAP_STATS_ENABLED
send_heap_info();
#endif
#if defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED
send_stack_info();
Kernel::attach_thread_terminate_hook(NULL);
@ -85,6 +101,7 @@ static void send_CPU_info()
}
#endif
#if defined(MBED_HEAP_STATS_ENABLED ) && MBED_HEAP_STATS_ENABLED
static void send_heap_info()
{
mbed_stats_heap_t heap_stats;
@ -92,6 +109,7 @@ static void send_heap_info()
greentea_send_kv("max_heap_usage",heap_stats.max_size);
greentea_send_kv("reserved_heap",heap_stats.reserved_size);
}
#endif
#if defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED
MBED_UNUSED static void send_stack_info()