Skip to content

Commit 8313769

Browse files
robertsipkartakacs
authored andcommitted
Create a standalone tool for coverage measurement (#245)
JSRemoteTest-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
1 parent 6834258 commit 8313769

File tree

9 files changed

+598
-187
lines changed

9 files changed

+598
-187
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ env:
2222
- OPTS="--device=rpi2 --app=iotjs" RUN_DOCKER=yes
2323
- OPTS="--device=rpi2 --app=jerryscript" RUN_DOCKER=yes
2424
- OPTS="--device=artik530 --app=iotjs" RUN_DOCKER=yes
25-
- OPTS="--device=artik530 --app=jerryscript" RUN_DOCKER=yes
2625
- OPTS="--device=artik053 --app=iotjs" RUN_DOCKER=yes
2726
- OPTS="--device=artik053 --app=jerryscript" RUN_DOCKER=yes
2827
- OPTS="--device=stm32f4dis --app=iotjs" RUN_DOCKER=yes

jstest/__main__.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def parse_options():
8484
help='do not measure memory statistics (default: %(default)s)')
8585

8686
parser.add_argument('--coverage',
87-
metavar='SERVER_ADDRESS(HOST:PORT)',
88-
help='use jerry-debugger to calculate the JS source code coverage')
87+
action='store_true', default=False,
88+
help='calculate the JS source code coverage (default: %(default)s)')
8989

9090
parser.add_argument('--quiet',
9191
action='store_true', default=False,
@@ -152,17 +152,17 @@ def adjust_options(options):
152152
'''
153153
if options.device == 'artik530' and options.app == 'jerryscript':
154154
jstest.console.warning('JerryScript is not supported for Tizen.')
155-
options.no_build = True
156-
options.no_flash = True
157-
options.no_test = True
155+
sys.exit(1)
158156

159157
# TODO: resolve this section, debugger should work on every target.
160158
if options.debugger:
161159
if options.device == 'stm32f4dis':
162-
jstest.console.warning('Debugger is not supported on STM32F4-Discovery')
160+
jstest.console.warning('Debugger is disabled, beacuse it is not supported on'
161+
' STM32F4-Discovery')
163162
options.debugger = None
164163
elif options.device == 'artik053' and options.app == 'jerryscript':
165-
jstest.console.warning('Debugger is not supported on ARTIK053 with JerryScript')
164+
jstest.console.warning('Debugger is disabled, because it is not supported on'
165+
' ARTIK053 with JerryScript')
166166
options.debugger = None
167167

168168
if options.emulate:
@@ -183,12 +183,18 @@ def adjust_options(options):
183183
atexit.register(pseudo_terminal.close_pseudo_terminal, options)
184184

185185
if options.coverage:
186+
if not options.debugger or options.debugger == 'no_address':
187+
jstest.console.error('Coverage measurement is require the enabled debugger option'
188+
' with a valid server ADDRESS')
189+
sys.exit(1)
190+
186191
if options.app != 'iotjs':
187192
jstest.console.warning('Coverage measurement is only supported with IoT.js!')
188-
options.coverage = None
193+
sys.exit(1)
189194

190-
elif options.buildtype != 'debug':
191-
jstest.console.warning('Coverage measurement is only supported with debug build type!')
195+
if options.buildtype != 'debug':
196+
jstest.console.warning('Buidltype was set to debug because the coverage measurement is'
197+
' only supported with debug build type!')
192198
# Overwrite the buildtype option to debug.
193199
# In IoT.js the code is minimized in release mode, which will mess up the line numbers.
194200
options.buildtype = 'debug'

jstest/resources/patches/coverage-client.diff

Lines changed: 0 additions & 100 deletions
This file was deleted.

jstest/resources/patches/jerryscript-coverage.diff

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
1-
diff --git a/jerry-core/debugger/debugger-ws.c b/jerry-core/debugger/debugger-ws.c
2-
index 0f12a69..eac1ac2 100644
3-
--- a/jerry-core/debugger/debugger-ws.c
4-
+++ b/jerry-core/debugger/debugger-ws.c
5-
@@ -22,6 +22,7 @@
6-
#include <arpa/inet.h>
7-
#include <errno.h>
8-
#include <fcntl.h>
9-
+#include <sys/socket.h>
10-
#include <unistd.h>
11-
12-
/* JerryScript debugger protocol is a simplified version of RFC-6455 (WebSockets). */
131
diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c
14-
index 55bd8b9..f73ccd5 100644
2+
index 4330ef4..26f8899 100644
153
--- a/jerry-core/parser/js/js-parser-statm.c
164
+++ b/jerry-core/parser/js/js-parser-statm.c
17-
@@ -341,7 +341,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
18-
cbc_argument_t last_cbc = context_p->last_cbc;
19-
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
20-
5+
@@ -332,7 +332,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
6+
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
7+
&& ident_line_counter != context_p->last_breakpoint_line)
8+
{
219
- parser_emit_cbc (context_p, CBC_BREAKPOINT_DISABLED);
2210
+ parser_emit_cbc (context_p, CBC_BREAKPOINT_ENABLED);
2311
parser_flush_cbc (context_p);
2412

2513
parser_append_breakpoint_info (context_p, JERRY_DEBUGGER_BREAKPOINT_LIST, ident_line_counter);
26-
@@ -1707,7 +1707,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
14+
@@ -1751,7 +1751,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
2715
{
2816
JERRY_ASSERT (context_p->last_breakpoint_line == 0);
2917

@@ -32,7 +20,7 @@ index 55bd8b9..f73ccd5 100644
3220
parser_flush_cbc (context_p);
3321

3422
parser_append_breakpoint_info (context_p, JERRY_DEBUGGER_BREAKPOINT_LIST, context_p->token.line);
35-
@@ -1777,7 +1777,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
23+
@@ -1821,7 +1821,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
3624
&& context_p->token.type != LEXER_KEYW_CASE
3725
&& context_p->token.type != LEXER_KEYW_DEFAULT)
3826
{
@@ -42,10 +30,10 @@ index 55bd8b9..f73ccd5 100644
4230

4331
parser_append_breakpoint_info (context_p, JERRY_DEBUGGER_BREAKPOINT_LIST, context_p->token.line);
4432
diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c
45-
index bdda834..41d7bff 100644
33+
index 4f145e3..707ca01 100644
4634
--- a/jerry-core/parser/js/js-parser.c
4735
+++ b/jerry-core/parser/js/js-parser.c
48-
@@ -1433,7 +1433,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
36+
@@ -1492,7 +1492,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
4937
&& !(context_p->status_flags & PARSER_DEBUGGER_BREAKPOINT_APPENDED))
5038
{
5139
/* Always provide at least one breakpoint. */
@@ -54,7 +42,7 @@ index bdda834..41d7bff 100644
5442
parser_flush_cbc (context_p);
5543

5644
parser_append_breakpoint_info (context_p, JERRY_DEBUGGER_BREAKPOINT_LIST, context_p->token.line);
57-
@@ -1819,7 +1819,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
45+
@@ -1887,7 +1887,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
5846
flags = cbc_flags[opcode];
5947

6048
#ifdef JERRY_DEBUGGER

jstest/resources/patches/tizenrt-coverage.diff

Lines changed: 0 additions & 38 deletions
This file was deleted.

jstest/resources/resources.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@
8080
"file": "%{patches}/tizenrt-mbedtls.diff"
8181
},
8282
{
83-
"condition": "'%{appname}' == 'iotjs' and %{coverage}",
84-
"file": "%{patches}/tizenrt-coverage.diff"
85-
},
86-
{
87-
"file": "%{patches}/tizenrt-openocd.diff"
83+
"file": "%{patches}/tizenrt-openocd.diff",
84+
"revert": false
8885
}
8986
]
9087
}
@@ -191,7 +188,7 @@
191188
"linker-map": "%{iotjs}/build/%{target}/%{build-type}/iotjs.map",
192189
"libdir": "%{iotjs}/build/%{target}/%{build-type}/lib",
193190
"image": "%{iotjs}/build/%{target}/%{build-type}/bin/iotjs",
194-
"coverage-client": "%{iotjs}/deps/jerry/jerry-debugger/jerry-client-ws.py",
191+
"coverage-client": "%{js-remote-test}/tools/coverage_client.py",
195192
"js-sources" : "%{iotjs}/src/js/"
196193
},
197194
"config": [
@@ -230,11 +227,6 @@
230227
"file": "%{patches}/jerryscript-coverage.diff",
231228
"submodule": "%{iotjs}/deps/jerry/"
232229
},
233-
{
234-
"condition": "'%{device}' in ['artik053', 'artik530', 'rpi2'] and %{coverage}",
235-
"file": "%{patches}/coverage-client.diff",
236-
"submodule": "%{iotjs}/deps/jerry/"
237-
},
238230
{
239231
"condition": "'%{device}' in ['artik530', 'rpi2'] and %{memstat}",
240232
"file": "%{patches}/linux-iotjs-stack.diff"

jstest/testrunner/devices/artik053.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def execute(self, testset, test):
5151
self.channel.putc(command[self.app])
5252
self.channel.readline()
5353

54-
if self.env.options.coverage and self.app == 'iotjs':
54+
if self.env.options.coverage:
5555
# Start the client script on a different thread for coverage.
5656
client_thread = Thread(target=testrunner_utils.run_coverage_script,
5757
kwargs={'env': self.env})

jstest/testrunner/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def parse_coverage_info(env, coverage_output):
9393
continue
9494

9595
filename, _ = os.path.splitext(js_name)
96+
if filename not in coverage_info:
97+
continue
9698

9799
# Iterate reached js files.
98100
for line_number, line_value in raw_data[js_name].iteritems():
@@ -159,7 +161,7 @@ def run_coverage_script(env):
159161
# Add latency because the start up of the debug server needs time.
160162
time.sleep(2)
161163

162-
address = env.options.coverage
164+
address = env.options.debugger
163165
iotjs = env.modules.iotjs
164166
coverage_client = iotjs.paths['coverage-client']
165167
device = env.options.device
@@ -171,9 +173,8 @@ def run_coverage_script(env):
171173
result_path = utils.join(result_dir, result_name)
172174

173175
utils.mkdir(result_dir)
174-
utils.execute(paths.PROJECT_ROOT, coverage_client, ['--non-interactive',
175-
'--coverage-output=%s' % result_path,
176-
address])
176+
utils.execute(paths.PROJECT_ROOT, 'python',
177+
[coverage_client, '--coverage-output', result_path, address])
177178

178179

179180
def read_port_from_url(url):

0 commit comments

Comments
 (0)