[tor-commits] [tor/master] Add tests for process environment functionality of process_t.

nickm at torproject.org nickm at torproject.org
Tue Dec 18 18:36:43 UTC 2018


commit 289ed0849d9b473cd0fbafada30c03638d73e541
Author: Alexander Færøy <ahf at torproject.org>
Date:   Mon Nov 26 04:59:12 2018 +0100

    Add tests for process environment functionality of process_t.
    
    This patch adds tests for the process_environment_t interaction in
    process_t.
    
    See: https://bugs.torproject.org/28179
---
 src/test/test_process.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/src/test/test_process.c b/src/test/test_process.c
index 4f86e786c..2fcb3f668 100644
--- a/src/test/test_process.c
+++ b/src/test/test_process.c
@@ -9,6 +9,7 @@
 #include "orconfig.h"
 #include "core/or/or.h"
 #include "test/test.h"
+#include "lib/process/env.h"
 
 #define PROCESS_PRIVATE
 #include "lib/process/process.h"
@@ -173,6 +174,56 @@ test_default_values(void *arg)
 }
 
 static void
+test_environment(void *arg)
+{
+  (void)arg;
+  process_init();
+
+  process_t *process = process_new("");
+  process_environment_t *env = NULL;
+
+  process_set_environment(process, "E", "F");
+  process_set_environment(process, "C", "D");
+  process_set_environment(process, "A", "B");
+
+  env = process_get_environment(process);
+  tt_mem_op(env->windows_environment_block, OP_EQ,
+            "A=B\0C=D\0E=F\0", 12);
+  tt_str_op(env->unixoid_environment_block[0], OP_EQ,
+            "A=B");
+  tt_str_op(env->unixoid_environment_block[1], OP_EQ,
+            "C=D");
+  tt_str_op(env->unixoid_environment_block[2], OP_EQ,
+            "E=F");
+  tt_ptr_op(env->unixoid_environment_block[3], OP_EQ,
+            NULL);
+  process_environment_free(env);
+
+  /* Reset our environment. */
+  smartlist_t *new_env = smartlist_new();
+  smartlist_add(new_env, (char *)"FOO=bar");
+  smartlist_add(new_env, (char *)"HELLO=world");
+
+  process_reset_environment(process, new_env);
+  smartlist_free(new_env);
+
+  env = process_get_environment(process);
+  tt_mem_op(env->windows_environment_block, OP_EQ,
+            "FOO=bar\0HELLO=world\0", 20);
+  tt_str_op(env->unixoid_environment_block[0], OP_EQ,
+            "FOO=bar");
+  tt_str_op(env->unixoid_environment_block[1], OP_EQ,
+            "HELLO=world");
+  tt_ptr_op(env->unixoid_environment_block[2], OP_EQ,
+            NULL);
+
+ done:
+  process_environment_free(env);
+  process_free(process);
+  process_free_all();
+}
+
+static void
 test_stringified_types(void *arg)
 {
   (void)arg;
@@ -589,6 +640,7 @@ test_win32(void *arg)
 
 struct testcase_t process_tests[] = {
   { "default_values", test_default_values, TT_FORK, NULL, NULL },
+  { "environment", test_environment, TT_FORK, NULL, NULL },
   { "stringified_types", test_stringified_types, TT_FORK, NULL, NULL },
   { "line_protocol_simple", test_line_protocol_simple, TT_FORK, NULL, NULL },
   { "line_protocol_multi", test_line_protocol_multi, TT_FORK, NULL, NULL },





More information about the tor-commits mailing list