diff --git a/garnet/tests/system_ota_tests/BUILD.gn b/garnet/tests/system_ota_tests/BUILD.gn index 8a92f174435988dca50f91bb3b00423ac422f985..853e71095e765a25fbf3e9ce0865a6d8c256347c 100644 --- a/garnet/tests/system_ota_tests/BUILD.gn +++ b/garnet/tests/system_ota_tests/BUILD.gn @@ -24,10 +24,7 @@ go_library("system_ota_tests_lib") { testonly = true name = "fuchsia.googlesource.com/system_ota_tests" deps = [ - "//garnet/go/src/far:far", - "//garnet/go/src/pm:pm_lib", - "//garnet/public/go/third_party:github.com/flynn/go-tuf", - "//garnet/public/go/third_party:golang.org/x/crypto", + "//src/testing/host_target_testing", ] non_go_deps = [ ":copy" ] metadata = { diff --git a/garnet/tests/system_ota_tests/config/config.go b/garnet/tests/system_ota_tests/upgrade_test/config.go similarity index 96% rename from garnet/tests/system_ota_tests/config/config.go rename to garnet/tests/system_ota_tests/upgrade_test/config.go index b88dbcbd07bb1f44033cf26e64b2259ce98c8921..3facb0e28ae7da773bf4dcd6cabd8ea88441e601 100644 --- a/garnet/tests/system_ota_tests/config/config.go +++ b/garnet/tests/system_ota_tests/upgrade_test/config.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package config +package upgrade import ( "flag" @@ -12,10 +12,10 @@ import ( "path/filepath" "strings" - "fuchsia.googlesource.com/system_ota_tests/artifacts" - "fuchsia.googlesource.com/system_ota_tests/device" - "fuchsia.googlesource.com/system_ota_tests/packages" - "fuchsia.googlesource.com/system_ota_tests/util" + "fuchsia.googlesource.com/host_target_testing/artifacts" + "fuchsia.googlesource.com/host_target_testing/device" + "fuchsia.googlesource.com/host_target_testing/packages" + "fuchsia.googlesource.com/host_target_testing/util" ) type Config struct { diff --git a/garnet/tests/system_ota_tests/upgrade_test/upgrade_test.go b/garnet/tests/system_ota_tests/upgrade_test/upgrade_test.go index 58b9f15394ec00655075869ebf69cafc4535bac5..c81382bd457dcefc47ec435139e909db63a9104e 100644 --- a/garnet/tests/system_ota_tests/upgrade_test/upgrade_test.go +++ b/garnet/tests/system_ota_tests/upgrade_test/upgrade_test.go @@ -12,15 +12,14 @@ import ( "os" "testing" - "fuchsia.googlesource.com/system_ota_tests/config" - "fuchsia.googlesource.com/system_ota_tests/packages" + "fuchsia.googlesource.com/host_target_testing/packages" ) -var c *config.Config +var c *Config func TestMain(m *testing.M) { var err error - c, err = config.NewConfig(flag.CommandLine) + c, err = NewConfig(flag.CommandLine) if err != nil { log.Fatalf("failed to create config: %s", err) } diff --git a/src/testing/BUILD.gn b/src/testing/BUILD.gn index 1332926ac7ab2a435b940d86914d55c8cbe90018..c06fc525aa1a480a945cb886a13ca81543aa31aa 100644 --- a/src/testing/BUILD.gn +++ b/src/testing/BUILD.gn @@ -6,6 +6,7 @@ group("testing") { testonly = true deps = [ ":tests", + "host_target_testing", "sl4f", ] } diff --git a/src/testing/host_target_testing/BUILD.gn b/src/testing/host_target_testing/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d38516ec38d194ac54ab30895af6f4c240441974 --- /dev/null +++ b/src/testing/host_target_testing/BUILD.gn @@ -0,0 +1,16 @@ +# Copyright 2019 The Fuchsia Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//build/go/go_library.gni") + +go_library("host_target_testing") { + testonly = true + name = "fuchsia.googlesource.com/host_target_testing" + deps = [ + "//garnet/go/src/far:far", + "//garnet/go/src/pm:pm_lib", + "//garnet/public/go/third_party:github.com/flynn/go-tuf", + "//garnet/public/go/third_party:golang.org/x/crypto", + ] +} diff --git a/src/testing/host_target_testing/OWNERS b/src/testing/host_target_testing/OWNERS new file mode 100644 index 0000000000000000000000000000000000000000..7c48945c10f9b9d064d666efc8c0878aed23b545 --- /dev/null +++ b/src/testing/host_target_testing/OWNERS @@ -0,0 +1,4 @@ +abarth@google.com +etryzelaar@google.com +raggi@google.com +* diff --git a/garnet/tests/system_ota_tests/artifacts/archive.go b/src/testing/host_target_testing/artifacts/archive.go similarity index 98% rename from garnet/tests/system_ota_tests/artifacts/archive.go rename to src/testing/host_target_testing/artifacts/archive.go index d6a4d01c638fd6a2043f685d02bd52bd6e0c1da3..b0f7467767f44d5ba4041e712c928141a6fe14a3 100644 --- a/garnet/tests/system_ota_tests/artifacts/archive.go +++ b/src/testing/host_target_testing/artifacts/archive.go @@ -12,7 +12,7 @@ import ( "path/filepath" "strings" - "fuchsia.googlesource.com/system_ota_tests/util" + "fuchsia.googlesource.com/host_target_testing/util" ) // Archive allows interacting with the build artifact repository. diff --git a/garnet/tests/system_ota_tests/artifacts/build.go b/src/testing/host_target_testing/artifacts/build.go similarity index 96% rename from garnet/tests/system_ota_tests/artifacts/build.go rename to src/testing/host_target_testing/artifacts/build.go index ef6c68513898ef7e56f41ca38bb38676b0803d0e..06c83d15435eca8e5cd669afb28be7a43eabcc75 100644 --- a/garnet/tests/system_ota_tests/artifacts/build.go +++ b/src/testing/host_target_testing/artifacts/build.go @@ -10,8 +10,8 @@ import ( "os" "path/filepath" - "fuchsia.googlesource.com/system_ota_tests/packages" - "fuchsia.googlesource.com/system_ota_tests/util" + "fuchsia.googlesource.com/host_target_testing/packages" + "fuchsia.googlesource.com/host_target_testing/util" ) type Build struct { diff --git a/garnet/tests/system_ota_tests/device/device.go b/src/testing/host_target_testing/device/device.go similarity index 97% rename from garnet/tests/system_ota_tests/device/device.go rename to src/testing/host_target_testing/device/device.go index a8a5d74d4f80df1c08f1a079e6c7f202481f6dfc..73c6f2cb1da6f4c3d873e6bd86b187936d046985 100644 --- a/garnet/tests/system_ota_tests/device/device.go +++ b/src/testing/host_target_testing/device/device.go @@ -16,8 +16,8 @@ import ( "testing" "time" - "fuchsia.googlesource.com/system_ota_tests/packages" - "fuchsia.googlesource.com/system_ota_tests/sshclient" + "fuchsia.googlesource.com/host_target_testing/packages" + "fuchsia.googlesource.com/host_target_testing/sshclient" "golang.org/x/crypto/ssh" ) diff --git a/garnet/tests/system_ota_tests/packages/package.go b/src/testing/host_target_testing/packages/package.go similarity index 100% rename from garnet/tests/system_ota_tests/packages/package.go rename to src/testing/host_target_testing/packages/package.go diff --git a/garnet/tests/system_ota_tests/packages/repo.go b/src/testing/host_target_testing/packages/repo.go similarity index 97% rename from garnet/tests/system_ota_tests/packages/repo.go rename to src/testing/host_target_testing/packages/repo.go index 8d7f75ea3ac347d48d313d54caf9dcf6baa8db15..9c1f943d81da39cc1a70ca5eaad1069c625eaa12 100644 --- a/garnet/tests/system_ota_tests/packages/repo.go +++ b/src/testing/host_target_testing/packages/repo.go @@ -11,8 +11,8 @@ import ( "os" "path/filepath" + "fuchsia.googlesource.com/host_target_testing/util" "fuchsia.googlesource.com/pm/repo" - "fuchsia.googlesource.com/system_ota_tests/util" ) type Repository struct { diff --git a/garnet/tests/system_ota_tests/packages/server.go b/src/testing/host_target_testing/packages/server.go similarity index 77% rename from garnet/tests/system_ota_tests/packages/server.go rename to src/testing/host_target_testing/packages/server.go index baf895249bc6ef8a11d825094972c58cbe589c96..30eb6a868d200c61a1dfd593e2217c97cd7c3047 100644 --- a/garnet/tests/system_ota_tests/packages/server.go +++ b/src/testing/host_target_testing/packages/server.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" "log" "net" "net/http" @@ -34,13 +33,18 @@ func newServer(dir string, localHostname string) (*Server, error) { port := listener.Addr().(*net.TCPAddr).Port log.Printf("Serving %s on :%d", dir, port) - configURL, configHash, err := writeConfig(dir, localHostname, port) + configURL, configHash, config, err := genConfig(dir, localHostname, port) if err != nil { listener.Close() return nil, err } mux := http.NewServeMux() + mux.HandleFunc("/host_target_testing/config.json", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + w.Write(config) + }) mux.Handle("/", http.FileServer(http.Dir(dir))) server := &http.Server{ @@ -81,7 +85,7 @@ func (lw *loggingWriter) WriteHeader(status int) { } // writeConfig writes the source config to the repository. -func writeConfig(dir string, localHostname string, port int) (configURL string, configHash string, err error) { +func genConfig(dir string, localHostname string, port int) (configURL string, configHash string, config []byte, err error) { type keyConfig struct { Type string Value string @@ -101,18 +105,18 @@ func writeConfig(dir string, localHostname string, port int) (configURL string, f, err := os.Open(filepath.Join(dir, "root.json")) if err != nil { - return "", "", err + return "", "", nil, err } defer f.Close() var signed tuf_data.Signed if err := json.NewDecoder(f).Decode(&signed); err != nil { - return "", "", err + return "", "", nil, err } var root tuf_data.Root if err := json.Unmarshal(signed.Signed, &root); err != nil { - return "", "", err + return "", "", nil, err } var rootKeys []keyConfig @@ -127,10 +131,10 @@ func writeConfig(dir string, localHostname string, port int) (configURL string, hostname := strings.SplitN(localHostname, "%", 2)[0] repoURL := fmt.Sprintf("http://[%s]:%d", hostname, port) - configURL = fmt.Sprintf("%s/system_ota_tests/config.json", repoURL) + configURL = fmt.Sprintf("%s/host_target_testing/config.json", repoURL) - config, err := json.Marshal(&sourceConfig{ - ID: "system_ota_tests", + config, err = json.Marshal(&sourceConfig{ + ID: "host_target_testing", RepoURL: repoURL, BlobRepoURL: fmt.Sprintf("%s/blobs", repoURL), RootKeys: rootKeys, @@ -139,21 +143,10 @@ func writeConfig(dir string, localHostname string, port int) (configURL string, }, }) if err != nil { - return "", "", err + return "", "", nil, err } h := sha256.Sum256(config) configHash = hex.EncodeToString(h[:]) - configDir := filepath.Join(dir, "system_ota_tests") - if err := os.MkdirAll(configDir, 0755); err != nil { - return "", "", err - } - - configPath := filepath.Join(configDir, "config.json") - log.Printf("writing %q", configPath) - if err := ioutil.WriteFile(configPath, config, 0644); err != nil { - return "", "", err - } - - return configURL, configHash, nil + return configURL, configHash, config, nil } diff --git a/garnet/tests/system_ota_tests/sshclient/sshclient.go b/src/testing/host_target_testing/sshclient/sshclient.go similarity index 100% rename from garnet/tests/system_ota_tests/sshclient/sshclient.go rename to src/testing/host_target_testing/sshclient/sshclient.go diff --git a/garnet/tests/system_ota_tests/util/util.go b/src/testing/host_target_testing/util/util.go similarity index 100% rename from garnet/tests/system_ota_tests/util/util.go rename to src/testing/host_target_testing/util/util.go