Skip to content

Commit

Permalink
QA: add support for running measurement_kit
Browse files Browse the repository at this point in the history
This will be very helpful for #810.

It will allow us, in fact, to compare the result obtained by MK to the one
obtained by miniooni in specific censorship conditions.
  • Loading branch information
bassosimone committed Aug 12, 2020
1 parent 944a390 commit 099573d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion QA/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def execute_jafar_and_miniooni(ooni_exe, outfile, experiment, tag, args):
[
"./jafar",
"-main-command",
"{} -no '{}' --home /tmp {}".format(ooni_exe, tmpoutfile, experiment),
"./QA/minioonilike.py {} -n -o '{}' --home /tmp {}".format(
ooni_exe, tmpoutfile, experiment
),
"-main-user",
"nobody", # should be present on Unix
"-tag",
Expand Down
59 changes: 59 additions & 0 deletions QA/minioonilike.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3

""" This script takes in input the name of the tool to run followed by
arguments and followed by the nettest name. The format recognized is
the same of miniooni. Depending on the tool that we want to run, we
reorder arguments so that they make sense for the tool.
This is necessary because, albeit miniooni, MK, and OONI v2.x have
more or less the same arguments, there are some differences. We could
modify other tools to match miniooni, but this seems useless. """

import argparse
import shlex
import sys

sys.path.insert(0, ".")
import common


def main():
apa = argparse.ArgumentParser()
apa.add_argument("command", nargs=1, help="command to execute")

# subset of arguments accepted by miniooni
apa.add_argument(
"-n", "--no-collector", action="count", help="don't submit measurement"
)
apa.add_argument("-o", "--reportfile", help="specify report file to use")
apa.add_argument("-i", "--input", help="input for nettests taking an input")
apa.add_argument("--home", help="override home directory")
apa.add_argument("nettest", nargs=1, help="nettest to run")
out = apa.parse_args()
command, nettest = out.command[0], out.nettest[0]

if "miniooni" not in command and "measurement_kit" not in command:
raise RuntimeError("unrecognized tool")

args = []
args.append(command)
if out.home and "miniooni" in command:
args.extend(["--home", out.home]) # home applies to miniooni only
if out.input:
if "miniooni" in command:
args.extend(["-i", out.input]) # input is -i for miniooni
if out.no_collector:
args.append("-n")
if out.reportfile:
args.extend(["-o", out.reportfile])
args.append(nettest)
if out.input and "measurement_kit" in command:
if nettest == "web_connectivity":
args.extend(["-u", out.input]) # MK's Web Connectivity uses -u for input

sys.stderr.write("minioonilike.py: {}\n".format(shlex.join(args)))
common.execute(args)


if __name__ == "__main__":
main()

0 comments on commit 099573d

Please sign in to comment.