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"
|
2019-12-02 14:15:50 +01:00
|
|
|
"github.com/ooni/probe-cli/internal/cli/onboard"
|
2018-05-03 14:59:55 +02:00
|
|
|
"github.com/ooni/probe-cli/internal/cli/root"
|
2020-11-13 17:14:26 +01:00
|
|
|
"github.com/ooni/probe-cli/internal/nettests"
|
2020-11-13 18:42:10 +01:00
|
|
|
"github.com/ooni/probe-cli/internal/ooni"
|
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
|
|
|
|
}
|
2018-09-17 11:51:54 +02:00
|
|
|
if *noCollector == true {
|
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
|
|
|
|
2020-12-01 16:52:12 +01:00
|
|
|
functionalRun := func(pred func(name string, gr nettests.Group) bool) error {
|
|
|
|
for name, group := range nettests.All {
|
|
|
|
if pred(name, group) != true {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Infof("Running %s tests", color.BlueString(name))
|
|
|
|
conf := nettests.RunGroupConfig{GroupName: name, Probe: probe}
|
|
|
|
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 {
|
|
|
|
return functionalRun(func(groupName string, gr nettests.Group) bool {
|
|
|
|
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,
|
2020-12-01 07:21:33 +01:00
|
|
|
})
|
2019-10-02 18:23:14 +02:00
|
|
|
})
|
2020-12-01 16:52:12 +01:00
|
|
|
|
|
|
|
easyRuns := []string{"im", "performance", "circumvention", "middlebox"}
|
|
|
|
for _, name := range easyRuns {
|
|
|
|
cmd.Command(name, "").Action(genRunWithGroupName(name))
|
|
|
|
}
|
|
|
|
|
|
|
|
unattendedCmd := cmd.Command("unattended", "")
|
|
|
|
unattendedCmd.Action(func(_ *kingpin.ParseContext) error {
|
|
|
|
return functionalRun(func(name string, gr nettests.Group) bool {
|
|
|
|
return gr.UnattendedOK == true
|
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 {
|
2020-12-01 16:52:12 +01:00
|
|
|
return functionalRun(func(name string, gr nettests.Group) bool {
|
|
|
|
return true
|
|
|
|
})
|
2018-02-07 19:02:18 +01:00
|
|
|
})
|
|
|
|
}
|