Commit Graph

59 Commits

Author SHA1 Message Date
Guillaume Chatelet
b555912e70 [libc] Better IntegerToString API
This patch is an alternative to D155902. It provides the following benefits:
 - No buffer manual allocation and error handling for the general case
 - More flexible API : width specifier, sign and prefix handling
 - Simpler code

The more flexible API removes the need for manually tweaking the buffer afterwards, and so prevents relying on implementation details of IntegerToString.

Reviewed By: michaelrj, jhuber6

Differential Revision: https://reviews.llvm.org/D156981
2023-08-09 07:33:29 +00:00
Guillaume Chatelet
98ab87f44d Revert "[libc] Better IntegerToString API"
This reverts commit 910cc05aae.
2023-08-08 20:52:50 +00:00
Guillaume Chatelet
910cc05aae [libc] Better IntegerToString API
This patch is an alternative to D155902. It provides the following benefits:
 - No buffer manual allocation and error handling for the general case
 - More flexible API : width specifier, sign and prefix handling
 - Simpler code

The more flexible API removes the need for manually tweaking the buffer afterwards, and so prevents relying on implementation details of IntegerToString.

Reviewed By: michaelrj, jhuber6

Differential Revision: https://reviews.llvm.org/D156981
2023-08-08 20:39:13 +00:00
Roland McGrath
cd328c10ad [libc] Use ASSERT_DEATH for EXPECT_DEATH under Fuchsia zxtest
The Fuchsia zxtest library has ASSERT_DEATH but not EXPECT_DEATH.
The latter may be added in the future, but for now just use the
former as substitute.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D156940
2023-08-02 17:57:44 -07:00
Joseph Huber
515bd1c9b8 [libc][Obvious] Fix timing on AMDGPU not being initialized
Summary:
Reviewer requested that this routine not be a macro, however that means
that it was not being intitialized as the static initializer was done
before the memcpy from the device. Fix this so we can get timing
information.
2023-07-05 16:08:37 -05:00
Joseph Huber
80504b06ad [libc][Obvious] Fix bad macro check on NVPTX tests
Summary:
I forgot to add the `defined()` check on NVPTX.
2023-07-05 15:54:12 -05:00
Joseph Huber
5db39796bf [libc] Support timing information in libc tests
This patch adds the necessary support to provide timing information in
`libc` tests. This is useful for determining which tests look what
amount of time. We also can use this as a test basis for providing more
fine-grained timing when implementing things on the GPU.

The main difficulty with this is the fact that the AMDGPU fixed
frequency clock operates at an unknown frequency. We need to read this
on a per-card basis from the driver and then copy it in. NVPTX on the
other hand has a fixed clock at a resolution of 1ns. I have also
increased the resolution of the print-outs as the majority of these are
below a millisecond for me.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D154446
2023-07-05 14:27:08 -05:00
Joseph Huber
485e2de6d5 [libc][nfc] Silence two warnings in tests
These currently give warnings for unused variables or a default case
where everything is covered.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D153137
2023-06-16 12:52:06 -05:00
Tue Ly
055be3c30c [libc] Enable hermetic floating point tests again.
Fixing an issue with LLVM libc's fenv.h defined rounding mode macros
differently from system libc, making get_round() return different values from
fegetround().  Also letting math tests to skip rounding modes that cannot be
set.  This should allow math tests to be run on platforms in which fenv.h is not
implemented yet.

This allows us to re-enable hermatic floating point tests in
https://reviews.llvm.org/D151123 and reverting https://reviews.llvm.org/D152742.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D152873
2023-06-14 10:53:35 -04:00
Guillaume Chatelet
9902fc8dad [libc] Enable custom logging in LibcTest
This patch mimics the behavior of Google Test and allow users to log custom messages after all flavors of ASSERT_ / EXPECT_.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D152630
2023-06-14 13:37:50 +00:00
Guillaume Chatelet
bdb07c98c4 Revert D152630 "[libc] Enable custom logging in LibcTest"
Failing buildbot https://lab.llvm.org/buildbot/#/builders/73/builds/49707
This reverts commit 9a7b4c9348.
2023-06-14 10:31:49 +00:00
Guillaume Chatelet
9a7b4c9348 [libc] Enable custom logging in LibcTest
This patch mimics the behavior of Google Test and allow users to log custom messages after all flavors of ASSERT_ / EXPECT_.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D152630
2023-06-14 10:26:18 +00:00
Tue Ly
1557256ab0 [libc] Add Int<> type and fix (U)Int<128> compatibility issues.
Add Int<> and Int128 types to replace the usage of __int128_t in math
functions.  Clean up to make sure that (U)Int128 and __(u)int128_t are
interchangeable in the code base.

Reviewed By: sivachandra, mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D152459
2023-06-13 09:40:48 -04:00
Guillaume Chatelet
8e44b849da [libc][NFC] Introduce a Location object for consistent failure logging
This is just an implementation detail.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D152532
2023-06-10 06:58:15 +00:00
Guillaume Chatelet
0fd0b74289 [libc][NFC] Clean up matchers namespace
This is a follow up to https://reviews.llvm.org/D152503

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D152533
2023-06-10 06:55:16 +00:00
Tue Ly
37458f6693 [libc][math] Move str method from FPBits class to testing utils.
str method of FPBits class is only used for pretty printing its objects
in tests.  It brings cpp::string dependency to FPBits class, which is not ideal
for embedded use case.  We move str method to a free function in test utils and
remove this dependency of FPBits class.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D152607
2023-06-10 02:50:58 -04:00
Guillaume Chatelet
fd2c74c8ed [libc][NFC] Simplify LibcTest and trim down string allocations
This is a bit of cleanup before working on logging via stream operator (i.e., `EXPECT_XXX() << ...`).

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D152503
2023-06-09 09:36:18 +00:00
Guillaume Chatelet
c76a3e795e [libc][NFC] Fixing various typos 2023-05-31 12:11:09 +00:00
Siva Chandra Reddy
4f1fe19df3 [libc] Make ErrnoSetterMatcher handle logging floating point values.
Along the way, couple of additional things have been done:

1. Move `ErrnoSetterMatcher.h` to `test/UnitTest` as all other matchers live
   there now.
2. `ErrnoSetterMatcher` ignores matching `errno` on GPUs.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D151129
2023-05-26 06:24:51 +00:00
Joseph Huber
4311246a3a Revert "[libc] Enable hermetic floating point tests"
This passed locally but unfortauntely it seems some tests are not ready
to be made hermetic. Revert for now until we can investigate
specifically which tests are failing and mark those as `UNIT_TEST_ONLY`.

This reverts commit 417ea79e79.
2023-05-25 19:15:02 -05:00
Joseph Huber
417ea79e79 [libc] Enable hermetic floating point tests
This patch enables us to run the floating point tests as hermetic.
Importantly we now use the internal versions of the `fesetround` and
`fegetround` functions.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D151123
2023-05-25 19:08:44 -05:00
Guillaume Chatelet
04e066df5e [libc] Display unit test runtime for hosted environments
With more tests added to LLVM libc each week we want to keep track of unittest's runtime, especially for low end build bots.

Top offender can be tracked with a bit of scripting (spoiler alert, mem function sweep tests are in the top ones)
```
ninja check-libc | grep "ms)" | awk '{print $(NF-1),$0}' | sort -nr | cut -f2- -d' '
```

Unfortunately this doesn't work for hermetic tests since `clock` is unavailable.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D151097
2023-05-23 09:23:12 +00:00
Siva Chandra Reddy
00bd8e9011 [libc] Add a str() method to FPBits which returns a string representation.
Unit tests for the str() method have also been added.

Previously, a separate test only helper function was being used by the
test matchers which has regressed over many cleanups. Moreover, being a
test only utility, it was not tested separately (and hence the
regression).

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D150906
2023-05-19 06:20:41 +00:00
Siva Chandra Reddy
b095aa3f9a [libc] Use the new wide integer to hex string facility in LibcTest.
The old code, which has regressed over many cleanups, has been replaced
with the new wide integer to hex string facility.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D150901
2023-05-18 20:48:21 +00:00
Joseph Huber
9698265e44 [libc] Add comparison specialization for cpp:string type
We compare this type in the string_test. It had no specialization here
so it could cause linker errors. This patch simply extends the interface
to support it.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D150904
2023-05-18 15:24:00 -05:00
Siva Chandra Reddy
d3b3304222 [libc] Add a functioning realloc for hermetic tests.
Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D150846
2023-05-18 16:51:18 +00:00
Siva Chandra Reddy
4dc205f016 [libc] Add a convenience CMake function add_unittest_framework_library.
This function is used to add unit test and hermetic test framework libraries.
It avoids the duplicated code to add compile options to each every test
framework libraries.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D150727
2023-05-17 21:13:50 +00:00
Siva Chandra Reddy
a5d98be515 [libc][Obvious] Bump hermetic alloc space to 64KB.
Few hermetic tests are failing as they are running out of memory.

Differential Revision: https://reviews.llvm.org/D150724
2023-05-16 21:23:16 +00:00
Siva Chandra Reddy
9d877369b7 [libc] Remove *TestMain libraries and combine them with the main test libraries.
There are not tests currently which use the main test framework but not
the `main` function from LibcTestMain.cpp. So, this change essentially
simplifies by merging the *TestMain libraries with the main test
libraries.

Reviewed By: michaelrj, jhuber6

Differential Revision: https://reviews.llvm.org/D150698
2023-05-16 20:55:36 +00:00
Joseph Huber
9417d9fc38 [libc] Make the bump pointer explicitly return null on buffer oveerrun
We use a simple bump ptr in the `libc` tests. If we run out of data we
can currently return other static memory and have weird failure cases.
We should fail more explicitly here by returning a null pointer instead.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D150529
2023-05-15 06:15:52 -05:00
Joseph Huber
cbcf55d32b [libc] Maintain proper alignment for the hermetic tests malloc
We use a bump pointer to implement malloc for the hermetic tests.
Currently, we bump the pointer up by any amount. This means that calling
`malloc(1)` will misalign the buffer so any following `malloc(8)`
accesses will not be aligned. This causes problems in architectures
which require alignment.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149863
2023-05-04 13:22:20 -05:00
Joseph Huber
f4002c1415 [libc] Enable running libc unit tests on NVPTX
The previous patches added the necessary support for global constructors
used to register tests. This patch enables the NVPTX target to build
and run the unit tests on the GPU. Currently this only tests the ctype
tests, but adding more should be straightforward from here on.

This ran all the ctest unit tests when run on an sm_70.

Depends on D149517 D149527

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149532
2023-05-04 08:36:29 -05:00
Joseph Huber
632fa3798c [libc] Enable running libc unit tests on AMDGPU
The previous patches added the necessary support for global constructors
used to register tests. This patch enables the AMDGPU target to build
and run the unit tests on the GPU. Currently this only tests the `ctype`
tests, but adding more should be straightforward from here on.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149517
2023-05-04 06:32:52 -05:00
Joseph Huber
9e6946c252 [libc] Revert rounding mode changes for hermetic tests
We got rid of the rounding mode here so that the hermetic tests wouldn't
depend on the system fenv.h. But this seemed to cause some bots to
break. Getting rid of this change for now, it should be fine for the CPU
builds.

Differential Revision: https://reviews.llvm.org/D149767
2023-05-03 11:51:42 -05:00
Joseph Huber
c00f8f1314 [libc] Split out FPExceptMatcher from the FP utils
The FPEceptMatcher.cpp file uses system utilities and includes C++
libraries. This patch pulls it out of the main `FPTestHelpers` target so
we can exclude it from hermetic only tests.

Depends on D149705

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149745
2023-05-03 11:37:49 -05:00
Joseph Huber
e2f8f77e15 [libc] Enable the 'stdlib' unit tests to be hermetic
This changes the `stdlib` tests to the new `add_libc_test` framework.
This applies to all but the exit tests.

Depends on D149691

Reviewed By: sivachandra, michaelrj

Differential Revision: https://reviews.llvm.org/D149705
2023-05-03 11:37:48 -05:00
Joseph Huber
9a20e024a2 [libc] Enable the 'string' unit tests to be hermetic
This changes over the string unit tests to the new `add_libc_test`
framework. The one test that wasn't changes was the memory utils because
it overran the static buffer used for the hermetic test's bump pointer.

Depends on D149656

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149662
2023-05-02 18:51:11 -05:00
Joseph Huber
2353b52eae [libc] Fix some missing features from the hermetic test support
This patch addresses some of the flags and features that are currently
missing from the hermetic test support. This mostly just fixes the
`add_libc_test` option failing to find a few dependencies or missing
arguments from the previous unit test support.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D149629
2023-05-02 09:40:24 -05:00
Siva Chandra Reddy
127487aa4d [libc] Add a new target named LibcHermeticTestMain.
The existing LibcTestMain has been renamed to LibcUnitTestMain.
Hermetic tests are linked to LibcHermeticTestMain and unit tests are
linked to LibcUnitTestMain.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D149303
2023-04-26 23:10:16 +00:00
Joseph Huber
5c9629a714 [libc][fix] Also remove the headers for the other flags
Summary:
This patch makes this only apply to the GPU build. This should be
handled more intelligently in the future so it's common between all of t
hem.
2023-04-26 17:08:18 -05:00
Joseph Huber
cb1facf48c [libc][fix] Only add the hermetic test flags in GPU mode
Summary:
This is a little broken, what we really need is a separate target to use
with the hermetic tests, but this is a stop-gap to get the bots green
again.
2023-04-26 16:58:43 -05:00
Joseph Huber
fb5a3bc8f8 [libc] Add path to include generated headers for hermetic tests
The generated header files live in the build directory's include path.
When targeting a hermetic build we want to make sure we only use headers
generated by the project itself if availible.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149216
2023-04-26 16:52:29 -05:00
Michael Jones
d94fe97280 [libc][bazel] add file printf targets and support
This patch adds targets for printf and fprintf to the bazel build.
Additionally, it adds support for the build system to specify where
files should be written for testing purposes. This was necessary to
enable the fprintf test under bazel.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D147008
2023-04-26 14:30:48 -07:00
Siva Chandra Reddy
1e8960c7a5 [libc] Add rule named add_libc_hermetic_test which adds a hermetic test.
A convenience wrapper name `add_libc_test` is also added which adds both
a unit test and a hermetic test. The ctype tests have been switched over
to use add_libc_test.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D148756
2023-04-24 22:43:59 +00:00
Siva Chandra Reddy
447d59e071 [libc][NFC] Move RoundingModeUtils to LibcFPTestHelpers.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D148602
2023-04-18 18:37:30 +00:00
Siva Chandra Reddy
e3645eadb8 [libc][NFC] Move ExecuteFunction test util to test/UnitTest.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D148611
2023-04-18 16:17:42 +00:00
Siva Chandra Reddy
dcf296b541 [libc][NFC] Remove the StreamWrapper class and use the new test logger.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D148452
2023-04-17 15:48:18 +00:00
Guillaume Chatelet
f5dcab0d89 [re-reland][libc] Adds string and TestLogger classes, use them in LibcTest
This is an implementation of https://discourse.llvm.org/t/rfc-running-libc-unit-tests-as-integration-tests/69461.

Differential Revision: https://reviews.llvm.org/D147231
2023-04-03 13:10:30 +00:00
Guillaume Chatelet
5a55dfb80c Revert D147231 "[reland][libc] Adds string and TestLogger classes, use them in LibcTest"
Build bot detected a memory leak.
This reverts commit b82d04ea4b.
2023-04-03 07:47:15 +00:00
Guillaume Chatelet
b82d04ea4b [reland][libc] Adds string and TestLogger classes, use them in LibcTest
This is an implementation of https://discourse.llvm.org/t/rfc-running-libc-unit-tests-as-integration-tests/69461.

Differential Revision: https://reviews.llvm.org/D147231
2023-04-03 07:35:37 +00:00