[libc-commits] [libc] [libc] Implement getrusage and corresponding unit tests. (PR #217684)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Tue Aug 25 13:53:23 PDT 2026
================
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for getrusage.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/sys_resource_macros.h"
+#include "hdr/types/struct_rusage.h"
+#include "src/sys/resource/getrusage.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcGetrusageTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcGetrusageTest, BasicTest) {
+ struct rusage usage = {};
+ ASSERT_THAT(LIBC_NAMESPACE::getrusage(RUSAGE_SELF, &usage), Succeeds());
+ // The number of soft page faults should be stably greater than 0.
+ ASSERT_TRUE(usage.ru_minflt > 0);
----------------
vonosmas wrote:
```suggestion
EXPECT_GT(usage.ru_minflt, 0L);
```
https://github.com/llvm/llvm-project/pull/217684
More information about the libc-commits
mailing list