summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test-cutils.c52
-rw-r--r--tests/vm/Makefile.include26
2 files changed, 69 insertions, 9 deletions
diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c
index 98671f1ac3..f5b780f012 100644
--- a/tests/unit/test-cutils.c
+++ b/tests/unit/test-cutils.c
@@ -2450,6 +2450,50 @@ static void test_qemu_strtosz_metric(void)
g_assert(endptr == str + 7);
}
+static void test_freq_to_str(void)
+{
+ g_assert_cmpstr(freq_to_str(999), ==, "999 Hz");
+ g_assert_cmpstr(freq_to_str(1000), ==, "1 KHz");
+ g_assert_cmpstr(freq_to_str(1010), ==, "1.01 KHz");
+}
+
+static void test_size_to_str(void)
+{
+ g_assert_cmpstr(size_to_str(0), ==, "0 B");
+ g_assert_cmpstr(size_to_str(1), ==, "1 B");
+ g_assert_cmpstr(size_to_str(1016), ==, "0.992 KiB");
+ g_assert_cmpstr(size_to_str(1024), ==, "1 KiB");
+ g_assert_cmpstr(size_to_str(512ull << 20), ==, "512 MiB");
+}
+
+static void test_iec_binary_prefix(void)
+{
+ g_assert_cmpstr(iec_binary_prefix(0), ==, "");
+ g_assert_cmpstr(iec_binary_prefix(10), ==, "Ki");
+ g_assert_cmpstr(iec_binary_prefix(20), ==, "Mi");
+ g_assert_cmpstr(iec_binary_prefix(30), ==, "Gi");
+ g_assert_cmpstr(iec_binary_prefix(40), ==, "Ti");
+ g_assert_cmpstr(iec_binary_prefix(50), ==, "Pi");
+ g_assert_cmpstr(iec_binary_prefix(60), ==, "Ei");
+}
+
+static void test_si_prefix(void)
+{
+ g_assert_cmpstr(si_prefix(-18), ==, "a");
+ g_assert_cmpstr(si_prefix(-15), ==, "f");
+ g_assert_cmpstr(si_prefix(-12), ==, "p");
+ g_assert_cmpstr(si_prefix(-9), ==, "n");
+ g_assert_cmpstr(si_prefix(-6), ==, "u");
+ g_assert_cmpstr(si_prefix(-3), ==, "m");
+ g_assert_cmpstr(si_prefix(0), ==, "");
+ g_assert_cmpstr(si_prefix(3), ==, "K");
+ g_assert_cmpstr(si_prefix(6), ==, "M");
+ g_assert_cmpstr(si_prefix(9), ==, "G");
+ g_assert_cmpstr(si_prefix(12), ==, "T");
+ g_assert_cmpstr(si_prefix(15), ==, "P");
+ g_assert_cmpstr(si_prefix(18), ==, "E");
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
@@ -2729,5 +2773,13 @@ int main(int argc, char **argv)
g_test_add_func("/cutils/strtosz/metric",
test_qemu_strtosz_metric);
+ g_test_add_func("/cutils/size_to_str",
+ test_size_to_str);
+ g_test_add_func("/cutils/freq_to_str",
+ test_freq_to_str);
+ g_test_add_func("/cutils/iec_binary_prefix",
+ test_iec_binary_prefix);
+ g_test_add_func("/cutils/si_prefix",
+ test_si_prefix);
return g_test_run();
}
diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index 588bc999cc..5f5b1fbfe6 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -1,8 +1,17 @@
# Makefile for VM tests
-.PHONY: vm-build-all vm-clean-all
+# Hack to allow running in an unconfigured build tree
+ifeq ($(wildcard $(SRC_PATH)/config-host.mak),)
+VM_PYTHON = PYTHONPATH=$(SRC_PATH)/python /usr/bin/env python3
+VM_VENV =
+HOST_ARCH := $(shell uname -m)
+else
+VM_PYTHON = $(TESTS_PYTHON)
+VM_VENV = check-venv
+HOST_ARCH = $(ARCH)
+endif
-HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
+.PHONY: vm-build-all vm-clean-all
EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
@@ -85,10 +94,10 @@ vm-clean-all:
$(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
$(SRC_PATH)/tests/vm/basevm.py \
$(SRC_PATH)/tests/vm/Makefile.include \
- check-venv
+ $(VM_VENV)
@mkdir -p $(IMAGES_DIR)
$(call quiet-command, \
- $(TESTS_PYTHON) $< \
+ $(VM_PYTHON) $< \
$(if $(V)$(DEBUG), --debug) \
$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
@@ -100,11 +109,10 @@ $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
--build-image $@, \
" VM-IMAGE $*")
-
# Build in VM $(IMAGE)
-vm-build-%: $(IMAGES_DIR)/%.img check-venv
+vm-build-%: $(IMAGES_DIR)/%.img $(VM_VENV)
$(call quiet-command, \
- $(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \
+ $(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
$(if $(V)$(DEBUG), --debug) \
$(if $(DEBUG), --interactive) \
$(if $(J),--jobs $(J)) \
@@ -128,9 +136,9 @@ vm-boot-serial-%: $(IMAGES_DIR)/%.img
-device virtio-net-pci,netdev=vnet \
|| true
-vm-boot-ssh-%: $(IMAGES_DIR)/%.img check-venv
+vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(VM_VENV)
$(call quiet-command, \
- $(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \
+ $(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
$(if $(J),--jobs $(J)) \
$(if $(V)$(DEBUG), --debug) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \