1
1
# This file is part of arduino-cli.
2
-
2
+ #
3
3
# Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
4
-
4
+ #
5
5
# This software is released under the GNU General Public License version 3,
6
6
# which covers the main part of arduino-cli.
7
7
# The terms of this license can be found at:
8
8
# https://www.gnu.org/licenses/gpl-3.0.en.html
9
-
9
+ #
10
10
# You can be released from the requirements of the above licenses by purchasing
11
11
# a commercial license. Buying such a license is mandatory if you want to modify or
12
12
# otherwise use the software for commercial activities involving the Arduino
13
13
# software without disclosing the source code of your own applications. To purchase
14
14
# a commercial license, send an email to license@arduino.cc.
15
- import pytest
16
15
import json
17
16
import os
17
+ import pytest
18
18
19
19
from .common import running_on_ci
20
20
@@ -62,11 +62,11 @@ def test_compile_with_simple_sketch(run_command, data_dir):
62
62
# let's test from the logs if the hex file produced by successful compile is moved to our sketch folder
63
63
log_json = open (log_file_path , 'r' )
64
64
json_log_lines = log_json .readlines ()
65
- assert is_message_in_json_log_lines ( "Executing `arduino compile`" , json_log_lines )
66
- assert is_message_in_json_log_lines (
67
- "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name ,
68
- fqbn = fqbn ),
69
- json_log_lines )
65
+ expected_trace_sequence = [
66
+ "Compile {sketch} for {fqbn} started" . format ( sketch = sketch_path , fqbn = fqbn ),
67
+ "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = fqbn )
68
+ ]
69
+ assert is_message_sequence_in_json_log_traces ( expected_trace_sequence , json_log_lines )
70
70
71
71
72
72
@pytest .mark .skipif (running_on_ci (), reason = "VMs have no serial ports" )
@@ -77,7 +77,7 @@ def test_compile_and_compile_combo(run_command, data_dir):
77
77
78
78
# Install required core(s)
79
79
result = run_command ("core install arduino:avr" )
80
- # result = run_command("core install arduino:samd")
80
+ result = run_command ("core install arduino:samd" )
81
81
assert result .ok
82
82
83
83
# Create a test sketch
@@ -126,31 +126,31 @@ def test_compile_and_compile_combo(run_command, data_dir):
126
126
for board in detected_boards :
127
127
log_file_name = "{fqbn}-compile.log" .format (fqbn = board .get ('fqbn' ))
128
128
log_file_path = os .path .join (data_dir , log_file_name )
129
- result = run_command (
130
- "compile -b {fqbn} --upload -p {address} {sketch_path} --log-format json --log-file {log_file} --log-level trace" .format (
131
- fqbn = board .get ('fqbn' ),
132
- address = board .get ('address' ),
133
- sketch_path = sketch_path ,
134
- log_file = log_file_path
135
- )
136
- )
129
+ command_log_flags = "--log-format json --log-file {} --log-level trace" .format (log_file_path )
130
+ result = run_command ("compile -b {fqbn} --upload -p {address} {sketch_path} {log_flags}" .format (
131
+ fqbn = board .get ('fqbn' ),
132
+ address = board .get ('address' ),
133
+ sketch_path = sketch_path ,
134
+ log_flags = command_log_flags
135
+ ))
137
136
assert result .ok
138
137
# check from the logs if the bin file were uploaded on the current board
139
138
log_json = open (log_file_path , 'r' )
140
139
json_log_lines = log_json .readlines ()
141
- assert is_message_in_json_log_lines ("Executing `arduino compile`" , json_log_lines )
142
- assert is_message_in_json_log_lines (
143
- "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name ,
144
- fqbn = board .get (
145
- 'fqbn' )),
146
- json_log_lines )
147
- assert is_message_in_json_log_lines ("Executing `arduino upload`" , json_log_lines )
148
- assert is_message_in_json_log_lines (
149
- "Upload {sketch} on {fqbn} successful" .format (sketch = sketch_name ,
150
- fqbn = board .get (
151
- 'fqbn' )),
152
- json_log_lines )
153
-
154
-
155
- def is_message_in_json_log_lines (message , log_json_lines ):
156
- return len ([index for index , entry in enumerate (log_json_lines ) if json .loads (entry ).get ("msg" ) == message ]) == 1
140
+ expected_trace_sequence = [
141
+ "Compile {sketch} for {fqbn} started" .format (sketch = sketch_path , fqbn = board .get ('fqbn' )),
142
+ "Compile {sketch} for {fqbn} successful" .format (sketch = sketch_name , fqbn = board .get ('fqbn' )),
143
+ "Upload {sketch} on {fqbn} started" .format (sketch = sketch_path , fqbn = board .get ('fqbn' )),
144
+ "Upload {sketch} on {fqbn} successful" .format (sketch = sketch_name , fqbn = board .get ('fqbn' ))
145
+ ]
146
+ assert is_message_sequence_in_json_log_traces (expected_trace_sequence , json_log_lines )
147
+
148
+
149
+ def is_message_sequence_in_json_log_traces (message_sequence , log_json_lines ):
150
+ trace_entries = []
151
+ for entry in log_json_lines :
152
+ entry = json .loads (entry )
153
+ if entry .get ("level" ) == "trace" :
154
+ if entry .get ("msg" ) in message_sequence :
155
+ trace_entries .append (entry .get ("msg" ))
156
+ return message_sequence == trace_entries
0 commit comments