Re enable athenad test (#1058)

* Renable athena test

* debug

* Revert "debug"

This reverts commit 30f68055f8.

* Specify correct pythonpath for tests

Co-authored-by: Andy <andyh2@me.com>
pull/1080/head
Willem Melching 2020-02-11 19:26:34 -08:00 committed by GitHub
parent b883e31bfe
commit 960b42c523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 103 deletions

3
Jenkinsfile vendored
View File

@ -6,6 +6,9 @@ pipeline {
}
}
environment {
COMMA_JWT = credentials('athena-test-jwt')
}
stages {
stage('EON Build/Test') {
steps {

View File

@ -99,7 +99,7 @@ git commit -a -m "openpilot v$VERSION release"
SCONS_CACHE=1 scons -j3
echo "[-] testing openpilot T=$SECONDS"
PYTHONPATH="$SOURCE_DIR:$SOURCE_DIR/pyextra" nosetests -s selfdrive/test/test_openpilot.py
PYTHONPATH="$TARGET_DIR:$TARGET_DIR/pyextra" nosetests -s selfdrive/test/test_openpilot.py
echo "[-] testing panda build T=$SECONDS"
pushd panda/board/

View File

@ -46,6 +46,7 @@ def start_build(name):
conn.send("echo \"git took $SECONDS seconds\"\n")
push = "PUSH=master-ci" if branch == "master" else ""
comma_jwt = "COMMA_JWT=" + os.getenv('COMMA_JWT', '')
conn.send("%s /data/openpilot_source/release/build_devel.sh\n" % push)
conn.send('echo "RESULT:" $?\n')

View File

@ -105,118 +105,118 @@ def test_uploader():
print("UPLOADER")
time.sleep(10.0)
# @phone_only
# def test_athena():
# print("ATHENA")
# start_daemon_process("manage_athenad")
# params = Params()
# manage_athenad_pid = params.get("AthenadPid")
# assert manage_athenad_pid is not None
# try:
# os.kill(int(manage_athenad_pid), 0)
# # process is running
# except OSError:
# assert False, "manage_athenad is dead"
@phone_only
def test_athena():
print("ATHENA")
start_daemon_process("manage_athenad")
params = Params()
manage_athenad_pid = params.get("AthenadPid")
assert manage_athenad_pid is not None
try:
os.kill(int(manage_athenad_pid), 0)
# process is running
except OSError:
assert False, "manage_athenad is dead"
# def expect_athena_starts(timeout=30):
# now = time.time()
# athenad_pid = None
# while athenad_pid is None:
# try:
# athenad_pid = subprocess.check_output(["pgrep", "-P", manage_athenad_pid], encoding="utf-8").strip()
# return athenad_pid
# except subprocess.CalledProcessError:
# if time.time() - now > timeout:
# assert False, f"Athena did not start within {timeout} seconds"
# time.sleep(0.5)
def expect_athena_starts(timeout=30):
now = time.time()
athenad_pid = None
while athenad_pid is None:
try:
athenad_pid = subprocess.check_output(["pgrep", "-P", manage_athenad_pid], encoding="utf-8").strip()
return athenad_pid
except subprocess.CalledProcessError:
if time.time() - now > timeout:
assert False, f"Athena did not start within {timeout} seconds"
time.sleep(0.5)
# def athena_post(payload, max_retries=5, wait=5):
# tries = 0
# while 1:
# try:
# resp = requests.post(
# "https://athena.comma.ai/" + params.get("DongleId", encoding="utf-8"),
# headers={
# "Authorization": "JWT " + os.getenv("COMMA_JWT"),
# "Content-Type": "application/json"
# },
# data=json.dumps(payload),
# timeout=30
# )
# resp_json = resp.json()
# if resp_json.get('error'):
# raise Exception(resp_json['error'])
# return resp_json
# except Exception as e:
# time.sleep(wait)
# tries += 1
# if tries == max_retries:
# raise
# else:
# print(f'athena_post failed {e}. retrying...')
def athena_post(payload, max_retries=5, wait=5):
tries = 0
while 1:
try:
resp = requests.post(
"https://athena.comma.ai/" + params.get("DongleId", encoding="utf-8"),
headers={
"Authorization": "JWT " + os.getenv("COMMA_JWT"),
"Content-Type": "application/json"
},
data=json.dumps(payload),
timeout=30
)
resp_json = resp.json()
if resp_json.get('error'):
raise Exception(resp_json['error'])
return resp_json
except Exception as e:
time.sleep(wait)
tries += 1
if tries == max_retries:
raise
else:
print(f'athena_post failed {e}. retrying...')
# def expect_athena_registers():
# resp = athena_post({
# "method": "echo",
# "params": ["hello"],
# "id": 0,
# "jsonrpc": "2.0"
# }, max_retries=12, wait=5)
# assert resp.get('result') == "hello", f'Athena failed to register ({resp})'
def expect_athena_registers():
resp = athena_post({
"method": "echo",
"params": ["hello"],
"id": 0,
"jsonrpc": "2.0"
}, max_retries=12, wait=5)
assert resp.get('result') == "hello", f'Athena failed to register ({resp})'
# try:
# athenad_pid = expect_athena_starts()
# # kill athenad and ensure it is restarted (check_output will throw if it is not)
# os.kill(int(athenad_pid), signal.SIGINT)
# expect_athena_starts()
try:
athenad_pid = expect_athena_starts()
# kill athenad and ensure it is restarted (check_output will throw if it is not)
os.kill(int(athenad_pid), signal.SIGINT)
expect_athena_starts()
# if not os.getenv('COMMA_JWT'):
# print('WARNING: COMMA_JWT env not set, will not test requests to athena.comma.ai')
# return
if not os.getenv('COMMA_JWT'):
print('WARNING: COMMA_JWT env not set, will not test requests to athena.comma.ai')
return
# expect_athena_registers()
expect_athena_registers()
# print("ATHENA: getSimInfo")
# resp = athena_post({
# "method": "getSimInfo",
# "id": 0,
# "jsonrpc": "2.0"
# })
# assert resp.get('result'), resp
# assert 'sim_id' in resp['result'], resp['result']
print("ATHENA: getSimInfo")
resp = athena_post({
"method": "getSimInfo",
"id": 0,
"jsonrpc": "2.0"
})
assert resp.get('result'), resp
assert 'sim_id' in resp['result'], resp['result']
# print("ATHENA: takeSnapshot")
# resp = athena_post({
# "method": "takeSnapshot",
# "id": 0,
# "jsonrpc": "2.0"
# })
# assert resp.get('result'), resp
# assert resp['result']['jpegBack'], resp['result']
print("ATHENA: takeSnapshot")
resp = athena_post({
"method": "takeSnapshot",
"id": 0,
"jsonrpc": "2.0"
})
assert resp.get('result'), resp
assert resp['result']['jpegBack'], resp['result']
# @with_processes(["thermald"])
# def test_athena_thermal():
# print("ATHENA: getMessage(thermal)")
# resp = athena_post({
# "method": "getMessage",
# "params": {"service": "thermal", "timeout": 5000},
# "id": 0,
# "jsonrpc": "2.0"
# })
# assert resp.get('result'), resp
# assert resp['result']['thermal'], resp['result']
# test_athena_thermal()
# finally:
# try:
# athenad_pid = subprocess.check_output(["pgrep", "-P", manage_athenad_pid], encoding="utf-8").strip()
# except subprocess.CalledProcessError:
# athenad_pid = None
@with_processes(["thermald"])
def test_athena_thermal():
print("ATHENA: getMessage(thermal)")
resp = athena_post({
"method": "getMessage",
"params": {"service": "thermal", "timeout": 5000},
"id": 0,
"jsonrpc": "2.0"
})
assert resp.get('result'), resp
assert resp['result']['thermal'], resp['result']
test_athena_thermal()
finally:
try:
athenad_pid = subprocess.check_output(["pgrep", "-P", manage_athenad_pid], encoding="utf-8").strip()
except subprocess.CalledProcessError:
athenad_pid = None
# try:
# os.kill(int(manage_athenad_pid), signal.SIGINT)
# os.kill(int(athenad_pid), signal.SIGINT)
# except (OSError, TypeError):
# pass
try:
os.kill(int(manage_athenad_pid), signal.SIGINT)
os.kill(int(athenad_pid), signal.SIGINT)
except (OSError, TypeError):
pass
# TODO: re-enable when jenkins test has /data/pythonpath -> /data/openpilot
# @phone_only