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_)
def check_exit(line, n = "0"): global T T += 1 print(color.INFO("test.py"), "received: ", line) status = line.split(" ")[-1].lstrip().rstrip() as_expected = status == n if as_expected: print(color.INFO("test.py"), "Exit status is ", status, "as expected") vm.exit(0, "Test " + str(T) + "/" + str(N) + " passed", keep_running = True) return as_expected else: print(color.WARNING("test.py"), "Exit status is", status, "expected", n) return as_expected
def check_exit(line, n="0"): global T T += 1 print "Python received: ", line status = line.split(" ")[-1].lstrip().rstrip() as_expected = status == n if as_expected: print color.INFO("test.py"), "Exit status is ", status, "as expected" vm.exit(0, "Test " + str(T) + "/" + str(N) + " passed") return as_expected else: print color.WARNING( "test.py"), "Exit status is", status, "expected", as_expected "expected " + n return as_expected
def check_vitals(string): print color.INFO("Checking vital signs") mem = get_mem() diff = mem - memuse_at_start pages = diff / PAGE_SIZE if diff % PAGE_SIZE != 0: print color.WARNING("Memory increase was not a multple of page size.") wait_for_tw() return False print color.INFO("Memory use at test end:"), mem, "bytes" print color.INFO( "Memory difference from test start:" ), memuse_at_start, "bytes (Diff:", diff, "b == ", pages, "pages)" sock_mem.close() vm.stop() wait_for_tw() return True
def fire_bursts(func, sub_test_name, lead_out=3): name_tag = "<" + sub_test_name + ">" print color.HEADER(test_name + " initiating " + sub_test_name) membase_start = func() mem_base = membase_start # Track heap behavior increases = 0 decreases = 0 constant = 0 for i in range(0, BURST_COUNT): print color.INFO(name_tag), " Run ", i + 1 memi = func() if memi > mem_base: memincrease = memi - mem_base increases += 1 elif memi == mem_base: memincrease = 0 constant += 1 else: memincrease = 0 decreases += 1 # We want to know how much each burst increases memory relative to the last burst mem_base = memi if memincrease > acceptable_increase: print color.WARNING( name_tag), "Memory increased by ", memincrease, "b, ", float( memincrease) / BURST_SIZE, "pr. packet \n" else: print color.OK(name_tag), "Memory increase ", memincrease, "b \n" # Memory can decrease, we don't care about that # if memincrease > 0: # mem_base += memincrease print color.INFO( name_tag ), "Heap behavior: ", "+", increases, ", -", decreases, ", ==", constant print color.INFO(name_tag), "Done. Checking for liveliness" if memory_increase(lead_out, membase_start) > acceptable_increase: print color.FAIL(sub_test_name + " failed ") return False print color.PASS(sub_test_name + " succeeded ") return True
def misc_working(misc_tests): global test_count test_count += len(misc_tests) if len(misc_tests) == 0: return 0 if ("misc" in args.skip): print pretty.WARNING("Misc test skipped") return 0 print pretty.HEADER("Building " + str(len(misc_tests)) + " misc") fail_count = 0 for test in misc_tests: build = test.start().wait_status() fail_count += 1 if build else 0 return fail_count
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 if validate_test.validate_path(path, verb): tests.append(path) else: print color.WARNING("Validator: " + path + " failed validation") return tests
def memory_increase(lead_time, expected_memuse = memuse_at_start): name_tag = "<" + test_name + "::memory_increase>" if lead_time: print color.INFO(name_tag),"Checking for memory increase after a lead time of ",lead_time,"s." # Give the VM a chance to free up resources before asking time.sleep(lead_time) use = get_mem() increase = use - expected_memuse percent = 0.0; if (increase): percent = float(increase) / expected_memuse if increase > acceptable_increase: print color.WARNING(name_tag), "Memory increased by ", percent, "%." print "(" , expected_memuse, "->", use, ",", increase,"b increase, but no increase expected.)" else: print color.OK(name_tag + "Memory constant, no leak detected") return increase
def misc_working(): global test_count if ("misc" in args.skip): print pretty.WARNING("Misc test skipped") return 0 misc_dir = 'misc' dirs = os.walk(misc_dir).next()[1] dirs.sort() print pretty.HEADER("Building " + str(len(dirs)) + " misc") test_count += len(dirs) fail_count = 0 for directory in dirs: misc = misc_dir + "/" + directory print "Building misc ", misc build = Test(misc, command = ['./test.sh'], name = directory).start().wait_status() run = 0 #TODO: Make a 'test' folder for each miscellanous test, containing test.py, vm.json etc. fail_count += 1 if build or run else 0 return fail_count
def stress_test(): """Perform stresstest""" global test_count test_count += 1 if ("stress" in args.skip): print pretty.WARNING("Stress test skipped") return 0 if (not validate_tests.validate_test("stress")): raise Exception("Stress test failed validation") print pretty.HEADER("Starting stress test") stress = Test("stress", clean = args.clean).start() if (stress and args.fail): print pretty.FAIL("Stress test failed") sys.exit(stress) return 1 if stress.wait_status() else 0
def stress_test(stress_tests): """Perform stresstest""" global test_count test_count += len(stress_tests) if len(stress_tests) == 0: return 0 if ("stress" in args.skip): print pretty.WARNING("Stress test skipped") return 0 if (not validate_tests.validate_test("stress")): raise Exception("Stress test failed validation") print pretty.HEADER("Starting stress test") for test in stress_tests: test.start() for test in stress_tests: return 1 if test.wait_status() else 0
def UDP_burst(burst_size = BURST_SIZE, burst_interval = BURST_INTERVAL): global memuse_at_start sock = socket.socket # SOCK_DGRAM is the socket type to use for UDP sockets sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(sock_timeout) # This is a stress-test, so we don't want to spend time checking the output # (especially not with python) # We just want to make sure the VM survives. data = "UDP is working as it's supposed to." try: for i in range(0, burst_size): sock.sendto(data, (HOST, PORT_FLOOD)) except Exception as e: print color.WARNING("<Test.py> Python socket timed out while sending. ") return False sock.close() time.sleep(burst_interval) return get_mem()
def print_skipped(tests): for test in tests: if test.skip_: print pretty.WARNING("* Skipping " + test.name_) print "Reason: {0:40}".format(test.skip_reason_)