File 1468-Print-last-test-case-before-core-dump-in-z_SUITE-cor.patch of Package erlang

From d9456ac8b48f647bfb840ee32aaf4ea5934a2dfe Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 14 Feb 2024 19:56:05 +0100
Subject: [PATCH] Print last test case before core dump in z_SUITE:core_files

---
 erts/test/z_SUITE.erl | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/erts/test/z_SUITE.erl b/erts/test/z_SUITE.erl
index 18a42f7c28..2864fb40a2 100644
--- a/erts/test/z_SUITE.erl
+++ b/erts/test/z_SUITE.erl
@@ -205,15 +205,39 @@ format_core(Conf, Core) ->
     %% Try print (log dir) name of offending application
     CoreDir = filename:dirname(Core),
     lists:foreach(fun(TestDir) ->
-			  case filelib:is_dir(filename:join(CoreDir,TestDir)) of
+                          FullTestDir = filename:join(CoreDir,TestDir),
+			  case filelib:is_dir(FullTestDir) of
 			      true ->
-				  io:format("  from ~s~n", [TestDir]);
+				  io:format("  from ~s\n", [TestDir]),
+                                  print_last_testcase(FullTestDir);
 			      false ->
 				  no
 			  end
 		  end,
 		  filelib:wildcard("*.logs", CoreDir)).
 
+print_last_testcase(FullTestDir) ->
+    lists:foreach(fun(RunDir) ->
+                          SuiteLog = filename:join([FullTestDir,RunDir,"suite.log"]),
+                          try last_testcase(SuiteLog) of
+                              TestCase ->
+                                  io:format("       ~s\n", [TestCase])
+                          catch
+                              error:Reason ->
+                                  io:format("  could not find last test case: ~p\n", [Reason])
+                          end
+		  end,
+		  filelib:wildcard("run.*", FullTestDir)).
+
+last_testcase(SuiteLog) ->
+    {ok, Bin} = file:read_file(SuiteLog),
+    case string:find(Bin, "\n=case", trailing) of
+        TailBin when is_binary(TailBin) ->
+            {match, [TestCase]} = re:run(TailBin, "=case\\s+(.+)",
+                                         [{capture,all_but_first,binary}]),
+            TestCase
+    end.
+
 format_core(#core_search_conf{file = false}, Core, Ignore) ->
     io:format("  ~s~s " ++ time_fstr() ++ "~s~n",
 	      [Ignore, Core] ++ mod_time_list(Core));
-- 
2.35.3

openSUSE Build Service is sponsored by