Skip to content

Commit 542fcca

Browse files
authored
Merge pull request #2137 from sg-/operators
Remove macro for operators. Enable these as default behavior
2 parents 03e9903 + 254ae0e commit 542fcca

20 files changed

+47
-123
lines changed

docs/TESTING.md

Lines changed: 34 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Note: This configuration file must be in [JSON format](http://www.w3schools.com/
2828
Note: Unfortunately JSON format is not allowing you to have comments inside JSON code.
2929

3030
Let’s see some example and let's try to configure small "test farm" with three devices connected to your host computer. In this example no peripherals (like SD card or EEPROM) are connected to our Mbed boards. We will use three platforms in this example:
31-
* [NXP LPC1768](https://mbed.org/platforms/mbed-LPC1768) board.
32-
* \[Freescale KL25Z](https://mbed.org/platforms/KL25Z) board and
33-
* [STMicro Nucleo F103RB](https://mbed.org/platforms/ST-Nucleo-F103RB) board.
31+
* [NXP LPC1768](https://mbed.org/platforms/mbed-LPC1768) board.
32+
* \[Freescale KL25Z](https://mbed.org/platforms/KL25Z) board and
33+
* [STMicro Nucleo F103RB](https://mbed.org/platforms/ST-Nucleo-F103RB) board.
3434
After connecting boards to our host machine (PC) we can check which serial ports and disks they occupy. For our example let's assume that:
35-
* ```LPC1768``` serial port is on ```COM4``` and disk drive is ```J:```.
36-
* ```KL25Z``` serial port is on ```COM39``` and disk drive is ```E:```.
37-
* ```NUCLEO_F103RB``` serial port is on ```COM11``` and disk drive is ```I:```.
35+
* ```LPC1768``` serial port is on ```COM4``` and disk drive is ```J:```.
36+
* ```KL25Z``` serial port is on ```COM39``` and disk drive is ```E:```.
37+
* ```NUCLEO_F103RB``` serial port is on ```COM11``` and disk drive is ```I:```.
3838
If you are working under Linux your port and disk could look like /dev/ttyACM5 and /media/usb5.
3939

4040
This information is needed to create ```muts_all.json``` configuration file. You can create it in ```mbed/tools/``` directory:
@@ -50,13 +50,13 @@ Its name will be passed to ```singletest.py``` script after ```-M``` (MUTs speci
5050
"disk":"J:\\",
5151
"peripherals": []
5252
},
53-
53+
5454
"2" : {"mcu": "KL25Z",
5555
"port":"COM39",
5656
"disk":"E:\\",
5757
"peripherals": []
5858
},
59-
59+
6060
"3" : {"mcu": "NUCLEO_F103RB",
6161
"port":"COM11",
6262
"disk":"I:\\",
@@ -65,7 +65,7 @@ Its name will be passed to ```singletest.py``` script after ```-M``` (MUTs speci
6565
}
6666
```
6767

68-
Note: We will leave field ```peripherals``` empty for the sake of this example. We will explain it later. All you need to do now is to properly fill fields ```mcu```, ```port``` and ```disk```.
68+
Note: We will leave field ```peripherals``` empty for the sake of this example. We will explain it later. All you need to do now is to properly fill fields ```mcu```, ```port``` and ```disk```.
6969

7070
Note: Please make sure files muts_all.json and test_spec.json are in tools/ directory. We will assume in this example they are.
7171
Where to find ```mcu``` names? You can use option ```-S``` of ```build.py``` script (in ```mbed/tools/``` directory) to check all supported off-line MCUs names.
@@ -104,15 +104,15 @@ muts_all.json:
104104
"port" : "COM77",
105105
"disk" : "G:\\",
106106
"peripherals" : ["TMP102", "digital_loop", "port_loop", "analog_loop", "SD"]},
107-
107+
108108
"2" : {"mcu" : "KL25Z",
109109
"port" : "COM89",
110110
"disk" : "F:\\",
111111
"peripherals" : ["SD", "24LC256", "KL25Z"],
112112
"copy_method" : "copy",
113113
"reset_type" : "default",
114114
"reset_tout" : "2"},
115-
115+
116116
"3" : {"mcu" : "LPC11U24",
117117
"port" : "COM76",
118118
"disk" : "E:\\",
@@ -123,10 +123,10 @@ Please note that for MUT no. 2 few extra parameters were defined: ```copy_method
123123

124124
* ```copy_method``` - STRING - tells test suite which binary copy method should be used.
125125
You may notice that ```singletest.py``` command line help contains description about:
126-
* Option ```-c``` (in MUTs file called ```copy_method```) with available copy methods supported by test suite plugin system.
126+
* Option ```-c``` (in MUTs file called ```copy_method```) with available copy methods supported by test suite plugin system.
127127
* Option ```-r``` (in MUTs file called reset_type) with available reset methods supported by test suite plugin system.
128128
* ```reset_type``` - STRING - some boards may require special reset handling, for example vendor specific command must be executed to reset device.
129-
* ```reset_tout``` - INTEGER - extra timeout just after device is reseted. May be used to wait for few seconds so device may finish booting, flashing data internally etc.
129+
* ```reset_tout``` - INTEGER - extra timeout just after device is reseted. May be used to wait for few seconds so device may finish booting, flashing data internally etc.
130130

131131
Part of help listing for singletest.py:
132132
```
@@ -208,11 +208,11 @@ Having multiple configuration files allows you to manage your test scenarios in
208208

209209
* Set up all platforms and toolchains used during testing.
210210
* Define (using script's ```-n``` switch) which tests you want to run during testing.
211-
* Just run regression (all tests). Regression is default setting for test script.
211+
* Just run regression (all tests). Regression is default setting for test script.
212212

213213
You can also force ```singletest.py``` script to:
214214
* Run only peripherals' tests (switch ```-P```) or
215-
* Just skip peripherals' tests (switch ```-C```).
215+
* Just skip peripherals' tests (switch ```-C```).
216216
* Build mbed SDK, libraries and corresponding tests with multiple cores, just use ```-j X``` option where ```X``` is number of cores you want to use for compilation.
217217
```
218218
$ python singletest.py -i test_spec.json -M muts_all.json -j 8
@@ -225,16 +225,16 @@ $ python singletest.py -i test_spec.json -M muts_all.json -j 8 -O
225225
* Execute each test case multiple times with ```--global-loops X``` option, where ```X``` number of repeats. Additionally use option ```-W``` to continue repeating test cases execution only if they continue to fail.
226226
```
227227
$ python singletest.py -i test_spec.json -M muts_all.json --global-loops 3 -W
228-
```
229-
* Option ```--loops``` can be used to overwrite global loop count and redefine loop count for particular tests. Define test loops as ```TEST_ID=X``` where ```X``` is integer and separate loops count definitions by comma if necessary. E.g. ```TEST_1=5,TEST_2=20,TEST_3=2```.
228+
```
229+
* Option ```--loops``` can be used to overwrite global loop count and redefine loop count for particular tests. Define test loops as ```TEST_ID=X``` where ```X``` is integer and separate loops count definitions by comma if necessary. E.g. ```TEST_1=5,TEST_2=20,TEST_3=2```.
230230
```
231231
$ python singletest.py -i test_spec.json -M muts_all.json RTOS_1=10,RTOS_2=5
232232
```
233233
This will execute test ```RTOS_1``` ten (10) times and test ```RTOS_2``` five (5) times.
234234
* Force non default copy method. Note that mbed platforms can be flashed with just binary drag&drop. We simply copy file onto mbed's disk and interface chip flashes target MCU with given binary. Force non standard (Python specific) copy method by using option ```-c COPY_METHOD``` where ```COPY_METHOD``` can be shell, command line copy command like: ```cp```, ```copy````, ```xcopy``` etc. Make sure those commands are available from command line!
235235
```
236236
$ python singletest.py -i test_spec.json -M muts_all.json -c cp
237-
```
237+
```
238238
* Run only selected tests. You can select which tests should be executed when you run test suite. Use ```-n``` switch to define tests by their ids you want to execute. Use comma to separate test ids:
239239
```
240240
$ python singletest.py -i test_spec.json -M muts_all.json -n RTOS_1,RTOS_2,RTOS_3,MBED_10,MBED_16,MBED_11
@@ -319,20 +319,20 @@ This example will show you how to configure single device, run general tests or
319319
2. We will also connect EEPROM ```24LC256``` to SDA, SCL pins of our Nucleo board and define 24LC256 peripheral to make sure our test suite will run all available tests for ```24LC256```.
320320

321321
Let's configure our one MUT and set uARM as the only compiler we will use to compiler Mbed SDK and tests.
322-
We also need to create two configuration files ```muts_all.json``` and ```test_spec.json``` to pass our small testbed configuration to test script.
322+
We also need to create two configuration files ```muts_all.json``` and ```test_spec.json``` to pass our small testbed configuration to test script.
323323

324324
muts_all.json:
325325
```json
326326
{
327-
"1" : {
327+
"1" : {
328328
"mcu": "NUCLEO_F334R8",
329329
"port":"COM46",
330330
"disk":"E:\\",
331331
"peripherals": ["24LC256"]
332332
}
333333
}
334334
```
335-
Note: By defining ```"peripherals": ["24LC256"]``` we are passing to test suite information that this particular board has EEPROM 24LC256 connected to our board.
335+
Note: By defining ```"peripherals": ["24LC256"]``` we are passing to test suite information that this particular board has EEPROM 24LC256 connected to our board.
336336

337337
test_spec.json:
338338
```json
@@ -342,7 +342,7 @@ test_spec.json:
342342
}
343343
}
344344
```
345-
Note:
345+
Note:
346346
* Please make sure device is connected before we will start running tests.
347347
* Please make sure files ```muts_all.json``` and ```test_spec.json``` are in ```mbed/tools/``` directory.
348348
Now you can call test suite and execute tests:
@@ -409,7 +409,7 @@ Execute above command to:
409409
* Force to loop test RTOS_1 to execute 3 times.
410410
* Force to loop test RTOS_2 to execute 4 times.
411411
* Force to loop test RTOS_3 to execute 5 times.
412-
* Force to loop test MBED_11 to execute 5 times.
412+
* Force to loop test MBED_11 to execute 5 times.
413413

414414
```
415415
$ python singletest.py -i test_spec.json -M muts_all.json -n RTOS_1,RTOS_2,RTOS_3,MBED_10,MBED_16,MBED_11 --shuffle --global-loops 3 --loops RTOS_1=3,RTOS_2=4,RTOS_3=5,MBED_11=5
@@ -421,15 +421,15 @@ $ python singletest.py -i test_spec.json -M muts_all.json -n RTOS_1,RTOS_2,RTOS_
421421

422422
Mbed SDK test suite supports writing tests using CppUTest. All you need to do it to provide CppUTest sources and includes with Mbed SDK port. This is already done for you so all you need to do it to get proper sources in your project directory.
423423
CppUTest’s core design principles are:
424-
* Simple in design and simple in use.
425-
* Portable to old and new platforms.
424+
* Simple in design and simple in use.
425+
* Portable to old and new platforms.
426426
* Build with Test-driven Development in mind.
427427

428428
## From where you can get more help about CppUTest library and unit testing
429429
• You can read [CppUTest manual](http://cpputest.github.io/manual.html)
430-
* [CppUTest forum](https://groups.google.com/forum/?fromgroups#!forum/cpputest)
430+
* [CppUTest forum](https://groups.google.com/forum/?fromgroups#!forum/cpputest)
431431
* [CppUTest on GitHub](https://github.com/cpputest/cpputest)
432-
* Finally, if you think unit testing is new concept for you, you can have a grasp of it on Wikipedia pages about [unit testing](http://en.wikipedia.org/wiki/Unit_testing) and continue from there.
432+
* Finally, if you think unit testing is new concept for you, you can have a grasp of it on Wikipedia pages about [unit testing](http://en.wikipedia.org/wiki/Unit_testing) and continue from there.
433433

434434
## How to add CppUTest to your current Mbed SDK installation
435435

@@ -494,7 +494,7 @@ $ hg clone https://mbed.org/users/rgrover1/code/cpputest/
494494

495495
After above three steps you should have proper directory structure. All you need to do now is to configure your ```mbed_settings.py``` in ```mbed``` directory. Please refer to mbed SDK build script documentation for details.
496496

497-
## CppUTest with mbed port
497+
## CppUTest with mbed port
498498
To make sure you actualy have CppUTest library with mbed SDK port you can go to CppUTest ```armcc``` platform directory:
499499
```
500500
$ cd c:/Projects/Project/cpputest/src/Platforms/armcc/
@@ -505,7 +505,7 @@ You should find part of code responsible for porting console on default serial p
505505
```c++
506506
#include "Serial.h"
507507
using namespace mbed;
508-
508+
509509
int PlatformSpecificPutchar(int c)
510510
{
511511
/* Please modify this block for test results to be reported as
@@ -514,7 +514,7 @@ int PlatformSpecificPutchar(int c)
514514
#define NEED_TEST_REPORT_AS_CONSOLE_OUTPUT 1
515515
#if NEED_TEST_REPORT_AS_CONSOLE_OUTPUT
516516
extern Serial console;
517-
517+
518518
#define NEED_LINE_FEED_IN_ADDITION_TO_NEWLINE 1
519519
#if NEED_LINE_FEED_IN_ADDITION_TO_NEWLINE
520520
/* CppUTest emits \n line terminators in its reports; some terminals
@@ -523,7 +523,7 @@ int PlatformSpecificPutchar(int c)
523523
console.putc('\r');
524524
}
525525
#endif /* #if NEED_LINE_FEED_IN_ADDITION_TO_NEWLINE */
526-
526+
527527
return (console.putc(c));
528528
#else /* NEED_TEST_REPORT_AS_CONSOLE_OUTPUT */
529529
return (0);
@@ -596,7 +596,7 @@ All tests defined in test suite are described in ```mbed/tools/tests.py``` file.
596596
Note: In dependency section we've added library ```CPPUTEST_LIBRARY``` which is pointing build script to CppUTest library with mbed port. This is a must for unit tests to be compiled with CppUTest library.
597597

598598
### Tests are now divided into two types:
599-
#### 'Hello world' tests
599+
#### 'Hello world' tests
600600
First type of test cases we call 'hello world' tests. They do not dependent on CppUTest library and are monolithic programs usually composed of one main function. You can find this tests in below example directories:
601601

602602
* ```mbed/libraries/tests/mbed/```
@@ -606,7 +606,7 @@ First type of test cases we call 'hello world' tests. They do not dependent on C
606606

607607
Usually ‘hello world’ test cases are using ```test_env.cpp``` and ```test_env.h``` files which implement simple test framework used to communicate with host test and help test framework instrument your tests.
608608

609-
Below you can see listing of ```test_env.h``` file which contains simple macro definitions used to communicate (via serial port printouts) between test case (on hardware) and host test script (on host computer).
609+
Below you can see listing of ```test_env.h``` file which contains simple macro definitions used to communicate (via serial port printouts) between test case (on hardware) and host test script (on host computer).
610610
Each use case should print on console basic information like:
611611
* Default test case timeout.
612612
* Which host test should be used to supervise test case execution.
@@ -717,53 +717,6 @@ TEST(BusOut_mask, led_1_nc_2_nc_nc_3)
717717
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
718718
CHECK_EQUAL(0x25, bus_data.mask());
719719
}
720-
721-
///////////////////////////////////////////////////////////////////////////////
722-
723-
#ifdef MBED_OPERATORS
724-
TEST_GROUP(BusOut_digitalout_write)
725-
{
726-
};
727-
728-
TEST(BusOut_digitalout_write, led_nc)
729-
{
730-
BusOut bus_data(NC);
731-
CHECK_EQUAL(false, bus_data[0].is_connected())
732-
}
733-
734-
TEST(BusOut_digitalout_write, led_1_2_3)
735-
{
736-
BusOut bus_data(LED1, LED2, LED3);
737-
bus_data[0].write(1);
738-
bus_data[1].write(1);
739-
bus_data[2].write(1);
740-
CHECK(bus_data[0].read());
741-
CHECK(bus_data[1].read());
742-
CHECK(bus_data[2].read());
743-
}
744-
745-
TEST(BusOut_digitalout_write, led_1_2_3_nc_nc)
746-
{
747-
BusOut bus_data(LED1, LED2, LED3, NC, NC);
748-
bus_data[0].write(0);
749-
bus_data[1].write(0);
750-
bus_data[2].write(0);
751-
CHECK(bus_data[0].read() == 0);
752-
CHECK(bus_data[1].read() == 0);
753-
CHECK(bus_data[2].read() == 0);
754-
}
755-
756-
TEST(BusOut_digitalout_write, led_1_nc_2_nc_nc_3)
757-
{
758-
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
759-
bus_data[0].write(1);
760-
bus_data[2].write(0);
761-
bus_data[5].write(0);
762-
CHECK(bus_data[0].read());
763-
CHECK(bus_data[2].read() == 0);
764-
CHECK(bus_data[5].read() == 0);
765-
}
766-
#endif
767720
```
768721
769722
## Example
@@ -789,7 +742,7 @@ Bellow snippet shows how to modify 'automated' flag so test suite will consider
789742
# 1. test runner - main function with call to CommandLineTestRunner::RunAllTests(ac, av)
790743
# 2. Serial console object to print test result on serial port console
791744
#
792-
745+
793746
# Unit testing with cpputest library
794747
{
795748
"id": "UT_1", "description": "Basic",

hal/api/AnalogIn.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class AnalogIn {
8484
return ret;
8585
}
8686

87-
#ifdef MBED_OPERATORS
8887
/** An operator shorthand for read()
8988
*
9089
* The float() operator can be used as a shorthand for read() to simplify common code sequences
@@ -102,7 +101,6 @@ class AnalogIn {
102101
// Underlying call is thread safe
103102
return read();
104103
}
105-
#endif
106104

107105
virtual ~AnalogIn() {
108106
// Do nothing

hal/api/AnalogOut.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class AnalogOut {
9999
return ret;
100100
}
101101

102-
#ifdef MBED_OPERATORS
103102
/** An operator shorthand for write()
104103
*/
105104
AnalogOut& operator= (float percent) {
@@ -120,7 +119,6 @@ class AnalogOut {
120119
// Underlying read call is thread safe
121120
return read();
122121
}
123-
#endif
124122

125123
virtual ~AnalogOut() {
126124
// Do nothing

hal/api/BusIn.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ class BusIn {
7171
return _nc_mask;
7272
}
7373

74-
#ifdef MBED_OPERATORS
7574
/** A shorthand for read()
7675
*/
7776
operator int();
7877

7978
/** Access to particular bit in random-iterator fashion
8079
*/
8180
DigitalIn & operator[] (int index);
82-
#endif
8381

8482
protected:
8583
DigitalIn* _pin[16];

hal/api/BusInOut.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class BusInOut {
8585
return _nc_mask;
8686
}
8787

88-
#ifdef MBED_OPERATORS
8988
/** A shorthand for write()
9089
*/
9190
BusInOut& operator= (int v);
@@ -98,7 +97,6 @@ class BusInOut {
9897
/** A shorthand for read()
9998
*/
10099
operator int();
101-
#endif
102100

103101
protected:
104102
virtual void lock();

hal/api/BusOut.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class BusOut {
6969
return _nc_mask;
7070
}
7171

72-
#ifdef MBED_OPERATORS
7372
/** A shorthand for write()
7473
*/
7574
BusOut& operator= (int v);
@@ -82,7 +81,6 @@ class BusOut {
8281
/** A shorthand for read()
8382
*/
8483
operator int();
85-
#endif
8684

8785
protected:
8886
virtual void lock();

hal/api/CallChain.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,12 @@ class CallChain {
154154
*/
155155
void call();
156156

157-
#ifdef MBED_OPERATORS
158157
void operator ()(void) {
159158
call();
160159
}
161160
pFunctionPointer_t operator [](int i) const {
162161
return get(i);
163162
}
164-
#endif
165163

166164
/* disallow copy constructor and assignment operators */
167165
private:
@@ -173,4 +171,3 @@ class CallChain {
173171
} // namespace mbed
174172

175173
#endif
176-

0 commit comments

Comments
 (0)