Commit d41ab5b9 authored by Anton Burtsev's avatar Anton Burtsev Committed by Vikram Narayanan
Browse files

New test module "bug" for testing BUG macros

parent 2aedcbde
......@@ -6,6 +6,8 @@
# if you use the top level makefile in lcd-domains/Makefile)
export LIBLCD = ../../liblcd/lib.a
obj-m += bug/
obj-m += load/
obj-m += ipc1/
......@@ -22,4 +24,4 @@ obj-m += pmfs/
obj-m += async/
obj-m += string_example/
\ No newline at end of file
obj-m += string_example/
# Main targets
obj-m += lcd_test_mod_bug_boot.o
lcd_test_mod_bug_boot-y += boot.o
obj-m += lcd_test_mod_bug_lcd.o
lcd_test_mod_bug_lcd-y += lcd.o
lcd_test_mod_bug_lcd-y += $(LIBLCD)
# We don't want the loop to be optimized away
CFLAGS_lcd.o = -O0
/**
* boot.c - non-isolated kernel module, does setup
*
*/
#include <lcd-domains/kliblcd.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int boot_main(void)
{
int ret;
struct lcd_info *mi;
cptr_t lcd;
/*
* Enter lcd mode
*/
ret = lcd_enter();
if (ret) {
LIBLCD_ERR("enter");
goto fail1;
}
/*
* Create a new lcd
*/
ret = lcd_create_module_lcd(&lcd,
LCD_DIR("bug"),
"lcd_test_mod_bug_lcd",
LCD_CPTR_NULL, &mi);
if (ret) {
LIBLCD_ERR("create module lcd");
goto fail2;
}
/*
* Set up boot info
*/
ret = lcd_dump_boot_info(mi);
if (ret) {
LIBLCD_ERR("dump boot info");
goto fail3;
}
/*
* Run it
*/
ret = lcd_run(lcd);
if (ret) {
LIBLCD_ERR("run lcd");
goto fail4;
}
/*
* Wait for 4 seconds
*/
msleep(4000);
/*
* Tear everything down
*/
ret = 0;
goto out;
out:
fail4:
fail3:
lcd_destroy_module_lcd(lcd, mi, LCD_CPTR_NULL);
fail2:
lcd_exit(0);
fail1:
return ret;
}
static void boot_exit(void)
{
/* nothing to do */
}
module_init(boot_main);
module_exit(boot_exit);
/*
* Simple LCD load test. This just spins in an infinite loop, so
* whoever boots this code should make sure they kill it after
* so much time.
*
* IMPORTANT: This code *does not* expect to be booted so that
* it can use kmalloc, page alloc, etc.
*
* IMPORTANT: This module should be compiled without
* optimizations (see Makefile in this directory).
* Otherwise, the loop in foo will be optimized away and
* we won't fully test the code.
*
* You may want to inspect the .ko before running with
* objdump -d.
*
* NOTE: If you disassemble the .ko, you will notice
* callq's that are not patched to jump to the correct
* place (e.g., they just jump to the next instruction).
* This is not an error. The module loading code
* patches these calls so that they work when the module
* is loaded. You can look at the relocation info in the
* .ko elf file with readelf -a.
*/
#include <lcd-domains/liblcd-config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <lcd-domains/liblcd.h>
#include <lcd-domains/liblcd-hacks.h>
static int foo(int x)
{
while (1)
x = 2;
return x + 5;
}
static int __noreturn __init test_init(void)
{
int r;
r = lcd_enter();
if (r)
goto fail1;
r = foo(10); /* never returns */
fail1:
lcd_exit(r);
}
/*
* make module loader happy (so we can unload). we don't actually call
* this before unloading the lcd (yet)
*/
static void __exit test_exit(void)
{
return;
}
module_init(test_init);
module_exit(test_exit);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment