[PATCH] D146387: [test-suite] Avoid segfault in CLAMR test on non-Linux systems

Dimitry Andric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 19 11:45:34 PDT 2023


dim created this revision.
dim added reviewers: brad, emaste.
Herald added subscribers: krytarowski, arichardson.
Herald added a project: All.
dim requested review of this revision.

On FreeBSD, the CLAMR test immediately segfaults on startup, when it
parses /proc/pid/status in the `memstats_memused()` function. This is
because the parser is not very robust, and the FreeBSD /proc format is
different than Linux.

I expect this code to crash on anything else than Linux, but for our
test purposes the memory statistics printed are not important, since
nobody ever looks at the produced output.

Since there is already a `MEMORY` define controlling the printing of
memory statistics, only call the `memstats_memused()` function if it is
explicitly enabled (which it is not, by default).


Repository:
  rT test-suite

https://reviews.llvm.org/D146387

Files:
  MultiSource/Benchmarks/DOE-ProxyApps-C++/CLAMR/clamr_cpuonly.cpp


Index: MultiSource/Benchmarks/DOE-ProxyApps-C++/CLAMR/clamr_cpuonly.cpp
===================================================================
--- MultiSource/Benchmarks/DOE-ProxyApps-C++/CLAMR/clamr_cpuonly.cpp
+++ MultiSource/Benchmarks/DOE-ProxyApps-C++/CLAMR/clamr_cpuonly.cpp
@@ -271,8 +271,8 @@
    mesh->parallel_output("CPU:  setup time               time was",cpu_time_main_setup, 0, "s");
    #endif 
 
-   long long mem_used = memstats_memused();
    #ifdef MEMORY
+   long long mem_used = memstats_memused();
    if (mem_used > 0) {
       mesh->parallel_output("Memory used      in startup ",mem_used, 0, "kB");
       mesh->parallel_output("Memory peak      in startup ",memstats_mempeak(), 0, "kB");
@@ -627,8 +627,8 @@
       //  Get overall program timing.
       double elapsed_time = cpu_timer_stop(tstart);
       
-      long long mem_used = memstats_memused();
       #ifdef MEMORY
+      long long mem_used = memstats_memused();
       if (mem_used > 0) {
          printf("Memory used      %lld kB\n",mem_used);
          printf("Memory peak      %lld kB\n",memstats_mempeak());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146387.506411.patch
Type: text/x-patch
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230319/1794d787/attachment.bin>


More information about the llvm-commits mailing list