2018-02-07 19:02:18 +01:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/alecthomas/kingpin"
|
2018-02-12 16:45:13 +01:00
|
|
|
"github.com/apex/log"
|
2018-06-29 16:50:05 +02:00
|
|
|
"github.com/fatih/color"
|
2021-02-02 10:32:46 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/cli/onboard"
|
|
|
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/cli/root"
|
|
|
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/nettests"
|
|
|
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
|
2022-04-29 13:41:09 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2018-02-07 19:02:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmd := root.Command("run", "Run a test group or OONI Run link")
|
2018-09-17 11:51:54 +02:00
|
|
|
noCollector := cmd.Flag("no-collector", "Disable uploading measurements to a collector").Bool()
|
|
|
|
|
2020-12-01 16:52:12 +01:00
|
|
|
var probe *ooni.Probe
|
2018-02-07 19:02:18 +01:00
|
|
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
2019-10-02 18:23:14 +02:00
|
|
|
var err error
|
2020-11-13 19:01:06 +01:00
|
|
|
probe, err = root.Init()
|
2018-02-12 16:45:13 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%s", err)
|
|
|
|
return err
|
|
|
|
}
|
2020-11-13 19:01:06 +01:00
|
|
|
if err = onboard.MaybeOnboarding(probe); err != nil {
|
2018-06-22 11:01:15 +02:00
|
|
|
log.WithError(err).Error("failed to perform onboarding")
|
|
|
|
return err
|
|
|
|
}
|
2021-03-30 11:59:29 +02:00
|
|
|
if *noCollector {
|
2020-11-13 20:07:30 +01:00
|
|
|
probe.Config().Sharing.UploadResults = false
|
2018-09-17 11:51:54 +02:00
|
|
|
}
|
2019-10-02 18:23:14 +02:00
|
|
|
return nil
|
|
|
|
})
|
2018-02-13 17:11:22 +01:00
|
|
|
|
2022-04-29 13:41:09 +02:00
|
|
|
functionalRun := func(runType model.RunType, pred func(name string, gr nettests.Group) bool) error {
|
2020-12-01 16:52:12 +01:00
|
|
|
for name, group := range nettests.All {
|
2021-03-30 11:59:29 +02:00
|
|
|
if !pred(name, group) {
|
2020-12-01 16:52:12 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Infof("Running %s tests", color.BlueString(name))
|
2021-03-30 11:59:29 +02:00
|
|
|
conf := nettests.RunGroupConfig{
|
|
|
|
GroupName: name,
|
|
|
|
Probe: probe,
|
|
|
|
RunType: runType,
|
|
|
|
}
|
2020-12-01 16:52:12 +01:00
|
|
|
if err := nettests.RunGroup(conf); err != nil {
|
|
|
|
log.WithError(err).Errorf("failed to run %s", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
genRunWithGroupName := func(targetName string) func(*kingpin.ParseContext) error {
|
|
|
|
return func(*kingpin.ParseContext) error {
|
2022-04-29 13:41:09 +02:00
|
|
|
return functionalRun(model.RunTypeManual, func(groupName string, gr nettests.Group) bool {
|
2020-12-01 16:52:12 +01:00
|
|
|
return groupName == targetName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 18:23:14 +02:00
|
|
|
websitesCmd := cmd.Command("websites", "")
|
2020-12-01 07:21:33 +01:00
|
|
|
inputFile := websitesCmd.Flag("input-file", "File containing input URLs").Strings()
|
|
|
|
input := websitesCmd.Flag("input", "Test the specified URL").Strings()
|
2019-10-02 18:23:14 +02:00
|
|
|
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
|
2020-12-01 16:52:12 +01:00
|
|
|
log.Infof("Running %s tests", color.BlueString("websites"))
|
2020-12-01 15:04:04 +01:00
|
|
|
return nettests.RunGroup(nettests.RunGroupConfig{
|
|
|
|
GroupName: "websites",
|
|
|
|
Probe: probe,
|
|
|
|
InputFiles: *inputFile,
|
|
|
|
Inputs: *input,
|
2022-04-29 13:41:09 +02:00
|
|
|
RunType: model.RunTypeManual,
|
2020-12-01 07:21:33 +01:00
|
|
|
})
|
2019-10-02 18:23:14 +02:00
|
|
|
})
|
2020-12-01 16:52:12 +01:00
|
|
|
|
2021-03-08 13:38:34 +01:00
|
|
|
easyRuns := []string{
|
|
|
|
"im", "performance", "circumvention", "middlebox", "experimental"}
|
2020-12-01 16:52:12 +01:00
|
|
|
for _, name := range easyRuns {
|
|
|
|
cmd.Command(name, "").Action(genRunWithGroupName(name))
|
|
|
|
}
|
|
|
|
|
|
|
|
unattendedCmd := cmd.Command("unattended", "")
|
|
|
|
unattendedCmd.Action(func(_ *kingpin.ParseContext) error {
|
2022-04-29 13:41:09 +02:00
|
|
|
return functionalRun(model.RunTypeTimed, func(name string, gr nettests.Group) bool {
|
2021-03-30 11:59:29 +02:00
|
|
|
return gr.UnattendedOK
|
2020-12-01 07:21:33 +01:00
|
|
|
})
|
2019-12-28 17:48:07 +01:00
|
|
|
})
|
2020-12-01 16:52:12 +01:00
|
|
|
|
2019-10-02 18:23:14 +02:00
|
|
|
allCmd := cmd.Command("all", "").Default()
|
|
|
|
allCmd.Action(func(_ *kingpin.ParseContext) error {
|
2022-04-29 13:41:09 +02:00
|
|
|
return functionalRun(model.RunTypeManual, func(name string, gr nettests.Group) bool {
|
2020-12-01 16:52:12 +01:00
|
|
|
return true
|
|
|
|
})
|
2018-02-07 19:02:18 +01:00
|
|
|
})
|
|
|
|
}
|