<commit_before>
#include <tilck/common/basic_defs.h>
#include <tilck/common/string_util.h>
#include <tilck/common/utils.h>

#include <tilck/kernel/irq.h>
#include <tilck/kernel/kmalloc.h>
#include <tilck/kernel/paging.h>
#include <tilck/kernel/debug_utils.h>
#include <tilck/kernel/process.h>

#include <tilck/kernel/hal.h>
#include <tilck/kernel/tasklet.h>
#include <tilck/kernel/sync.h>
#include <tilck/kernel/fault_resumable.h>
#include <tilck/kernel/timer.h>

void simple_test_kthread(void *arg)
{
   u32 i;
   DEBUG_ONLY(uptr esp);
   DEBUG_ONLY(uptr saved_esp = get_curr_stack_ptr());

   printk("[kthread] This is a kernel thread, arg = %p\n", arg);

   for (i = 0; i < 256*MB; i++) {

#if !defined(NDEBUG) && !defined(RELEASE)

      /*
       * This VERY IMPORTANT check ensures us that in NO WAY functions like
       * save_current_task_state() and kernel_context_switch() changed value
       * of the stack pointer. Unfortunately, we cannot reliably do this check
       * in RELEASE (= optimized) builds because the compiler plays with the
       * stack pointer and 'esp' and 'saved_esp' differ by a constant value.
       */
      esp = get_curr_stack_ptr();

      if (esp != saved_esp)
         panic("esp: %p != saved_esp: %p [curr-saved: %d], i = %u",
               esp, saved_esp, esp - saved_esp, i);
#else

      (void)esp;
      (void)saved_esp;

#endif

      if (!(i % (64*MB))) {
         printk("[kthread] i = %i\n", i/MB);
      }
   }

   printk("[kthread] completed\n");

   if ((uptr)arg == 1) {
      printk("[kthread] DEBUG QEMU turn off machine\n");
      debug_qemu_turn_off_machine();
   }
}

void selftest_kthread_med(void)
{
   if (!kthread_create(simple_test_kthread, (void *)1))
      panic("Unable to create the simple test kthread");
}

void selftest_kernel_sleep_short()
{
   const u64 wait_ticks = TIMER_HZ;
   u64 before = get_ticks();
<commit_msg>[self_tests] Minor fix<commit_after>
#include <tilck/common/basic_defs.h>
#include <tilck/common/string_util.h>
#include <tilck/common/utils.h>

#include <tilck/kernel/irq.h>
#include <tilck/kernel/kmalloc.h>
#include <tilck/kernel/paging.h>
#include <tilck/kernel/debug_utils.h>
#include <tilck/kernel/process.h>

#include <tilck/kernel/hal.h>
#include <tilck/kernel/tasklet.h>
#include <tilck/kernel/sync.h>
#include <tilck/kernel/fault_resumable.h>
#include <tilck/kernel/timer.h>

void simple_test_kthread(void *arg)
{
   u32 i;
   DEBUG_ONLY(uptr esp);
   DEBUG_ONLY(uptr saved_esp = get_curr_stack_ptr());

   printk("[kthread] This is a kernel thread, arg = %p\n", arg);

   for (i = 0; i < 256*MB; i++) {

#if !defined(NDEBUG) && !defined(RELEASE)

      /*
       * This VERY IMPORTANT check ensures us that in NO WAY functions like
       * save_current_task_state() and kernel_context_switch() changed value
       * of the stack pointer. Unfortunately, we cannot reliably do this check
       * in RELEASE (= optimized) builds because the compiler plays with the
       * stack pointer and 'esp' and 'saved_esp' differ by a constant value.
       */
      esp = get_curr_stack_ptr();

      if (esp != saved_esp)
         panic("esp: %p != saved_esp: %p [curr-saved: %d], i = %u",
               esp, saved_esp, esp - saved_esp, i);

#endif

      if (!(i % (64*MB))) {
         printk("[kthread] i = %i\n", i/MB);
      }
   }

   printk("[kthread] completed\n");

   if ((uptr)arg == 1) {
      printk("[kthread] DEBUG QEMU turn off machine\n");
      debug_qemu_turn_off_machine();
   }
}

void selftest_kthread_med(void)
{
   if (!kthread_create(simple_test_kthread, (void *)1))
      panic("Unable to create the simple test kthread");
}

void selftest_kernel_sleep_short()
{
   const u64 wait_ticks = TIMER_HZ;
   u64 before = get_ticks();

{'fraction_non_alphanumeric': 0.14152452025586354, 'fraction_numerical': 0.007462686567164179, 'mean_word_length': 3.3588850174216027, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3283405', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1342, 'n_words': 335}