summaryrefslogtreecommitdiffstats
path: root/src/VBox/Disassembler/testcase/Makefile.kmk
blob: 3506b217d8103fddf9cb5fe8df8feaf90d756408 (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# $Id: Makefile.kmk $
## @file
# Sub-Makefile for the VBox Disassembler.
#

#
# Copyright (C) 2006-2019 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#

SUB_DEPTH = ../../../..
include $(KBUILD_PATH)/subheader.kmk
ifdef VBOX_WITH_TESTCASES


PROGRAMS               += tstDisasm-1
tstDisasm-1_TEMPLATE    = VBOXR3TSTEXE
tstDisasm-1_DEFS        = IN_DIS
tstDisasm-1_SOURCES     = \
	tstDisasm-1.cpp \
	tstDisasm-1A.asm
tstDisasm-1_LIBS        = \
	$(PATH_STAGE_LIB)/DisasmR3$(VBOX_SUFF_LIB) \
	$(LIB_RUNTIME)


PROGRAMS += tstDisasm-2
tstDisasm-2_TEMPLATE    = VBOXR3TSTEXE
tstDisasm-2_DEFS        = IN_DIS
tstDisasm-2_SOURCES     = \
	tstDisasm-2.cpp
tstDisasm-2_LIBS        = \
	$(PATH_STAGE_LIB)/DisasmR3$(VBOX_SUFF_LIB) \
	$(LIB_RUNTIME)

# Tests that will be build, disassembled and re-build from disassembly.
VBOX_DISAS_TESTS_BUILD = \
	tstAsmFnstsw-1.asm \
	tstAsmLock-1.asm \
	tstAsmMovFixedReg-1.asm \
	tstAsmMovSeg-1.asm \
	tstAsmMovzx-1.asm \
	tstAsmPop-1.asm \
	tstAsmPush-1.asm \
	tstAsmSignExtend-1.asm \
	tstAsmRegs-1.asm \
	tstAsm3DNow-1.asm \

# Tests that only contains invalid/undefined instructions.
VBOX_DISAS_TESTS_INVALID = \
	tstAsmLock-2.asm \
	tstAsmLock-3.asm

# Tests that will be disassembled and re-build from disassembly (list of binaries).
## @todo tstBinMovzx-1.bin: does C7 imply 32-bit reg in 16-bit mode, or what exactly does it do?
VBOX_DISAS_TESTS_BINARIES := \
	tstBinMovzx-1.bin \
	tstBinFnstsw-1.bin
ifeq ($(USER)x,bird)
VBOX_DISAS_TESTS_BINARIES += \
	tstBin-1.bin \
	tstBin-2.bin \
	tstBin-3.bin \
	tstBin-4.bin \
	tstBin-5.bin \
	tstBin-6.bin
#	$(PATH_STAGE_BIN)/testcase/tstDisasm-2$(SUFF_EXEC)
endif
VBOX_DISAS_TESTS_BINARIES_NOT_16BIT := \
	tstBinFnstsw-1.bin
VBOX_DISAS_TESTS_BINARIES_NOT_32BIT :=
VBOX_DISAS_TESTS_BINARIES_NOT_64BIT :=


#
# The gory bits...
#

# Where we put the output files from the testcases.
VBOX_DISAS_TEST_OUT_DIR := $(PATH_TARGET)/Disassembler/testcase
BLDDIRS += $(VBOX_DISAS_TEST_OUT_DIR)

# Generate the rules for creating the .bin files.
VBOX_DISAS_TESTS_BIN = $(VBOX_DISAS_TESTS_BUILD) $(VBOX_DISAS_TESTS_INVALID)
VBOX_DISAS_TEST_CLEAN += $(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/,\
	$(VBOX_DISAS_TESTS_BIN:.asm=-16.bin)\
	$(VBOX_DISAS_TESTS_BIN:.asm=-32.bin)\
	$(VBOX_DISAS_TESTS_BIN:.asm=-64.bin))

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BIN:.asm=-16.bin)): $(PATH_SUB_CURRENT)/$$(patsubst %-16.bin,%.asm,$$(notdir $$(@))) | $$(dir $$@)
	@$(ECHO) "Assembling: $(<F) into $(@F)"
	$(TOOL_YASM_AS) -f bin -a x86 --force-strict -DTEST_BITS=16 -o $@ $<

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BIN:.asm=-32.bin)): $(PATH_SUB_CURRENT)/$$(patsubst %-32.bin,%.asm,$$(notdir $$(@))) | $$(dir $$@)
	@$(ECHO) "Assembling: $(<F) into $(@F)"
	$(TOOL_YASM_AS) -f bin -a x86 --force-strict -DTEST_BITS=32 -o $@ $<

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BIN:.asm=-64.bin)): $(PATH_SUB_CURRENT)/$$(patsubst %-64.bin,%.asm,$$(notdir $$(@))) | $$(dir $$@)
	@$(ECHO) "Assembling: $(<F) into $(@F)"
	$(TOOL_YASM_AS) -f bin -a x86 --force-strict -DTEST_BITS=64 -o $@ $<


# Generate the rules for the 'build' tests.
VBOX_DISAS_TEST_CLEAN += $(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/,\
	$(VBOX_DISAS_TESTS_BUILD:.asm=-16-disas.asm)\
	$(VBOX_DISAS_TESTS_BUILD:.asm=-32-disas.asm)\
	$(VBOX_DISAS_TESTS_BUILD:.asm=-64-disas.asm))

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BUILD:.asm=-16-disas.asm)): $$(subst -disas.asm,.bin,$$@) $$(tstDisasm-2_1_STAGE_TARGET) | $$(dir $$@)
	@$(ECHO) "Generating: $(@F) from $(<F)"
	$(REDIRECT) -E VBOX_LOG_DEST=nofile -o $@ -- $(tstDisasm-2_1_STAGE_TARGET) --style=yasm --cpumode=16 $<

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BUILD:.asm=-32-disas.asm)): $$(subst -disas.asm,.bin,$$@) $$(tstDisasm-2_1_STAGE_TARGET) | $$(dir $$@)
	@$(ECHO) "Generating: $(@F) from $(<F)"
	$(REDIRECT) -E VBOX_LOG_DEST=nofile -o $@ -- $(tstDisasm-2_1_STAGE_TARGET) --style=yasm --cpumode=32 $<

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BUILD:.asm=-64-disas.asm)): $$(subst -disas.asm,.bin,$$@) $$(tstDisasm-2_1_STAGE_TARGET) | $$(dir $$@)
	@$(ECHO) "Generating: $(@F) from $(<F)"
	$(REDIRECT) -E VBOX_LOG_DEST=nofile -o $@ -- $(tstDisasm-2_1_STAGE_TARGET) --style=yasm --cpumode=64 $<


VBOX_DISAS_TEST_CLEAN += $(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/,\
	$(VBOX_DISAS_TESTS_BUILD:.asm=-16-disas.bin)\
	$(VBOX_DISAS_TESTS_BUILD:.asm=-32-disas.bin)\
	$(VBOX_DISAS_TESTS_BUILD:.asm=-64-disas.bin))

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BUILD:.asm=-16-disas.bin)): $$(subst .bin,.asm,$$@) | $$(dir $$@)
	@$(ECHO) "Re-assembling: $(<F) into $(@F)"
	$(TOOL_YASM_AS) -f bin -a x86 --force-strict -DTEST_BITS=16 -o $@ $<

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BUILD:.asm=-32-disas.bin)): $$(subst .bin,.asm,$$@) | $$(dir $$@)
	@$(ECHO) "Re-assembling: $(<F) into $(@F)"
	$(TOOL_YASM_AS) -f bin -a x86 --force-strict -DTEST_BITS=32 -o $@ $<

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_BUILD:.asm=-64-disas.bin)): $$(subst .bin,.asm,$$@) | $$(dir $$@)
	@$(ECHO) "Re-assembling: $(<F) into $(@F)"
	$(TOOL_YASM_AS) -f bin -a x86 --force-strict -DTEST_BITS=64 -o $@ $<


VBOX_DISAS_TESTS += $(foreach test, $(VBOX_DISAS_TESTS_BUILD:.asm=), $(test)-16.tst $(test)-32.tst $(test)-64.tst)
$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/,\
$(VBOX_DISAS_TESTS_BUILD:.asm=-16.tst)\
$(VBOX_DISAS_TESTS_BUILD:.asm=-32.tst)\
$(VBOX_DISAS_TESTS_BUILD:.asm=-64.tst) ): $$(subst .tst,-disas.bin,$$@) | $$(dir $$@)
	@$(ECHO) "Verifying build: $(<F) and $(@F:.tst=.bin)"
	@$(RM) -f $@
	$(CMP) $(@:.tst=.bin) $<
	@$(APPEND) $@ "done"
	@$(ECHO) " PASSED:  $(<F) [re-assembled]"



# Generate the rules for the 'invalid' tests.
VBOX_DISAS_TESTS += $(foreach test, $(VBOX_DISAS_TESTS_INVALID:.asm=), $(test)-16.tst $(test)-32.tst $(test)-64.tst)

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-16.tst)): $$(patsubst %.tst,%.bin,$$@) $$(tstDisasm-2_1_STAGE_TARGET) | $$(dir $$@)
	@$(ECHO) "TESTING: $(@F) [--undef-op=all]"
	@$(RM) -f $@
	$(REDIRECT) -E VBOX_LOG_DEST=nofile -- $(tstDisasm-2_1_STAGE_TARGET) --undef-op=all --cpumode=16 $<
	@$(APPEND) $@ "done"
	@$(ECHO) " PASSED:  $(@F) [--undef-op=all]"

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-32.tst)): $$(patsubst %.tst,%.bin,$$@) $$(tstDisasm-2_1_STAGE_TARGET) | $$(dir $$@)
	@$(ECHO) "TESTING: $(@F) [--undef-op=all]"
	@$(RM) -f $@
	$(REDIRECT) -E VBOX_LOG_DEST=nofile -- $(tstDisasm-2_1_STAGE_TARGET) --undef-op=all --cpumode=32 $<
	@$(APPEND) $@ "done"
	@$(ECHO) " PASSED:  $(@F) [--undef-op=all]"

$(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-64.tst)): $$(patsubst %.tst,%.bin,$$@) $$(tstDisasm-2_1_STAGE_TARGET) | $$(dir $$@)
	@$(ECHO) "TESTING: $(@F) [--undef-op=all]"
	@$(RM) -f $@
	$(REDIRECT) -E VBOX_LOG_DEST=nofile -- $(tstDisasm-2_1_STAGE_TARGET) --undef-op=all --cpumode=64 $<
	@$(APPEND) $@ "done"
	@$(ECHO) " PASSED:  $(@F) [--undef-op=all]"


# Generate the rules for the binary tests.
define def_vbox_disas_binary_rules
$(outbase).asm: $(full_binary) $$$$(tstDisasm-2_1_STAGE_TARGET) | $(VBOX_DISAS_TEST_OUT_DIR)/
	@$$(ECHO) "Generating: $$(@F) from $$(<F)"
	$$(REDIRECT) -E VBOX_LOG_DEST=nofile -o $$@ -- $$(tstDisasm-2_1_STAGE_TARGET) --style=yasm --cpumode=$(bits) --undef-op=db $$<

$(outbase).bin + $(outbase).lst: $(outbase).asm
	@$$(ECHO) "Re-assembling: $$(<F) into $$(@F)"
	$$(TOOL_YASM_AS) -f bin -a x86 --force-strict -l $(outbase).lst -o $$@ $$<

$(outbase).tst: $(outbase).bin
	@$$(ECHO) "Verifying build: $$(<F) against $(not-dir $(full_binary))"
	@$$(RM) -f $$@
	$$(CMP) -l $(full_binary) $$<
	@$$(APPEND) $$@ "done"
	@$$(ECHO) " PASSED:  $$(<F) [binary]"

$(name).tst:: $(outbase).tst
VBOX_DISAS_TEST_CLEAN += $(outbase).tst $(outbase).bin $(outbase).asm
VBOX_DISAS_TESTS += $(name)-rebuild-$(bits).tst
endef # def_vbox_disas_binary_rules

define def_vbox_disas_binary
local name := $(notdir $(basename $(binary)))
local full_binary := $(abspathex $(binary),$(PATH_SUB_CURRENT))
local outbase := $(VBOX_DISAS_TEST_OUT_DIR)/$(name)-rebuild-$(bits)
$(eval $(def_vbox_disas_binary_rules))
endef # def_vbox_disas_binary

## @todo 64-bit is problematic because of bugs like POP RDI ending up as POP EDI (incorrect default opmode).
#$(foreach bits, 64, $(foreach binary, $(VBOX_DISAS_TESTS_BINARIES), $(evalvalctx def_vbox_disas_binary)))
$(foreach bits, 32 16, $(foreach binary, $(filter-out $(VBOX_DISAS_TESTS_BINARIES_NOT_$(bits)BIT), $(VBOX_DISAS_TESTS_BINARIES)) \
	, $(evalvalctx def_vbox_disas_binary)))


# Add the .tst to the clean up.
VBOX_DISAS_TEST_CLEAN += $(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/, $(VBOX_DISAS_TESTS))
OTHER_CLEAN += $(VBOX_DISAS_TEST_CLEAN)

# We don't want any of the tests rules to run in parallel because the
# output will be difficult to follow. Abusing VBOX_DISAS_TEST_CLEAN here...
.NOTPARALLEL: $$(VBOX_DISAS_TEST_CLEAN)


#
# Add the tests to the target list for the testing pass.
# (kBuild r1646)
#
TESTING += $(addprefix $(VBOX_DISAS_TEST_OUT_DIR)/,$(VBOX_DISAS_TESTS))


#
# The test aliases
#
# To run the tstAsmLock-3.asm test:        kmk tstAsmLock-3.tst
# To run the 64-bit tstAsmLock-3.asm test: kmk tstAsmLock-3-64.tst
#
define def_vbox_test_aliases
local test_base := $(basename $(test))
local test_root := $(patsubst %-16,%,$(patsubst %-32,%,$(patsubst %-64,%,$(test_base))))
$(test_base).tst:: $(VBOX_DISAS_TEST_OUT_DIR)/$(test)
$(test_root).tst:: $(test_base).tst
$(test_base).o:: $(test_base).tst
$(test_base).obj:: $(test_base).tst
$(test_root).o:: $(test_root).tst
$(test_root).obj:: $(test_root).tst
endef
$(foreach test,$(VBOX_DISAS_TESTS),$(evalvalctx def_vbox_test_aliases))

endif # VBOX_WITH_TESTCASES
include $(FILE_KBUILD_SUB_FOOTER)