<commit_before>#include <sys/mimiker.h>
#include <sys/kenv.h>
#include <sys/ktest.h>
#include <sys/libkern.h>
#include <sys/time.h>
#include <sys/sched.h>

#define KTEST_MAX_NO 1024
#define KTEST_FAIL(args...)                                                    \
  do {                                                                         \
    kprintf(args);                                                             \
    ktest_atomically_print_failure();                                          \
  } while (0)

/* Linker set that stores all kernel tests. */
SET_DECLARE(tests, test_entry_t);
/* Stores currently running test data. */
static test_entry_t *current_test = NULL;
/* A null-terminated array of pointers to the tested test list. */
static test_entry_t *autorun_tests[KTEST_MAX_NO] = {NULL};

int ktest_test_running_flag = 0;

/* The initial seed, as set from command-line. */
static unsigned ktest_seed = 0;
static unsigned ktest_repeat = 1; /* Number of repetitions of each test. */
static unsigned seed = 0;         /* Current seed */

/* If we get preempted while printing out the [TEST_PASSED] string, the monitor
   process might not find the pattern it's looking for. */
static void ktest_atomically_print_success(void) {
  SCOPED_NO_PREEMPTION();
  kprintf(TEST_PASSED_STRING);
}

static void ktest_atomically_print_failure(void) {
  SCOPED_NO_PREEMPTION();
  kprintf(TEST_FAILED_STRING);
}

__noreturn void ktest_failure(void) {
  if (current_test == NULL)
    panic("current_test == NULL in ktest_failure! This is most likely a bug in "
          "the test framework!\n");
  ktest_atomically_print_failure();
  if (autorun_tests[0]) {
    kprintf("Failure while running multiple tests.\n");
    for (test_entry_t **ptr = autorun_tests; *ptr != NULL; ptr++) {
      test_entry_t *t = *ptr;
      kprintf("  %s", t->test_name);
      if (t == current_test) {
        kprintf("  <---- FAILED\n");
        break;
      } else {
        kprintf("\n");
      }
    }
    kprintf("The seed used for this test order was: %u. Start kernel with "
            "`test=all seed=%u repeat=%u` to reproduce this test case.\n",
            ktest_seed, ktest_seed, ktest_repeat);
  } else {<commit_msg>Do not interrupt printing TEST PASSED / FAILED messages.<commit_after>#include <sys/mimiker.h>
#include <sys/kenv.h>
#include <sys/ktest.h>
#include <sys/libkern.h>
#include <sys/time.h>
#include <sys/interrupt.h>

#define KTEST_MAX_NO 1024
#define KTEST_FAIL(args...)                                                    \
  do {                                                                         \
    kprintf(args);                                                             \
    ktest_atomically_print_failure();                                          \
  } while (0)

/* Linker set that stores all kernel tests. */
SET_DECLARE(tests, test_entry_t);
/* Stores currently running test data. */
static test_entry_t *current_test = NULL;
/* A null-terminated array of pointers to the tested test list. */
static test_entry_t *autorun_tests[KTEST_MAX_NO] = {NULL};

int ktest_test_running_flag = 0;

/* The initial seed, as set from command-line. */
static unsigned ktest_seed = 0;
static unsigned ktest_repeat = 1; /* Number of repetitions of each test. */
static unsigned seed = 0;         /* Current seed */

/* If we get interrupted while printing out the [TEST_PASSED] string, the
 * monitor process might not find the pattern it's looking for. */
static void ktest_atomically_print_success(void) {
  SCOPED_INTR_DISABLED();
  kprintf(TEST_PASSED_STRING);
}

static void ktest_atomically_print_failure(void) {
  SCOPED_INTR_DISABLED();
  kprintf(TEST_FAILED_STRING);
}

__noreturn void ktest_failure(void) {
  if (current_test == NULL)
    panic("current_test == NULL in ktest_failure! This is most likely a bug in "
          "the test framework!\n");
  ktest_atomically_print_failure();
  if (autorun_tests[0]) {
    kprintf("Failure while running multiple tests.\n");
    for (test_entry_t **ptr = autorun_tests; *ptr != NULL; ptr++) {
      test_entry_t *t = *ptr;
      kprintf("  %s", t->test_name);
      if (t == current_test) {
        kprintf("  <---- FAILED\n");
        break;
      } else {
        kprintf("\n");
      }
    }
    kprintf("The seed used for this test order was: %u. Start kernel with "
            "`test=all seed=%u repeat=%u` to reproduce this test case.\n",
            ktest_seed, ktest_seed, ktest_repeat);
  } else {
{'fraction_non_alphanumeric': 0.11140879660638535, 'fraction_numerical': 0.004465282429113641, 'mean_word_length': 2.3185185185185184, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4286453', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1344, 'n_words': 383}