diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-03-30 13:29:46 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-03-31 16:33:01 +0300 |
commit | 7083a1dc7d395df78d8e208c26ad996c5a6394f5 (patch) | |
tree | 439e894cdd30b968efbbba852f03c131a5c846e7 /tests/process/driver.cxx | |
parent | 7190ae233819cd68f5fce2564f7221ffe23a83bf (diff) |
Add notion of thread environment
Diffstat (limited to 'tests/process/driver.cxx')
-rw-r--r-- | tests/process/driver.cxx | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx index 4b5dd16..b018ac1 100644 --- a/tests/process/driver.cxx +++ b/tests/process/driver.cxx @@ -40,8 +40,6 @@ import butl.timestamp; using namespace std; using namespace butl; -static const char* envvars[] = {"ABC=1", "DEF", nullptr}; - using cstrings = vector<const char*>; bool @@ -94,18 +92,16 @@ exec (const path& p, if (bin) args.push_back ("-b"); + const char* evars[] = { + "PAR1", "PAR2=2P", "PAR6=66", "PAR7", // Override the process variables. + "THR1", "THR2=2T", // Override the thread variables. + "CHD1", // Unset a non-existing variable. + "CHD2=C2", // Add the new variable. + nullptr}; + if (env) - { args.push_back ("-e"); - // Here we set the environment variables for the current process to make - // sure that the child process will not see the variable that is requested - // to be unset, and will see the other one unaffected. - // - setenv ("DEF", "2"); - setenv ("XYZ", "3"); - } - if (cwd != nullptr) args.push_back (cwd); @@ -123,7 +119,7 @@ exec (const path& p, out ? -1 : -2, err ? (out ? 1 : -1) : -2, cwd, - env ? envvars : nullptr); + env ? evars : nullptr); try { @@ -157,12 +153,12 @@ exec (const path& p, process pr3 (args.data (), -1, -1, -2, cwd, - env ? envvars : nullptr); + env ? evars : nullptr); process pr2 (args.data (), pr, bin_mode (move (pr3.out_fd)).get (), -2, cwd, - env ? envvars : nullptr); + env ? evars : nullptr); ifdstream is (bin_mode (move (pr3.in_ofd))); o = is.read_binary (); @@ -329,12 +325,23 @@ main (int argc, const char* argv[]) if (env) { - // Check that the ABC variable is set, the DEF is unset and the XYZ is - // left unchanged. + // Check that the variables are (un)set as expected. // - if (getenv ("ABC") != optional<string> ("1") || - getenv ("DEF") || - getenv ("XYZ") != optional<string> ("3")) + if (getenv ("PAR1") || + getenv ("PAR2") != optional<string> ("2P") || + getenv ("PAR3") != optional<string> ("P3") || + getenv ("PAR4") || + getenv ("PAR5") != optional<string> ("5P") || + getenv ("PAR6") != optional<string> ("66") || + getenv ("PAR7") || + + getenv ("THR1") || + getenv ("THR2") != optional<string> ("2T") || + getenv ("THR3") != optional<string> ("T3") || + getenv ("THR4") || + + getenv ("CHD1") || + getenv ("CHD2") != optional<string> ("C2")) return 1; } @@ -364,6 +371,26 @@ main (int argc, const char* argv[]) return 0; } + // Here we set the process and thread environment variables to make sure + // that the child process will not see the variables that are requested to + // be unset, will see change for the variables that are requested to be set, + // and will see the other ones unaffected. + // + setenv ("PAR1", "P1"); + setenv ("PAR2", "P2"); + setenv ("PAR3", "P3"); + setenv ("PAR4", "P4"); + setenv ("PAR5", "P5"); + setenv ("PAR6", "P6"); + setenv ("PAR7", "P7"); + + const char* tevars[] = { + "THR1=T1", "THR2=T2", "THR3=T3", "THR4", + "PAR4", "PAR5=5P", "PAR6", "PAR7=7P", // Override the process variables. + nullptr}; + + auto_thread_env ate (tevars); + dir_path owd (dir_path::current_directory ()); // Test processes created as "already terminated". |