Initial commit

Adds readme and build scripts. Rng test util is a stub.

Change-Id: I23e4ccab072ae399a0c29b18e7286420bcd849a6
diff --git a/.cargo/config b/.cargo/config
new file mode 100644
index 0000000..746bd01
--- /dev/null
+++ b/.cargo/config
@@ -0,0 +1,3 @@
+[target.aarch64-unknown-linux-musl]
+linker = "aarch64-linux-gnu-gcc"
+rustflags = [ "-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc" ]
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0f9d898
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+target
+out
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..e12886a
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,4 @@
+[[package]]
+name = "linux_tests"
+version = "0.1.0"
+
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..af0b732
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,13 @@
+# Copyright 2018 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.
+
+[package]
+name = "linux_tests"
+version = "0.1.0"
+authors = ["rust-fuchsia@fuchsia.com"]
+publish = false
+repository = "https://zircon-guest.googlesource.com/linux-tests/"
+license = "BSD-3-Clause"
+
+[dependencies]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..5efeef9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+// Copyright 2018 The Fuchsia Authors. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//    * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//    * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//    * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f7143d3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+# Linux Tests
+This repository contains utilities for running integration tests for Linux guests under Machina.
+
+## Build
+First install rust (follow the instructions of the rustup tool):
+```
+$ curl https://sh.rustup.rs -sSf | sh
+$ source ~/.cargo/env
+```
+
+Next we add some new targets for cross-compiling and static linking. Rust supports statically linking libc by replacing the usual gnu libc with musl (see [The Rust Book: Advanced Linking](https://doc.rust-lang.org/1.9.0/book/advanced-linking.html)).
+```
+$ rustup target add x86_64-unknown-linux-musl
+$ rustup target add aarch64-unknown-linux-musl
+```
+
+Lastly, run the build script for your desired architecture. This will invoke cargo for you as well as create an ext2 image in out/.
+```
+$ ./build.sh {arm64|x64}
+```
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..d066ad1
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+# Copyright 2018 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.
+
+set -eo pipefail
+
+usage() {
+  echo "usage: ${0} {arm64, x64}"
+  exit 1
+}
+
+case "${1}" in
+arm64)
+  ARCH="arm64"
+  TARGET="aarch64-unknown-linux-musl";;
+x64)
+  ARCH="x64"
+  TARGET="x86_64-unknown-linux-musl";;
+*)
+  usage;;
+esac
+
+declare -r OUT_DIR="out/${ARCH}"
+declare -r IMAGE_FILE="out/linux-tests-${ARCH}.img"
+
+cargo build --target=${TARGET}
+
+mkdir -p ${OUT_DIR}
+cp target/${TARGET}/debug/virtio_rng_test_util ${OUT_DIR}
+
+declare -r BLOCK_SIZE=4096
+declare -r ADDITIONAL_BLOCKS=1024
+declare -r SIZE=$(du -sb ${OUT_DIR} | grep -o '^[0-9]*')
+declare -r BLOCKS=$(($((${SIZE}/${BLOCK_SIZE}))+${ADDITIONAL_BLOCKS}))
+mke2fs -q -d "${OUT_DIR}" -t ext2 -b ${BLOCK_SIZE} "${IMAGE_FILE}" ${BLOCKS}
diff --git a/src/bin/virtio_rng_test_util.rs b/src/bin/virtio_rng_test_util.rs
new file mode 100644
index 0000000..c567ea9
--- /dev/null
+++ b/src/bin/virtio_rng_test_util.rs
@@ -0,0 +1,8 @@
+// Copyright 2018 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.
+#![deny(warnings)]
+
+fn main() {
+    println!("PASS");
+}