From a5c162275d712c63151cab8f25eecbcfb1719e2a Mon Sep 17 00:00:00 2001
From: Aaron Green <aarongreen@google.com>
Date: Mon, 13 May 2019 21:23:42 +0000
Subject: [PATCH] [fuzzing] Run scripts/fuzzing/test/* as host test.

This CL extends the host test for host fuzzers to also run the python
unit tests for 'fx fuzz'.

Bugs: SEC-170
Test: fx set core.x64 --with //src/fuzzing:tests
      fx run-host-test fuzzing_host_test
Change-Id: Ic2568e5603b34d35a94ebe85161f476f7854c330
---
 src/fuzzing/BUILD.gn     |  8 ++++----
 src/fuzzing/host_test.go | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/fuzzing/BUILD.gn b/src/fuzzing/BUILD.gn
index e2c7b803428..bdd572d5b17 100644
--- a/src/fuzzing/BUILD.gn
+++ b/src/fuzzing/BUILD.gn
@@ -8,17 +8,17 @@ import("//build/go/go_test.gni")
 group("tests") {
   testonly = true
   public_deps = [
-    ":host_fuzzers_test($host_toolchain)",
+    ":fuzzing_host_test($host_toolchain)",
   ]
 }
 
-go_library("host_fuzzers_test_lib") {
+go_library("fuzzing_host_test_lib") {
   name = "fuzzing"
 }
 
-go_test("host_fuzzers_test") {
+go_test("fuzzing_host_test") {
   gopackage = "fuzzing"
   deps = [
-    ":host_fuzzers_test_lib",
+    ":fuzzing_host_test_lib",
   ]
 }
diff --git a/src/fuzzing/host_test.go b/src/fuzzing/host_test.go
index 96e4e80c411..03660fa461b 100644
--- a/src/fuzzing/host_test.go
+++ b/src/fuzzing/host_test.go
@@ -21,6 +21,28 @@ type FuzzSpec struct {
 	Targets []string `json:"fuzz_targets"`
 }
 
+func TestFxFuzzLib(t *testing.T) {
+	fuchsiaDir, found := os.LookupEnv("FUCHSIA_DIR")
+	if !found {
+		t.SkipNow()
+	}
+	scriptsFuzzingTests := []string{
+		"cipd_test.py",
+		"device_test.py",
+		"fuzzer_test.py",
+		"host_test.py",
+	}
+	for _, test := range scriptsFuzzingTests {
+		pytest := path.Join(fuchsiaDir, "scripts", "fuzzing", "test", test)
+		cmd := exec.Command("python", pytest)
+		output, err := cmd.CombinedOutput()
+		if err != nil {
+			t.Errorf("%s failed:: %v", test, err)
+		}
+		t.Log(string(output[:]))
+	}
+}
+
 func TestHostFuzzers(t *testing.T) {
 	// Search the build directory structure for host variant fuzzer builds.
 	// This is necessarily sensitive to the layout of the build directory and
-- 
GitLab