Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 49 additions & 26 deletions etc/boot
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ if not os.path.isdir(INCLUDEOS_PREFIX + "/includeos"):
print "Couldn't find IncludeOS installation. If you installed to a non-default location (e.g. not " + default_loc + ") please set the environment variable INCLUDEOS_PREFIX to point to this location."
sys.exit(0)

# Location of vmrunner
sys.path.append(INCLUDEOS_PREFIX + "/includeos")

from vmrunner.prettify import color


# Argparse
parser = argparse.ArgumentParser(
description="IncludeOS vmrunner. Builds and runs an IncludeOS service")
Expand All @@ -37,51 +43,68 @@ parser.add_argument("--create-bridge", dest="bridge", action="store_true",
parser.add_argument("-g", "--grub", dest="grub", action="store_true",
help="Create image with GRUB bootloader that will boot provided binary")

parser.add_argument('binary', action="store", type=str,
help="Filename of the IncludeOS service binary")
parser.add_argument("-j", "--config", dest="config", type = str, metavar = "PATH",
help="Location of VM config file - JSON validated against a schema")

parser.add_argument('vm_location', action="store", type = str,
help="Location of the IncludeOS service binary, image or source")

parser.add_argument('vmargs', nargs='*', help="Arguments to pass on to the VM start / main")

args = parser.parse_args()

# Location of vmrunner
sys.path.append(INCLUDEOS_PREFIX + "/includeos")

from vmrunner.prettify import color
# Pretty printing from this command
nametag = "<boot>"
INFO = color.INFO(nametag)

# Override VM output prepension
color.VM_PREPEND = ""

# Pretty printing from this command
nametag = "<boot>"
INFO = color.INFO(nametag)
# in verbose mode we will set VERBOSE=1 for this environment
VERB = False
if (args.verbose):
os.environ["VERBOSE"] = "1"
VERB = True
print INFO, "VERBOSE mode set for environment"
# Avoid the verbose var to hang around next run
elif "VERBOSE" in os.environ:
del os.environ["VERBOSE"]

# Note: importing vmrunner will make it start looking for VM's
# vmrunner also relies on the verbose env var to be set on initialization
from vmrunner import vmrunner


# We can boot either a binary without bootloader, or an image with bootloader allready attached
has_bootloader = False

print INFO , "Args to pass to VM: ", args.vmargs
if VERB: print INFO , "Args to pass to VM: ", args.vmargs
# path w/name of VM image to run
image_name = args.binary
image_name = args.vm_location

# if the binary argument is a directory, go there immediately and
# then initialize stuff ...
if (os.path.isdir(args.binary)):
image_name = os.path.abspath(args.binary)
print "Changing directory to: " + image_name
os.chdir(os.path.abspath(args.binary))
if (os.path.isdir(args.vm_location)):
image_name = os.path.abspath(args.vm_location)
if VERB: print INFO, "Changing directory to " + image_name
os.chdir(os.path.abspath(args.vm_location))

# in verbose mode we will just set VERBOSE=1 for this environment
if (args.verbose):
os.environ['VERBOSE'] = "1"

# Note: importing vmrunner will make it start looking for VM's
from vmrunner import vmrunner
if len(vmrunner.vms) < 1:
print color.FAIL("No vm description files found - nothing to boot")
# This should never happen - there should always be a default
print color.FAIL("No vm object found in vmrunner - nothing to boot")
exit(-1)

print color.INFO(nametag), len(vmrunner.vms), "VM initialized. Commencing build- and boot..."
if VERB:
print INFO, len(vmrunner.vms), "VM initialized. Commencing build- and boot..."

config = None
if args.config:
config = os.path.abspath(args.config)
if VERB: print INFO, "Using config file", config

vm = vmrunner.vms[0]
vm = vmrunner.vm(config = config)

# For multible JSON configs, find the one matching the provided image name
for vm_ in vmrunner.vms:
Expand All @@ -99,15 +122,15 @@ if (args.bridge):
# If the binary name is a folder, such as ".", build the service
if (os.path.isdir(image_name)):
vm.cmake()
# also, set image name to
# also, set image name to
image_name = open("binary.txt", 'r').read()
# If the binary name has an extension (e.g. a '.'), assume it has a bootloader attached
# NOTE: the idea is to support e.g. .vdi and virtualbox etc. in the future
elif ("." in args.binary):
elif ("." in args.vm_location):
has_bootloader = True

if (args.grub):
print INFO, "Creating GRUB image from ", args.binary
print INFO, "Creating GRUB image from ", args.vm_location
subprocess.call(INCLUDEOS_PREFIX + "/includeos/scripts/grubify.sh " + image_name, shell=True)
image_name = image_name + ".grub.img"
has_bootloader = True
Expand All @@ -116,6 +139,6 @@ if (args.grub):
if (args.build): exit(0);

if (not has_bootloader):
vm.boot(timeout = None, kernel_args=" ".join(args.vmargs), image_name = image_name)
vm.boot(timeout = None, multiboot = True, kernel_args = " ".join(args.vmargs), image_name = image_name)
else:
vm.boot(timeout = None, multiboot = False, kernel_args = None, image_name = image_name)
3 changes: 3 additions & 0 deletions test/net/integration/http/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void Service::ready()
client_->send(std::move(req), {inet.gateway(), 9011},
[] (auto err, auto res)
{
if (err)
printf("Error: %s \n", err.to_string().c_str());

CHECKSERT(!err, "No error");
CHECKSERT(res->body() == "/testing", "Received body: \"/testing\"");
printf("Response:\n%s\n", res->to_string().c_str());
Expand Down
9 changes: 5 additions & 4 deletions test/net/integration/http/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys
import os
import thread

includeos_src = os.environ.get('INCLUDEOS_SRC',
os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))).split('/test')[0])
Expand All @@ -23,7 +24,7 @@ def do_GET(s):
s.wfile.write("%s" % s.path)


def Client_test(trigger_line):
def Client_test():
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST, PORT), RequestHandler)
global DO_SERVE
Expand All @@ -32,11 +33,11 @@ def Client_test(trigger_line):
DO_SERVE = False
httpd.server_close()

# Start web server in a separate thread
thread.start_new_thread(Client_test, ())

# Get an auto-created VM from the vmrunner
vm = vmrunner.vms[0]

# Add custom event-handler
vm.on_output("Testing against local server", Client_test)

# Boot the VM, taking a timeout as parameter
vm.cmake().boot(20).clean()
16 changes: 7 additions & 9 deletions test/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from vmrunner.prettify import color as pretty
from vmrunner import validate_vm
import validate_all
import validate_tests

startdir = os.getcwd()

Expand Down Expand Up @@ -54,10 +54,7 @@ def print_skipped(tests):
for test in tests:
if test.skip_:
print pretty.WARNING("* Skipping " + test.name_)
if "validate_vm" in test.skip_reason_:
validate_vm.validate_path(test.path_, verb = True)
else:
print " Reason: {0:40}".format(test.skip_reason_)
print "Reason: {0:40}".format(test.skip_reason_)


class Test:
Expand Down Expand Up @@ -179,9 +176,10 @@ def check_valid(self):
self: Class function
"""
# Test 1
if not validate_vm.validate_path(self.path_, verb = False):
valid, err = validate_tests.validate_test(self.path_, verb = False)
if not valid:
self.skip_ = True
self.skip_reason_ = 'Failed validate_vm, missing files'
self.skip_reason_ = err
return

# Test 2
Expand Down Expand Up @@ -212,7 +210,7 @@ def stress_test():
print pretty.WARNING("Stress test skipped")
return 0

if (not validate_vm.validate_path("stress")):
if (not validate_tests.validate_test("stress")):
raise Exception("Stress test failed validation")

print pretty.HEADER("Starting stress test")
Expand Down Expand Up @@ -383,7 +381,7 @@ def filter_tests(all_tests, arguments):
or x.name_ in add_args ]

# 2) Remove tests defined by the skip argument
print pretty.INFO("Tests to skip"), ", ".join(skip_args)
print pretty.INFO("Tests marked skip on command line"), ", ".join(skip_args)
skipped_tests = [ x for x in tests_added
if x.type_ in skip_args
or x.category_ in skip_args
Expand Down
30 changes: 0 additions & 30 deletions test/validate_all.py

This file was deleted.

56 changes: 56 additions & 0 deletions test/validate_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
import sys
sys.path.insert(0, ".")
sys.path.insert(0, "..")

import subprocess
import os
from vmrunner import validate_vm
from vmrunner.prettify import color

# Verify if a given path is a valid integration test
def validate_test(path, verb = False):

try:
# Load any valid configs in path
valid_configs = validate_vm.load_config(path)
if not valid_configs:
raise Exception("No valid JSON config in path")

# Additional requirements for tests
required_files = ["CMakeLists.txt", "test.py"]

for f in required_files:
if not os.path.isfile(path + "/" + f):
raise Exception("Required file " + f + " missing")

if verb:
print "<validate_test> \tPASS: ",path
return True, "PASS"

except Exception as err:
if verb:
print "<validate_test> \tFAIL: ", path, ": " , err.message

return False, err.message


def valid_tests(verb = False):
tests = []

dirs = os.walk('.').next()[1]
for directory in dirs:
subdirs = os.walk(directory).next()[1]
if "integration" in subdirs:
subdirs = os.walk(directory + "/integration").next()[1]
if subdirs:
for d in subdirs:
path = directory + "/integration/" + d
passed, err = validate_test(path, verb)
if passed:
tests.append(path)

return tests

if __name__ == "__main__":
valid_tests(verb = True)
2 changes: 1 addition & 1 deletion vmrunner/prettify.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def code(fg = WHITE, bg = BLACK, style = NORMAL, fg_intensity = FG_NORMAL, bg_in

@staticmethod
def WARNING(string):
return color.C_WARNING + "[ WARNING ] " + string.rstrip() + color.C_ENDC + "\n"
return color.C_WARNING + "[ WARNING ] " + string.rstrip() + color.C_ENDC

@staticmethod
def FAIL(string):
Expand Down
Loading