Merge remote-tracking branch 'upstream/master'

pull/485/head
ytsuboi 2014-09-07 19:59:40 +09:00
commit b55e3b42b4
29 changed files with 477 additions and 147 deletions

View File

@ -22,7 +22,7 @@
#include "system_nrf51822.h"
#define __SYSTEM_CLOCK (16000000UL) //!< nRF51 devices use a fixed System Clock Frequency of 16MHz
#define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
static bool is_manual_peripheral_setup_needed(void);
static bool is_disabled_in_debug_needed(void);
@ -36,7 +36,6 @@ static bool is_disabled_in_debug_needed(void);
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
#endif
void SystemCoreClockUpdate(void)
{
SystemCoreClock = __SYSTEM_CLOCK;
@ -44,12 +43,16 @@ void SystemCoreClockUpdate(void)
void SystemInit(void)
{
/* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
It can also be done in the application main() function. */
// Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
// to enable the use of peripherals" found at Product Anomaly document for your device found at
// https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
// that do not need it is that the new peripherals in the second generation devices (LPCOMP for
// example) will not be available.
if (is_manual_peripheral_setup_needed()){
if (is_manual_peripheral_setup_needed())
{
*(uint32_t volatile *)0x40000504 = 0xC007FFDF;
*(uint32_t volatile *)0x40006C18 = 0x00008000;
}
@ -57,12 +60,18 @@ void SystemInit(void)
// Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
// register is incorrect" found at Product Anomaly document four your device found at
// https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed.
if (is_disabled_in_debug_needed()){
if (is_disabled_in_debug_needed())
{
NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
}
// Start the external 32khz crystal oscillator.
#ifdef TARGET_HRM1017
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
#else
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
#endif
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;

View File

@ -16,7 +16,7 @@
{ \
__asm( \
"svc %0\n" \
"bx r14" : : "I" (number) : "r0" \
"bx r14" : : "I" ((uint32_t)number) : "r0" \
); \
}
#elif defined (__ICCARM__)

View File

@ -81,6 +81,11 @@ void analogin_init(analogin_t *obj, PinName pin) {
// Get ADC registers structure address
adc = (ADC_TypeDef *)(obj->adc);
// Enable the HSI
RCC_HSICmd(ENABLE);
// Wait until HSI oscillator is ready
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET) {}
// Enable ADC clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

View File

@ -0,0 +1,100 @@
#include "mbed.h"
#include "test_env.h"
#include <string.h>
#define BUFFER_SIZE 256
#define CLEAN_BUFFER(BUFF) memset(BUFF, 0x00, BUFFER_SIZE)
#define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999
#define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
#define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910
int main()
{
char buffer[BUFFER_SIZE] = {0};
bool result = true;
bool cmp_result;
{
CLEAN_BUFFER(buffer);
sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS);
cmp_result = TESTENV_STRCMP(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS);
cmp_result = TESTENV_STRCMP(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
sprintf(buffer, "%x %X %x %X %x %X %x %X %x %X %x %X", POSITIVE_INTEGERS);
cmp_result = TESTENV_STRCMP(buffer, "8000 C8E 3e7 64 1 0 1 1087 3e7 101B 7ff8 1869F");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f", FLOATS);
cmp_result = TESTENV_STRCMP(buffer, "0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g", FLOATS);
cmp_result = TESTENV_STRCMP(buffer, "0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+006 4.2468e+007 2.12006e+008");
cmp_result = cmp_result || TESTENV_STRCMP(buffer, "0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E", FLOATS);
cmp_result = TESTENV_STRCMP(buffer, "2.000000e-003 9.243000E-001 1.591320e+001 7.917737E+002 6.208200e+003 2.571950E+004 4.268160e+005 6.429271E+006 4.246802e+007 2.120065E+008");
cmp_result = cmp_result || TESTENV_STRCMP(buffer, "2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
char str[] ="- This, a sample string.";
char * pch = strtok (str," ,.-");
while (pch != NULL) {
strcat(buffer, pch);
pch = strtok (NULL, " ,.-");
}
cmp_result = TESTENV_STRCMP(buffer, "Thisasamplestring");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
{
CLEAN_BUFFER(buffer);
char str[] = "This is a sample string";
char key[] = "aeiou";
char *pch = strpbrk(str, key);
while (pch != NULL)
{
char buf[2] = {*pch, '\0'};
strcat(buffer, buf);
pch = strpbrk(pch + 1,key);
}
cmp_result = TESTENV_STRCMP(buffer, "iiaaei");
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
result = result && cmp_result;
}
notify_completion(result);
return 0;
}

View File

@ -19,9 +19,9 @@ DevNull null("null");
int main()
{
printf("MBED: re-routing stdout to /null\n");
printf("MBED: re-routing stdout to /null\r\n");
freopen("/null", "w", stdout);
printf("MBED: printf redirected to /null\n"); // This shouldn't appear
printf("MBED: printf redirected to /null\r\n"); // This shouldn't appear
// If failure message can be seen test should fail :)
notify_completion(false); // This is 'false' on purpose
return 0;

View File

@ -1,4 +1,5 @@
#include "mbed.h"
#include "test_env.h"
#if defined(TARGET_NUCLEO_F103RB) || \
defined(TARGET_NUCLEO_L152RE) || \
@ -22,9 +23,12 @@ int main() {
Serial pc(TXPIN, RXPIN);
pc.baud(115200);
pc.puts("{{");
pc.puts(TEST_ENV_START); // Host test is expecting preamble
pc.puts("}}");
while (1) {
pc.gets(buf, 256);
pc.printf("%s", buf);
}
}

View File

@ -24,4 +24,7 @@ void notify_performance_coefficient(const char* measurement_name, const double v
// Test functionality useful during testing
unsigned int testenv_randseed();
// Macros, unit test like to provide basic comparisons
#define TESTENV_STRCMP(GIVEN,EXPECTED) (strcmp(GIVEN,EXPECTED) == 0)
#endif

View File

@ -3,5 +3,5 @@
int main()
{
printf("Hello World\n");
notify_completion(true);
while(1);
}

View File

@ -1,36 +1,21 @@
#include "mbed.h"
#include "test_env.h"
/* This test purpose is to verify the behaviour when the program does not link
* any symbol from the mbed library.
* In the past we had an issue where the stdio retargeting was not linked in.
*/
/*
scanf("%d", &Value);
fprintf(stdout, "Test 3: fprintf(stdout, ...) test\r\n");
fprintf(stderr, "Test 4: fprintf(stderr, ...) test\r\n");
fscanf(stdin, "%d", &Value);
fprintf(stdout, "Test 3: fprintf(stdout, ...) test\r\n");
fprintf(stderr, "Test 4: fprintf(stderr, ...) test\r\n");
printf("Test 5: fscanf(stdin, ...) test\r\n");
printf(" Type number and press Enter: \n");
fscanf(stdin, "%d", &Value);
printf("\n Your value was: %d\r\n", Value);
printf("Test complete\r\n");
*/
int main() {
union {
int value_int;
};
notify_start();
while (true)
{
// SCANFm PRINTF family
// SCANF PRINTF family
value_int = 0;
scanf("%d", &value_int);
printf("Your value was: %d\r\n", value_int);

View File

@ -1,54 +1,121 @@
/*
start
one
two
three
elements in the map:
a1 => 50
c3 => 150
{success}
{end}
*/
#include "test_env.h"
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <math.h>
using namespace std;
#define BUFFER_SIZE 128
#define TABLE_SIZE(TAB) (sizeof(TAB) / sizeof(TAB[0]))
int main() {
printf("start"NL);
queue<string> queueObject;
queueObject.push("one");
queueObject.push("two");
queueObject.push("three");
#define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,1,4231,999,4123,32760,99999
#define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
#define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910
#define FLOATS_STR "0.002","0.92430","15.91320","791.77368","6208.2","25719.4952","426815.982588","6429271.046","42468024.93","212006462.910"
while (!queueObject.empty()) {
string& s = queueObject.front();
printf("%s"NL, s.c_str());
queueObject.pop();
template <class T, class F>
void BubbleSort(T& array, size_t array_size, F functor)
{
bool flag = true;
size_t numLength = array_size;
for(size_t i = 1; (i <= numLength) && flag; i++) {
flag = false;
for (size_t j = 0; j < (numLength - 1); j++) {
if (functor(array[j+1], array[j])) {
int temp = array[j];
array[j] = array[j + 1];
array[j+1] = temp;
flag = true;
}
}
}
map<string,string> m;
map<string,string>::iterator it;
m["a1"] = "50";
m["b2"] = "100";
m["c3"] = "150";
m["d4"] = "200";
it = m.find("b2");
if (it == m.end()) {
printf("lookup error"NL);
}
m.erase(it);
m.erase(m.find("d4"));
printf("elements in the map:"NL);
printf("a1 => %s"NL, m.find("a1")->second.c_str());
printf("c3 => %s"NL, m.find("c3")->second.c_str());
notify_completion(true);
}
struct printInt {
void operator()(int i) {
printf("%d ", i);
}
};
struct printFloat {
void operator()(float f) {
printf("%f ", f);
}
};
struct printString {
void operator()(char* s) {
printf("%s ", s);
}
};
struct greaterAbs {
bool operator()(int a, int b) {
return abs(a) > abs(b);
}
};
int main()
{
int p_integers[] = {POSITIVE_INTEGERS};
int n_integers[] = {NEGATIVE_INTEGERS};
float floats[] = {FLOATS};
bool result = true;
{
std::vector<int> v_pints(p_integers, p_integers + TABLE_SIZE(p_integers));
bool equal_result = std::equal(v_pints.begin(), v_pints.end(), p_integers);
result = result && equal_result;
printf("[%s] Fill vector with data\r\n", equal_result ? "OK" : "FAIL");
}
{
char* floats_str[] = {FLOATS_STR};
float floats_transform[TABLE_SIZE(floats_str)] = {0.0};
std::transform(floats_str, floats_str + TABLE_SIZE(floats_str), floats_transform, atof);
bool equal_result = std::equal(floats_transform, floats_transform + TABLE_SIZE(floats_transform), floats);
result = result && equal_result;
printf("[%s] Transform float strings\r\n", equal_result ? "OK" : "FAIL");
std::for_each(floats_str, floats_str + TABLE_SIZE(floats_str), printString());
printf("\r\n");
std::for_each(floats_transform, floats_transform + TABLE_SIZE(floats_transform), printFloat());
printf("\r\n");
}
{
std::vector<int> v_nints_1(n_integers, n_integers + TABLE_SIZE(n_integers));
std::vector<int> v_nints_2(n_integers, n_integers + TABLE_SIZE(n_integers));
{
BubbleSort(v_nints_1, v_nints_1.size(), std::greater<int>());
std::sort(v_nints_2.begin(), v_nints_2.end(), std::greater<int>());
bool equal_result = std::equal(v_nints_1.begin(), v_nints_1.end(), v_nints_2.begin());
result = result && equal_result;
printf("[%s] Sort integers\r\n", equal_result ? "OK" : "FAIL");
std::for_each(v_nints_1.begin(), v_nints_1.end(), printInt());
printf("\r\n");
std::for_each(v_nints_2.begin(), v_nints_2.end(), printInt());
printf("\r\n");
}
{
BubbleSort(v_nints_1, v_nints_1.size(), greaterAbs());
std::sort(v_nints_2.begin(), v_nints_2.end(), greaterAbs());
bool equal_result = std::equal(v_nints_1.begin(), v_nints_1.end(), v_nints_2.begin());
result = result && equal_result;
printf("[%s] Sort integers\r\n", equal_result ? "OK" : "FAIL");
std::for_each(v_nints_1.begin(), v_nints_1.end(), printInt());
printf("\r\n");
std::for_each(v_nints_2.begin(), v_nints_2.end(), printInt());
printf("\r\n");
}
}
notify_completion(result);
return 0;
}

View File

@ -1,4 +1,5 @@
#include "mbed.h"
#include "test_env.h"
#include "EthernetInterface.h"
struct s_ip_address
@ -11,6 +12,7 @@ struct s_ip_address
#define MAX_ECHO_LOOPS 100
int main() {
char buffer[256] = {0};
char out_buffer[] = "Hello World\n";
@ -36,7 +38,7 @@ int main() {
wait(1);
}
// Test loop for multiple client conenctions
// Test loop for multiple client connections
bool result = true;
int count_error = 0;
for (int i = 0; i < MAX_ECHO_LOOPS; i++) {

View File

@ -5,8 +5,10 @@
namespace {
const char *HTTP_SERVER_NAME = "utcnist.colorado.edu";
const int HTTP_SERVER_PORT = 37;
const float YEARS_TO_PASS = 114.0;
}
int main() {
bool result = false;
EthernetInterface eth;
@ -30,14 +32,14 @@ int main() {
const int n = sock.receiveFrom(nist, in_buffer_tab, sizeof(in_buffer_tab));
if (n > 0) {
result = true;
const unsigned int timeRes = ntohl(in_buffer_uint);
const float years = timeRes / 60.0 / 60.0 / 24.0 / 365;
printf("UDP: Received %d bytes from server %s on port %d\r\n", n, nist.get_address(), nist.get_port());
printf("UDP: %u seconds since 01/01/1900 00:00 GMT ... %s\r\n", timeRes, timeRes > 0 ? "[OK]" : "[FAIL]");
printf("UDP: %.2f years since 01/01/1900 00:00 GMT ... %s\r\n", years, timeRes > 114.0 ? "[OK]" : "[FAIL]");
result = true;
printf("UDP: %.2f years since 01/01/1900 00:00 GMT ... %s\r\n", years, timeRes > YEARS_TO_PASS ? "[OK]" : "[FAIL]");
if (years < 114.0) {
if (years < YEARS_TO_PASS) {
result = false;
}
}

View File

@ -9,7 +9,7 @@ INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
LINKER_SCRIPT = {{linker_script}}
SOFTDEVICE = mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_NRF51822/Lib/s110_nrf51822_6_0_0/s110_nrf51822_6.0.0_softdevice.hex
SOFTDEVICE = mbed/TARGET_ARCH_BLE/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_softdevice.hex
###############################################################################
AS = $(GCC_BIN)arm-none-eabi-as
@ -23,7 +23,7 @@ CPU = -mcpu=cortex-m0 -mthumb
CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections
CC_SYMBOLS = {% for s in symbols %}-D{{s}} {% endfor %}
LD_FLAGS = -mcpu=cortex-m0 -mthumb -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float
LD_FLAGS = -mcpu=cortex-m0 -mthumb -Wl,--gc-sections -Wl,--wrap=main --specs=nano.specs -u _printf_float -u _scanf_float
LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
ifeq ($(DEBUG), 1)
@ -32,7 +32,7 @@ else
CC_FLAGS += -DNDEBUG -Os
endif
all: $(PROJECT).hex merge
all: $(PROJECT).hex
clean:
rm -f $(PROJECT).hex $(PROJECT).elf $(OBJECTS)
@ -54,4 +54,4 @@ $(PROJECT).hex: $(PROJECT).elf
$(OBJCOPY) -O ihex $< $@
merge:
$(SREC_CAT) $(SOFTDEVICE) -intel $(PROJECT).hex -binary --offset 0x14000 -o combined.hex -intel --line-length=46
$(SREC_CAT) $(SOFTDEVICE) -intel $(PROJECT).hex -intel -o combined.hex -intel --line-length=44

View File

@ -9,7 +9,7 @@ INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
LINKER_SCRIPT = {{linker_script}}
SOFTDEVICE = mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_softdevice.hex
SOFTDEVICE = mbed/TARGET_NRF51822/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_softdevice.hex
###############################################################################
AS = $(GCC_BIN)arm-none-eabi-as
@ -32,7 +32,7 @@ else
CC_FLAGS += -DNDEBUG -Os
endif
all: $(PROJECT).hex merge
all: $(PROJECT).hex
clean:
rm -f $(PROJECT).hex $(PROJECT).elf $(OBJECTS)
@ -54,4 +54,4 @@ $(PROJECT).hex: $(PROJECT).elf
$(OBJCOPY) -O ihex $< $@
merge:
$(SREC_CAT) $(SOFTDEVICE) -intel $(PROJECT).hex -intel --offset 0x16000 -o combined.hex -intel --line-length=46
$(SREC_CAT) $(SOFTDEVICE) -intel $(PROJECT).hex -intel -o combined.hex -intel --line-length=44

View File

@ -20,17 +20,26 @@ from sys import stdout
class DevNullTest(DefaultTest):
def run(self):
c = self.mbed.serial_read(512)
c = self.mbed.serial_read(128)
if c is None:
self.print_result("ioerr_serial")
return
# Data from serial received correctly
print "Received %d bytes" % len(c)
if "{failure}" not in c:
print "Received %d bytes:"% len(c)
print c
stdout.flush()
# Check for expected and unexpected prints in Mbed output
result = True
if "re-routing stdout to /null" not in c:
result = False
if "printf redirected to /null" in c:
result = False
if "{failure}" in c:
result = False
if result:
self.print_result('success')
else:
self.print_result('failure')
stdout.flush()
if __name__ == '__main__':
DevNullTest().run()

View File

@ -14,6 +14,8 @@ 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.
"""
import uuid
from sys import stdout
from host_test import Test
@ -24,11 +26,27 @@ class EchoTest(Test):
self.mbed.reset()
def test(self):
# Let's wait for Mbed to print its readiness, usually "{{start}}"
if self.mbed.serial_timeout(None) is None:
self.print_result("ioerr_serial")
return
c = self.mbed.serial_read(len('{{start}}'))
if c is None:
self.print_result("ioerr_serial")
return
print c
stdout.flush()
if self.mbed.serial_timeout(1) is None:
self.print_result("ioerr_serial")
return
self.mbed.flush()
self.notify("Starting the ECHO test")
TEST="longer serial test"
check = True
for i in range(1, 100):
TEST = str(uuid.uuid4())
self.mbed.serial_write(TEST + "\n")
l = self.mbed.serial.readline().strip()
if not l: continue
@ -38,8 +56,7 @@ class EchoTest(Test):
self.notify('"%s" != "%s"' % (l, TEST))
else:
if (i % 10) == 0:
self.notify('.')
self.notify(TEST)
return check

View File

@ -17,32 +17,31 @@ limitations under the License.
from host_test import DefaultTest
from sys import stdout
import re
class HelloTest(DefaultTest):
HELLO_WORLD = "Hello World\n"
HELLO_WORLD = "Hello World"
def run(self):
c = self.mbed.serial_read(1)
c = self.mbed.serial_read(128)
if c is None:
self.print_result("ioerr_serial")
return
data_to_read = len(self.HELLO_WORLD)
read_buffer = ''
if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6
#Read additional 39 bytes of TargetID
if self.mbed.serial_read(39) is None:
self.print_result("ioerr_serial")
return
print "Read %d bytes"% len(c)
print c
stdout.flush()
result = True
# Because we can have targetID here let's try to decode
if len(c) < len(self.HELLO_WORLD):
result = False
elif c[0] == '$':
# We are looking for targetID here
res = re.search('^[$]+[0-9a-fA-F]+' + self.HELLO_WORLD, c)
result = res is not None
else:
data_to_read -= 1
read_buffer += c
c = self.mbed.serial_read(data_to_read)
read_buffer += c
if c is None:
self.print_result("ioerr_serial")
return
stdout.write(read_buffer)
if read_buffer == self.HELLO_WORLD: # Hello World received
result = (c.startswith(self.HELLO_WORLD))
if result: # Hello World received
self.print_result('success')
else:
self.print_result('failure')

View File

@ -77,7 +77,7 @@ class Mbed:
(self.options, _) = parser.parse_args()
self.DEFAULT_RESET_TOUT = 2
self.DEFAULT_RESET_TOUT = 0
self.DEFAULT_TOUT = 10
if self.options.port is None:
@ -89,7 +89,7 @@ class Mbed:
self.extra_serial = None
self.serial = None
self.timeout = self.DEFAULT_TOUT if self.options.timeout is None else self.options.timeout
print 'Host test instrumentation on port: "%s" with serial: "%s"' % (self.port, self.disk)
print 'Host test instrumentation on port: "%s" and disk: "%s"' % (self.port, self.disk)
def init_serial(self, baud=9600, extra_baud=9600):
""" Initialize serial port. Function will return error is port can't be opened or initialized

View File

@ -43,12 +43,16 @@ class RTCTest(DefaultTest):
test_result = test_result and (time_str == correct_time_str)
result_msg = "OK" if (time_str == correct_time_str) else "FAIL"
print "Got RTC time: " + c[:-1] + " ... " + result_msg
stdout.flush()
else:
print c
test_result = False
break
if test_result: # All numbers are the same
self.print_result('success')
else:
self.print_result('failure')
stdout.flush()
if __name__ == '__main__':
RTCTest().run()

View File

@ -28,9 +28,26 @@ class StdioTest(DefaultTest):
def run(self):
test_result = True
# Let's wait for Mbed to print its readiness, usually "{{start}}"
if self.mbed.serial_timeout(None) is None:
self.print_result("ioerr_serial")
return
c = self.mbed.serial_read(len('{{start}}'))
if c is None:
self.print_result("ioerr_serial")
return
print c
stdout.flush()
if self.mbed.serial_timeout(1) is None:
self.print_result("ioerr_serial")
return
for i in range(1, 5):
random_integer = random.randint(-10000, 10000)
random_integer = random.randint(-99999, 99999)
print "Generated number: " + str(random_integer)
stdout.flush()
self.mbed.serial_write(str(random_integer) + "\n")
serial_stdio_msg = ""
@ -53,7 +70,7 @@ class StdioTest(DefaultTest):
stdout.flush()
break
else:
print "Error: No IP and port information sent from server"
print "Error: No data from MUT sent"
self.print_result('error')
exit(-2)
@ -61,7 +78,6 @@ class StdioTest(DefaultTest):
self.print_result('success')
else:
self.print_result('failure')
stdout.flush()
if __name__ == '__main__':
StdioTest().run()

View File

@ -19,6 +19,7 @@ from SocketServer import BaseRequestHandler, TCPServer
import socket
from host_test import Test
from sys import stdout
from time import sleep
SERVER_IP = str(socket.gethostbyname(socket.getfqdn()))
SERVER_PORT = 7
@ -31,7 +32,25 @@ class TCPEchoClientTest(Test):
def send_server_ip_port(self, ip_address, port_no):
print "Resetting target..."
self.mbed.reset()
# Let's wait for Mbed to print its readiness, usually "{{start}}"
if self.mbed.serial_timeout(None) is None:
self.print_result("ioerr_serial")
return
c = self.mbed.serial_read(len('TCPCllient waiting for server IP and port...'))
if c is None:
self.print_result("ioerr_serial")
return
print c
stdout.flush()
if self.mbed.serial_timeout(1) is None:
self.print_result("ioerr_serial")
return
print "Sending server IP Address to target..."
stdout.flush()
connection_str = ip_address + ":" + str(port_no) + "\n"
self.mbed.serial_write(connection_str)

View File

@ -130,7 +130,8 @@ class UDPEchoServerTest(DefaultTest):
sleep(1)
summary_datagram_success = (float(len(dict_udp_recv_datagrams)) / float(self.TEST_PACKET_COUNT)) * 100.0
# print dict_udp_recv_datagrams
print "Datagrams recved after +%d sec: %.3f%% (%d / %d), stress=%.3f ms" % (d, summary_datagram_success, len(dict_udp_recv_datagrams), self.TEST_PACKET_COUNT, self.TEST_STRESS_FACTOR)
print "Datagrams received after +%d sec: %.3f%% (%d / %d), stress=%.3f ms" % (d, summary_datagram_success, len(dict_udp_recv_datagrams), self.TEST_PACKET_COUNT, self.TEST_STRESS_FACTOR)
stdout.flush()
# Getting control data from test
print
@ -138,6 +139,7 @@ class UDPEchoServerTest(DefaultTest):
mbed_stats = self.get_control_data()
print mbed_stats
print
stdout.flush()
# Receiving serial data from mbed
print

View File

@ -30,6 +30,23 @@ class UDPEchoClientTest(Test):
def send_server_ip_port(self, ip_address, port_no):
print "Resetting target..."
self.mbed.reset()
# Let's wait for Mbed to print its readiness, usually "{{start}}"
if self.mbed.serial_timeout(None) is None:
self.print_result("ioerr_serial")
return
c = self.mbed.serial_read(len('UDPCllient waiting for server IP and port...'))
if c is None:
self.print_result("ioerr_serial")
return
print c
stdout.flush()
if self.mbed.serial_timeout(1) is None:
self.print_result("ioerr_serial")
return
print "Sending server IP Address to target..."
connection_str = ip_address + ":" + str(port_no) + "\n"
self.mbed.serial_write(connection_str)

View File

@ -55,6 +55,7 @@ class WaitusTest(DefaultTest):
print ". in %.2f sec (%.2f) [%s]" % (delta, deviation, msg)
else:
print ". skipped"
stdout.flush()
start = time();
measurement_time = time() - start_serial_pool
print "Completed in %.2f sec" % (measurement_time)
@ -63,7 +64,6 @@ class WaitusTest(DefaultTest):
self.print_result('success')
else:
self.print_result('failure')
stdout.flush()
if __name__ == '__main__':
WaitusTest().run()

View File

@ -19,10 +19,9 @@ limitations under the License.
TEST BUILD & RUN
"""
import sys
from os.path import join, abspath, dirname
from subprocess import call
from shutil import copy
from time import sleep
from shutil import copy
from os.path import join, abspath, dirname
# Be sure that the tools directory is in the search path
ROOT = abspath(join(dirname(__file__), ".."))

View File

@ -88,7 +88,7 @@ def get_version():
""" Returns test script version
"""
single_test_version_major = 1
single_test_version_minor = 1
single_test_version_minor = 2
return (single_test_version_major, single_test_version_minor)
@ -188,6 +188,7 @@ if __name__ == '__main__':
_opts_copy_method=opts.copy_method,
_opts_mut_reset_type=opts.mut_reset_type,
_opts_jobs=opts.jobs,
_opts_waterfall_test=opts.waterfall_test,
_opts_extend_test_timeout=opts.extend_test_timeout)
# Runs test suite in CLI mode

View File

@ -19,6 +19,7 @@ Author: Przemyslaw Wirkus <Przemyslaw.wirkus@arm.com>
import os
import re
import sys
import json
import pprint
import random
@ -40,6 +41,7 @@ from workspace_tools.tests import TESTS
from workspace_tools.tests import TEST_MAP
from workspace_tools.paths import BUILD_DIR
from workspace_tools.paths import HOST_TESTS
from workspace_tools.utils import ToolException
from workspace_tools.utils import construct_enum
from workspace_tools.targets import TARGET_MAP
from workspace_tools.test_db import BaseDBAccess
@ -47,7 +49,7 @@ from workspace_tools.settings import EACOMMANDER_CMD
from workspace_tools.build_api import build_project, build_mbed_libs, build_lib
from workspace_tools.build_api import get_target_supported_toolchains
from workspace_tools.libraries import LIBRARIES, LIBRARY_MAP
from workspace_tools.test_mysql import MySQLDBAccess
from workspace_tools.toolchains import TOOLCHAIN_BIN_PATH
class ProcessObserver(Thread):
@ -153,6 +155,7 @@ class SingleTestRunner(object):
_opts_copy_method=None,
_opts_mut_reset_type=None,
_opts_jobs=None,
_opts_waterfall_test=None,
_opts_extend_test_timeout=None):
""" Let's try hard to init this object
"""
@ -196,6 +199,7 @@ class SingleTestRunner(object):
self.opts_copy_method = _opts_copy_method
self.opts_mut_reset_type = _opts_mut_reset_type
self.opts_jobs = _opts_jobs if _opts_jobs is not None else 1
self.opts_waterfall_test = _opts_waterfall_test
self.opts_extend_test_timeout = _opts_extend_test_timeout
# File / screen logger initialization
@ -364,19 +368,21 @@ class SingleTestRunner(object):
MACROS.extend(LIBRARY_MAP[lib_id]['macros'])
project_name = self.opts_firmware_global_name if self.opts_firmware_global_name else None
path = build_project(test.source_dir,
join(build_dir, test_id),
T,
toolchain,
test.dependencies,
options=build_project_options,
clean=clean_project_options,
verbose=self.opts_verbose,
name=project_name,
macros=MACROS,
inc_dirs=INC_DIRS,
jobs=self.opts_jobs)
try:
path = build_project(test.source_dir,
join(build_dir, test_id),
T,
toolchain,
test.dependencies,
options=build_project_options,
clean=clean_project_options,
verbose=self.opts_verbose,
name=project_name,
macros=MACROS,
inc_dirs=INC_DIRS,
jobs=self.opts_jobs)
except ToolException:
return test_summary, self.shuffle_random_seed
if self.opts_only_build_tests:
# With this option we are skipping testing phase
continue
@ -735,6 +741,10 @@ class SingleTestRunner(object):
duration,
test_index)
# If we perform waterfall test we test until we get OK and we stop testing
if self.opts_waterfall_test and single_test_result == self.TEST_RESULT_OK:
break
if self.db_logger:
self.db_logger.disconnect()
@ -790,6 +800,7 @@ class SingleTestRunner(object):
if verbose:
print "Executing '" + " ".join(cmd) + "'"
print "Test::Output::Start"
proc = Popen(cmd, stdout=PIPE, cwd=HOST_TESTS)
obs = ProcessObserver(proc)
@ -804,6 +815,8 @@ class SingleTestRunner(object):
if c:
output.append(c)
if verbose:
sys.stdout.write(c)
# Give the mbed under test a way to communicate the end of the test
if c in ['\n', '\r']:
if '{end}' in line:
@ -812,15 +825,21 @@ class SingleTestRunner(object):
else:
line += c
try:
c = obs.queue.get(block=True, timeout=0.5)
except Empty, _:
c = None
if c:
output.append(c)
if verbose:
sys.stdout.write(c)
if verbose:
print "Test::Output::Finish"
# Stop test process
obs.stop()
# Handle verbose mode
if verbose:
print "Test::Output::Start"
print "".join(output)
print "Test::Output::Finish"
# Parse test 'output' data
result = self.TEST_RESULT_TIMEOUT
for line in "".join(output).splitlines():
@ -999,6 +1018,7 @@ def print_test_configuration_from_json(json_data, join_delim=", "):
# { target : [conflicted toolchains] }
toolchain_conflicts = {}
toolchain_path_conflicts = []
for k in json_data:
# k should be 'targets'
targets = json_data[k]
@ -1010,8 +1030,9 @@ def print_test_configuration_from_json(json_data, join_delim=", "):
row = [target_name]
toolchains = targets[target]
for toolchain in sorted(toolchains_info_cols):
# Check for conflicts
# Check for conflicts: target vs toolchain
conflict = False
conflict_path = False
if toolchain in toolchains:
if toolchain not in target_supported_toolchains:
conflict = True
@ -1022,12 +1043,21 @@ def print_test_configuration_from_json(json_data, join_delim=", "):
cell_val = 'Yes' if toolchain in toolchains else '-'
if conflict:
cell_val += '*'
# Check for conflicts: toolchain vs toolchain path
if toolchain in TOOLCHAIN_BIN_PATH:
toolchain_path = TOOLCHAIN_BIN_PATH[toolchain]
if not os.path.isdir(toolchain_path):
conflict_path = True
if toolchain not in toolchain_path_conflicts:
toolchain_path_conflicts.append(toolchain)
if conflict_path:
cell_val += '#'
row.append(cell_val)
pt.add_row(row)
# generate result string
result = pt.get_string() # Test specification table
if toolchain_conflicts: # Print conflicts if exist
if toolchain_conflicts or toolchain_path_conflicts:
result += "\n"
result += "Toolchain conflicts:\n"
for target in toolchain_conflicts:
@ -1036,6 +1066,13 @@ def print_test_configuration_from_json(json_data, join_delim=", "):
conflict_target_list = join_delim.join(toolchain_conflicts[target])
sufix = 's' if len(toolchain_conflicts[target]) > 1 else ''
result += "\t* Target %s does not support %s toolchain%s\n"% (target, conflict_target_list, sufix)
for toolchain in toolchain_path_conflicts:
# Let's check toolchain configuration
if toolchain in TOOLCHAIN_BIN_PATH:
toolchain_path = TOOLCHAIN_BIN_PATH[toolchain]
if not os.path.isdir(toolchain_path):
result += "\t# Toolchain %s path not found: %s\n"% (toolchain, toolchain_path)
return result
@ -1290,6 +1327,7 @@ def factory_db_logger(db_url):
""" Factory database driver depending on database type supplied in database connection string db_url
"""
if db_url is not None:
from workspace_tools.test_mysql import MySQLDBAccess
(db_type, username, password, host, db_name) = BaseDBAccess().parse_db_connection_string(db_url)
if db_type == 'mysql':
return MySQLDBAccess()
@ -1424,6 +1462,12 @@ def get_default_test_options_parser():
dest='test_global_loops_value',
help='Set global number of test loops per test. Default value is set 1')
parser.add_option('-W', '--waterfall',
dest='waterfall_test',
default=False,
action="store_true",
help='Used with --loops or --global-loops options. Tests until OK result occurs and assumes test passed.')
parser.add_option('-N', '--firmware-name',
dest='firmware_global_name',
help='Set global name for all produced projects. Note, proper file extension will be added by buid scripts.')

View File

@ -324,7 +324,7 @@ TESTS = [
{
"id": "MBED_2", "description": "stdio",
"source_dir": join(TEST_DIR, "mbed", "stdio"),
"dependencies": [MBED_LIBRARIES],
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"duration": 20,
"automated": True,
"host_test": "stdio_auto"
@ -510,6 +510,13 @@ TESTS = [
"source_dir": join(TEST_DIR, "mbed", "pin_toggling"),
"dependencies": [MBED_LIBRARIES],
},
{
"id": "MBED_33", "description": "C string operations",
"source_dir": join(TEST_DIR, "mbed", "cstring"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"duration": 10,
"automated": False,
},
# CMSIS RTOS tests
{
@ -720,7 +727,7 @@ TESTS = [
{
"id": "NET_13", "description": "TCP client echo loop",
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client_loop"),
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY, TEST_MBED_LIB],
"automated": True,
"duration": 15,
"host_test": "tcpecho_client_auto",

View File

@ -690,15 +690,34 @@ class mbedToolchain:
self.notify({'type': 'var', 'key': key, 'val': value})
from workspace_tools.settings import ARM_BIN
from workspace_tools.settings import GCC_ARM_PATH, GCC_CR_PATH, GCC_CS_PATH, CW_EWL_PATH, CW_GCC_PATH
from workspace_tools.settings import IAR_PATH
TOOLCHAIN_BIN_PATH = {
'ARM': ARM_BIN,
'uARM': ARM_BIN,
'GCC_ARM': GCC_ARM_PATH,
'GCC_CS': GCC_CS_PATH,
'GCC_CR': GCC_CR_PATH,
'GCC_CW_EWL': CW_EWL_PATH,
'GCC_CW_NEWLIB': CW_GCC_PATH,
'IAR': IAR_PATH
}
from workspace_tools.toolchains.arm import ARM_STD, ARM_MICRO
from workspace_tools.toolchains.gcc import GCC_ARM, GCC_CS, GCC_CR
from workspace_tools.toolchains.gcc import GCC_CW_EWL, GCC_CW_NEWLIB
from workspace_tools.toolchains.iar import IAR
TOOLCHAIN_CLASSES = {
'ARM': ARM_STD, 'uARM': ARM_MICRO,
'GCC_ARM': GCC_ARM, 'GCC_CS': GCC_CS, 'GCC_CR': GCC_CR,
'GCC_CW_EWL': GCC_CW_EWL, 'GCC_CW_NEWLIB': GCC_CW_NEWLIB,
'ARM': ARM_STD,
'uARM': ARM_MICRO,
'GCC_ARM': GCC_ARM,
'GCC_CS': GCC_CS,
'GCC_CR': GCC_CR,
'GCC_CW_EWL': GCC_CW_EWL,
'GCC_CW_NEWLIB': GCC_CW_NEWLIB,
'IAR': IAR
}