summaryrefslogtreecommitdiff
path: root/tests/Makefile
blob: 240753e2667a4299057e24ded12e570dbb56e4d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

PKG_CONFIG ?= pkg-config

BASE_VER ?= 125070
PC_DEPS = libchrome-$(BASE_VER)
PC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
PC_LIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))

ifeq ($(FIRMWARE_ARCH),)
CFLAGS += -DCHROMEOS_ENVIRONMENT
CXXFLAGS += -DCHROMEOS_ENVIRONMENT
endif

INCLUDES += -I./include \
		-I$(FWDIR)/lib/include \
		-I$(FWDIR)/lib/cgptlib/include \
		-I$(FWDIR)/lib/cryptolib/include \
		-I$(FWDIR)/lib/tpm_lite/include \
		-I$(HOSTDIR)/include \
		$(PC_CFLAGS)

BUILD_ROOT = ${BUILD}/tests

TEST_NAMES = cgptlib_test \
	     rollback_index2_tests \
	     rsa_padding_test \
	     rsa_utility_tests \
	     rsa_verify_benchmark \
	     sha_benchmark \
	     sha_tests \
	     stateful_util_tests \
	     utility_string_tests \
	     utility_tests \
	     tpm_bootmode_tests \
	     vboot_api_init_tests \
	     vboot_api_firmware_tests \
	     vboot_common_tests \
	     vboot_common2_tests \
	     vboot_common3_tests \
	     vboot_ec_tests \
	     vboot_firmware_tests \
	     vboot_nvstorage_test \
	     vboot_api_devmode_tests \
	     vboot_audio_tests \
	     vboot_api_kernel_tests

TEST_BINS = $(addprefix ${BUILD_ROOT}/,$(TEST_NAMES))

TEST_LIB = ${BUILD_ROOT}/test.a
TEST_LIB_SRCS = test_common.c timer_utils.c crc32_test.c
TEST_LIB_OBJS = $(TEST_LIB_SRCS:%.c=${BUILD_ROOT}/%.o)
ALL_DEPS = $(addsuffix .d,${TEST_BINS} ${TEST_LIB_OBJS})
# Allow multiple definitions, so tests can mock functions from other libraries
CFLAGS +=  -MMD -MF $@.d -Xlinker --allow-multiple-definition
CXXFLAGS +=  -MMD -MF $@.d -Xlinker --allow-multiple-definition
LDLIBS += $(PC_LIBS) -luuid

LIBS := ${TEST_LIB} $(HOSTLIB)

ifneq (${RUNTESTS},)
EXTRA_TARGET = runtests
endif

all: $(TEST_BINS) ${EXTRA_TARGET}

rbtest: $(BUILD_ROOT)/rollback_index_test

cgptmanager_tests: $(BUILD_ROOT)/CgptManagerTests

${TEST_LIB}: ${TEST_LIB_OBJS}
	rm -f $@
	$(AR) rc $@ $^


${BUILD_ROOT}/CgptManagerTests.o: CgptManagerTests.cc
	$(CXX) -DWITH_UTIL_MAIN $(CXXFLAGS) $(INCLUDES) -c $< -o $@

${BUILD_ROOT}/CgptManagerTests: ${BUILD_ROOT}/CgptManagerTests.o
	$(CXX) $(CXXFLAGS) $(INCLUDES) $(LDFLAGS) $^ \
	${BUILD}/cgpt/libcgpt-cc.a -lgtest -lgflags $(LDLIBS) -o $@

${BUILD_ROOT}/vboot_audio_for_test.o : $(FWDIR)/lib/vboot_audio.c
	$(CC) $(CFLAGS) -DCUSTOM_MUSIC $(INCLUDES) \
	-MMD -MF $@.d -c -o $@ $<

${BUILD_ROOT}/vboot_audio_tests: vboot_audio_tests.c \
		${BUILD_ROOT}/vboot_audio_for_test.o ${LIBS}
	$(CC) $(CFLAGS) $(INCLUDES) $< ${BUILD_ROOT}/vboot_audio_for_test.o \
	${LIBS} -o $@ -lcrypto -lrt

${BUILD_ROOT}/rollback_index_test.o : rollback_index_test.c
	$(CC) $(CFLAGS) -I/usr/include $(INCLUDES) -MMD -MF $@.d -c -o $@ $<

${BUILD_ROOT}/rollback_index_test: rollback_index_test.c ${HOSTLIB}
	$(CC) $(CFLAGS) -I/usr/include $(INCLUDES) $< -o $@ \
        -ltlcl ${HOSTLIB} -lcrypto -lrt

# Compile rollback_index.c for unit test, so it uses the same implementation
# as it does in the firmware.
${BUILD_ROOT}/rollback_index_for_test.o : $(FWDIR)/lib/rollback_index.c
	$(CC) $(CFLAGS) -DROLLBACK_UNITTEST $(INCLUDES) \
	-MMD -MF $@.d -c -o $@ $<

${BUILD_ROOT}/rollback_index2_tests: rollback_index2_tests.c \
		${BUILD_ROOT}/rollback_index_for_test.o ${LIBS}
	$(CC) $(CFLAGS) $(INCLUDES) $< ${BUILD_ROOT}/rollback_index_for_test.o \
	${LIBS} -o $@ -lcrypto -lrt

${BUILD_ROOT}/%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDES) -MMD -MF $@.d -c -o $@ $<

${BUILD_ROOT}/%: %.c ${LIBS}
	$(CC) $(CFLAGS) $(INCLUDES) $< ${LIBS} -o $@ -lcrypto -lrt

# TODO: port these tests to new API, if not already eqivalent
# functionality in other tests
#
#		big_firmware_tests
#		firmware_image_tests
#		firmware_rollback_tests
#		firmware_splicing_tests
#		firmware_verify_benchmark
#		verify_firmware_fuzz_driver
#
#		big_kernel_tests
#		kernel_image_tests
#		kernel_rollback_tests
#		kernel_splicing_tests
#		kernel_verify_benchmark
#		verify_kernel_fuzz_driver

# Generate test keys
genkeys:
	./gen_test_keys.sh

# Run cgpt tests
runcgpttests:
	${BUILD_ROOT}/cgptlib_test
	./run_cgpt_tests.sh  ${BUILD}/cgpt/cgpt

# Run CgptManager tests
runcgptmanagertests:
	${BUILD_ROOT}/CgptManagerTests --v=1

# Run crypto tests
runcryptotests:
	./run_rsa_tests.sh
	${BUILD_ROOT}/rsa_utility_tests
	${BUILD_ROOT}/sha_tests
	./run_vboot_common_tests.sh
	./run_vboot_ec_tests.sh

# Run other misc tests
runmisctests:
	./run_vbutil_tests.sh
	${BUILD_ROOT}/rollback_index2_tests
	${BUILD_ROOT}/stateful_util_tests
	${BUILD_ROOT}/tpm_bootmode_tests
	${BUILD_ROOT}/utility_string_tests
	${BUILD_ROOT}/utility_tests
	${BUILD_ROOT}/vboot_api_init_tests
	${BUILD_ROOT}/vboot_api_firmware_tests
	${BUILD_ROOT}/vboot_firmware_tests

#This will exercise vbutil_kernel and vbutil_firmware
runfuzztests:
	./gen_fuzz_test_cases.sh
	./run_preamble_tests.sh
	./run_vbutil_kernel_arg_tests.sh

# Run bmpblk_utility tests
runbmptests:
	$(MAKE) BUILD=$(shell readlink -f ${BUILD}) -C bitmaps runtests

runsoundtests:
	${BUILD_ROOT}/vboot_api_devmode_tests
	${BUILD_ROOT}/vboot_audio_tests

ALLTESTS=runcgpttests runcryptotests runmisctests runfuzztests \
	runbmptests runsoundtests

runtests: genkeys ${ALLTESTS}

# TODO: tests to run when ported to new API
#	./run_image_verification_tests.sh
#	# Splicing tests
#	${BUILD_ROOT}/firmware_splicing_tests
#	${BUILD_ROOT}/kernel_splicing_tests
#	# Rollback Tests
#	${BUILD_ROOT}/firmware_rollback_tests
#	${BUILD_ROOT}/kernel_rollback_tests

install-rbtest: $(BUILD_ROOT)/rollback_index_test
	mkdir -p $(DESTDIR)
	cp -f $(BUILD_ROOT)/rollback_index_test $(DESTDIR)

-include ${ALL_DEPS}