Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 * Copyright (c) 2013-2017, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "mbed.h" 00018 #include "greentea-client/test_env.h" 00019 #include "utest/utest.h" 00020 #include "unity/unity.h" 00021 00022 #if defined(MBED_RTOS_SINGLE_THREAD) 00023 #error [NOT_SUPPORTED] test not supported 00024 #endif 00025 00026 #if !DEVICE_USTICKER 00027 #error [NOT_SUPPORTED] test not supported 00028 #endif 00029 00030 //FastModels not support time drifting test 00031 #if defined(__ARM_FM) 00032 #error [NOT_SUPPORTED] test not supported 00033 #endif 00034 00035 using utest::v1::Case; 00036 00037 #if defined(__CORTEX_M23) || defined(__CORTEX_M33) 00038 #define TEST_STACK_SIZE 512 00039 #else 00040 #define TEST_STACK_SIZE 256 00041 #endif 00042 #define ONE_MILLI_SEC 1000 00043 00044 volatile uint32_t elapsed_time_ms = 0; 00045 static const int test_timeout = 40; 00046 00047 00048 void update_tick_thread(Mutex *mutex) 00049 { 00050 while (true) { 00051 Thread::wait(1); 00052 mutex->lock(); 00053 ++elapsed_time_ms; 00054 mutex->unlock(); 00055 } 00056 } 00057 00058 00059 /** Tests is to measure the accuracy of Thread::wait() over a period of time 00060 00061 Given 00062 a thread updating elapsed_time_ms every milli sec 00063 and host script for time measurement accuracy check (More details on tests can be found in timing_drift_auto.py) 00064 When host query what is current count base_time 00065 Then Device responds by the elapsed_time_ms 00066 When host query what is current count final_time 00067 Then Device responds by the elapsed_time_ms 00068 When host computes the drift considering base_time, final_time, transport delay and measurement stretch 00069 Then host send the results back to device pass/fail based on tolerance 00070 */ 00071 void test(void) 00072 { 00073 char _key[11] = { }; 00074 char _value[128] = { }; 00075 int expected_key = 1; 00076 Mutex mutex; 00077 uint32_t elapsed_time; 00078 00079 Thread tick_thread(osPriorityHigh, TEST_STACK_SIZE); 00080 tick_thread.start(callback(update_tick_thread, &mutex)); 00081 00082 greentea_send_kv("timing_drift_check_start", 0); 00083 00084 // wait for 1st signal from host 00085 do { 00086 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00087 expected_key = strcmp(_key, "base_time"); 00088 } while (expected_key); 00089 00090 mutex.lock(); 00091 elapsed_time = elapsed_time_ms; 00092 mutex.unlock(); 00093 // send base_time 00094 greentea_send_kv(_key, elapsed_time * ONE_MILLI_SEC); 00095 00096 // wait for 2nd signal from host 00097 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00098 00099 mutex.lock(); 00100 elapsed_time = elapsed_time_ms; 00101 mutex.unlock(); 00102 // send final_time 00103 greentea_send_kv(_key, elapsed_time * ONE_MILLI_SEC); 00104 00105 //get the results from host 00106 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00107 00108 TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key, "Host side script reported a fail..."); 00109 } 00110 00111 Case cases[] = { 00112 Case("Test Thread::wait accuracy", test) 00113 }; 00114 00115 utest::v1::status_t greentea_test_setup(const size_t number_of_cases) 00116 { 00117 GREENTEA_SETUP(test_timeout, "timing_drift_auto"); 00118 return utest::v1::greentea_test_setup_handler(number_of_cases); 00119 } 00120 00121 utest::v1::Specification specification(greentea_test_setup, cases); 00122 00123 int main() 00124 { 00125 utest::v1::Harness::run(specification); 00126 }
Generated on Tue Aug 9 2022 00:37:14 by
1.7.2