[compiler-rt] [llvm-lit] Add REQUIRES: shell in compiler-rt tests that use the `ulimit` command in lit internal shell (PR #105339)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 16:44:16 PDT 2024


https://github.com/Harini0924 updated https://github.com/llvm/llvm-project/pull/105339

>From ff93c18900641e1200529cad6256e985c76b5716 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Tue, 20 Aug 2024 19:19:50 +0000
Subject: [PATCH 1/4] [llvm-lit] Add REQUIRES: shell in tests that use the
 ulimit command

Added REQUIRES: shell in 6 files that use the ulimit command because lit
internal shell doesn't support this command.
---
 compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp | 1 +
 compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp    | 1 +
 compiler-rt/test/fuzzer/ulimit.test                          | 1 +
 compiler-rt/test/hwasan/TestCases/print-memory-usage.c       | 1 +
 compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp       | 1 +
 5 files changed, 5 insertions(+)

diff --git a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
index b096624a7f95b9..31541dd20ee489 100644
--- a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
+++ b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
@@ -7,6 +7,7 @@
 // Limit this test to Linux since we're relying on allocator internal
 // limits (shadow memory size, allocation limits etc.)
 
+REQUIRES: shell
 // RUN: %clangxx_asan -O0 %s -o %t
 // RUN: ulimit -v 22024290304
 // RUN: not %run %t malloc 2>&1 \
diff --git a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
index e6e82a47572056..02284e8f0cc3e6 100644
--- a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
@@ -1,3 +1,4 @@
+REQUIRES: shell
 // Check that UAR mode can handle very deep recusrion.
 // RUN: %clangxx_asan -O2 %s -o %t
 // RUN: ulimit -s 4096
diff --git a/compiler-rt/test/fuzzer/ulimit.test b/compiler-rt/test/fuzzer/ulimit.test
index 223f2ac9bb6e2e..3e1c9ceedbb3c3 100644
--- a/compiler-rt/test/fuzzer/ulimit.test
+++ b/compiler-rt/test/fuzzer/ulimit.test
@@ -1,4 +1,5 @@
 # FIXME: Disabled on Windows for now because Windows has no ulimit command.
+REQUIRES: shell
 UNSUPPORTED: target={{.*windows.*}}
 RUN: %cpp_compiler %S/SimpleTest.cpp -o %t-SimpleTest
 RUN: ulimit -s 1000
diff --git a/compiler-rt/test/hwasan/TestCases/print-memory-usage.c b/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
index 2c89d4e70ebc74..7c095e03125de5 100644
--- a/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
+++ b/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
@@ -1,3 +1,4 @@
+REQUIRES: shell
 // Tests __hwasan_print_memory_usage.
 // RUN: %clang_hwasan %s -o %t
 // RUN: ulimit -s 1000
diff --git a/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp b/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
index 61492ec34533fe..30c47abe02936a 100644
--- a/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
+++ b/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
@@ -1,3 +1,4 @@
+REQUIRES: shell
 // MSAN re-execs on unlimited stacks. We use that to verify ReExec() uses the
 // right path.
 // RUN: %clangxx_msan -O0 %s -o %t && ulimit -s unlimited && %run %t | FileCheck %s

>From 9b26939d4d1ed185be2ee884a197575b9b4a4181 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Tue, 20 Aug 2024 20:31:52 +0000
Subject: [PATCH 2/4] [llvm-lit] Found one more test that uses the ulimit
 command

---
 compiler-rt/test/fuzzer/merge-posix.test | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compiler-rt/test/fuzzer/merge-posix.test b/compiler-rt/test/fuzzer/merge-posix.test
index 9fece647ca60b9..8e1c66c1863b40 100644
--- a/compiler-rt/test/fuzzer/merge-posix.test
+++ b/compiler-rt/test/fuzzer/merge-posix.test
@@ -1,3 +1,4 @@
+REQUIRES: shell
 XFAIL: ios
 UNSUPPORTED: target={{.*windows.*}}
 RUN: %cpp_compiler %S/FullCoverageSetTest.cpp -o %t-FullCoverageSetTest

>From d98bcb183be3537b8bee43ac2bae0ba45387a6ae Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Tue, 20 Aug 2024 20:50:17 +0000
Subject: [PATCH 3/4] [llvm-lit] fixed formatter issues

---
 .../TestCases/Linux/allocator_oom_test.cpp    | 11 ++++++-----
 .../asan/TestCases/Posix/deep_call_stack.cpp  |  6 +++---
 .../hwasan/TestCases/print-memory-usage.c     | 19 ++++++++++---------
 .../msan/Linux/reexec_unlimited_stack.cpp     |  9 +++++----
 4 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
index 31541dd20ee489..d0555ca8636620 100644
--- a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
+++ b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
@@ -7,7 +7,7 @@
 // Limit this test to Linux since we're relying on allocator internal
 // limits (shadow memory size, allocation limits etc.)
 
-REQUIRES: shell
+REQUIRES : shell
 // RUN: %clangxx_asan -O0 %s -o %t
 // RUN: ulimit -v 22024290304
 // RUN: not %run %t malloc 2>&1 \
@@ -35,12 +35,13 @@ REQUIRES: shell
 // REQUIRES: shadow-scale-3
 // UNSUPPORTED: android, target={{(s390|aarch64|powerpc64le).*}}
 
+#include <assert.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdio.h>
-#include <assert.h>
 
-int main(int argc, char **argv) {
+           int
+           main(int argc, char **argv) {
   assert(argc == 2);
   const char *action = argv[1];
   fprintf(stderr, "%s:\n", action);
@@ -63,7 +64,7 @@ int main(int argc, char **argv) {
   } else if (!strcmp(action, "realloc")) {
     x = realloc(0, size);
   } else if (!strcmp(action, "realloc-after-malloc")) {
-    char *t = (char*)malloc(100);
+    char *t = (char *)malloc(100);
     *t = 42;
     x = realloc(t, size);
     assert(*t == 42);
diff --git a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
index 02284e8f0cc3e6..5ae6ea9edcdafe 100644
--- a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
@@ -1,4 +1,4 @@
-REQUIRES: shell
+REQUIRES : shell
 // Check that UAR mode can handle very deep recusrion.
 // RUN: %clangxx_asan -O2 %s -o %t
 // RUN: ulimit -s 4096
@@ -11,8 +11,8 @@ REQUIRES: shell
 
 #include <stdio.h>
 
-__attribute__((noinline))
-void RecursiveFunc(int depth, int *ptr) {
+           __attribute__((noinline)) void
+           RecursiveFunc(int depth, int *ptr) {
   if ((depth % 1000) == 0)
     printf("[%05d] ptr: %p\n", depth, ptr);
   if (depth == 0)
diff --git a/compiler-rt/test/hwasan/TestCases/print-memory-usage.c b/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
index 7c095e03125de5..4599e513f72cc7 100644
--- a/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
+++ b/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
@@ -1,24 +1,23 @@
-REQUIRES: shell
+REQUIRES : shell
 // Tests __hwasan_print_memory_usage.
 // RUN: %clang_hwasan %s -o %t
 // RUN: ulimit -s 1000
 // RUN: %run %t 2>&1 | FileCheck %s
 
 #include <pthread.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <sanitizer/hwasan_interface.h>
 
-int state;
+           int state;
 __thread volatile char *sink;
 
-__attribute__((noinline))
-void *malloc_and_use(int size) {
-  char *x = (char*)malloc(size);
+__attribute__((noinline)) void *malloc_and_use(int size) {
+  char *x = (char *)malloc(size);
   for (int i = 0; i < size; i++)
-    x[i] = 42;  // make this memory used.
+    x[i] = 42; // make this memory used.
   return x;
 }
 
@@ -29,7 +28,8 @@ void *T1(void *arg) {
   }
 
   __sync_fetch_and_add(&state, 1);
-  while (__sync_fetch_and_add(&state, 0) != 4) {}
+  while (__sync_fetch_and_add(&state, 0) != 4) {
+  }
   return NULL;
 }
 
@@ -58,7 +58,8 @@ int main() {
   pthread_create(&t2, NULL, T1, NULL);
   pthread_create(&t3, NULL, T1, NULL);
   pthread_create(&t4, NULL, T4, NULL);
-  while (__sync_fetch_and_add(&state, 0) != 3) {}
+  while (__sync_fetch_and_add(&state, 0) != 3) {
+  }
   pthread_join(t4, NULL);
 
   __hwasan_print_memory_usage();
diff --git a/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp b/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
index 30c47abe02936a..46e76f43f32ed8 100644
--- a/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
+++ b/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
@@ -1,4 +1,4 @@
-REQUIRES: shell
+REQUIRES : shell
 // MSAN re-execs on unlimited stacks. We use that to verify ReExec() uses the
 // right path.
 // RUN: %clangxx_msan -O0 %s -o %t && ulimit -s unlimited && %run %t | FileCheck %s
@@ -6,14 +6,15 @@ REQUIRES: shell
 #include <stdio.h>
 
 #if !defined(__GLIBC_PREREQ)
-#define __GLIBC_PREREQ(a, b) 0
+#  define __GLIBC_PREREQ(a, b) 0
 #endif
 
 #if __GLIBC_PREREQ(2, 16)
-#include <sys/auxv.h>
+#  include <sys/auxv.h>
 #endif
 
-int main() {
+           int
+           main() {
 #if __GLIBC_PREREQ(2, 16)
   // Make sure AT_EXECFN didn't get overwritten by re-exec.
   puts(reinterpret_cast<const char *>(getauxval(AT_EXECFN)));

>From ed84ad277c02800ab00d707517a2636ced5709ea Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Tue, 20 Aug 2024 23:41:56 +0000
Subject: [PATCH 4/4] [llvm-lit] Added `//` prefix and fixed the clang
 formatter issues.

---
 .../TestCases/Linux/allocator_oom_test.cpp    | 12 +++++-------
 .../asan/TestCases/Posix/deep_call_stack.cpp  |  6 +++---
 .../hwasan/TestCases/print-memory-usage.c     | 19 +++++++++----------
 .../msan/Linux/reexec_unlimited_stack.cpp     |  9 ++++-----
 4 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
index d0555ca8636620..f60a6a4ef79e6d 100644
--- a/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
+++ b/compiler-rt/test/asan/TestCases/Linux/allocator_oom_test.cpp
@@ -7,7 +7,6 @@
 // Limit this test to Linux since we're relying on allocator internal
 // limits (shadow memory size, allocation limits etc.)
 
-REQUIRES : shell
 // RUN: %clangxx_asan -O0 %s -o %t
 // RUN: ulimit -v 22024290304
 // RUN: not %run %t malloc 2>&1 \
@@ -32,16 +31,15 @@ REQUIRES : shell
 // ASan shadow memory on s390 is too large for this test.
 // AArch64 bots fail on this test.
 // TODO(alekseys): Android lit do not run ulimit on device.
-// REQUIRES: shadow-scale-3
+// REQUIRES: shell, shadow-scale-3
 // UNSUPPORTED: android, target={{(s390|aarch64|powerpc64le).*}}
 
-#include <assert.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
+#include <assert.h>
 
-           int
-           main(int argc, char **argv) {
+int main(int argc, char **argv) {
   assert(argc == 2);
   const char *action = argv[1];
   fprintf(stderr, "%s:\n", action);
@@ -64,7 +62,7 @@ REQUIRES : shell
   } else if (!strcmp(action, "realloc")) {
     x = realloc(0, size);
   } else if (!strcmp(action, "realloc-after-malloc")) {
-    char *t = (char *)malloc(100);
+    char *t = (char*)malloc(100);
     *t = 42;
     x = realloc(t, size);
     assert(*t == 42);
diff --git a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
index 5ae6ea9edcdafe..929a26f8c8e7ce 100644
--- a/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
+++ b/compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp
@@ -1,4 +1,4 @@
-REQUIRES : shell
+// REQUIRES: shell
 // Check that UAR mode can handle very deep recusrion.
 // RUN: %clangxx_asan -O2 %s -o %t
 // RUN: ulimit -s 4096
@@ -11,8 +11,8 @@ REQUIRES : shell
 
 #include <stdio.h>
 
-           __attribute__((noinline)) void
-           RecursiveFunc(int depth, int *ptr) {
+__attribute__((noinline))
+void RecursiveFunc(int depth, int *ptr) {
   if ((depth % 1000) == 0)
     printf("[%05d] ptr: %p\n", depth, ptr);
   if (depth == 0)
diff --git a/compiler-rt/test/hwasan/TestCases/print-memory-usage.c b/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
index 4599e513f72cc7..f8da534375ed82 100644
--- a/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
+++ b/compiler-rt/test/hwasan/TestCases/print-memory-usage.c
@@ -1,23 +1,24 @@
-REQUIRES : shell
+// REQUIRES: shell
 // Tests __hwasan_print_memory_usage.
 // RUN: %clang_hwasan %s -o %t
 // RUN: ulimit -s 1000
 // RUN: %run %t 2>&1 | FileCheck %s
 
 #include <pthread.h>
-#include <stdio.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 
 #include <sanitizer/hwasan_interface.h>
 
-           int state;
+int state;
 __thread volatile char *sink;
 
-__attribute__((noinline)) void *malloc_and_use(int size) {
-  char *x = (char *)malloc(size);
+__attribute__((noinline))
+void *malloc_and_use(int size) {
+  char *x = (char*)malloc(size);
   for (int i = 0; i < size; i++)
-    x[i] = 42; // make this memory used.
+    x[i] = 42;  // make this memory used.
   return x;
 }
 
@@ -28,8 +29,7 @@ void *T1(void *arg) {
   }
 
   __sync_fetch_and_add(&state, 1);
-  while (__sync_fetch_and_add(&state, 0) != 4) {
-  }
+  while (__sync_fetch_and_add(&state, 0) != 4) {}
   return NULL;
 }
 
@@ -58,8 +58,7 @@ int main() {
   pthread_create(&t2, NULL, T1, NULL);
   pthread_create(&t3, NULL, T1, NULL);
   pthread_create(&t4, NULL, T4, NULL);
-  while (__sync_fetch_and_add(&state, 0) != 3) {
-  }
+  while (__sync_fetch_and_add(&state, 0) != 3) {}
   pthread_join(t4, NULL);
 
   __hwasan_print_memory_usage();
diff --git a/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp b/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
index 46e76f43f32ed8..e08340430950d4 100644
--- a/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
+++ b/compiler-rt/test/msan/Linux/reexec_unlimited_stack.cpp
@@ -1,4 +1,4 @@
-REQUIRES : shell
+// REQUIRES: shell
 // MSAN re-execs on unlimited stacks. We use that to verify ReExec() uses the
 // right path.
 // RUN: %clangxx_msan -O0 %s -o %t && ulimit -s unlimited && %run %t | FileCheck %s
@@ -6,15 +6,14 @@ REQUIRES : shell
 #include <stdio.h>
 
 #if !defined(__GLIBC_PREREQ)
-#  define __GLIBC_PREREQ(a, b) 0
+#define __GLIBC_PREREQ(a, b) 0
 #endif
 
 #if __GLIBC_PREREQ(2, 16)
-#  include <sys/auxv.h>
+#include <sys/auxv.h>
 #endif
 
-           int
-           main() {
+int main() {
 #if __GLIBC_PREREQ(2, 16)
   // Make sure AT_EXECFN didn't get overwritten by re-exec.
   puts(reinterpret_cast<const char *>(getauxval(AT_EXECFN)));



More information about the llvm-commits mailing list