-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathtest_channels_shell.py
62 lines (53 loc) · 1.92 KB
/
test_channels_shell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE
import subprocess
import sys
import bootstrap_channels
from common import screenshot, wait_for
STD = '/data/data/com.termux.nix/files/home/.cache/nix-on-droid-self-test'
def run(d):
bootstrap_channels.run(d)
# re-login for variety. the other on-device-test (uiautomator one) does not
d('input text "exit"')
screenshot(d, 'pre-relogin')
d.ui.press('enter')
nod = d.app('com.termux.nix')
nod.launch()
d.ui.press('enter')
screenshot(d, 'post-relogin')
wait_for(d, 'bash-5.2$')
# run tests in a way that'd display progress in CI
user = d.su('stat -c %U /data/data/com.termux.nix').output.strip()
# WARNING: assumes `su 0` style `su` that doesn't support -c from now on
print(f'{user=}')
sys.stdout.flush()
sys.stderr.flush()
for cmd in [
'id',
f'mkdir -p {STD}',
f'touch {STD}/confirmation-granted',
'/data/data/com.termux.nix/files/usr/bin/login echo test',
'/data/data/com.termux.nix/files/usr/bin/login id',
(
'cd /data/data/com.termux.nix/files/home; '
'pwd; '
'id; '
'env PATH= /data/data/com.termux.nix/files/usr/bin/login '
' nix-on-droid on-device-test'
),
]:
print(f'running {cmd} as {user} with capture:')
p = subprocess.Popen(
['adb', 'shell', 'su', '0', 'su', user, 'sh', '-c', f"'{cmd}'"],
encoding='utf-8',
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
out = ''
while p.poll() is None:
line = p.stdout.readline()
out += line
sys.stdout.write('> ' + line)
sys.stdout.flush()
print(f'returncode: {p.returncode}')
# guess what, it can swallow the exit code!
assert 'tests, 0 failures in' in out # of the last command