int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Interrupt vector relocation); MBED_HOSTTEST_START("MBED_A18"); // First test, no table reallocation { printf("Starting first test (interrupts not relocated).\r\n"); bool ret = test_once(); if (ret == false) { MBED_HOSTTEST_RESULT(false); } } // Relocate interrupt table and test again { printf("Starting second test (interrupts relocated).\r\n"); memcpy(int_table, (void*)SCB->VTOR, sizeof(int_table)); SCB->VTOR = (uint32_t)int_table; bool ret = test_once(); if (ret == false) { MBED_HOSTTEST_RESULT(false); } } MBED_HOSTTEST_RESULT(true); }
int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(HTTP client hello world); MBED_HOSTTEST_START("NET_7"); char http_request_buffer[BUFFER_SIZE + 1] = {0}; HTTPClient http; EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); //GET data { bool result = true; const char *url_hello_txt = "http://developer.mbed.org/media/uploads/donatien/hello.txt"; printf("HTTP_GET: Trying to fetch page '%s'...\r\n", url_hello_txt); HTTPResult ret = http.get(url_hello_txt, http_request_buffer, BUFFER_SIZE); if (ret == HTTP_OK) { printf("HTTP_GET: Read %d chars: '%s' ... [OK]\r\n", strlen(http_request_buffer), http_request_buffer); } else { printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode()); result = false; } if (result == false) { eth.disconnect(); MBED_HOSTTEST_RESULT(false); } } //POST data { bool result = true; const char *url_httpbin_post = "http://httpbin.org/post"; HTTPText text(http_request_buffer, BUFFER_SIZE); HTTPMap map; map.put("Hello", "World"); map.put("test", "1234"); printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post); HTTPResult ret = http.post(url_httpbin_post, map, &text); if (ret == HTTP_OK) { printf("HTTP_POST: Read %d chars ... [OK]\r\n", strlen(http_request_buffer)); printf("HTTP_POST: %s\r\n", http_request_buffer); } else { printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode()); result = false; } if (result == false) { eth.disconnect(); MBED_HOSTTEST_RESULT(false); } } eth.disconnect(); MBED_HOSTTEST_RESULT(true); }
int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(InterruptIn); MBED_HOSTTEST_START("MBED_A7"); IN_OUT_CLEAR; //Test falling edges first in.rise(NULL); in.fall(in_handler); flipper(); if(checks != 5) { printf("MBED: falling edges test failed: %d\r\n",checks); MBED_HOSTTEST_RESULT(false); } //Now test rising edges in.rise(in_handler); in.fall(NULL); flipper(); if (checks != 10) { printf("MBED: raising edges test failed: %d\r\n", checks); MBED_HOSTTEST_RESULT(false); } //Now test switch off edge detection in.rise(NULL); in.fall(NULL); flipper(); if (checks != 10) { printf("MBED: edge detection switch off test failed: %d\r\n", checks); MBED_HOSTTEST_RESULT(false); } //Finally test both in.rise(in_handler); in.fall(in_handler); flipper(); if (checks != 20) { printf("MBED: Simultaneous rising and falling edges failed: %d\r\n", checks); MBED_HOSTTEST_RESULT(false); } MBED_HOSTTEST_RESULT(true); }
/* EXPECTED OUTPUT: ******************* Static::init Static::stack_test Stack::init Stack::hello Stack::destroy Static::check_init: OK Heap::init Heap::hello Heap::destroy *******************/ int main (void) { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(C++); MBED_HOSTTEST_START("MBED_12"); bool result = true; for (;;) { // Global stack object simple test s.stack_test(); if (s.check_init() == false) { result = false; break; } // Heap test object simple test Test *m = new Test("Heap"); m->hello(); if (m->check_init() == false) { result = false; } delete m; break; } MBED_HOSTTEST_RESULT(result); }
int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(PortInOut); MBED_HOSTTEST_START("MBED_A11"); bool check = true; port1.output(); port2.input(); port1 = MASK_1; wait(0.1); if (port2 != MASK_2) check = false; port1 = 0; wait(0.1); if (port2 != 0) check = false; port1.input(); port2.output(); port2 = MASK_2; wait(0.1); if (port1 != MASK_1) check = false; port2 = 0; wait(0.1); if (port1 != 0) check = false; MBED_HOSTTEST_RESULT(check); }
int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Semihost file system); MBED_HOSTTEST_START("MBED_A2"); pc.printf("Test the Stream class\n"); printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No")); char mac[16]; mbed_mac_address(mac); printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); LocalFileSystem local("local"); FILE *f; char *str = TEST_STRING; char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING)); int str_len = strlen(TEST_STRING); // Write f = test_open("w"); test_write(f, str, str_len); test_close(f); // Read f = test_open("r"); test_read(f, buffer, str_len); test_close(f); // Check the two strings are equal MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0)); }
int main (void) { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Mail messaging); MBED_HOSTTEST_START("RTOS_6"); Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); bool result = true; int result_counter = 0; while (true) { osEvent evt = mail_box.get(); if (evt.status == osEventMail) { mail_t *mail = (mail_t*)evt.value.p; const float expected_voltage = CREATE_VOLTAGE(mail->counter); const float expected_current = CREATE_CURRENT(mail->counter); // Check using macros if received values correspond to values sent via queue bool expected_values = (expected_voltage == mail->voltage) && (expected_current == mail->current); result = result && expected_values; const char *result_msg = expected_values ? "OK" : "FAIL"; printf("%3d %.2fV %.2fA ... [%s]\r\n", mail->counter, mail->voltage, mail->current, result_msg); mail_box.free(mail); if (result == false || ++result_counter == QUEUE_SIZE) { break; } } } MBED_HOSTTEST_RESULT(result); return 0; }
int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Basic); MBED_HOSTTEST_START("MBED_A1"); MBED_HOSTTEST_RESULT(true); }
static void run() { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_DESCRIPTION(mbed TLS example on hashing); MBED_HOSTTEST_START("MBEDTLS_EX_HASHING"); MBED_HOSTTEST_RESULT(example() == 0); }
int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_DESCRIPTION(Mutex resource lock); MBED_HOSTTEST_START("RTOS_2"); const int t1_delay = THREAD_DELAY * 1; const int t2_delay = THREAD_DELAY * 2; const int t3_delay = THREAD_DELAY * 3; Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE); Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE); while (true) { // Thread 1 action Thread::wait(t1_delay); manipulate_protected_zone(t1_delay); if (change_counter >= SIGNALS_TO_EMIT or mutex_defect == true) { t2.terminate(); t3.terminate(); break; } } fflush(stdout); MBED_HOSTTEST_RESULT(!mutex_defect); return 0; }
static void run() { MBED_HOSTTEST_TIMEOUT(40); MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_DESCRIPTION(mbed TLS selftest program); MBED_HOSTTEST_START("MBEDTLS_SELFTEST"); MBED_HOSTTEST_RESULT(selftest(0, NULL) == 0); }
int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(SD FileHandle RW Speed); MBED_HOSTTEST_START("PERF_2"); // Test header printf("\r\n"); printf("SD Card FileHandle Performance Test\r\n"); printf("File name: %s\r\n", bin_filename); printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024); // Initialize buffer srand(testenv_randseed()); char *buffer_end = buffer + sizeof(buffer); std::generate (buffer, buffer_end, RandomChar); bool result = true; for (;;) { printf("Write test...\r\n"); if (test_sf_file_write_fhandle(bin_filename, KIB_RW) == false) { result = false; break; } printf("Read test...\r\n"); if (test_sf_file_read_fhandle(bin_filename, KIB_RW) == false) { result = false; break; } break; } MBED_HOSTTEST_RESULT(result); }
int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(I2C MMA7660 accelerometer); MBED_HOSTTEST_START("MBED_A13"); if (!MMA.testConnection()) MBED_HOSTTEST_RESULT(false); for(int i = 0; i < 5; i++) { printf("x: %f, y: %f, z: %f\r\n", MMA.x(), MMA.y(), MMA.z()); wait(0.2); } MBED_HOSTTEST_RESULT(true); }
int main (void) { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(ISR (Queue)); MBED_HOSTTEST_START("RTOS_8"); Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE); Ticker ticker; ticker.attach(queue_isr, 1.0); int isr_puts_counter = 0; bool result = true; while (true) { osEvent evt = queue.get(); if (evt.status != osEventMessage) { printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status); result = false; break; } else { printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v); if (evt.value.v == QUEUE_PUT_ISR_VALUE) { isr_puts_counter++; } if (isr_puts_counter >= QUEUE_SIZE) { break; } } } MBED_HOSTTEST_RESULT(result); return 0; }
void app_start(int argc, char *argv[]) { (void) argc; (void) argv; MBED_HOSTTEST_TIMEOUT(5); MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_DESCRIPTION(Socket Abstraction Layer construction and utility test); MBED_HOSTTEST_START("SAL_INIT_UTIL"); int tests_pass = 1; int rc; EthernetInterface eth; /* Initialise with DHCP, connect, and start up the stack */ eth.init(); eth.connect(); do { socket_error_t err = lwipv4_socket_init(); if (!TEST_EQ(err,SOCKET_ERROR_NONE)) { tests_pass = 0; break; } rc = socket_api_test_create_destroy(SOCKET_STACK_LWIP_IPV4, SOCKET_AF_INET6); tests_pass = tests_pass && rc; rc = socket_api_test_socket_str2addr(SOCKET_STACK_LWIP_IPV4, SOCKET_AF_INET6); tests_pass = tests_pass && rc; } while (0); MBED_HOSTTEST_RESULT(tests_pass); }
int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(SPI C12832 display); MBED_HOSTTEST_START("MBED_35"); C12832 lcd(D11, D13, D12, D7, D10); // clear the screen lcd.cls(); // print the first line and wait 3 sec lcd.locate(0,3); lcd.printf("mbed application board!"); // print the counter prefix; the number will be printed in the while loop lcd.locate(0,15); lcd.printf("Counting:"); int i=1, j=0; while(i++,i<=200) { lcd.locate(42,15); lcd.printf("%d", i); if (i % 50 == 0) { lcd.invert(j = j ? 0 : 1); }; wait(0.001); } MBED_HOSTTEST_RESULT(1); }
int main (void) { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(Semaphore resource lock); MBED_HOSTTEST_START("RTOS_3"); const int t1_delay = THREAD_DELAY * 1; const int t2_delay = THREAD_DELAY * 2; const int t3_delay = THREAD_DELAY * 3; Thread t1(test_thread, (void *)t1_delay, osPriorityNormal, STACK_SIZE); Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE); Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE); while (true) { if (change_counter >= SEM_CHANGES or sem_defect == true) { t1.terminate(); t2.terminate(); t3.terminate(); break; } } fflush(stdout); MBED_HOSTTEST_RESULT(!sem_defect); return 0; }
void check(int i) { Actual.cbExpect = i; if (Actual.finSeq) { Actual.fin = true; } delete ser; if (0 != memcmp(&Actual, &CurrentTest, sizeof(Actual))) { MBED_HOSTTEST_RESULT(0); } if (next(&CurrentTest)) { testIdx++; test(); } else { testIdx++; printf("Tested %u possible calling combinations of Series\r\n",testIdx); MBED_HOSTTEST_RESULT(1); } }
void blink() { if (count) { if (count == 1) { MBED_HOSTTEST_RESULT(true); } count--; } myled = !myled; }
void app_start(int, char**) { int rc; MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_DESCRIPTION(Test the socket stack registry); MBED_HOSTTEST_START("STACK_REGISTRY"); rc = test_socket_stack_registry(); MBED_HOSTTEST_RESULT(rc); }
static void run() { /* Use 115200 bps for consistency with other examples */ Serial pc(USBTX, USBRX); pc.baud(115200); MBED_HOSTTEST_TIMEOUT(40); MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_DESCRIPTION(mbed TLS selftest program); MBED_HOSTTEST_START("MBEDTLS_SELFTEST"); MBED_HOSTTEST_RESULT(selftest(0, NULL) == 0); }
int main() { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(detect_auto); MBED_HOSTTEST_DESCRIPTION(Simple detect test); MBED_HOSTTEST_START("DTCT_1"); notify_start(); printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME); printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID); printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID); MBED_HOSTTEST_RESULT(true); }
void runTest() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(dev_null_auto); MBED_HOSTTEST_DESCRIPTION(stdout redirected to dev null); MBED_HOSTTEST_START("EXAMPLE_1"); printf("MBED: re-routing stdout to /null\r\n"); freopen("/null", "w", stdout); printf("MBED: printf redirected to /null\r\n"); // This shouldn't appear // If failure message can be seen test should fail :) MBED_HOSTTEST_RESULT(false); // This is 'false' on purpose }
void app_start(int, char*[]) { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(default); MBED_HOSTTEST_DESCRIPTION(sbrk mini test); MBED_HOSTTEST_START("SBRK_MINI_TEST"); if (!early_test.passed()) { printf("MBED: Failed at %s:%d\r\n", early_test.file(), early_test.line()); } MBED_HOSTTEST_RESULT(early_test.passed()); return; }
int main() { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut); MBED_HOSTTEST_START("MBED_A4"); float t = temperature.read(); printf("TMP102: Temperature: %f\n\r", t); // In our test environment (ARM office) we should get a temperature within // the range ]15, 30[C bool result = (t > 15.0) && (t < 30.0); MBED_HOSTTEST_RESULT(result); }
void endTest(bool status) { if (loopCount > 0) { printf("\r\n#####\r\n"); printf("\r\nTest loops left %d, current result=%d\r\n", loopCount, tests_pass); printf("\r\n#####\r\n"); loopCount--; testId = 0; /* Schedule tests run again */ FunctionPointer0<void> fpNextTest(testMeshApi, &TestMeshApi::runTests); minar::Scheduler::postCallback(fpNextTest.bind()).delay(minar::milliseconds(3000)); } else { MBED_HOSTTEST_RESULT(status); } }
int main() { MBED_HOSTTEST_TIMEOUT(20); MBED_HOSTTEST_SELECT(dev_null); MBED_HOSTTEST_DESCRIPTION(CAN Loopback); MBED_HOSTTEST_START("MBED_A27"); #if !defined(TARGET_VK_RZ_A1H) can1.mode(CAN::Reset); #endif if (!can1.mode(CAN::LocalTest)) { printf("Mode change failed\n"); } char success_count = 0; for (char i=0; i < TEST_ITERATIONS; i++) { unsigned int id = 1337; CANMessage tx_msg(id, &i, sizeof(i)); bool sent = false; if (can1.write(tx_msg)) { printf("Sent %u: %d\n", id, i); sent = true; } wait_ms(50); bool read = false; CANMessage rx_msg; if (can1.read(rx_msg)) { printf("Read %u: %d\n", rx_msg.id, rx_msg.data[0]); read = (rx_msg.id == id) && (rx_msg.data[0] == i); } bool success = sent && read; if (success) { success_count++; } } MBED_HOSTTEST_RESULT(success_count == TEST_ITERATIONS); }
int main() { MBED_HOSTTEST_TIMEOUT(10); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(DigitalInOut); MBED_HOSTTEST_START("MBED_A6"); bool check = true; d1.output(); d2.input(); d1 = 1; wait(0.1); if (d2 != 1) { printf("MBED: First check failed! d2 is %d\n", (int)d2); check = false; } d1 = 0; wait(0.1); if (d2 != 0) { printf("MBED: Second check failed! d2 is %d\n", (int)d2); check = false; } d1.input(); d2.output(); d2 = 1; wait(0.1); if (d1 != 1) { printf("MBED: Third check failed! d1 is %d\n", (int)d1); check = false; } d2 = 0; wait(0.1); if (d1 != 0) { printf("MBED: Fourth check failed! d1 is %d\n", (int)d1); check = false; } MBED_HOSTTEST_RESULT(check); }
void endTime() { MBED_HOSTTEST_RESULT(true); }
int main() { MBED_HOSTTEST_TIMEOUT(15); MBED_HOSTTEST_SELECT(default_auto); MBED_HOSTTEST_DESCRIPTION(I2C EEPROM read write test); MBED_HOSTTEST_START("MBED_A19"); const int EEPROM_MEM_ADDR = 0xA0; const char MARK = 0x66; int fw = 0; int fr = 0; int fc = 0; int i2c_stat = 0; bool result = true; i2c.frequency(i2c_freq_hz); printf("I2C: I2C Frequency: %d Hz\r\n", i2c_freq_hz); printf("I2C: Write 0x%2X at address 0x0000 test ... \r\n", MARK); // Data write { char data[] = { 0, 0, MARK }; if ((i2c_stat = i2c.write(EEPROM_MEM_ADDR, data, sizeof(data))) != 0) { printf("Unable to write data to EEPROM (i2c_stat = 0x%02X), aborting\r\n", i2c_stat); notify_completion(false); return 1; } // ACK polling (assumes write will be successful eventually) while (i2c.write(EEPROM_MEM_ADDR, data, 0) != 0) ; } printf("I2C: Read data from address 0x0000 test ... \r\n"); // Data read (actual test) for (int i = 0; i < ntests; i++) { // Write data to EEPROM memory { char data[] = { 0, 0 }; if ((i2c_stat = i2c.write(EEPROM_MEM_ADDR, data, 2, true)) != 0) { printf("Test %d failed at write, i2c_stat is 0x%02X\r\n", i, i2c_stat); fw++; continue; } } // us delay if specified if (i2c_delay_us != 0) wait_us(i2c_delay_us); // Read data { char data[1] = { 0 }; if ((i2c_stat = i2c.read(EEPROM_MEM_ADDR, data, 1)) != 0) { printf("Test %d failed at read, i2c_stat is 0x%02X\r\n", i, i2c_stat); fr++; continue; } if (data[0] != MARK) { printf("Test %d failed at data match\r\n", i); fc++; } } } result = (fw + fr + fc == 0); printf("EEPROM: Test result ... [%s]\r\n", result ? "OK" : "FAIL"); if (!result) { printf("Test Statistics:\r\n"); printf("\tTotal tests: %d\r\n", ntests); printf("\tFailed at write: %d\r\n", fw); printf("\tFailed at read: %d\r\n", fr); printf("\tData mismatch: %d\r\n", fc); printf("\tTotal failures: %d\r\n", fw + fr + fc); } MBED_HOSTTEST_RESULT(result); }