Skip to content

Commit e673ad5

Browse files
author
Roberto Sora
committed
add log lines to compile and upload in case of success and related tests
1 parent 9d46ef9 commit e673ad5

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

commands/compile/compile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
215215
return nil, fmt.Errorf("copying elf file: %s", err)
216216
}
217217

218+
logrus.Infof("Compile %s for %s successful", sketch.Name, fqbnIn)
219+
218220
return &rpc.CompileResp{}, nil
219221
}

commands/upload/upload.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
248248
if err := cmd.Wait(); err != nil {
249249
return nil, fmt.Errorf("uploading error: %s", err)
250250
}
251+
252+
logrus.Infof("Upload %s on %s successful", sketch.Name, fqbnIn)
253+
251254
return &rpc.UploadResp{}, nil
252255
}
253256

test/test_compile.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,31 @@ def test_compile_with_simple_sketch(run_command, data_dir):
4242
result = run_command("core install arduino:avr")
4343
assert result.ok
4444

45-
sketch_path = os.path.join(data_dir, "CompileIntegrationTest")
45+
sketch_name = "CompileIntegrationTest"
46+
sketch_path = os.path.join(data_dir, sketch_name)
47+
fqbn = "arduino:avr:uno"
4648

4749
# Create a test sketch
48-
result = run_command("sketch new CompileIntegrationTest")
50+
result = run_command("sketch new {}".format(sketch_name))
4951
assert result.ok
5052
assert "Sketch created in: {}".format(sketch_path) in result.stdout
5153

5254
# Build sketch for arduino:avr:uno
53-
result = run_command("compile -b arduino:avr:uno {}".format(sketch_path))
55+
log_file_name = "compile.log"
56+
log_file_path = os.path.join(data_dir, log_file_name)
57+
result = run_command(
58+
"compile -b {fqbn} {sketch_path} --log-format json --log-file {log_file} --log-level trace".format(
59+
fqbn=fqbn, sketch_path=sketch_path, log_file=log_file_path))
5460
assert result.ok
55-
assert "Sketch uses" in result.stdout
61+
62+
# let's test from the logs if the hex file produced by successful compile is moved to our sketch folder
63+
log_json = open(log_file_path, 'r')
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)
5670

5771

5872
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
@@ -110,20 +124,33 @@ def test_compile_and_compile_combo(run_command, data_dir):
110124

111125
# Build sketch for each detected board
112126
for board in detected_boards:
113-
log_file = "compile.log"
127+
log_file_name = "{fqbn}-compile.log".format(fqbn=board.get('fqbn'))
128+
log_file_path = os.path.join(data_dir, log_file_name)
114129
result = run_command(
115130
"compile -b {fqbn} --upload -p {address} {sketch_path} --log-format json --log-file {log_file} --log-level trace".format(
116131
fqbn=board.get('fqbn'),
117132
address=board.get('address'),
118133
sketch_path=sketch_path,
119-
log_file=log_file
134+
log_file=log_file_path
120135
)
121136
)
122-
log_json = open(log_file,'r')
123-
log_json_lines = log_json.readlines()
124-
assert is_value_in_any_json_log_message("copying sketch build output",log_json_lines)
125-
assert is_value_in_any_json_log_message("Executing `arduino upload`",log_json_lines)
126137
assert result.ok
127-
128-
def is_value_in_any_json_log_message(value,log_json_lines ):
129-
return bool([index for index, line in enumerate(log_json_lines) if json.loads(line).get("msg") == value])
138+
# check from the logs if the bin file were uploaded on the current board
139+
log_json = open(log_file_path, 'r')
140+
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

0 commit comments

Comments
 (0)