blob: f59a3ed7e7b924b6e0f10c6ed31cb528e297f89c [file]
# Copyright 2020 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
import("//build/testing/boot_tests/zbi_test.gni")
import("//build/zbi/zbi_input.gni")
import("//zircon/kernel/kernel_package.gni")
import("//zircon/kernel/lib/code-patching/code-patching.gni")
import("//zircon/kernel/phys/elf/kernel_elf_binary.gni")
import("//zircon/kernel/phys/elf/kernel_elf_interp.gni")
import("//zircon/kernel/phys/zbi-runtime/zbi_executable.gni")
code_patching_hermetic_alternative("multiply_by_two") {
visibility = [ ":*" ]
testonly = true
sources = [ "multiply_by_two.S" ]
deps = [ "//zircon/kernel/lib/arch" ]
}
code_patching_hermetic_alternative("multiply_by_ten") {
visibility = [ ":*" ]
testonly = true
sources = [ "multiply_by_ten.S" ]
deps = [ "//zircon/kernel/lib/arch" ]
}
code_patching_hermetic_stub("multiply_by_factor") {
visibility = [ ":*" ]
testonly = true
case_id_header = "test.h"
deps = [
":multiply_by_ten",
":multiply_by_two",
]
include_dirs = [ "." ]
}
# This is identical to multiply_by_factor except for its patch case ID. The
# two stubs are identical trap fills of the same size, so identical code
# folding must not be allowed to merge them.
code_patching_hermetic_stub("multiply_by_factor_twin") {
visibility = [ ":*" ]
testonly = true
case_id_header = "test.h"
deps = [
":multiply_by_ten",
":multiply_by_two",
]
include_dirs = [ "." ]
}
source_set("add-one") {
visibility = [ ":*" ]
testonly = true
public_deps = [ ":test-api" ]
sources = [ "add-one.S" ]
deps = [
"//zircon/kernel/lib/arch",
"//zircon/kernel/lib/code-patching",
]
}
config("addend-two.config") {
visibility = [ ":*" ]
defines = [ "ADDEND=2" ]
}
config("addend-three.config") {
visibility = [ ":*" ]
defines = [ "ADDEND=3" ]
}
config("addend-bias.config") {
visibility = [ ":*" ]
defines = [ "ADDEND_BIAS=100" ]
}
config("addend-ten.config") {
visibility = [ ":*" ]
defines = [ "ADDEND=10" ]
}
# This tests the per-version $deps feature rather than $add_configs:
# the dependency's public_configs determine how the alternative is compiled.
source_set("addend-ten") {
visibility = [ ":*" ]
testonly = true
public_configs = [ ":addend-ten.config" ]
}
code_patching_hermetic_multiversion("add_value") {
visibility = [ ":*" ]
testonly = true
case_id_header = "test.h"
public_deps = [ ":test-api" ]
sources = [ "add-value.cc" ]
versions = [
{
subdir = "by-config"
add_configs = [ ":addend-two.config" ]
},
{
# If removing the bias config failed, this would add 103 instead of 3.
add_configs = [
":addend-bias.config",
":addend-three.config",
]
remove_configs = [ ":addend-bias.config" ]
},
{
subdir = "by-deps"
name = "add_ten"
deps = [ ":addend-ten" ]
},
]
}
config("test-include") {
visibility = [ ":*" ]
include_dirs = [ "." ]
}
source_set("test-api") {
visibility = [ ":*" ]
testonly = true
public = [ "test.h" ]
public_configs = [ ":test-include" ]
public_deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
]
}
zbi_executable("zbi-self-code-patching-test.executable") {
testonly = true
sources = [ "self-code-patching-test.cc" ]
# The test of multiply_by_factor_twin needs identical code folding, which is
# otherwise enabled only in some build configurations.
configs += [ "//build/config:icf" ]
deps = [
":add-one",
":add_value",
":multiply_by_factor",
":multiply_by_factor_twin",
":test-api",
"..:zbi-test-main",
"//src/lib/zbitl",
"//zircon/kernel/lib/code-patching",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/kernel/phys/address-space",
"//zircon/kernel/phys/allocation",
"//zircon/kernel/phys/elf",
"//zircon/kernel/phys/lib/memalloc",
"//zircon/kernel/phys/zbi-runtime",
"//zircon/system/ulib/fbl",
]
include_dirs = [ "." ]
}
code_patches("code-patches") {
testonly = true
deps = [ ":zbi-self-code-patching-test.executable" ]
}
# We use a kernel package to transport code-patches.bin and the patch
# alternatives, as that is how they will be transported in production.
kernel_package("code-patches-test") {
visibility = [ ":*" ]
testonly = true
deps = [
":add_value",
":code-patches",
":multiply_by_ten",
":multiply_by_two",
]
}
zbi_executable("elf-code-patching-test.executable") {
visibility = [ ":*" ]
testonly = true
sources = [ "elf-code-patching-test.cc" ]
deps = [
":test-api",
"..:zbi-test-main",
"//src/lib/zbitl",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/kernel/phys/address-space",
"//zircon/kernel/phys/allocation",
"//zircon/kernel/phys/elf",
"//zircon/kernel/phys/kernel-package",
"//zircon/kernel/phys/runtime",
"//zircon/kernel/phys/zbi-runtime",
"//zircon/system/ulib/fbl",
]
}
# This tags a test module with the PT_INTERP matching the test's build ID.
kernel_elf_interp("elf-code-patching-test.interp") {
visibility = [ ":*" ]
testonly = true
deps = [ ":elf-code-patching-test.executable" ]
}
kernel_elf_binary("elf-code-patching-test-add-one") {
visibility = [ ":*" ]
testonly = true
install_name = "add-one"
ldflags = [ "-Wl,-e,AddOne" ]
deps = [
":add-one",
":elf-code-patching-test.interp",
"//zircon/kernel/phys:boot-options",
]
}
kernel_elf_binary("elf-code-patching-test-multiply") {
visibility = [ ":*" ]
testonly = true
install_name = "multiply_by_factor"
ldflags = [ "-Wl,-e,multiply_by_factor" ]
deps = [
":elf-code-patching-test.interp",
":multiply_by_factor",
"//zircon/kernel/phys:boot-options",
]
}
kernel_elf_binary("elf-code-patching-test-add-value") {
visibility = [ ":*" ]
testonly = true
install_name = "add_value"
ldflags = [ "-Wl,-e,add_value" ]
deps = [
":add_value",
":elf-code-patching-test.interp",
"//zircon/kernel/phys:boot-options",
]
}
kernel_package("elf-code-patching-test-data") {
visibility = [ ":*" ]
testonly = true
deps = [
":elf-code-patching-test-add-one($phys_toolchain)",
":elf-code-patching-test-add-value($phys_toolchain)",
":elf-code-patching-test-multiply($phys_toolchain)",
]
}
zbi_test("elf-code-patching-test") {
deps = [
":elf-code-patching-test-data",
":elf-code-patching-test.executable",
]
}
zbi_test("zbi-self-code-patching-test") {
args = []
deps = [
":code-patches-test($phys_toolchain)",
":zbi-self-code-patching-test.executable($phys_toolchain)",
]
}
group("code-patching") {
testonly = true
deps = [
":elf-code-patching-test",
":zbi-self-code-patching-test",
]
}