VirtualStackTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 
  2. #include "../testTools.h"
  3. #include "../../DFPSR/base/virtualStack.h"
  4. START_TEST(VirtualStack)
  5. { // Single threaded
  6. // TODO: Allocate structures with explicit alignment requirements exceeding the largest element's size.
  7. VirtualStackAllocation<int32_t> x(9);
  8. {
  9. ASSERT_EQUAL((uintptr_t)(x.getUnsafe()) % alignof(int32_t), 0);
  10. x[0] = 01;
  11. x[1] = 12;
  12. x[2] = 23;
  13. x[3] = 34;
  14. x[4] = 45;
  15. x[5] = 56;
  16. x[6] = 67;
  17. x[7] = 78;
  18. x[8] = 89;
  19. VirtualStackAllocation<int32_t> y(3);
  20. {
  21. ASSERT_EQUAL((uintptr_t)(y.getUnsafe()) % alignof(int32_t), 0);
  22. y[0] = 2147483000;
  23. y[1] = -2147483000;
  24. y[2] = 65;
  25. #ifdef SAFE_POINTER_CHECKS
  26. ASSERT_CRASH(y[-1]);
  27. #endif
  28. ASSERT_EQUAL(y[0], 2147483000);
  29. ASSERT_EQUAL(y[1], -2147483000);
  30. ASSERT_EQUAL(y[2], 65);
  31. #ifdef SAFE_POINTER_CHECKS
  32. ASSERT_CRASH(y[3]);
  33. #endif
  34. }
  35. //#ifdef SAFE_POINTER_CHECKS
  36. // TODO: Implement and test memory safety against deallocated data by remembering the allocation's identity in the pointer and erasing it when freeing.
  37. //#endif
  38. }
  39. #ifdef SAFE_POINTER_CHECKS
  40. ASSERT_CRASH(x[-1]);
  41. #endif
  42. ASSERT_EQUAL(x[0], 01);
  43. ASSERT_EQUAL(x[1], 12);
  44. ASSERT_EQUAL(x[2], 23);
  45. ASSERT_EQUAL(x[3], 34);
  46. ASSERT_EQUAL(x[4], 45);
  47. ASSERT_EQUAL(x[5], 56);
  48. ASSERT_EQUAL(x[6], 67);
  49. ASSERT_EQUAL(x[7], 78);
  50. ASSERT_EQUAL(x[8], 89);
  51. #ifdef SAFE_POINTER_CHECKS
  52. ASSERT_CRASH(x[9]);
  53. #endif
  54. }
  55. { // Multi threaded
  56. // TODO: Create a bruteforce test using multiple threads.
  57. }
  58. END_TEST