Skip to content

Commit

Permalink
unittest: add kernel and user task tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jul 22, 2022
1 parent d120274 commit 96658a9
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/unittests.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cmdline.h>
#include <console.h>
#include <cpuid.h>
#include <ktf.h>
Expand All @@ -30,8 +31,9 @@
#include <string.h>
#include <symbols.h>
#include <test.h>
#include <usermode.h>

#include <cmdline.h>
#include <smp/smp.h>

static char opt_string[4];
string_cmd("string", opt_string);
Expand Down Expand Up @@ -64,6 +66,34 @@ static void cpu_freq_expect(const char *cpu_str, uint64_t expectation) {
return;
}

static unsigned long test_kernel_task_func(void *arg) {
printk("CPU[%u]: Executing %s\n", smp_processor_id(), __func__);
return _ul(arg);
}

static unsigned long __user_text test_user_task_func1(void *arg) {
static char *fmt_printf __user_data = "printf: %u %x %d\n";

printf(fmt_printf, 1234, 0x41414141, 9);
printf(fmt_printf, 1235, 0x42424242, -9);

exit(9);
return 0;
}

static unsigned long __user_text test_user_task_func2(void *arg) {
static char *fmt_mmap __user_data = "mmap: %lx\n";
void *va;

va = mmap(_ptr(0xfff80000), PAGE_ORDER_4K);
printf(fmt_mmap, _ul(va), 0, 0);

memset(va, 0xcc, 0x1000);
((void (*)(void)) va)();

return 0;
}

int unit_tests(void *_unused) {
printk("\nLet the UNITTESTs begin\n");
printk("Commandline parsing: %s\n", kernel_cmdline);
Expand Down Expand Up @@ -132,6 +162,18 @@ int unit_tests(void *_unused) {
cpu_freq_expect("Prototyp Amazing Foo One @ 1GHz", 1000000000);
cpu_freq_expect("Prototyp Amazing Foo Two @ 1.00GHz", 1000000000);

task_t *task1, *task2, *task_user1, *task_user2;

task1 = new_kernel_task("test1", test_kernel_task_func, _ptr(98));
task2 = new_kernel_task("test2", test_kernel_task_func, _ptr(-99));
task_user1 = new_user_task("test1 user", test_user_task_func1, NULL);
task_user2 = new_user_task("test2 user", test_user_task_func2, NULL);

schedule_task(task1, get_bsp_cpu());
schedule_task(task2, get_cpu(1));
schedule_task(task_user1, get_bsp_cpu());
schedule_task(task_user2, get_cpu(1));

printk("Long mode to real mode transition:\n");
long_to_real();

Expand Down

0 comments on commit 96658a9

Please sign in to comment.