2019-11-08 12:33:47 +03:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the Apache 2.0 License.import test_suite
|
|
|
|
|
2020-01-29 18:09:28 +03:00
|
|
|
import infra.e2e_args
|
2019-11-08 12:33:47 +03:00
|
|
|
import infra.ccf
|
|
|
|
import suite.test_suite as s
|
|
|
|
import suite.test_requirements as reqs
|
2020-01-24 15:37:51 +03:00
|
|
|
import infra.logging_app as app
|
2019-11-08 12:33:47 +03:00
|
|
|
import time
|
|
|
|
import json
|
2020-01-24 15:37:51 +03:00
|
|
|
import sys
|
2019-11-08 12:33:47 +03:00
|
|
|
from enum import Enum
|
2020-04-07 13:05:24 +03:00
|
|
|
import random
|
|
|
|
import os
|
2019-11-08 12:33:47 +03:00
|
|
|
|
|
|
|
from loguru import logger as LOG
|
|
|
|
|
|
|
|
|
|
|
|
class TestStatus(Enum):
|
|
|
|
success = 1
|
|
|
|
failure = 2
|
|
|
|
skipped = 3
|
|
|
|
|
|
|
|
|
|
|
|
def run(args):
|
|
|
|
|
2020-04-24 17:32:30 +03:00
|
|
|
seed = None
|
2020-04-07 13:05:24 +03:00
|
|
|
if os.getenv("SHUFFLE_SUITE"):
|
2020-04-17 14:53:01 +03:00
|
|
|
seed = os.getenv("SHUFFLE_SUITE_SEED")
|
|
|
|
if seed is None:
|
|
|
|
seed = time.time()
|
|
|
|
seed = int(seed)
|
2020-04-24 17:32:30 +03:00
|
|
|
LOG.success(f"Shuffling full suite with seed {seed}")
|
2020-04-07 13:05:24 +03:00
|
|
|
random.seed(seed)
|
2020-04-24 17:32:30 +03:00
|
|
|
random.shuffle(s.full_suite)
|
|
|
|
s.validate_tests_signature(s.full_suite)
|
2019-11-08 12:33:47 +03:00
|
|
|
|
|
|
|
if args.enforce_reqs is False:
|
|
|
|
LOG.warning("Test requirements will be ignored")
|
|
|
|
|
|
|
|
hosts = ["localhost", "localhost"]
|
2020-01-24 15:37:51 +03:00
|
|
|
txs = app.LoggingTxs()
|
2020-02-06 18:27:18 +03:00
|
|
|
network = infra.ccf.Network(
|
|
|
|
hosts, args.binary_dir, args.debug_nodes, args.perf_nodes, txs=txs
|
|
|
|
)
|
2019-11-08 12:33:47 +03:00
|
|
|
network.start_and_join(args)
|
|
|
|
|
2020-04-24 17:32:30 +03:00
|
|
|
LOG.info(f"Running {len(s.full_suite)} full_suite for {args.test_duration} seconds")
|
2019-11-08 12:33:47 +03:00
|
|
|
|
|
|
|
run_tests = {}
|
2020-01-24 15:37:51 +03:00
|
|
|
success = True
|
2019-11-08 12:33:47 +03:00
|
|
|
elapsed = args.test_duration
|
|
|
|
|
2020-04-24 17:32:30 +03:00
|
|
|
for i, test in enumerate(s.full_suite):
|
2019-11-08 12:33:47 +03:00
|
|
|
status = None
|
|
|
|
reason = None
|
|
|
|
|
|
|
|
if elapsed <= 0:
|
|
|
|
LOG.warning(f"Test duration time ({args.test_duration} seconds) is up!")
|
|
|
|
break
|
|
|
|
|
|
|
|
try:
|
|
|
|
LOG.debug(f"Running {s.test_name(test)}...")
|
|
|
|
test_time_before = time.time()
|
|
|
|
|
|
|
|
# Actually run the test
|
|
|
|
new_network = test(network, args)
|
|
|
|
status = TestStatus.success
|
|
|
|
|
|
|
|
except reqs.TestRequirementsNotMet as ce:
|
|
|
|
LOG.warning(f"Test requirements for {s.test_name(test)} not met")
|
|
|
|
status = TestStatus.skipped
|
|
|
|
reason = str(ce)
|
|
|
|
new_network = network
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
LOG.exception(f"Test {s.test_name(test)} failed")
|
|
|
|
status = TestStatus.failure
|
|
|
|
new_network = network
|
|
|
|
|
|
|
|
test_elapsed = time.time() - test_time_before
|
|
|
|
|
|
|
|
# Construct test report
|
|
|
|
run_tests[i] = {
|
|
|
|
"name": s.test_name(test),
|
|
|
|
"status": status.name,
|
|
|
|
"elapsed (s)": round(test_elapsed, 2),
|
|
|
|
}
|
|
|
|
|
|
|
|
if reason is not None:
|
|
|
|
run_tests[i]["reason"] = reason
|
|
|
|
|
|
|
|
# If the test function did not return a network, it is not possible to continue
|
|
|
|
if new_network is None:
|
|
|
|
raise ValueError(f"Network returned by {s.test_name(test)} is None")
|
|
|
|
|
|
|
|
# If the network was changed (e.g. recovery test), stop the previous network
|
|
|
|
# and use the new network from now on
|
|
|
|
if new_network != network:
|
|
|
|
network.stop_all_nodes()
|
|
|
|
network = new_network
|
|
|
|
|
|
|
|
LOG.debug(f"Test {s.test_name(test)} took {test_elapsed:.2f} secs")
|
|
|
|
|
|
|
|
# For now, if a test fails, the entire test suite if stopped
|
|
|
|
if status is TestStatus.failure:
|
2020-01-24 15:37:51 +03:00
|
|
|
success = False
|
2019-11-08 12:33:47 +03:00
|
|
|
break
|
|
|
|
|
|
|
|
elapsed -= test_elapsed
|
|
|
|
|
2020-01-20 16:47:03 +03:00
|
|
|
network.stop_all_nodes()
|
|
|
|
|
2020-04-17 12:03:29 +03:00
|
|
|
if success:
|
2020-04-24 17:32:30 +03:00
|
|
|
LOG.success(f"Full suite passed. Ran {len(run_tests)}/{len(s.full_suite)}")
|
2020-04-17 12:03:29 +03:00
|
|
|
else:
|
2020-04-24 17:32:30 +03:00
|
|
|
LOG.error(f"Suite failed. Ran {len(run_tests)}/{len(s.full_suite)}")
|
|
|
|
|
|
|
|
if seed:
|
|
|
|
LOG.info(f"Full suite was shuffled with seed: {seed}")
|
2020-04-17 12:03:29 +03:00
|
|
|
|
|
|
|
for idx, test in run_tests.items():
|
|
|
|
status = test["status"]
|
|
|
|
if status == TestStatus.success.name:
|
|
|
|
log_fn = LOG.success
|
|
|
|
elif status == TestStatus.skipped.name:
|
|
|
|
log_fn = LOG.warning
|
|
|
|
else:
|
|
|
|
log_fn = LOG.error
|
|
|
|
log_fn(f"Test #{idx}:\n{json.dumps(test, indent=4)}")
|
2019-11-08 12:33:47 +03:00
|
|
|
|
2020-01-24 15:37:51 +03:00
|
|
|
if not success:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-11-08 12:33:47 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
def add(parser):
|
|
|
|
parser.add_argument(
|
2020-04-24 17:32:30 +03:00
|
|
|
"--test-duration", help="Duration of full suite (s)", type=int
|
2019-11-08 12:33:47 +03:00
|
|
|
)
|
|
|
|
|
2020-01-29 18:09:28 +03:00
|
|
|
args = infra.e2e_args.cli_args(add)
|
2020-03-25 19:02:04 +03:00
|
|
|
args.package = args.app_script and "liblua_generic" or "liblogging"
|
2019-11-08 12:33:47 +03:00
|
|
|
|
|
|
|
run(args)
|