Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| dbebc0a7cc | |||
| eb6167ae63 | |||
| ace684facc | |||
| f11d2bc921 | |||
| 331a1ecb0b | 
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							| @ -2,13 +2,17 @@ | ||||
| ifneq ($(KERNELRELEASE),) | ||||
| # kbuild part of makefile
 | ||||
| obj-m   := hello1.o hello2.o | ||||
| ccflags-y := -I$(obj)/inc | ||||
| ccflags-y := -I$(obj)/inc -g | ||||
| else | ||||
| # normal makefile
 | ||||
| KDIR ?= /lib/modules/`uname -r`/build | ||||
| 
 | ||||
| default: | ||||
| 	$(MAKE) -C $(KDIR) M=$$PWD | ||||
| 	cp hello1.ko hello1.ko.unstripped | ||||
| 	$(CROSS_COMPILE)strip -g hello1.ko | ||||
| 
 | ||||
| clean: | ||||
| 	$(MAKE) -C $(KDIR) M=$$PWD clean | ||||
| 
 | ||||
| endif | ||||
|  | ||||
							
								
								
									
										36
									
								
								hello1.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								hello1.c
									
									
									
									
									
								
							| @ -44,10 +44,10 @@ struct TimingList { | ||||
| 	ktime_t t_after; | ||||
| }; | ||||
| 
 | ||||
| static unsigned int msg_count = 1; | ||||
| static struct TimingList *tl_head; | ||||
| static unsigned int bug_generator; | ||||
| 
 | ||||
| static struct TimingList* write_first_node(void) | ||||
| static struct TimingList *write_first_node(void) | ||||
| { | ||||
| 	tl_head = kmalloc(sizeof(struct TimingList), GFP_KERNEL); | ||||
| 	tl_head->next = NULL; | ||||
| @ -55,18 +55,22 @@ static struct TimingList* write_first_node(void) | ||||
| 	return tl_head; | ||||
| } | ||||
| 
 | ||||
| static struct TimingList* insert_next_node(struct TimingList *tail) | ||||
| static struct TimingList *insert_next_node(struct TimingList *tail) | ||||
| { | ||||
| 	struct TimingList *new_tl_node = kmalloc(sizeof(struct TimingList), | ||||
| 						GFP_KERNEL); | ||||
| 
 | ||||
| 	tail->next = new_tl_node; | ||||
| 	new_tl_node->next = NULL; | ||||
| 	if (bug_generator == 2) { | ||||
| 		new_tl_node = NULL; | ||||
| 	} else { | ||||
| 		tail->next = new_tl_node; | ||||
| 		new_tl_node->next = NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	return new_tl_node; | ||||
| } | ||||
| 
 | ||||
| static struct TimingList* add_new_node(struct TimingList *tail) | ||||
| static struct TimingList *add_new_node(struct TimingList *tail) | ||||
| { | ||||
| 	if (tail == NULL) | ||||
| 		return write_first_node(); | ||||
| @ -94,27 +98,21 @@ void destroy_list(void) | ||||
| 		curr_tl = next_tl; | ||||
| 	} | ||||
| } | ||||
| EXPORT_SYMBOL(destroy_list); | ||||
| 
 | ||||
| static int __init hello_init(void) | ||||
| { | ||||
| 	if (msg_count > 10) { | ||||
| 		pr_err("Error: msg_count too large (%d > 10)\n", msg_count); | ||||
| 		return -EINVAL; | ||||
| 	} | ||||
| 
 | ||||
| 	if (msg_count == 0 || msg_count >= 5) { | ||||
| 		pr_warn("Warning: msg_count = %d (msg_count == 0 or 5 <= msg_count <= 10)\n", msg_count); | ||||
| 	} | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| void print_hello(void) | ||||
| void print_hello(int msg_count) | ||||
| { | ||||
| 	int i; | ||||
| 	struct TimingList *current_tail = tl_head; | ||||
| 
 | ||||
| 	for (i = 0; i < msg_count; i++) { | ||||
| 		bug_generator = i; | ||||
| 
 | ||||
| 		current_tail = add_new_node(current_tail); | ||||
| 
 | ||||
| 		current_tail->t_before = ktime_get(); | ||||
| @ -122,17 +120,13 @@ void print_hello(void) | ||||
| 		current_tail->t_after = ktime_get(); | ||||
| 	} | ||||
| } | ||||
| EXPORT_SYMBOL(print_hello); | ||||
| 
 | ||||
| static void __exit hello_exit(void) | ||||
| { | ||||
| 	destroy_list(); | ||||
| } | ||||
| 
 | ||||
| module_param(msg_count, uint, 0444); | ||||
| MODULE_PARM_DESC(msg_count, "Amount of hello world outputs on load"); | ||||
| 
 | ||||
| EXPORT_SYMBOL(print_hello); | ||||
| EXPORT_SYMBOL(destroy_list); | ||||
| 
 | ||||
| module_init(hello_init); | ||||
| module_exit(hello_exit); | ||||
|  | ||||
							
								
								
									
										12
									
								
								hello2.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								hello2.c
									
									
									
									
									
								
							| @ -40,9 +40,16 @@ MODULE_AUTHOR("Serhii Popovych <serhii.popovych@globallogic.com>"); | ||||
| MODULE_DESCRIPTION("Hello, world in Linux Kernel Training"); | ||||
| MODULE_LICENSE("Dual BSD/GPL"); | ||||
| 
 | ||||
| static unsigned int msg_count = 1; | ||||
| 
 | ||||
| static int __init hello_init(void) | ||||
| { | ||||
| 	print_hello(); | ||||
| 	BUG_ON(msg_count > 10); | ||||
| 
 | ||||
| 	if (msg_count == 0 || msg_count >= 5) | ||||
| 		pr_warn("Warning: msg_count = %d (msg_count == 0 or 5 <= msg_count <= 10)\n", msg_count); | ||||
| 
 | ||||
| 	print_hello(msg_count); | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| @ -51,5 +58,8 @@ static void __exit hello_exit(void) | ||||
| 	destroy_list(); | ||||
| } | ||||
| 
 | ||||
| module_param(msg_count, uint, 0444); | ||||
| MODULE_PARM_DESC(msg_count, "Amount of hello world outputs on load"); | ||||
| 
 | ||||
| module_init(hello_init); | ||||
| module_exit(hello_exit); | ||||
|  | ||||
| @ -1,2 +1,2 @@ | ||||
| void print_hello(void); | ||||
| void print_hello(int msg_count); | ||||
| void destroy_list(void); | ||||
|  | ||||
							
								
								
									
										18
									
								
								test.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										18
									
								
								test.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,18 @@ | ||||
| #!/bin/sh | ||||
| 
 | ||||
| if [ -z "$1" ]; then | ||||
| 	echo "Error: no script supplied" | ||||
| 	echo "Usage: $0 path/to/testing/script" | ||||
| 	exit 1 | ||||
| fi | ||||
| 
 | ||||
| while read l; do | ||||
| 	if [ -z "$l" ]; then | ||||
| 		continue; | ||||
| 	fi; | ||||
| 
 | ||||
| 	echo "$ $l"; | ||||
| 	$($l); | ||||
| 
 | ||||
| 	echo -e "" | ||||
| done < $1 | ||||
							
								
								
									
										33
									
								
								tests/lab5-test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								tests/lab5-test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| insmod hello2.ko | ||||
| 
 | ||||
| insmod hello1.ko | ||||
| 
 | ||||
| insmod hello2.ko | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=0 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=1 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=3 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=5 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=8 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=10 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko msg_count=12 | ||||
| rmmod hello2.ko | ||||
| 
 | ||||
| insmod hello2.ko | ||||
| rmmod hello1.ko | ||||
| 
 | ||||
| rmmod hello2.ko | ||||
| rmmod hello1.ko | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user