Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a python script to contact the POSIX test server #624

Merged
merged 3 commits into from
Aug 31, 2022
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
24 changes: 7 additions & 17 deletions .github/workflows/posix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,13 @@ jobs:
# get the current branch
branch=${{ env.GITHUB_HEAD_REF_SLUG }}
echo "Status: $id $commit $branch"
# craft the execution request
request="http://ctrl.pash.ndr.md/job=issue&branch=$branch&commit=$commit&benchmark=CORRECTNESS"
echo "$request"
# issue the request
curl -s "$request"
# poll until we get the results
while true; do
echo "Sleeping"
sleep 360;
# fetch some of the latest results in case some other actions happened
data=$(curl -s "ctrl.pash.ndr.md/job=fetch_runs&count=50");
results=$(echo $data | jq '.rows | .[] | select((.commit=='\"$commit\"') and .bench=="CORRECTNESS")')
if [ ! -z "$results" ]; then
# results are found
break;
fi
done
# Get the client script
# TODO: Not clear if the best is to use $commit or $branch here
wget "https://raw.githubusercontent.com/binpash/pash/$commit/scripts/ws-client.py"
# Issue the request and wait for it to end
python3 ws-client.py -m run -c "$commit" -b "$branch" > results.txt
results=$(cat results.txt)
# Process the results
data_result="$(echo $results | jq -r 'select(.commit=='\"$commit\"') | .tests' | jq . | jq -r '.[].csv' | sed 's/# //g')"
os=$(echo $results | jq -r ' select(.commit=='\"$commit\"') | .specs.os')
ram=$(echo $results | jq -r ' select(.commit=='\"$commit\"') | .specs.ram')
Expand Down
107 changes: 107 additions & 0 deletions scripts/ws-client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import argparse
import json
import sys
import time

from websocket import create_connection

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--target_branch",
help="the target branch to fork and run the tests on")
parser.add_argument("-c", "--target_commit",
help="the target commit to checkout to run the tests on")
parser.add_argument("-m", "--mode",
help="the execution mode. `run` runs and waits until the results are there, `wait` just waits, and `check` just returns the current task",
choices=['run', 'wait', 'check'],
default='run')
args = parser.parse_args()
return args

def issue_test_run(websocket, target_commit, target_branch):
run_tests_req_data = {"cmd": {"job": "issue",
"benchmark": "CORRECTNESS",
"commit": target_commit,
"branch": target_branch,
}}
msg = json.dumps(run_tests_req_data)
websocket.send(msg)
print("POSIX Tests request made for branch:", target_branch, "and commit:", target_commit, file=sys.stderr)

def fetch_runs(websocket):
data = {"cmd": {"job": "/fetch_runs",
"count": 50}}
msg = json.dumps(data)
# print("Sending:", msg, file=sys.stderr)
websocket.send(msg)
# print("Sent!", file=sys.stderr)
res = websocket.recv()
runs_data = json.loads(res)
return runs_data

def current_task(websocket):
data = {"cmd": {"job": "/current_task"}}
msg = json.dumps(data)
# print("Sending:", msg, file=sys.stderr)
websocket.send(msg)
# print("Sent!", file=sys.stderr)
res = websocket.recv()
res_data = json.loads(res)
return res_data

def wait_for_result(websocket, target_commit):
found = False
sleep_duration = 360

while not found:

## Fetch all runs
runs_data = fetch_runs(websocket)
result_rows = runs_data["data"]["rows"]

## Check if target commit exists in latest runs
for row in result_rows:
# print(row["commit"], row["bench"], file=sys.stderr)
if row["commit"] == target_commit and row["bench"] == "CORRECTNESS":
print("FOUND COMMIT:", target_commit)
found = True
result_row = row

if not found:
print("Results not present for commit:", target_commit, file=sys.stderr)
print("Sleeping for", sleep_duration, "seconds", file=sys.stderr)
time.sleep(sleep_duration)
return result_row


## Parse the arguments
args = parse_args()

## Create a websocket connection
ws = create_connection("ws://antikythera.csail.mit.edu:52277/")

## Just check and exit
if args.mode == "check":
## Debug only
print(current_task(ws))

elif args.mode in ["run", "wait"]:
# target_commit = "e5937bca7644c6cae0a1b8214fa980b12145bbed"
# target_branch = "pip-libdash"
target_commit = args.target_commit
target_branch = args.target_branch

if args.mode == "run":
## Issue the POSIX tests requests
issue_test_run(ws, target_commit, target_branch)

##
## Wait until we have the POSIX test results
##
result_row = wait_for_result(ws, target_commit)

## Output the relevant test
print(result_row)


ws.close()