Skip to content

Commit ab2433c

Browse files
committed
Test bugfix: bugfixed RTOS (mutex, semaphore) - not thread safe stdio causes test result prints to be interrupted by threads' printing
test bugfix: added support for targetID print from device for 'hello world' and 'stdio' testcases
1 parent d96e6ca commit ab2433c

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

libraries/tests/rtos/mbed/mutex/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ DigitalOut led(LED1);
1616

1717
volatile int change_counter = 0;
1818
volatile bool changing_counter = false;
19+
volatile bool mutex_defect = false;
1920

2021
bool manipulate_protected_zone(const int thread_delay) {
2122
bool result = true;
2223

2324
stdio_mutex.lock(); // LOCK
2425
if (changing_counter == true) {
25-
print_char('e'); // if changing_counter is true access is not exclusively
26+
// 'e' stands for error. If changing_counter is true access is not exclusively
27+
print_char('e');
2628
result = false;
27-
notify_completion(false);
28-
exit(1);
29+
mutex_defect = true;
2930
}
3031
changing_counter = true;
3132

@@ -53,17 +54,19 @@ int main() {
5354
const int t3_delay = THREAD_DELAY * 3;
5455
Thread t2(test_thread, (void *)t2_delay);
5556
Thread t3(test_thread, (void *)t3_delay);
56-
bool result = true;
5757

5858
while (true) {
5959
// Thread 1 action
6060
Thread::wait(t1_delay);
6161
manipulate_protected_zone(t1_delay);
62-
if (change_counter >= SIGNALS_TO_EMIT) {
62+
if (change_counter >= SIGNALS_TO_EMIT or mutex_defect == true) {
63+
t2.terminate();
64+
t3.terminate();
6365
break;
6466
}
6567
}
6668

67-
notify_completion(result);
69+
fflush(stdout);
70+
notify_completion(!mutex_defect);
6871
return 0;
6972
}

libraries/tests/rtos/mbed/semaphore/main.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "test_env.h"
33
#include "rtos.h"
44

5-
#define THREAD_DELAY 100
5+
#define THREAD_DELAY 75
66
#define SEMAPHORE_SLOTS 2
77
#define SEM_CHANGES 100
88

@@ -16,6 +16,7 @@ Semaphore two_slots(SEMAPHORE_SLOTS);
1616

1717
volatile int change_counter = 0;
1818
volatile int sem_counter = 0;
19+
volatile bool sem_defect = false;
1920

2021
void test_thread(void const *delay) {
2122
const int thread_delay = int(delay);
@@ -26,8 +27,7 @@ void test_thread(void const *delay) {
2627
const char msg = sem_lock_failed ? 'e' : sem_counter + '0';
2728
print_char(msg);
2829
if (sem_lock_failed) {
29-
notify_completion(false);
30-
exit(1);
30+
sem_defect = true;
3131
}
3232
Thread::wait(thread_delay);
3333
print_char('.');
@@ -46,10 +46,15 @@ int main (void) {
4646
Thread t3(test_thread, (void *)t3_delay);
4747

4848
while (true) {
49-
if (change_counter >= SEM_CHANGES) {
50-
notify_completion(true);
49+
if (change_counter >= SEM_CHANGES or sem_defect == true) {
50+
t1.terminate();
51+
t2.terminate();
52+
t3.terminate();
5153
break;
5254
}
5355
}
56+
57+
fflush(stdout);
58+
notify_completion(!sem_defect);
5459
return 0;
5560
}

workspace_tools/build_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
limitations under the License.
1616
"""
1717

18-
import tempfile
1918
import re
20-
from os.path import join, exists, basename
21-
from shutil import rmtree
19+
import tempfile
20+
2221
from types import ListType
22+
from shutil import rmtree
23+
from os.path import join, exists, basename
2324

2425
from workspace_tools.utils import mkdir, run_cmd, run_cmd_ext
25-
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
2626
from workspace_tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON
27-
from workspace_tools.libraries import Library
2827
from workspace_tools.targets import TARGET_NAMES, TARGET_MAP
28+
from workspace_tools.libraries import Library
29+
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
2930

3031

3132
def build_project(src_path, build_path, target, toolchain_name,

workspace_tools/host_tests/hello_auto.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,27 @@ class HelloTest(DefaultTest):
2222
HELLO_WORLD = "Hello World\n"
2323

2424
def run(self):
25-
c = self.mbed.serial_read(len(self.HELLO_WORLD))
25+
c = self.mbed.serial_read(1)
26+
if c is None:
27+
self.print_result("ioerr_serial")
28+
return
29+
data_to_read = len(self.HELLO_WORLD)
30+
read_buffer = ''
31+
if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6
32+
#Read additional 39 bytes of TargetID
33+
if self.mbed.serial_read(39) is None:
34+
self.print_result("ioerr_serial")
35+
return
36+
else:
37+
data_to_read -= 1
38+
read_buffer += c
39+
c = self.mbed.serial_read(data_to_read)
40+
read_buffer += c
2641
if c is None:
2742
self.print_result("ioerr_serial")
2843
return
29-
stdout.write(c)
30-
if c == self.HELLO_WORLD: # Hello World received
44+
stdout.write(read_buffer)
45+
if read_buffer == self.HELLO_WORLD: # Hello World received
3146
self.print_result('success')
3247
else:
3348
self.print_result('failure')

workspace_tools/host_tests/stdio_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from sys import stdout
2323

2424
class StdioTest(DefaultTest):
25-
PATTERN_INT_VALUE = "^Your value was: (-?\d+)"
25+
PATTERN_INT_VALUE = "Your value was: (-?\d+)"
2626
re_detect_int_value = re.compile(PATTERN_INT_VALUE)
2727

2828
def run(self):

workspace_tools/host_tests/wait_us_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def run(self):
3232
return
3333
if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6
3434
#Read additional 39 bytes of TargetID
35-
if not self.mbed.serial_read(39):
35+
if self.mbed.serial_read(39) is None:
3636
self.print_result("ioerr_serial")
3737
return
3838
c = self.mbed.serial_read(1) # Re-read first 'tick'

0 commit comments

Comments
 (0)