env.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <unordered_map>
  3. #include <util/folder/path.h>
  4. #include <util/generic/string.h>
  5. #include <util/generic/strbuf.h>
  6. #include <util/system/src_location.h>
  7. // @brief return full path to arcadia root
  8. TString ArcadiaSourceRoot();
  9. // @brief return full path for file or folder specified by known source location `where` and `path` which is relative to parent folder of `where`
  10. // for the instance: there is 2 files in folder test example_ut.cpp and example.data, so full path to test/example.data can be obtained
  11. // from example_ut.cpp as ArcadiaFromCurrentLocation(__SOURCE_FILE__, "example.data")
  12. TString ArcadiaFromCurrentLocation(TStringBuf where, TStringBuf path);
  13. // @brief return build folder path
  14. TString BuildRoot();
  15. // @brief return full path to built artefact, where path is relative from arcadia root
  16. TString BinaryPath(TStringBuf path);
  17. // @brief return true if environment is testenv otherwise false
  18. bool FromYaTest();
  19. // @brief returns TestsData dir (from env:ARCADIA_TESTS_DATA_DIR or path to existing folder `arcadia_tests_data` within parent folders)
  20. TString GetArcadiaTestsData();
  21. // @brief return current working dir (from env:TEST_WORK_PATH or cwd)
  22. TString GetWorkPath();
  23. // @brief return tests output path (workdir + testing_out_stuff)
  24. TFsPath GetOutputPath();
  25. // @brief return path from env:YA_TEST_RAM_DRIVE_PATH
  26. const TString& GetRamDrivePath();
  27. // @brief return path from env:YA_TEST_OUTPUT_RAM_DRIVE_PATH
  28. const TString& GetOutputRamDrivePath();
  29. // @brief return test parameter by name. If not exists, return an empty string
  30. const TString& GetTestParam(TStringBuf name);
  31. // @brief return test parameter by name. If not exists, return specified default value
  32. const TString& GetTestParam(TStringBuf name, const TString& def);
  33. // @brief return path to global resource. If not exists, aborts the test run
  34. const TString& GetGlobalResource(TStringBuf name);
  35. // @brief return path to the gdb
  36. const TString& GdbPath();
  37. // @brief register the process. Test suite will be marked as failed if the process is terminated with a core dump file after testing
  38. void WatchProcessCore(int pid, const TFsPath& binaryPath, const TFsPath& cwd = TFsPath());
  39. // @brief mark the process as successfully completed - a test machinery won't try to recover core dump file for the process
  40. void StopProcessCoreWatching(int pid);
  41. #define SRC_(path) ArcadiaFromCurrentLocation(__SOURCE_FILE__, path)
  42. namespace NPrivate {
  43. class TTestEnv {
  44. public:
  45. TTestEnv();
  46. void ReInitialize();
  47. void AddTestParam(TStringBuf name, TStringBuf value);
  48. bool IsRunningFromTest;
  49. TString ArcadiaTestsDataDir;
  50. TString SourceRoot;
  51. TString BuildRoot;
  52. TString WorkPath;
  53. TString RamDrivePath;
  54. TString YtHddPath;
  55. TString TestOutputRamDrivePath;
  56. TString GdbPath;
  57. TString CoreSearchFile;
  58. TString EnvFile;
  59. std::unordered_map<TString, TString> TestParameters;
  60. std::unordered_map<TString, TString> GlobalResources;
  61. };
  62. TString GetCwd();
  63. const TTestEnv& GetTestEnv();
  64. }