// SPDX-License-Identifier: MPL-2.0
#include "kernel/tests/test_queues.h"
#include "kernel/tests/test_utils.h"
#include "std/mem.h"
#include "std/print.h"
#include "std/queue.h"
SH_STATUS sh_test_benchmark_queues() {
  sh_tsc_TSC_VALUE *tsc_value=sh_test_get_tsc_values_buffer_ptr();
  sh_mem_set_8((sh_uint8*)tsc_value,0x00,sizeof(sh_tsc_TSC_VALUE)*10000);
  sh_print(SH_TEST,"Benchmarking keyboard events queues...\n");
  sh_tsc_TSC_VALUE start=0;
  sh_tsc_TSC_VALUE end=0;
  SH_STATUS status;
  sh_queue_KBD_EVENT queue;
  status=sh_queue_event_init(&queue,4096);
  if (sh_status_error(status)) {
    sh_print(SH_TEST,"Test failed for initialization of queue. See detail below:\n");
    sh_printf(SH_TEST,"Error code: %8s\n",status);
  }
  for (sh_iter64 i=0;i<10000;i++) {
    sh_kbd_EVENT event={.timestamp=i};
    start=sh_tsc_get_kernel_current_tsc();
    status=sh_queue_event_push(&queue,event);
    end=sh_tsc_get_kernel_current_tsc();
    tsc_value[i]=end-start;
    if (status!=SH_STATUS_SUCCESS) {
      sh_print(SH_ERROR,"Test failed for pushing objects on queue. See detail below:\n");
      sh_printf(SH_ERROR,"Error code: %8s\n",status);
      sh_printf(SH_ERROR,"Index: %8u\n",i);
      return SH_STATUS_TEST_FAILED;
    }
  }
  sh_test_compute_print_stats("pushing objects",tsc_value,10000,SH_TRUE);
  return SH_STATUS_SUCCESS;
}
