Skip to content

Commit 0017be8

Browse files
rtakacsLaszloLango
authored andcommitted
Add a flasher module to the project. (#213)
JSRemoteTest-DCO-1.0-Signed-off-by: Roland Takacs [email protected]
1 parent 58532a6 commit 0017be8

File tree

16 files changed

+167
-118
lines changed

16 files changed

+167
-118
lines changed

jstest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from jstest.builder.builder import Builder
1616
from jstest.common import console, paths, symbol_resolver, utils
1717
from jstest.emulate import pseudo_terminal
18+
from jstest.flasher import flasher
1819
from jstest.testresult import TestResult
1920
from jstest.testrunner.testrunner import TestRunner
2021

jstest/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import jstest
2222
from jstest import Builder, TestResult, TestRunner
23-
from jstest import paths, pseudo_terminal, utils
23+
from jstest import flasher, paths, pseudo_terminal, utils
2424

2525

2626
def parse_options():
@@ -184,6 +184,8 @@ def main():
184184
builder = Builder(env)
185185
builder.build()
186186

187+
flasher.flash(env)
188+
187189
testrunner = TestRunner(env)
188190
testrunner.run()
189191
testrunner.save()

jstest/builder/builder.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def init_modules(modules):
2323
'''
2424
for build_info in modules.values():
2525
for command in build_info.get('init', []):
26-
exec_cmd(command)
26+
utils.execute_config_command(command)
2727

2828

2929
def build_modules(modules):
@@ -33,10 +33,10 @@ def build_modules(modules):
3333
# FIXME: remove the sorted function that helps to
3434
# build iotjs and jerryscript before NuttX.
3535
for _, build_info in sorted(modules.iteritems()):
36-
exec_cmd(build_info.get('build'))
36+
utils.execute_config_command(build_info.get('build'))
3737

3838

39-
def save_artifacts(modules, builddir):
39+
def save_artifacts(modules):
4040
'''
4141
Copy the created files (libs, linker.map, ...) into the build folder.
4242
'''
@@ -49,32 +49,7 @@ def save_artifacts(modules, builddir):
4949
src = artifact.get('src')
5050
dst = artifact.get('dst')
5151

52-
utils.copy(src, utils.join(builddir, dst))
53-
54-
55-
def exec_cmd(command):
56-
'''
57-
Run the command defined in the build.config file.
58-
'''
59-
cwd = command.get('cwd', '.')
60-
cmd = command.get('cmd', '')
61-
args = command.get('args', [])
62-
env = command.get('env', {})
63-
64-
# Update the arguments and the env variables with
65-
# the values under the condition-options.
66-
for option in command.get('conditional-options', []):
67-
if not eval(option.get('condition')):
68-
continue
69-
70-
args.extend(option.get('args', []))
71-
env = utils.merge_dicts(env, option.get('env', {}))
72-
73-
# Convert array values to string to be real env values.
74-
for key, value in env.iteritems():
75-
env[key] = ' '.join(value)
76-
77-
utils.execute(cwd, cmd, args=args, env=env)
52+
utils.copy(src, dst)
7853

7954

8055
class Builder(object):
@@ -84,7 +59,6 @@ class Builder(object):
8459
def __init__(self, env):
8560
self.env = env
8661
self.device = env.options.device
87-
self.build_dir = env.paths.builddir
8862

8963
# Do not initialize the modules if the build is disabled.
9064
if env.options.no_build:
@@ -106,7 +80,7 @@ def build(self):
10680

10781
init_modules(modules)
10882
build_modules(modules)
109-
save_artifacts(modules, self.build_dir)
83+
save_artifacts(modules)
11084

11185
# Create build information.
11286
builder_utils.create_build_info(self.env)
@@ -136,7 +110,7 @@ def should_build(self, build_info):
136110

137111
# If dst is provided, check that first. If it doesn't, it's
138112
# enough just check the src.
139-
if dst and not utils.exists(utils.join(self.build_dir, dst)):
113+
if dst and not utils.exists(dst):
140114
return True
141115

142116
if not dst and not utils.exists(src):

jstest/common/builtins.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,35 @@ def print_message(**params):
7272
console.log(params['args'][0])
7373

7474

75+
def init_freya_config(**params):
76+
'''
77+
Resolve the %{iotjs-dirname} symbol in the Freya configuration file.
78+
'''
79+
iotjs_src = params['args'][0]
80+
build_dir = params['args'][1]
81+
82+
pattern = 's/%%{iotjs-dirname}/%s/g' % utils.basename(iotjs_src)
83+
84+
utils.execute(build_dir, 'sed', ['-i', pattern, 'iotjs-freya.config'])
85+
86+
87+
def mount_fs_writable(**params):
88+
'''
89+
Remount the file system as writable.
90+
'''
91+
addr = params['args'][0]
92+
port = params['args'][1]
93+
94+
utils.execute('.', 'ssh', [addr, '-p %s' % port, 'mount -o remount,rw /'])
95+
96+
7597
NATIVES = {
7698
'print': print_message,
7799
'genromfs': genromfs,
78100
'config_internet': config_internet,
79-
'push_environment': push_environment
101+
'push_environment': push_environment,
102+
'init_freya_config': init_freya_config,
103+
'mount_fs_writable': mount_fs_writable
80104
}
81105

82106

jstest/common/paths.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
BUILDER_MODULES_PATH = os.path.join(JSTEST_PATH, 'builder', 'modules')
4343

44+
FLASH_CONFIG_FILE = os.path.join(JSTEST_PATH, 'flasher', 'flash.config')
45+
4446
#
4547
# ================================
4648
#

jstest/common/symbol_resolver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ def resolve_symbol(symbol, env):
9797
'device': env.options.device,
9898
'appname': env.options.app,
9999
'ip-addr': env.options.ip,
100+
'port': env.options.port,
101+
'user': env.options.username,
100102
'gateway': env.options.router,
101103
'netmask': env.options.netmask,
102104
'build-type': env.options.buildtype,
105+
'remote-workdir': env.options.remote_workdir,
103106
'use-stack': 'no-stack' if env.options.no_memstat else 'stack',
104107
'communication': 'telnet' if env.options.ip else 'serial',
105108
'target': _TARGETS[env.options.device],

jstest/common/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ def execute(cwd, cmd, args=None, env=None, quiet=False, strict=True):
9595
return exec_shell(cwd, cmd, args, env, quiet, strict)
9696

9797

98+
def execute_config_command(command):
99+
'''
100+
Run the command defined in the build.config file.
101+
'''
102+
condition = command.get('condition', 'True')
103+
104+
if not eval(condition):
105+
return
106+
107+
cwd = command.get('cwd', '.')
108+
cmd = command.get('cmd', '')
109+
args = command.get('args', [])
110+
env = command.get('env', {})
111+
112+
# Update the arguments and the env variables with
113+
# the values under the condition-options.
114+
for option in command.get('conditional-options', []):
115+
if not eval(option.get('condition')):
116+
continue
117+
118+
args.extend(option.get('args', []))
119+
env = merge_dicts(env, option.get('env', {}))
120+
121+
# Convert array values to string to be real env values.
122+
for key, value in env.iteritems():
123+
env[key] = ' '.join(value)
124+
125+
execute(cwd, cmd, args=args, env=env)
126+
127+
98128
def print_command(cwd, cmd, args):
99129
'''
100130
Helper function to print commands.

jstest/flasher/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Required for Python to search this directory for module files.

jstest/flasher/flash.config

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"stm32f4dis": {
3+
"flash": {
4+
"cwd": "%{stlink}",
5+
"cmd": "build/Release/st-flash",
6+
"args": ["write", "%{build-dir}/nuttx.bin", "0x8000000"]
7+
}
8+
},
9+
"artik053": {
10+
"flash": {
11+
"cwd": "%{tizenrt}/os",
12+
"cmd": "make",
13+
"args": ["download", "ALL"]
14+
}
15+
},
16+
"artik530": {
17+
"init": [
18+
{
19+
"condition": "('%{appname}' == 'iotjs') and %{memstat}",
20+
"cmd": "function(init_freya_config)",
21+
"args": ["%{gbs-iotjs}", "%{build-dir}"]
22+
},
23+
{
24+
"cmd": "function(mount_fs_writable)",
25+
"args": ["%{user}@%{ip-addr}", "%{port}"]
26+
}
27+
],
28+
"flash": {
29+
"cmd": "rsync",
30+
"args": [
31+
"--rsh", "ssh -p %{port}",
32+
"--recursive",
33+
"--compress",
34+
"--delete",
35+
"%{build-dir}/",
36+
"%{user}@%{ip-addr}:%{remote-workdir}"
37+
]
38+
}
39+
},
40+
"rpi2": {
41+
"init": [
42+
{
43+
"condition": "('%{appname}' == 'iotjs') and %{memstat}",
44+
"cmd": "function(init_freya_config)",
45+
"args": ["%{iotjs}", "%{build-dir}"]
46+
}
47+
],
48+
"flash": {
49+
"cmd": "rsync",
50+
"args": [
51+
"--rsh", "ssh -p %{port}",
52+
"--recursive",
53+
"--compress",
54+
"--delete",
55+
"%{build-dir}/",
56+
"%{user}@%{ip-addr}:%{remote-workdir}"
57+
]
58+
}
59+
}
60+
}

jstest/flasher/flasher.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from jstest.common import utils, paths
16+
17+
18+
def flash(env):
19+
'''
20+
Flash the device.
21+
'''
22+
if env.options.no_flash:
23+
return
24+
25+
config = utils.read_config_file(paths.FLASH_CONFIG_FILE, env)
26+
# Get the device specific flash instructions.
27+
flash_info = config[env.options.device]
28+
29+
# Do the initialization steps.
30+
for command in flash_info.get('init', []):
31+
utils.execute_config_command(command)
32+
# Flash the device.
33+
utils.execute_config_command(flash_info.get('flash'))

0 commit comments

Comments
 (0)