| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package main |
| |
| import ( |
| "bufio" |
| "flag" |
| "fmt" |
| _ "net/http/pprof" |
| "os" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/app" |
| "android.googlesource.com/platform/tools/gpu/framework/file" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| "android.googlesource.com/platform/tools/gpu/framework/task" |
| "android.googlesource.com/platform/tools/gpu/tools/robotester" |
| "android.googlesource.com/platform/tools/gpu/tools/robotester/db" |
| "android.googlesource.com/platform/tools/gpu/tools/robotester/server" |
| "android.googlesource.com/platform/tools/gpu/tools/robotester/service" |
| ) |
| |
| const defaultDatabase = "mysql://buildbot:buildbot@localhost:3306/buildbot" |
| |
| var ( |
| build file.Path |
| www file.Path |
| data file.Path |
| port int |
| dbAddress app.URLFlag |
| |
| offline bool |
| ignoreLocalChanges bool |
| noBuild bool |
| disableClean bool |
| eraseDatabase bool |
| useLDPreload bool |
| ) |
| |
| func main() { |
| dbAddress.Set(defaultDatabase) |
| flag.Var(&build, "build", "The path to the build output directory.") |
| flag.Var(&www, "www", "The path to the www directory.") |
| flag.Var(&data, "data", "The path to data directory.") |
| flag.IntVar(&port, "port", 9000, "The webserver's port.") |
| flag.Var(&dbAddress, "db", "The database to connect to") |
| |
| flag.BoolVar(&offline, "offline", false, "Don't fetch new changes.") |
| flag.BoolVar(&ignoreLocalChanges, "ignore-local-changes", false, "Permit local changes to the source directory.") |
| flag.BoolVar(&noBuild, "no-build", false, "Do not compile the code, use the currently built binaries as-is. Implies --offline and --ignore-local-changes.") |
| flag.BoolVar(&disableClean, "disable-clean", false, "Disable the clean before build step.") |
| |
| flag.BoolVar(&eraseDatabase, "erase-database", false, "Wipes-clean the entire database and then returns.") |
| flag.BoolVar(&useLDPreload, "ld-preload", false, "Use LD_PRELOAD to register interceptor instead of JDWP.") |
| |
| app.DefaultStyle = "Detailed" |
| app.ShortHelp = "RoboTester is an automated testing server for the GAPI project." |
| app.Version = app.VersionSpec{Major: 0, Minor: 1} |
| app.Run(run) |
| } |
| |
| func run(ctx log.Context) error { |
| ctx, cancel := task.WithCancel(ctx) |
| // Start by logging into the database |
| db, err := db.Open(ctx, dbAddress.URL) |
| if err != nil { |
| return ctx.Cause(err).LogError("Couldn't log into database") |
| } |
| defer db.Close(ctx) |
| |
| if eraseDatabase { |
| fmt.Println(` |
| ********************************** |
| *** ERASE THE ENTIRE DATABASE? *** |
| ********************************** |
| |
| You are about to erase the entire database. |
| |
| This cannot be undone. |
| |
| To proceed, type 'YES' and press enter: |
| `) |
| l, err := bufio.NewReader(os.Stdin).ReadString('\n') |
| if err != nil { |
| return err |
| } |
| if l == "YES\n" { |
| if err := db.EraseAll(ctx); err != nil { |
| return err |
| } |
| println("Database cleared.") |
| } else { |
| println("Aborted") |
| } |
| return nil |
| } |
| |
| go func() { |
| println("Press enter to stop...") |
| os.Stdin.Read([]byte{0}) |
| cancel() |
| }() |
| |
| if data.IsEmpty() { |
| data = file.Abs("data") |
| } |
| if build.IsEmpty() { |
| return ctx.AsError("You must supply the path to a valid build directory") |
| } |
| config, err := service.Prepare(ctx, build, data) |
| if err != nil { |
| return err |
| } |
| if www.IsEmpty() { |
| www = file.Abs(config.Source).Join("cmd/robotester/www") |
| } |
| if useLDPreload { |
| config.UseLDPreload = true |
| } |
| if offline { |
| config.Offline = true |
| } |
| if ignoreLocalChanges { |
| config.IgnoreLocalChanges = true |
| } |
| if noBuild { |
| config.Offline = true |
| config.IgnoreLocalChanges = true |
| config.NoBuild = true |
| } |
| if disableClean { |
| config.DisableClean = true |
| } |
| server.Run(ctx, server.Config{ |
| WWW: www.System(), |
| Data: config.Data, |
| Src: config.Source, |
| Artifacts: config.Artifacts, |
| Address: fmt.Sprintf(":%d", port), |
| }, db) |
| return robotester.Run(ctx, config, db) |
| } |