File 2442-snmp-test-Host-analysis.patch of Package erlang
From c3c5879981f22615bb0f3ddcb1888d90f02ee3bf Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Mon, 4 May 2020 11:43:20 +0200
Subject: [PATCH 2/3] [snmp|test] Host analysis
Do the host analyze first and the skip test second since
some of the skip tests (windows) use info retrieved by the
analyzis.
---
 lib/snmp/test/snmp_test_lib.erl | 114 +++++++++++++++++---------------
 1 file changed, 59 insertions(+), 55 deletions(-)
diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl
index 40aa71d630..e6213cc085 100644
--- a/lib/snmp/test/snmp_test_lib.erl
+++ b/lib/snmp/test/snmp_test_lib.erl
@@ -625,6 +625,25 @@ init_per_suite(Config) ->
 
     ct:timetrap(minutes(2)),
 
+    try analyze_and_print_host_info() of
+        {Factor, HostInfo} when is_integer(Factor) ->
+            try maybe_skip(HostInfo) of
+                true ->
+                    {skip, "Unstable host and/or os (or combo thererof)"};
+                false ->
+                    snmp_test_global_sys_monitor:start(),
+                    [{snmp_factor, Factor} | Config]
+            catch
+                throw:{skip, _} = SKIP ->
+                    SKIP
+            end
+    catch
+        throw:{skip, _} = SKIP ->
+            SKIP
+    end.
+
+maybe_skip(HostInfo) ->
+
     %% We have some crap machines that causes random test case failures
     %% for no obvious reason. So, attempt to identify those without actually
     %% checking for the host name...
@@ -683,8 +702,7 @@ init_per_suite(Config) ->
         end,
     SkipWindowsOnVirtual =
         fun() ->
-                SysInfo = which_win_system_info(),
-                SysMan  = win_sys_info_lookup(system_manufacturer, SysInfo),
+                SysMan = win_sys_info_lookup(system_manufacturer, HostInfo),
                 case string:to_lower(SysMan) of
                     "vmware" ++ _ ->
                         true;
@@ -695,23 +713,7 @@ init_per_suite(Config) ->
     COND = [{unix,  [{linux, LinuxVersionVerify}, 
                      {darwin, DarwinVersionVerify}]},
             {win32, SkipWindowsOnVirtual}],
-    try os_based_skip(COND) of
-        true ->
-            {skip, "Unstable host and/or os (or combo thererof)"};
-        false ->
-            %% Factor = analyze_and_print_host_info(),
-            try analyze_and_print_host_info() of
-                Factor ->
-                    snmp_test_global_sys_monitor:start(),
-                    [{snmp_factor, Factor} | Config]
-            catch
-                throw:{skip, _} = SKIP ->
-                    SKIP
-            end
-    catch
-        throw:{skip, _} = SKIP ->
-            SKIP
-    end.
+    os_based_skip(COND).
 
 
 end_per_suite(Config) when is_list(Config) ->
@@ -985,11 +987,11 @@ analyze_and_print_linux_host_info(Version) ->
     try linux_which_meminfo() of
         AddFactor ->
             io:format("TS Scale Factor: ~w~n", [timetrap_scale_factor()]),
-            Factor + AddFactor
+            {Factor + AddFactor, []}
     catch
         _:_:_ ->
             io:format("TS Scale Factor: ~w~n", [timetrap_scale_factor()]),
-            Factor
+            {Factor, []}
     end.
 
 
@@ -1296,12 +1298,12 @@ analyze_and_print_openbsd_host_info(Version) ->
                     true ->
                         3
                 end,
-            CPUFactor + MemAddFactor
+            {CPUFactor + MemAddFactor, []}
         end
     catch
         _:_:_ ->
             io:format("TS Scale Factor: ~w~n", [timetrap_scale_factor()]),
-            1
+            {2, []}
     end.
     
 
@@ -1384,7 +1386,7 @@ analyze_and_print_freebsd_host_info(Version) ->
                     true ->
                         3
                 end,
-            CPUFactor + MemAddFactor
+            {CPUFactor + MemAddFactor, []}
         end
     catch
         _:_:_ ->
@@ -1392,14 +1394,15 @@ analyze_and_print_freebsd_host_info(Version) ->
                       "~n   Num Schedulers: ~s"
                       "~n", [str_num_schedulers()]),
             io:format("TS Scale Factor: ~w~n", [timetrap_scale_factor()]),
-            case erlang:system_info(schedulers) of
-                1 ->
-                    10;
-                2 ->
-                    5;
-                _ ->
-                    2
-            end
+            Factor = case erlang:system_info(schedulers) of
+                         1 ->
+                             10;
+                         2 ->
+                             5;
+                         _ ->
+                             2
+                     end,
+            {Factor, []}
     end.
 
 
@@ -1523,21 +1526,22 @@ analyze_and_print_netbsd_host_info(Version) ->
                     true ->
                         3
                 end,
-            CPUFactor + MemAddFactor
+            {CPUFactor + MemAddFactor, []}
         end
     catch
         _:_:_ ->
             io:format("CPU:"
                       "~n   Num Schedulers: ~w"
                       "~n", [erlang:system_info(schedulers)]),
-            case erlang:system_info(schedulers) of
-                1 ->
-                    10;
-                2 ->
-                    5;
-                _ ->
-                    2
-            end
+            Factor = case erlang:system_info(schedulers) of
+                         1 ->
+                             10;
+                         2 ->
+                             5;
+                         _ ->
+                             2
+                     end,
+            {Factor, []}
     end.
 
 analyze_netbsd_cpu(Extract) ->
@@ -1701,19 +1705,19 @@ analyze_and_print_solaris_host_info(Version) ->
             _:_:_ ->
                 10
         end,
-    try erlang:system_info(schedulers) of
-        1 ->
-            10;
-        2 ->
-            5;
-        N when (N =< 6) ->
-            2;
-        _ ->
-            1
-    catch
-        _:_:_ ->
-            10
-    end + MemFactor.    
+    {try erlang:system_info(schedulers) of
+         1 ->
+             10;
+         2 ->
+             5;
+         N when (N =< 6) ->
+             2;
+         _ ->
+             1
+     catch
+         _:_:_ ->
+             10
+     end + MemFactor, []}.    
 
 
 
@@ -1787,7 +1791,7 @@ analyze_and_print_win_host_info(Version) ->
             _ ->
                 2
         end,
-    CPUFactor + MemFactor.
+    {CPUFactor + MemFactor, SysInfo}.
 
 win_sys_info_lookup(Key, SysInfo) ->
     win_sys_info_lookup(Key, SysInfo, "-").
-- 
2.26.1