Patchwork [V4,4/5] libqblock test build system

login
register
mail settings
Submitter Wayne Xia
Date Sept. 27, 2012, 2:24 a.m.
Message ID <1348712642-4427-5-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/187260/
State New
Headers show

Comments

Wayne Xia - Sept. 27, 2012, 2:24 a.m.
This patch will create a new directory in ./tests, make check-libqblock will
build an executable binary, make clean or make check-clean will delete generated
binaries.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 .gitignore                        |    2 +
 Makefile                          |    1 +
 tests/Makefile                    |   45 +++++++++++++++++++++++++++++++++++++
 tests/libqblock/libqblock-qcow2.c |    4 +++
 4 files changed, 52 insertions(+), 0 deletions(-)
 create mode 100644 tests/libqblock/libqblock-qcow2.c
Paolo Bonzini - Sept. 27, 2012, 8:30 a.m.
Il 27/09/2012 04:24, Wenchao Xia ha scritto:
> +#libqblock
> +LIBQBLOCK_TEST_DIR=$(SRC_PATH)/tests/libqblock/test_images
> +qtest-lib-y=$(patsubst %.o, %.lo,$(qtest-obj-y))

I don't think you need qtest-obj-y for anything.

> +libqblock-la-path = $(libqblock-lib-path)/$(libqblock-lib-la)
> +
> +tests/libqblock/%.lo: QEMU_INCLUDES += -I$(libqblock-lib-path) -Itests
> +
> +check-libqblock-y = tests/libqblock/check-libqblock-qcow2$(EXESUF)
> +tests/libqblock/check-libqblock-qcow2$(EXESUF): tests/libqblock/libqblock-qcow2.lo $(libqblock-la-path) $(qtest-lib-y)

No need to use .lo here.

> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -shared -rpath $(libdir) -o $@ $^,"  lt LINK $@")
> +

> +$(libqblock-la-path):
> +	@echo "Building libqblock.la..."
> +	$(call quiet-command,$(MAKE) -C $(SRC_PATH) $(libqblock-lib-la),)

No need for this.

> +$(LIBQBLOCK_TEST_DIR):
> +	@echo "Make libqblock test directory"
> +	mkdir $(LIBQBLOCK_TEST_DIR)

You can leave the files in tests/ directly, and avoid this as well.

> +check-libqblock: $(libqblock-la-path) $(LIBQBLOCK_TEST_DIR) $(patsubst %,check-%, $(check-libqblock-y))

Please add

check: check-libqblock

here, so that if libtool is present the check is run automatically.

Paolo
Wayne Xia - Sept. 27, 2012, 9:56 a.m.
于 2012-9-27 16:30, Paolo Bonzini 写道:
> Il 27/09/2012 04:24, Wenchao Xia ha scritto:
>> +#libqblock
>> +LIBQBLOCK_TEST_DIR=$(SRC_PATH)/tests/libqblock/test_images
>> +qtest-lib-y=$(patsubst %.o, %.lo,$(qtest-obj-y))
>
> I don't think you need qtest-obj-y for anything.
>
  OK, I will remove it.

>> +libqblock-la-path = $(libqblock-lib-path)/$(libqblock-lib-la)
>> +
>> +tests/libqblock/%.lo: QEMU_INCLUDES += -I$(libqblock-lib-path) -Itests
>> +
>> +check-libqblock-y = tests/libqblock/check-libqblock-qcow2$(EXESUF)
>> +tests/libqblock/check-libqblock-qcow2$(EXESUF): tests/libqblock/libqblock-qcow2.lo $(libqblock-la-path) $(qtest-lib-y)
>
> No need to use .lo here.
>
OK.

>> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -shared -rpath $(libdir) -o $@ $^,"  lt LINK $@")
>> +
>
>> +$(libqblock-la-path):
>> +	@echo "Building libqblock.la..."
>> +	$(call quiet-command,$(MAKE) -C $(SRC_PATH) $(libqblock-lib-la),)
>
> No need for this.
OK.

>
>> +$(LIBQBLOCK_TEST_DIR):
>> +	@echo "Make libqblock test directory"
>> +	mkdir $(LIBQBLOCK_TEST_DIR)
>
> You can leave the files in tests/ directly, and avoid this as well.
   Having a new directory will make clean easier, otherwise the script
will need to know each image file names created, whose filename are
generated in test C code at runtime.

>
>> +check-libqblock: $(libqblock-la-path) $(LIBQBLOCK_TEST_DIR) $(patsubst %,check-%, $(check-libqblock-y))
>
> Please add
>
> check: check-libqblock
>
> here, so that if libtool is present the check is run automatically.
OK.

>
> Paolo
>
Paolo Bonzini - Sept. 27, 2012, 10:17 a.m.
Il 27/09/2012 11:56, Wenchao Xia ha scritto:
>>
>>> +$(LIBQBLOCK_TEST_DIR):
>>> +    @echo "Make libqblock test directory"
>>> +    mkdir $(LIBQBLOCK_TEST_DIR)
>>
>> You can leave the files in tests/ directly, and avoid this as well.
>   Having a new directory will make clean easier, otherwise the script
> will need to know each image file names created, whose filename are
> generated in test C code at runtime.

If you want a subdirectory for images, you can create it in the test code.

Paolo
Wayne Xia - Sept. 28, 2012, 3:04 a.m.
于 2012-9-27 18:17, Paolo Bonzini 写道:
> Il 27/09/2012 11:56, Wenchao Xia ha scritto:
>>>
>>>> +$(LIBQBLOCK_TEST_DIR):
>>>> +    @echo "Make libqblock test directory"
>>>> +    mkdir $(LIBQBLOCK_TEST_DIR)
>>>
>>> You can leave the files in tests/ directly, and avoid this as well.
>>    Having a new directory will make clean easier, otherwise the script
>> will need to know each image file names created, whose filename are
>> generated in test C code at runtime.
>
> If you want a subdirectory for images, you can create it in the test code.
>
   My original idea is creating and deleting them in C test code, but I
found that there is many "assert" in the code, which may cause the clean
step missing. So I think it is simpler to clean them in Makefile, make
sure the temporal files are deleted.

> Paolo
>
Paolo Bonzini - Sept. 28, 2012, 7:52 a.m.
Il 28/09/2012 05:04, Wenchao Xia ha scritto:
>>>>> +$(LIBQBLOCK_TEST_DIR):
>>>>> +    @echo "Make libqblock test directory"
>>>>> +    mkdir $(LIBQBLOCK_TEST_DIR)
>>>>
>>>> You can leave the files in tests/ directly, and avoid this as well.
>>>    Having a new directory will make clean easier, otherwise the script
>>> will need to know each image file names created, whose filename are
>>> generated in test C code at runtime.
>>
>> If you want a subdirectory for images, you can create it in the test
>> code.
>>
>   My original idea is creating and deleting them in C test code, but I
> found that there is many "assert" in the code, which may cause the clean
> step missing. So I think it is simpler to clean them in Makefile, make
> sure the temporal files are deleted.

Yes, you can mkdir() in the test code, and delete the whole directory
from the Makefile.

Paolo
Wayne Xia - Sept. 28, 2012, 9:46 a.m.
于 2012-9-28 15:52, Paolo Bonzini 写道:
> Il 28/09/2012 05:04, Wenchao Xia ha scritto:
>>>>>> +$(LIBQBLOCK_TEST_DIR):
>>>>>> +    @echo "Make libqblock test directory"
>>>>>> +    mkdir $(LIBQBLOCK_TEST_DIR)
>>>>>
>>>>> You can leave the files in tests/ directly, and avoid this as well.
>>>>     Having a new directory will make clean easier, otherwise the script
>>>> will need to know each image file names created, whose filename are
>>>> generated in test C code at runtime.
>>>
>>> If you want a subdirectory for images, you can create it in the test
>>> code.
>>>
>>    My original idea is creating and deleting them in C test code, but I
>> found that there is many "assert" in the code, which may cause the clean
>> step missing. So I think it is simpler to clean them in Makefile, make
>> sure the temporal files are deleted.
>
> Yes, you can mkdir() in the test code, and delete the whole directory
> from the Makefile.
>
   Ok, I got your idea.

> Paolo
>

Patch

diff --git a/.gitignore b/.gitignore
index 824c0d2..080a88b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -95,3 +95,5 @@  cscope.*
 tags
 TAGS
 *~
+tests/libqblock/check-*
+tests/libqblock/test_images
diff --git a/Makefile b/Makefile
index 128bc6a..7cfb555 100644
--- a/Makefile
+++ b/Makefile
@@ -237,6 +237,7 @@  clean:
 	rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
+	$(MAKE) check-clean
 	for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard libqblock; do \
 	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
 	rm -f $$d/qemu-options.def; \
diff --git a/tests/Makefile b/tests/Makefile
index 26a67ce..668c825 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -84,6 +84,17 @@  check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)
 qtest-obj-y = tests/libqtest.o $(oslib-obj-y) $(tools-obj-y)
 $(check-qtest-y): $(qtest-obj-y)
 
+#libqblock
+LIBQBLOCK_TEST_DIR=$(SRC_PATH)/tests/libqblock/test_images
+qtest-lib-y=$(patsubst %.o, %.lo,$(qtest-obj-y))
+libqblock-la-path = $(libqblock-lib-path)/$(libqblock-lib-la)
+
+tests/libqblock/%.lo: QEMU_INCLUDES += -I$(libqblock-lib-path) -Itests
+
+check-libqblock-y = tests/libqblock/check-libqblock-qcow2$(EXESUF)
+tests/libqblock/check-libqblock-qcow2$(EXESUF): tests/libqblock/libqblock-qcow2.lo $(libqblock-la-path) $(qtest-lib-y)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -shared -rpath $(libdir) -o $@ $^,"  lt LINK $@")
+
 .PHONY: check-help
 check-help:
 	@echo "Regression testing targets:"
@@ -93,7 +104,9 @@  check-help:
 	@echo " make check-qtest          Run qtest tests"
 	@echo " make check-unit           Run qobject tests"
 	@echo " make check-block          Run block tests"
+	@echo " make check-libqblock      Run libqblock tests"
 	@echo " make check-report.html    Generates an HTML test report"
+	@echo " make check-clean          Clean the test"
 	@echo
 	@echo "Please note that HTML reports do not regenerate if the unit tests"
 	@echo "has not changed."
@@ -116,6 +129,11 @@  $(patsubst %, check-qtest-%, $(QTEST_TARGETS)): check-qtest-%: $(check-qtest-y)
 $(patsubst %, check-%, $(check-unit-y)): check-%: %
 	$(call quiet-command,gtester $(GTESTER_OPTIONS) -m=$(SPEED) $*,"GTESTER $*")
 
+#libqblock tests
+.PHONY: $(patsubst %, check-%, $(check-libqblock-y))
+$(patsubst %, check-%, $(check-libqblock-y)): check-%: %
+	$(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester $(GTESTER_OPTIONS) -m=$(SPEED) $*,"GTESTER $*")
+
 # gtester tests with XML output
 
 $(patsubst %, check-report-qtest-%.xml, $(QTEST_TARGETS)): check-report-qtest-%.xml: $(check-qtest-y)
@@ -148,4 +166,31 @@  check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-unit check-qtest
 
+ifeq ($(LIBTOOL),)
+check-libqblock:
+	@echo "libtool is missing, skip libqblock test."
+else
+$(libqblock-la-path):
+	@echo "Building libqblock.la..."
+	$(call quiet-command,$(MAKE) -C $(SRC_PATH) $(libqblock-lib-la),)
+$(LIBQBLOCK_TEST_DIR):
+	@echo "Make libqblock test directory"
+	mkdir $(LIBQBLOCK_TEST_DIR)
+
+check-libqblock: $(libqblock-la-path) $(LIBQBLOCK_TEST_DIR) $(patsubst %,check-%, $(check-libqblock-y))
+endif
+
+check-clean:
+	$(MAKE) -C tests/tcg clean
+	rm -f tests/*.lo tests/*.o
+	rm -rf tests/.libs
+	rm -f tests/libqblock/*.lo tests/libqblock/*.o
+	rm -rf tests/libqblock/.libs
+	rm -f trace/*.lo trace/*.o
+	rm -rf trace/.libs
+	rm -f $(check-libqblock-y)
+	rm -rf $(LIBQBLOCK_TEST_DIR)
+	rm -f $(check-unit-y)
+	rm -f $(check-qtest-i386-y) $(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y)
+
 -include $(wildcard tests/*.d)
diff --git a/tests/libqblock/libqblock-qcow2.c b/tests/libqblock/libqblock-qcow2.c
new file mode 100644
index 0000000..c05c0c4
--- /dev/null
+++ b/tests/libqblock/libqblock-qcow2.c
@@ -0,0 +1,4 @@ 
+int main(int argc, char **argv)
+{
+    return 0;
+}