Skip to content

Commit

Permalink
Use googletest to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed Feb 15, 2024
1 parent 3617681 commit 6417880
Show file tree
Hide file tree
Showing 76 changed files with 322 additions and 653 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Create sysroot
run: |
sudo debootstrap --arch=riscv64 --verbose --include=fakeroot,symlinks --resolve-deps --variant=minbase --components=main,universe focal sysroot
sudo debootstrap --arch=riscv64 --verbose --include=fakeroot,symlinks,googletest --resolve-deps --variant=minbase --components=main,universe jammy sysroot
# Remove unused files to minimize cache
sudo chroot sysroot symlinks -cr .
sudo chown ${USER} -R sysroot
Expand All @@ -72,6 +72,7 @@ jobs:
- name: Build
shell: bash -ex -o pipefail {0}
run: |
export QEMU_LD_PREFIX=$(pwd)/sysroot
cmake -S . -B build -GNinja \
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
-DCMAKE_TOOLCHAIN_FILE=$(pwd)/CMakeToolchain/riscv.clang.cross.cmake \
Expand Down Expand Up @@ -115,11 +116,6 @@ jobs:
path: sysroot
key: sysroot-${{ hashFiles('./.github/workflows/build_and_test.yml') }}

- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install -y -qq libgmp-dev libmpfr-dev
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -133,12 +129,10 @@ jobs:
env:
CTEST_OUTPUT_ON_FAILURE: "TRUE"
run: |
if [[ -n "${{ matrix.qemu_cpu }}" ]]; then
export QEMU_CPU="${{ matrix.qemu_cpu }}"
fi
export QEMU_LD_PREFIX=$(pwd)/sysroot
export QEMU_CPU="${{ matrix.qemu_cpu }}"
cd build
ctest -j$(nproc)
ctest -j$(nproc) --output-on-failure
- name: Upload test-${{ strategy.job-index }} artifacts
uses: actions/upload-artifact@v4
Expand Down
183 changes: 93 additions & 90 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,110 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.22)
project(veclibm C)
project(veclibm C CXX)

# Adds a test target
include(CTest)
option(VECLIBM_BUILD_TESTS "Build tests" ON)

if (VECLIBM_BUILD_TESTS)
# Adds a test target
include(CTest)

include(GoogleTest)

set(GTest_ROOT ${CMAKE_SYSROOT}/usr/src/googletest/googletest)
add_subdirectory(${GTest_ROOT} "${CMAKE_CURRENT_BINARY_DIR}/googletest" EXCLUDE_FROM_ALL)
endif()

set(PROJECT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_acosD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_acosDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_acospiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_acospiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_asinD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_asinDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_asinpiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_asinpiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atanD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atanDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atanpiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atanpiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atan2D.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atan2DI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atan2piD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atan2piDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_acoshD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_acoshDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_asinhD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_asinhDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atanhD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_atanhDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cbrtD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cbrtDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cdfnormD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cdfnormDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_erfD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_erfDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_erfcD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_erfcDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_expD_tbl.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_expD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_expDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_exp2D.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_exp2DI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_exp10D.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_exp10DI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_expm1D.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_expm1DI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_logD_tbl.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_logD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_logDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_log2D.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_log2DI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_log10D.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_log10DI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_log1pD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_log1pDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_powD_tbl.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_powD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_powDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_2ovpi_tbl.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cosD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cosDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cospiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_cospiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sinD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sinDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sinpiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sinpiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sincosD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sincosDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sincospiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sincospiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_tanD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_tanDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_tanpiD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_tanpiDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_coshD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_coshDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sinhD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_sinhDI.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_tanhD.c
${CMAKE_CURRENT_SOURCE_DIR}/src/rvvlm_tanhDI.c
src/rvvlm_acosD.c
src/rvvlm_acosDI.c
src/rvvlm_acospiD.c
src/rvvlm_acospiDI.c
src/rvvlm_asinD.c
src/rvvlm_asinDI.c
src/rvvlm_asinpiD.c
src/rvvlm_asinpiDI.c
src/rvvlm_atanD.c
src/rvvlm_atanDI.c
src/rvvlm_atanpiD.c
src/rvvlm_atanpiDI.c
src/rvvlm_atan2D.c
src/rvvlm_atan2DI.c
src/rvvlm_atan2piD.c
src/rvvlm_atan2piDI.c
src/rvvlm_acoshD.c
src/rvvlm_acoshDI.c
src/rvvlm_asinhD.c
src/rvvlm_asinhDI.c
src/rvvlm_atanhD.c
src/rvvlm_atanhDI.c
src/rvvlm_cbrtD.c
src/rvvlm_cbrtDI.c
src/rvvlm_cdfnormD.c
src/rvvlm_cdfnormDI.c
src/rvvlm_erfD.c
src/rvvlm_erfDI.c
src/rvvlm_erfcD.c
src/rvvlm_erfcDI.c
src/rvvlm_expD_tbl.c
src/rvvlm_expD.c
src/rvvlm_expDI.c
src/rvvlm_exp2D.c
src/rvvlm_exp2DI.c
src/rvvlm_exp10D.c
src/rvvlm_exp10DI.c
src/rvvlm_expm1D.c
src/rvvlm_expm1DI.c
src/rvvlm_logD_tbl.c
src/rvvlm_logD.c
src/rvvlm_logDI.c
src/rvvlm_log2D.c
src/rvvlm_log2DI.c
src/rvvlm_log10D.c
src/rvvlm_log10DI.c
src/rvvlm_log1pD.c
src/rvvlm_log1pDI.c
src/rvvlm_powD_tbl.c
src/rvvlm_powD.c
src/rvvlm_powDI.c
src/rvvlm_2ovpi_tbl.c
src/rvvlm_cosD.c
src/rvvlm_cosDI.c
src/rvvlm_cospiD.c
src/rvvlm_cospiDI.c
src/rvvlm_sinD.c
src/rvvlm_sinDI.c
src/rvvlm_sinpiD.c
src/rvvlm_sinpiDI.c
src/rvvlm_sincosD.c
src/rvvlm_sincosDI.c
src/rvvlm_sincospiD.c
src/rvvlm_sincospiDI.c
src/rvvlm_tanD.c
src/rvvlm_tanDI.c
src/rvvlm_tanpiD.c
src/rvvlm_tanpiDI.c
src/rvvlm_coshD.c
src/rvvlm_coshDI.c
src/rvvlm_sinhD.c
src/rvvlm_sinhDI.c
src/rvvlm_tanhD.c
src/rvvlm_tanhDI.c
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(vecm
${PROJECT_SOURCES}
)

target_include_directories(vecm
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_compile_options(vecm
PUBLIC
$<$<COMPILE_LANGUAGE:C>:-std=c11>
)

set(CMAKE_BUILD_TYPE "Release"
CACHE STRING
"The type of build to perform. Choose from [Release, Debug, RelWithDebInfo]"
)

# Add tests as well. Split this out into its own file. This means that the tests
# are in a 'test' subdirectory of the current build directory
add_subdirectory(test)
if (VECLIBM_BUILD_TESTS)
# Add tests as well. Split this out into its own file. This means that the tests
# are in a 'test' subdirectory of the current build directory
add_subdirectory(test)
endif()
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,44 @@ We sometimes provide multiple implementations for a single function as each may

A simple test program test_funcs.c uses the existing long double function as a reference. At this point we only aim to develop double-precision (and perhaps single-precision) functions, thus testing their accuracy with long-double function is deemed sufficient.

# building & testing

It is being built and tested on GitHub Actions. See `.github/workflows/build_and_test.yml` for reference.

## cross-compiling

You first need a sysroot with enough dependencies:
```
sudo debootstrap --arch=riscv64 --verbose --include=fakeroot,symlinks,googletest --resolve-deps --variant=minbase --components=main,universe jammy sysroot
```

Then, assuming you've the necessary toolchains installed (refer to the [GHA workflow file](https://github.com/rivosinc/veclibm/blob/main/.github/workflows/build_and_test.yml) for versions and steps), you can run cmake:
```
cmake -S . -B build -DCMAKE_INSTALL_PREFIX="$(pwd)/install" -DCMAKE_TOOLCHAIN_FILE=$(pwd)/CMakeToolchain/riscv.clang.cross.cmake -DCMAKE_SYSROOT=$(pwd)/sysroot
```

Finally, you can build with:
```
cmake --build build
```

This will build both the `libvecm.so` library as well as the tests.

## testing

_The following steps take the assumption you're cross-compiling and using QEMU to execute the riscv64 binary on your host machine._

The easiest is to simply run `test/test_veclibm`:
```
QEMU_CPU=rv64,zba=true,zbb=true,zbs=true,v=true QEMU_LD_PREFIX=$(pwd)/sysroot build/test/test_veclibm
```

To run only a specific test, for example the `erf.test`, you can filter with:
```
QEMU_CPU=rv64,zba=true,zbb=true,zbs=true,v=true QEMU_LD_PREFIX=$(pwd)/sysroot build/test/test_veclibm --gtest_filter=erf.test
```

Refer to the help for more options:
```
QEMU_CPU=rv64,zba=true,zbb=true,zbs=true,v=true QEMU_LD_PREFIX=$(pwd)/sysroot build/test/test_veclibm --help
```
44 changes: 23 additions & 21 deletions include/rvvlm_fp.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <assert.h>

#ifndef _GNU_SOURCE
Expand Down Expand Up @@ -189,31 +191,31 @@ static_assert(false, "API_SIGNATURE ill or undefined" __FILE__);
#define VMVU_VX MAKE_FUNC(__riscv_vmv_v_x_u)
#define VFMV_VF MAKE_FUNC(__riscv_vfmv_v_f_f)

const INT int_Zero = 0;
const UINT uint_Zero = 0;
static const INT int_Zero = 0;
static const UINT uint_Zero = 0;

#if (BIT_WIDTH == 64)
#define EXP_BIAS 1023
#define MAN_LEN 52
const uint64_t class_sNaN = 0x100;
const uint64_t class_qNaN = 0x200;
const uint64_t class_NaN = 0x300;
const uint64_t class_negInf = 0x1;
const uint64_t class_posInf = 0x80;
const uint64_t class_Inf = 0x81;
const uint64_t class_negZero = 0x8;
const uint64_t class_posZero = 0x10;
const uint64_t class_Zero = 0x18;
const uint64_t class_negDenorm = 0x4;
const uint64_t class_posDenorm = 0x20;
const uint64_t class_Denorm = 0x24;
const uint64_t class_negNormal = 0x2;
const uint64_t class_posNormal = 0x40;
const uint64_t class_Normal = 0x42;
const uint64_t class_negative = 0x7;
const uint64_t class_positive = 0xe0;
const uint64_t class_finite_neg = 0x06;
const uint64_t class_finite_pos = 0x60;
static const uint64_t class_sNaN = 0x100;
static const uint64_t class_qNaN = 0x200;
static const uint64_t class_NaN = 0x300;
static const uint64_t class_negInf = 0x1;
static const uint64_t class_posInf = 0x80;
static const uint64_t class_Inf = 0x81;
static const uint64_t class_negZero = 0x8;
static const uint64_t class_posZero = 0x10;
static const uint64_t class_Zero = 0x18;
static const uint64_t class_negDenorm = 0x4;
static const uint64_t class_posDenorm = 0x20;
static const uint64_t class_Denorm = 0x24;
static const uint64_t class_negNormal = 0x2;
static const uint64_t class_posNormal = 0x40;
static const uint64_t class_Normal = 0x42;
static const uint64_t class_negative = 0x7;
static const uint64_t class_positive = 0xe0;
static const uint64_t class_finite_neg = 0x06;
static const uint64_t class_finite_pos = 0x60;

static const double fp_sNaN = __builtin_nans("");
static const double fp_qNaN = __builtin_nan("");
Expand Down
Loading

0 comments on commit 6417880

Please sign in to comment.