[libc-commits] [PATCH] D158867: [libc] Add more test cases to the argument list tests

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Aug 25 10:53:50 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: arsenm, JonChesterfield, sivachandra, lntue, michaelrj, tra.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
jhuber6 requested review of this revision.
Herald added a subscriber: wdng.

This patch adds some extra cases to the existing argument list test in
`libc`, mainly dealing with arguments of varying sizes and primitive
types.

The purpose of this patch is to provide a wider test area when we begin
to provide varargs support on the GPU as there is no other runtime code
that really tests it. So, running these tests more exhaustively in the
GPU libc project will serve as the runtime tests for GPU vararg support in
D158246 <https://reviews.llvm.org/D158246>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158867

Files:
  libc/test/src/__support/arg_list_test.cpp


Index: libc/test/src/__support/arg_list_test.cpp
===================================================================
--- libc/test/src/__support/arg_list_test.cpp
+++ libc/test/src/__support/arg_list_test.cpp
@@ -56,3 +56,78 @@
   ASSERT_EQ(sum_two_nums(3, 5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024),
             40);
 }
+
+bool check_primitives(int first, ...) {
+  va_list vlist;
+  va_start(vlist, first);
+  __llvm_libc::internal::ArgList args(vlist);
+  va_end(vlist);
+
+  if (args.next_var<int>() != 0)
+    return false;
+  if (args.next_var<int>() != 0)
+    return false;
+  if (args.next_var<int>() != 0)
+    return false;
+  if (args.next_var<long>() != 0)
+    return false;
+  if (args.next_var<long>() != 0)
+    return false;
+  if (args.next_var<intmax_t>() != 0)
+    return false;
+  if (args.next_var<size_t>() != 0)
+    return false;
+  if (args.next_var<ptrdiff_t>() != 0)
+    return false;
+  if (args.next_var<double>() != 0)
+    return false;
+  if (args.next_var<double>() != 0)
+    return false;
+  if (args.next_var<long>() != 0)
+    return false;
+  if (args.next_var<void *>() != 0)
+    return false;
+  return true;
+}
+
+TEST(LlvmLibcArgListTest, TestPrimitiveTypes) {
+  char x1 = 0;
+  short x2 = 0;
+  int x3 = 0;
+  long x4 = 0;
+  long long x5 = 0;
+  intmax_t x6 = 0;
+  size_t x7 = 0;
+  ptrdiff_t x8 = 0;
+  float x9 = 0;
+  double x10 = 0;
+  long double x11 = 0;
+  void *x12 = 0;
+  ASSERT_TRUE(
+      check_primitives(0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12));
+}
+
+struct S {
+  char c;
+  short s;
+  int i;
+  long l;
+  float f;
+  double d;
+};
+
+long int check_struct_type(int first, ...) {
+  va_list vlist;
+  va_start(vlist, first);
+  __llvm_libc::internal::ArgList args(vlist);
+  va_end(vlist);
+
+  S s = args.next_var<S>();
+  int last = args.next_var<int>();
+  return s.c + s.s + s.i + s.l + s.f + s.d + last;
+}
+
+TEST(LlvmLibcArgListTest, TestStructTypes) {
+  S s{'\x1', 1, 1, 1l, 1.0f, 1.0};
+  ASSERT_EQ(check_struct_type(0, s, 1), 7l);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158867.553544.patch
Type: text/x-patch
Size: 2035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230825/defb1eef/attachment.bin>


More information about the libc-commits mailing list