test/security_manager_sc: flush coverage data before exit

This commit is contained in:
Matthias Ringwald 2020-09-21 17:11:00 +02:00
parent 35e92150ad
commit b4394846ba
3 changed files with 19 additions and 6 deletions

View File

@ -79,7 +79,7 @@ VPATH += ${BTSTACK_ROOT}/chipset/zephyr
CFLAGS += $(shell pkg-config libusb-1.0 --cflags) CFLAGS += $(shell pkg-config libusb-1.0 --cflags)
LDFLAGS += $(shell pkg-config libusb-1.0 --libs) LDFLAGS += $(shell pkg-config libusb-1.0 --libs)
CFLAGS += -fprofile-arcs -ftest-coverage -fsanitize=address,undefined CFLAGS += -fprofile-arcs -ftest-coverage -fsanitize=address,undefined -DCOVERAGE
CORE_OBJ = $(CORE:.c=.o) CORE_OBJ = $(CORE:.c=.o)
COMMON_OBJ = $(COMMON:.c=.o) COMMON_OBJ = $(COMMON:.c=.o)

View File

@ -63,6 +63,11 @@
#include "l2cap.h" #include "l2cap.h"
#include "btstack_stdin.h" #include "btstack_stdin.h"
#ifdef COVERAGE
// guesswork:
void __gcov_flush(void);
#endif
#define HEARTBEAT_PERIOD_MS 1000 #define HEARTBEAT_PERIOD_MS 1000
const uint8_t adv_data[] = { const uint8_t adv_data[] = {
@ -343,6 +348,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
} }
static void stdin_process(char c){ static void stdin_process(char c){
log_info("stdin: %c (%02x)", c, c);
// passkey input // passkey input
if (ui_digits_for_passkey && c >= '0' && c <= '9'){ if (ui_digits_for_passkey && c >= '0' && c <= '9'){
printf("%c", c); printf("%c", c);
@ -422,7 +428,11 @@ static void stdin_process(char c){
sm_request_pairing(connection_handle); sm_request_pairing(connection_handle);
break; break;
case 'x': case 'x':
printf("Exit\n"); #ifdef COVERAGE
log_info("Flush gcov");
__gcov_flush();
#endif
printf("EXIT\n");
exit(0); exit(0);
break; break;
default: default:

View File

@ -49,7 +49,7 @@ failures = [
debug = False debug = False
regenerate = False regenerate = False
# usb_paths = ['4', '6'] # usb_paths = ['4', '6']
usb_paths = ['3', '5'] usb_paths = ['1', '2']
class Node: class Node:
@ -117,7 +117,7 @@ class Node:
args.append('-o') args.append('-o')
args.append(self.oob_data) args.append(self.oob_data)
print('%s - "%s"' % (self.name, ' '.join(args))) print('%s - "%s"' % (self.name, ' '.join(args)))
self.p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) self.p = subprocess.Popen(args, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(self.stdin, self.stdout) = (self.p.stdin, self.p.stdout) (self.stdin, self.stdout) = (self.p.stdin, self.p.stdout)
self.linebuffer = '' self.linebuffer = ''
@ -137,10 +137,13 @@ class Node:
self.peer_addr = addr self.peer_addr = addr
def write(self, string): def write(self, string):
self.stdin.write(string) self.stdin.write(string.encode('utf-8'))
def terminate(self): def terminate(self):
self.write('x') self.write('x')
# wait for 'EXIT' message indicating coverage data was written
while not self.got_line():
self.read_stdout()
self.p.terminate() self.p.terminate()
def run(test_descriptor, nodes): def run(test_descriptor, nodes):