summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-07 22:46:15 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-11-07 22:46:15 -0300
commit77207f9b5855189a4e818ed087f702080afc2068 (patch)
treea2e2f69541ac912a69e4ffe374beb1ee125d738c
parent01bf9a34d667466417b807a1187b2bc4ba6fa87f (diff)
csharp: Fix running headless tests in dotnet
Summary: CoreCLR, the runtime of dotnet, has some issues regarding storing environment variables (see dotnet/coreclr issue #15812), keeping them in a local cache instead of flushing to the native `setenv`. This commit replaces the usage of `System.Environment.SetEnvironmentVariable` with a `setenv` wrapper. Test Plan: Run without DISPLAY set and with dotnet. Reviewers: felipealmeida, brunobelo, segfaultxavi, YOhoho Reviewed By: brunobelo Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10619
-rw-r--r--src/bindings/mono/efl_mono/meson.build1
-rw-r--r--src/bindings/mono/eina_mono/eina_common.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_environment.cs53
-rw-r--r--src/bindings/mono/eina_mono/meson.build3
-rw-r--r--src/lib/efl_mono/efl_custom_exports_mono.c11
-rw-r--r--src/tests/efl_mono/Main.cs10
6 files changed, 76 insertions, 4 deletions
diff --git a/src/bindings/mono/efl_mono/meson.build b/src/bindings/mono/efl_mono/meson.build
index 8bfba31..e93d323 100644
--- a/src/bindings/mono/efl_mono/meson.build
+++ b/src/bindings/mono/efl_mono/meson.build
@@ -41,6 +41,7 @@ if get_option('build-tests')
41 mono_friend_assemblies += 'efl_sharp_test_suite' 41 mono_friend_assemblies += 'efl_sharp_test_suite'
42 else 42 else
43 mono_friend_assemblies += 'efl_mono_test' 43 mono_friend_assemblies += 'efl_mono_test'
44 mono_friend_assemblies += 'efl-mono-suite'
44 endif 45 endif
45endif 46endif
46 47
diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs
index 9465891..a4f2ff4 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -31,7 +31,7 @@ internal delegate void EinaFreeCb(IntPtr data);
31 31
32} 32}
33 33
34internal static class NativeCustomExportFunctions 34internal static partial class NativeCustomExportFunctions
35{ 35{
36 [DllImport(efl.Libs.CustomExports)] public static extern void 36 [DllImport(efl.Libs.CustomExports)] public static extern void
37 efl_mono_native_free(IntPtr ptr); 37 efl_mono_native_free(IntPtr ptr);
diff --git a/src/bindings/mono/eina_mono/eina_environment.cs b/src/bindings/mono/eina_mono/eina_environment.cs
new file mode 100644
index 0000000..7cef31c
--- /dev/null
+++ b/src/bindings/mono/eina_mono/eina_environment.cs
@@ -0,0 +1,53 @@
1using System;
2using System.Runtime.InteropServices;
3
4namespace Eina
5{
6
7/// <summary>
8/// Class to deal with native Environment variables.
9///
10/// <para>To be used in place of <see cref="System.Environment" /> methods when
11/// accessing the native environment directly.</para>
12/// <para>Since EFL 1.24.</para>
13/// </summary>
14internal static class Environment
15{
16 /// <summary>
17 /// Returns the value of the environment variable named <c>name</c>.
18 ///
19 /// <para>Since EFL 1.24</para>
20 /// </summary>
21 /// <param name="name">The name of the variable to be retrieved</param>
22 /// <returns>The value of the variable. <c>null</c> if not set.</returns>
23 public static string GetEnv(string name)
24 {
25 return Eina.NativeCustomExportFunctions.efl_mono_native_getenv(name);
26 }
27
28 /// <summary>
29 /// Sets a native environment variable.
30 ///
31 /// <para>Since EFL 1.24</para>
32 /// </summary>
33 /// <param name="name">The name of the variable</param>
34 /// <param name="value">The value to be set.</param>
35 /// <param name="overwrite"><c>true</c> if an existing variable must be overwritten.</param>
36 public static void SetEnv(string name, string value, bool overwrite=true)
37 {
38 Eina.Error error = Eina.NativeCustomExportFunctions.efl_mono_native_setenv(name, value, overwrite ? 1 : 0);
39 Eina.Error.Raise(error);
40 }
41}
42
43internal static partial class NativeCustomExportFunctions
44{
45 [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
46 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]
47 public static extern string efl_mono_native_getenv(string name);
48
49 [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
50 public static extern Eina.Error efl_mono_native_setenv(string name, string value, int overwrite);
51}
52
53} \ No newline at end of file
diff --git a/src/bindings/mono/eina_mono/meson.build b/src/bindings/mono/eina_mono/meson.build
index 1d9e4e6..82c418f 100644
--- a/src/bindings/mono/eina_mono/meson.build
+++ b/src/bindings/mono/eina_mono/meson.build
@@ -16,5 +16,6 @@ mono_files += files(
16 'eina_value.cs', 16 'eina_value.cs',
17 'eina_promises.cs', 17 'eina_promises.cs',
18 'eina_accessor.cs', 18 'eina_accessor.cs',
19 'eina_strbuf.cs' 19 'eina_strbuf.cs',
20 'eina_environment.cs',
20) 21)
diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c
index c3e8191..ede573f 100644
--- a/src/lib/efl_mono/efl_custom_exports_mono.c
+++ b/src/lib/efl_mono/efl_custom_exports_mono.c
@@ -202,6 +202,17 @@ EAPI Efl_Substitute_Ctor_Cb efl_mono_avoid_top_level_constructor_callback_addr_g
202 return &_efl_mono_avoid_top_level_constructor_cb; 202 return &_efl_mono_avoid_top_level_constructor_cb;
203} 203}
204 204
205// Environment wrappers //
206EAPI const char *efl_mono_native_getenv(const char *name)
207{
208 return getenv(name);
209}
210
211EAPI Eina_Error efl_mono_native_setenv(const char *name, const char *value, int overwrite)
212{
213 return setenv(name, value, overwrite);
214}
215
205// Iterator Wrapper // 216// Iterator Wrapper //
206 217
207typedef struct _Eina_Iterator_Wrapper_Mono 218typedef struct _Eina_Iterator_Wrapper_Mono
diff --git a/src/tests/efl_mono/Main.cs b/src/tests/efl_mono/Main.cs
index 059ad4c..7829cf3 100644
--- a/src/tests/efl_mono/Main.cs
+++ b/src/tests/efl_mono/Main.cs
@@ -30,8 +30,13 @@ class TestMain
30 30
31 static int Main(string[] args) 31 static int Main(string[] args)
32 { 32 {
33 if (Environment.GetEnvironmentVariable("ELM_ENGINE") == null) 33 /// We do not use System.Environment due to CoreCLR open issues regarding
34 Environment.SetEnvironmentVariable("ELM_ENGINE", "buffer"); 34 /// setenv modifying the actual C environment. See issue #1592 in CoreCLR repo.
35 Eina.Config.Init();
36 if (Eina.Environment.GetEnv("ELM_ENGINE") == null)
37 {
38 Eina.Environment.SetEnv("ELM_ENGINE", "buffer", true);
39 }
35 40
36 Efl.All.Init(Efl.Csharp.Components.Ui); 41 Efl.All.Init(Efl.Csharp.Components.Ui);
37 42
@@ -114,6 +119,7 @@ class TestMain
114 Console.WriteLine("[ END SUITE ] " + ckRunSuite); 119 Console.WriteLine("[ END SUITE ] " + ckRunSuite);
115 120
116 Efl.All.Shutdown(); 121 Efl.All.Shutdown();
122 Eina.Config.Shutdown(); // For the extra init in getenv/setenv above
117 123
118 if (!pass) 124 if (!pass)
119 return -1; 125 return -1;