Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions unix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ wallet (on testnet, always with the same seed). But there are other options:
- `--segregate` => scroll down to `Running simulators in parallel` section
- `--bricked` => simulate a system w/ bricked SE1: no more pin tries, etc.
- `--fails N` => simulate N wrong PIN attempts before login, where (1 <= N <= 13)
- `--log` => enable logging to `/tmp/cc_simulator.log`, or to `/tmp/cc-simulators/<pid>/cc_simulator.log` when used with `--segregate`

See `variant/sim_settings.py` for the details of settings-related options.

Expand Down
19 changes: 17 additions & 2 deletions unix/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,15 @@ def sock_cleanup():
cc_mpy = os.path.join(cwd, "coldcard-mpy")
sim_boot = os.path.join(cwd, "sim_boot.py")

log_base_dir = "/tmp"

if segregate:
os.makedirs("/tmp/cc-simulators", exist_ok=True)
os.chdir("/tmp/cc-simulators")
# our new work /tmp/cc-simulators/<PID>
os.mkdir(str(pid))
os.chdir(str(pid))
log_base_dir = os.getcwd()
os.mkdir("MicroSD")
os.mkdir("settings")
os.mkdir("VirtDisk")
Expand Down Expand Up @@ -903,8 +906,20 @@ def sock_cleanup():
child.kill()
return

xterm = subprocess.Popen(['xterm', '-title', 'Coldcard Simulator REPL',
'-geom', '132x40+650+40', '-e'] + cc_cmd,
xterm_args = ['xterm', '-title', 'Coldcard Simulator REPL', '-geom', '132x40+650+40']

log = ("--log" in sys.argv)
if log:
logfile = os.path.join(log_base_dir, 'cc_simulator.log')
# create or truncate logfile and set correct permissions before starting xterm
file_desc = os.open(logfile, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644)
os.close(file_desc)

xterm_args.extend(['-l', '-lf', logfile, '-e'])
else:
xterm_args.extend(['-e'])

xterm = subprocess.Popen(xterm_args + cc_cmd,
env=env,
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
pass_fds=pass_fds, shell=False)
Expand Down