Skip to content

Commit

Permalink
allow tests to run on CPU only but fail in TearDownTestSuite to avoid…
Browse files Browse the repository at this point in the history
… CI passing like that
  • Loading branch information
yshekel committed Aug 19, 2024
1 parent b811ac5 commit 9759cef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
18 changes: 8 additions & 10 deletions icicle_v3/tests/test_curve_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static inline std::string s_ref_target;
class CurveApiTest : public ::testing::Test
{
public:
static inline std::list<std::string> s_regsitered_devices;
static inline std::list<std::string> s_registered_devices;

// SetUpTestSuite/TearDownTestSuite are called once for the entire test suite
static void SetUpTestSuite()
Expand All @@ -38,18 +38,16 @@ class CurveApiTest : public ::testing::Test
#endif
icicle_load_backend_from_env_or_default();

// check targets are loaded and choose main and reference targets
auto regsitered_devices = get_registered_devices_list();
ASSERT_GE(regsitered_devices.size(), 2);

const bool is_cuda_registered = is_device_registered("CUDA");
const bool is_cpu_registered = is_device_registered("CPU");
const bool is_cpu_ref_registered = is_device_registered("CPU_REF");
// if cuda is available, want main="CUDA", ref="CPU", otherwise main="CPU", ref="CPU_REF".
if (!is_cuda_registered) { ICICLE_LOG_ERROR << "CUDA device not found. Testing CPU vs CPU"; }
s_main_target = is_cuda_registered ? "CUDA" : "CPU";
s_ref_target = is_cuda_registered ? "CPU" : "CPU_REF";
s_ref_target = "CPU";
}
static void TearDownTestSuite()
{
// make sure to fail in CI if only have one device
ICICLE_ASSERT(is_device_registered("CUDA")) << "missing CUDA backend";
}
static void TearDownTestSuite() {}

// SetUp/TearDown are called before and after each test
void SetUp() override {}
Expand Down
18 changes: 9 additions & 9 deletions icicle_v3/tests/test_device_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ using namespace icicle;
class DeviceApiTest : public ::testing::Test
{
public:
static inline std::vector<std::string> s_regsitered_devices;
static inline std::vector<std::string> s_registered_devices;
// SetUpTestSuite/TearDownTestSuite are called once for the entire test suite
static void SetUpTestSuite()
{
#ifdef BACKEND_BUILD_DIR
setenv("ICICLE_BACKEND_INSTALL_DIR", BACKEND_BUILD_DIR, 0 /*=replace*/);
#endif
icicle_load_backend_from_env_or_default();
s_regsitered_devices = get_registered_devices_list();
ASSERT_GT(s_regsitered_devices.size(), 0);
s_registered_devices = get_registered_devices_list();
ASSERT_GT(s_registered_devices.size(), 0);
}
static void TearDownTestSuite() {}

Expand All @@ -46,7 +46,7 @@ TEST_F(DeviceApiTest, MemoryCopySync)
{
int input[2] = {1, 2};

for (const auto& device_type : s_regsitered_devices) {
for (const auto& device_type : s_registered_devices) {
int output[2] = {0, 0};

icicle::Device dev = {device_type, 0};
Expand All @@ -65,7 +65,7 @@ TEST_F(DeviceApiTest, MemoryCopySync)
TEST_F(DeviceApiTest, MemoryCopyAsync)
{
int input[2] = {1, 2};
for (const auto& device_type : s_regsitered_devices) {
for (const auto& device_type : s_registered_devices) {
int output[2] = {0, 0};

icicle::Device dev = {device_type, 0};
Expand All @@ -87,7 +87,7 @@ TEST_F(DeviceApiTest, MemoryCopyAsync)
TEST_F(DeviceApiTest, CopyDeviceInference)
{
int input[2] = {1, 2};
for (const auto& device_type : s_regsitered_devices) {
for (const auto& device_type : s_registered_devices) {
int output[2] = {0, 0};

icicle::Device dev = {device_type, 0};
Expand All @@ -105,7 +105,7 @@ TEST_F(DeviceApiTest, CopyDeviceInference)
TEST_F(DeviceApiTest, Memest)
{
char expected[2] = {1, 1};
for (const auto& device_type : s_regsitered_devices) {
for (const auto& device_type : s_registered_devices) {
char host_mem[2] = {0, 0};

// icicle::Device dev = {device_type, 0};
Expand All @@ -123,7 +123,7 @@ TEST_F(DeviceApiTest, Memest)

TEST_F(DeviceApiTest, ApiError)
{
for (const auto& device_type : s_regsitered_devices) {
for (const auto& device_type : s_registered_devices) {
icicle::Device dev = {device_type, 0};
icicle_set_device(dev);
void* dev_mem = nullptr;
Expand All @@ -149,7 +149,7 @@ TEST_F(DeviceApiTest, AvailableMemory)

TEST_F(DeviceApiTest, InvalidDevice)
{
for (const auto& device_type : s_regsitered_devices) {
for (const auto& device_type : s_registered_devices) {
icicle::Device dev = {device_type, 10}; // no such device-id thus expecting an error
ASSERT_EQ(eIcicleError::INVALID_DEVICE, icicle_set_device(dev));
}
Expand Down
16 changes: 7 additions & 9 deletions icicle_v3/tests/test_field_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ class FieldApiTest : public ::testing::Test
#endif
icicle_load_backend_from_env_or_default();

// check targets are loaded and choose main and reference targets
auto regsitered_devices = get_registered_devices_list();
ASSERT_GE(regsitered_devices.size(), 2);

const bool is_cuda_registered = is_device_registered("CUDA");
const bool is_cpu_registered = is_device_registered("CPU");
const bool is_cpu_ref_registered = is_device_registered("CPU_REF");
// if cuda is available, want main="CUDA", ref="CPU", otherwise main="CPU", ref="CPU_REF".
if (!is_cuda_registered) { ICICLE_LOG_ERROR << "CUDA device not found. Testing CPU vs CPU"; }
s_main_target = is_cuda_registered ? "CUDA" : "CPU";
s_reference_target = is_cuda_registered ? "CPU" : "CPU_REF";
s_reference_target = "CPU";
}
static void TearDownTestSuite()
{
// make sure to fail in CI if only have one device
ICICLE_ASSERT(is_device_registered("CUDA")) << "missing CUDA backend";
}
static void TearDownTestSuite() {}

// SetUp/TearDown are called before and after each test
void SetUp() override {}
Expand Down

0 comments on commit 9759cef

Please sign in to comment.