Misc.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include "pal.h"
  4. #include "pal_debug.h"
  5. #include "api.h"
  6. int main (int argc, const char ** argv, const char ** envp)
  7. {
  8. unsigned long time1 = DkSystemTimeQuery();
  9. unsigned long time2 = DkSystemTimeQuery();
  10. pal_printf("Time Query 1: %ld\n", time1);
  11. pal_printf("Time Query 2: %ld\n", time2);
  12. if (time1 <= time2)
  13. pal_printf("Query System Time OK\n");
  14. unsigned long time3 = DkSystemTimeQuery();
  15. DkThreadDelayExecution(10000);
  16. unsigned long time4 = DkSystemTimeQuery();
  17. pal_printf("Sleeped %ld Microseconds\n", time4 - time3);
  18. if (time3 < time4 && time4 - time3 > 10000)
  19. pal_printf("Delay Execution for 10000 Microseconds OK\n");
  20. unsigned long time5 = DkSystemTimeQuery();
  21. DkThreadDelayExecution(3000000);
  22. unsigned long time6 = DkSystemTimeQuery();
  23. pal_printf("Sleeped %ld Microseconds\n", time6 - time5);
  24. if (time5 < time6 && time6 - time5 > 3000000)
  25. pal_printf("Delay Execution for 3 Seconds OK\n");
  26. unsigned long data[100];
  27. memset(data, 0, sizeof(data));
  28. for (int i = 0 ; i < 100 ; i++) {
  29. int ret = DkRandomBitsRead(&data[i], sizeof(unsigned long));
  30. if (ret < 0) {
  31. pal_printf("DkRandomBitsRead() failed!\n");
  32. return 1;
  33. }
  34. }
  35. bool same = false;
  36. for (int i = 1 ; i < 100 ; i++)
  37. for (int j = 0 ; j < i ; j++)
  38. if (data[i] == data[j]) same = true;
  39. if (!same)
  40. pal_printf("Generate Random Bits OK\n");
  41. return 0;
  42. }