Skip to content

Commit

Permalink
tests: incorporate test kernel
Browse files Browse the repository at this point in the history
Contributes to #1, #2
  • Loading branch information
fabianfreyer committed Feb 18, 2018
1 parent 53e3518 commit 19ca4d4
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ peda-session-*
!.codecov.yml

tests/test-allocator
tests/test-mock-bhyveload
tests/test-mock-bhyveload
tests/test-multiboot
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CFLAGS+= -g
OBJS= loader.o multiboot.o allocator.o

LIBELF= -lelf
.export LIBELF

.PHONY: all
all: libmultiboot.so libmultiboot.so.full libmultiboot.a libmultiboot_p.a
Expand Down
1 change: 1 addition & 0 deletions tests/Kyuafile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test_suite("libmultiboot")

atf_test_program{name="test-allocator", }
atf_test_program{name="test-mock-bhyveload", }
atf_test_program{name="test-multiboot", }
35 changes: 33 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
LDFLAGS=-L/usr/local/lib
OBJCOPY?=objcopy

LIBELF= -lelf
LIBATF_C=/usr/local/lib/libatf-c.a

LDFLAGS=-L/usr/local/lib

UNAME_S!=uname -s
OUTPUT_BFD=elf64-x86-64
.if ${UNAME_S:MFreeBSD}
OUTPUT_BFD=elf64-x86-64-freebsd
.endif

MB_DIR=data/multiboot
MB_TESTCASES=data_multiboot_mmap.o data_multiboot_modules.o

.PHONY: all
all: test-allocator test-loader test-mock-bhyveload
all: test-allocator test-loader test-mock-bhyveload test-multiboot

.PHONY: check
check: all
Expand All @@ -11,12 +24,30 @@ check: all

.PHONY: clean
clean:
$(MAKE) -C data/multiboot clean
rm -f test-allocator.o
rm -f test-mock-bhyveload.o
rm -f mock/bhyveload.o
rm -f test-allocator
rm *.gcda *.gcno *.gcov

.PHONY: ${MB_DIR}/mmap.elf
${MB_DIR}/mmap.elf:
$(MAKE) -C data/multiboot mmap.elf

.PHONY: ${MB_DIR}/modules.elf
${MB_DIR}/modules.elf:
$(MAKE) -C data/multiboot modules.elf

data_multiboot_mmap.o: ${MB_DIR}/mmap.elf
$(OBJCOPY) --input binary --binary-architecture i386 --output ${OUTPUT_BFD} $> $@

data_multiboot_modules.o: ${MB_DIR}/modules.elf
$(OBJCOPY) --input binary --binary-architecture i386 --output ${OUTPUT_BFD} $> $@

test-multiboot: test-multiboot.o ${MB_TESTCASES} ../libmultiboot_p.a
$(CC) ${LDFLAGS} ${CFLAGS} -o $@ $> ${LIBATF_C} ${LIBELF}

test-mock-bhyveload: test-mock-bhyveload.o mock/bhyveload.o mock/compat-strlcat.o mock/compat-strlcpy.o
$(CC) ${LDFLAGS} ${CFLAGS} -o $@ $> ${LIBATF_C} ${LIBELF}

Expand Down
42 changes: 42 additions & 0 deletions tests/data-multiboot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2018, Fabian Freyer <fabian.freyer@physik.tu-berlin.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#pragma once

#define MB_TESTCASE(name) \
extern char _binary_data_multiboot_ ## name ## _elf_end; \
extern char _binary_data_multiboot_ ## name ## _elf_start; \

#define MB_TESTDATA_SYMBOL(name, suffix) _binary_data_multiboot_ ## name ## _elf_ ## suffix
#define MB_TESTDATA_START(name) &MB_TESTDATA_SYMBOL(name, start)
#define MB_TESTDATA_END(name) &MB_TESTDATA_SYMBOL(name, end)
#define MB_TESTDATA_SIZE(name) (MB_TESTDATA_START(name) - MB_TESTDATA_END(name))

MB_TESTCASE(mmap)
MB_TESTCASE(modules)
58 changes: 58 additions & 0 deletions tests/test-multiboot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018, Fabian Freyer <fabian.freyer@physik.tu-berlin.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <atf-c.h>
#include <tests/data-multiboot.h>
#include <stdio.h>

ATF_TC(testdata);
ATF_TC_HEAD(testdata, tc)
{
atf_tc_set_md_var(tc, "descr", "Test whether multiboot test data exists");
}
ATF_TC_BODY(testdata, tc)
{
printf("%p", MB_TESTDATA_START(mmap));
ATF_CHECK_EQ_MSG(0, (NULL == MB_TESTDATA_START(mmap)),
"mmap testcase data not found");
ATF_CHECK_EQ_MSG(0, (NULL == MB_TESTDATA_END(mmap)),
"mmap testcase data end not found");
ATF_CHECK_EQ_MSG(0, (0 < MB_TESTDATA_SIZE(mmap)), "mmap test size");

ATF_CHECK_EQ_MSG(0, (NULL == MB_TESTDATA_START(modules)),
"modules testcase data not found");
ATF_CHECK_EQ_MSG(0, (NULL == MB_TESTDATA_END(modules)),
"modules testcase data end not found");
ATF_CHECK_EQ_MSG(0, (0 < MB_TESTDATA_SIZE(modules)), "mmap test size");
}

ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, testdata);

return atf_no_error();
}

0 comments on commit 19ca4d4

Please sign in to comment.