From 0ab5310b8a4a235b5389d5c1ffb3290f74906044 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 8 Oct 2014 21:26:56 +0200 Subject: [PATCH] hw: enable kernel-internal tests via run tool Kernel tests are done by replacing the implementation of an otherwise empty function 'Kernel::test' that gets called once at the primary CPU as soon as all kernel initialization is done. To achieve this, the test binary that implements 'Kernel::test' must be linked against the core lib and must then replace the core binary when composing the boot image. The latter can be done conveniently in a run script by setting the new argument 'core_type' of the function 'build_boot_image' to the falue 'test'. If no kernel test is needed the argument does not have to be given - it is set to 'core' by default which results in a "normal" Genode image. ref #1225 --- repos/base-hw/lib/import/import-core.mk | 8 +++++++ repos/base-hw/run/env | 31 +++++++++++++++++-------- repos/base-hw/src/core/dummy.cc | 0 repos/base-hw/src/core/kernel/kernel.cc | 6 +++++ repos/base-hw/src/core/kernel/test.cc | 7 ++++++ repos/base-hw/src/core/target.mk | 4 ++-- 6 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 repos/base-hw/lib/import/import-core.mk delete mode 100644 repos/base-hw/src/core/dummy.cc create mode 100644 repos/base-hw/src/core/kernel/test.cc diff --git a/repos/base-hw/lib/import/import-core.mk b/repos/base-hw/lib/import/import-core.mk new file mode 100644 index 0000000000..57cf3fd27b --- /dev/null +++ b/repos/base-hw/lib/import/import-core.mk @@ -0,0 +1,8 @@ +# +# \brief Automatically included by targets that depend on the core lib +# \author Martin Stein +# \date 2011-12-16 +# + +# add include paths +INC_DIR += $(REP_DIR)/src/core/include diff --git a/repos/base-hw/run/env b/repos/base-hw/run/env index 2510e81543..b3ab592627 100644 --- a/repos/base-hw/run/env +++ b/repos/base-hw/run/env @@ -52,7 +52,18 @@ proc create_boot_directory { } { } -proc build_boot_image {binaries} { +proc build_boot_image {binaries {core_type core}} { + if {$core_type == "test"} { + set core_bin "test-[run_name]" + set core_target "test/[run_name]" + } elseif {$core_type == "core"} { + set core_bin "core" + set core_target "core" + } else { + puts stderr "Error: Unknown core type '$core_type'" + exit -1 + } + global run_target # strip binaries @@ -94,7 +105,7 @@ proc build_boot_image {binaries} { # generate header for each boot module except core set i 1 foreach binary $binaries { - if {$binary == "core"} { continue } + if {$binary == $core_bin} { continue } exec echo -e \ "\n.long _boot_module_${i}_name" \ "\n.long _boot_module_${i}_begin" \ @@ -111,7 +122,7 @@ proc build_boot_image {binaries} { # generate name string for each module except core set i 1 foreach binary $binaries { - if {$binary == "core"} { continue } + if {$binary == $core_bin} { continue } exec echo -e \ "\n.p2align DATA_ACCESS_ALIGNM_LOG2" \ "\n_boot_module_${i}_name:" \ @@ -129,7 +140,7 @@ proc build_boot_image {binaries} { # include raw data of modules consecutively but page aligned set i 1 foreach binary $binaries { - if {$binary == "core"} { continue } + if {$binary == $core_bin} { continue } exec echo -e \ "\n.p2align MIN_PAGE_SIZE_LOG2" \ "\n_boot_module_${i}_begin:" \ @@ -147,10 +158,10 @@ proc build_boot_image {binaries} { exec ln -s $boot_modules boot_modules.s # recompile core with boot modules - exec cp -L bin/core core/core.standalone - exec find . -type f -name "core" -delete + exec cp -L bin/$core_bin $core_target/$core_bin.standalone + exec find . -type f -name $core_bin -delete set timeout 10000 - set pid [eval "spawn make core"] + set pid [eval "spawn make $core_target"] expect { eof { } } if {[lindex [wait $pid] end] != 0} { clean_boot_modules @@ -162,7 +173,7 @@ proc build_boot_image {binaries} { # offer ELF image set elf_img "[run_dir]/image.elf" - exec cp -L bin/core $elf_img + exec cp -L bin/$core_bin $elf_img exec [cross_dev_prefix]strip $elf_img build_uboot_image $elf_img @@ -178,8 +189,8 @@ proc build_boot_image {binaries} { } # retrieve stand-alone core - exec cp core/core.standalone bin/core - exec rm core/core.standalone + exec cp $core_target/$core_bin.standalone bin/$core_bin + exec rm $core_target/$core_bin.standalone } diff --git a/repos/base-hw/src/core/dummy.cc b/repos/base-hw/src/core/dummy.cc deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/repos/base-hw/src/core/kernel/kernel.cc b/repos/base-hw/src/core/kernel/kernel.cc index e5af77e94f..67d5199b85 100644 --- a/repos/base-hw/src/core/kernel/kernel.cc +++ b/repos/base-hw/src/core/kernel/kernel.cc @@ -73,6 +73,11 @@ namespace Kernel Signal_context_pool * signal_context_pool() { return unmanaged_singleton(); } Signal_receiver_pool * signal_receiver_pool() { return unmanaged_singleton(); } + /** + * Hook that enables automated testing of kernel internals + */ + void test(); + /** * Static kernel PD that describes core */ @@ -320,6 +325,7 @@ extern "C" void init_kernel_multiprocessor() } /* kernel initialization finished */ Genode::printf("kernel initialized\n"); + test(); } } diff --git a/repos/base-hw/src/core/kernel/test.cc b/repos/base-hw/src/core/kernel/test.cc new file mode 100644 index 0000000000..cd678f1a35 --- /dev/null +++ b/repos/base-hw/src/core/kernel/test.cc @@ -0,0 +1,7 @@ +/* + * \brief Dummy implementation of kernel-internal test + * \author Martin Stein + * \date 2014-09-30 + */ + +namespace Kernel { void test() { } } diff --git a/repos/base-hw/src/core/target.mk b/repos/base-hw/src/core/target.mk index c512fc259e..b0817a8145 100644 --- a/repos/base-hw/src/core/target.mk +++ b/repos/base-hw/src/core/target.mk @@ -10,5 +10,5 @@ TARGET = core # library that provides the whole configuration LIBS += core -# add empty source to trigger build though all config is provided via lib -SRC_CC += dummy.cc +# add C++ sources +SRC_CC += kernel/test.cc