memory_ut.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "../pg_compat.h"
  2. extern "C" {
  3. #include <yql/essentials/parser/pg_wrapper/postgresql/src/include/postgres.h>
  4. #include <yql/essentials/parser/pg_wrapper/postgresql/src/include/utils/memutils.h>
  5. }
  6. #include "arena_ctx.h"
  7. #include <yql/essentials/minikql/mkql_alloc.h>
  8. #include <library/cpp/testing/unittest/registar.h>
  9. namespace NYql {
  10. Y_UNIT_TEST_SUITE(TPGMemoryTests) {
  11. Y_UNIT_TEST(TestArenaContextBasic) {
  12. TArenaMemoryContext arena;
  13. auto p1 = palloc(123);
  14. auto p2 = palloc(456);
  15. Y_UNUSED(p2);
  16. pfree(p1);
  17. }
  18. Y_UNIT_TEST(TestMkqlContextBasic) {
  19. NKikimr::NMiniKQL::TScopedAlloc alloc(__LOCATION__);
  20. auto p1 = palloc(123);
  21. auto p2 = palloc(456);
  22. Y_UNUSED(p2);
  23. pfree(p1);
  24. }
  25. Y_UNIT_TEST(TestArenaContextCleanupChild) {
  26. TArenaMemoryContext arena;
  27. auto tmpContext = AllocSetContextCreate(CurrentMemoryContext, "Tmp", ALLOCSET_SMALL_SIZES);
  28. auto oldcontext = MemoryContextSwitchTo(tmpContext);
  29. auto p1 = palloc(123);
  30. Y_UNUSED(p1);
  31. MemoryContextSwitchTo(oldcontext);
  32. }
  33. Y_UNIT_TEST(TestMkqlContextCleanupChild) {
  34. NKikimr::NMiniKQL::TScopedAlloc alloc(__LOCATION__);
  35. auto tmpContext = AllocSetContextCreate(CurrentMemoryContext, "Tmp", ALLOCSET_SMALL_SIZES);
  36. auto oldcontext = MemoryContextSwitchTo(tmpContext);
  37. auto p1 = palloc(123);
  38. Y_UNUSED(p1);
  39. MemoryContextSwitchTo(oldcontext);
  40. }
  41. }
  42. }