Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Move weak_object tests from unittests to E2E #1678

Open
wants to merge 1 commit into
base: intel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions SYCL/WeakObject/weak_object_copy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of the copy ctor and assignment operator for
// `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckCopy {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};

sycl::ext::oneapi::weak_object<SyclObjT> WeakObjCopyCtor{WeakObj};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjCopyAssign = WeakObj;

assert(!WeakObjCopyCtor.expired());
assert(!WeakObjCopyAssign.expired());

assert(WeakObjCopyCtor.lock() == Obj);
assert(WeakObjCopyAssign.lock() == Obj);
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckCopy>(Q);
return 0;
}
24 changes: 24 additions & 0 deletions SYCL/WeakObject/weak_object_expired.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of `expired()` for `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckExpired {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> NullWeakObj;

assert(!WeakObj.expired());
assert(NullWeakObj.expired());
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckExpired>(Q);
return 0;
}
32 changes: 32 additions & 0 deletions SYCL/WeakObject/weak_object_lock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of `lock()` for `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckLock {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> NullWeakObj;

SyclObjT LObj = WeakObj.lock();
assert(LObj == Obj);

try {
SyclObjT LNull = NullWeakObj.lock();
assert(false && "Locking empty weak object did not throw.");
} catch (sycl::exception &E) {
assert(E.code() == sycl::make_error_code(sycl::errc::invalid) &&
"Unexpected thrown error code.");
}
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckLock>(Q);
return 0;
}
33 changes: 33 additions & 0 deletions SYCL/WeakObject/weak_object_move.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of the copy ctor and assignment operator for
// `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckMove {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj1{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj2{Obj};

sycl::ext::oneapi::weak_object<SyclObjT> WeakObjMoveCtor{
std::move(WeakObj1)};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjMoveAssign =
std::move(WeakObj2);

assert(!WeakObjMoveCtor.expired());
assert(!WeakObjMoveAssign.expired());

assert(WeakObjMoveCtor.lock() == Obj);
assert(WeakObjMoveAssign.lock() == Obj);
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckMove>(Q);
return 0;
}
54 changes: 54 additions & 0 deletions SYCL/WeakObject/weak_object_owner_before.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of owner_before semantics for `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckOwnerBefore {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> NullWeakObj;

assert((WeakObj.owner_before(NullWeakObj) &&
!NullWeakObj.owner_before(WeakObj)) ||
(NullWeakObj.owner_before(WeakObj) &&
!WeakObj.owner_before(NullWeakObj)));

assert(!WeakObj.owner_before(Obj));
assert(!Obj.ext_oneapi_owner_before(WeakObj));

assert(!Obj.ext_oneapi_owner_before(Obj));
}
};

template <typename SyclObjT> struct WeakObjectCheckOwnerBeforeMulti {
void operator()(SyclObjT Obj1, SyclObjT Obj2) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj1{Obj1};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj2{Obj2};

assert(
(WeakObj1.owner_before(WeakObj2) && !WeakObj2.owner_before(WeakObj1)) ||
(WeakObj2.owner_before(WeakObj1) && !WeakObj1.owner_before(WeakObj2)));

assert(!WeakObj1.owner_before(Obj1));
assert(!Obj1.ext_oneapi_owner_before(WeakObj1));

assert(!WeakObj2.owner_before(Obj2));
assert(!Obj2.ext_oneapi_owner_before(WeakObj2));

assert((Obj1.ext_oneapi_owner_before(Obj2) &&
!Obj2.ext_oneapi_owner_before(Obj1)) ||
(Obj2.ext_oneapi_owner_before(Obj1) &&
!Obj1.ext_oneapi_owner_before(Obj2)));
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckOwnerBefore>(Q);
runTestMulti<WeakObjectCheckOwnerBeforeMulti>(Q);
return 0;
}
98 changes: 98 additions & 0 deletions SYCL/WeakObject/weak_object_owner_less.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of owner_less semantics for `weak_object`.

#include "weak_object_utils.hpp"

#include <map>

template <typename SyclObjT> struct WeakObjectCheckOwnerLess {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> NullWeakObj;
sycl::ext::oneapi::owner_less<SyclObjT> Comparator;

assert((Comparator(WeakObj, NullWeakObj) &&
!Comparator(NullWeakObj, WeakObj)) ||
(Comparator(NullWeakObj, WeakObj) &&
!Comparator(WeakObj, NullWeakObj)));

assert(!Comparator(WeakObj, Obj));
assert(!Comparator(Obj, WeakObj));
}
};

template <typename SyclObjT> struct WeakObjectCheckOwnerLessMulti {
void operator()(SyclObjT Obj1, SyclObjT Obj2) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj1{Obj1};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj2{Obj2};
sycl::ext::oneapi::owner_less<SyclObjT> Comparator;

assert(
(Comparator(WeakObj1, WeakObj2) && !Comparator(WeakObj2, WeakObj1)) ||
(Comparator(WeakObj2, WeakObj1) && !Comparator(WeakObj1, WeakObj2)));

assert(!Comparator(WeakObj1, Obj1));
assert(!Comparator(Obj1, WeakObj1));

assert(!Comparator(WeakObj2, Obj2));
assert(!Comparator(Obj2, WeakObj2));
}
};

template <typename SyclObjT> struct WeakObjectCheckOwnerLessMap {
void operator()(SyclObjT Obj1, SyclObjT Obj2) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj1{Obj1};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj2{Obj2};

std::map<sycl::ext::oneapi::weak_object<SyclObjT>, int,
sycl::ext::oneapi::owner_less<SyclObjT>>
Map;
Map[WeakObj1] = 1;
Map[WeakObj2] = 2;

assert(Map.size() == (size_t)2);
assert(Map[WeakObj1] == 1);
assert(Map[WeakObj2] == 2);
assert(Map[Obj1] == 1);
assert(Map[Obj2] == 2);

Map[WeakObj1] = 2;
Map[WeakObj2] = 3;

assert(Map.size() == (size_t)2);
assert(Map[WeakObj1] == 2);
assert(Map[WeakObj2] == 3);
assert(Map[Obj1] == 2);
assert(Map[Obj2] == 3);

Map[Obj1] = 5;
Map[Obj2] = 6;

assert(Map.size() == (size_t)2);
assert(Map[WeakObj1] == 5);
assert(Map[WeakObj2] == 6);
assert(Map[Obj1] == 5);
assert(Map[Obj2] == 6);

Map[sycl::ext::oneapi::weak_object<SyclObjT>{Obj1}] = 10;
Map[sycl::ext::oneapi::weak_object<SyclObjT>{Obj2}] = 13;

assert(Map.size() == (size_t)2);
assert(Map[WeakObj1] == 10);
assert(Map[WeakObj2] == 13);
assert(Map[Obj1] == 10);
assert(Map[Obj2] == 13);
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckOwnerLess>(Q);
runTestMulti<WeakObjectCheckOwnerLessMulti>(Q);
runTestMulti<WeakObjectCheckOwnerLessMap>(Q);
return 0;
}
37 changes: 37 additions & 0 deletions SYCL/WeakObject/weak_object_reset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of `reset()` for `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckReset {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> NullWeakObj;

WeakObj.reset();
assert(WeakObj.expired());
assert(!WeakObj.owner_before(NullWeakObj));
assert(!NullWeakObj.owner_before(WeakObj));

std::optional<SyclObjT> TLObj = WeakObj.try_lock();
assert(!TLObj.has_value());

try {
SyclObjT LObj = WeakObj.lock();
assert(false && "Locking reset weak object did not throw.");
} catch (sycl::exception &E) {
assert(E.code() == sycl::make_error_code(sycl::errc::invalid) &&
"Unexpected thrown error code.");
}
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckReset>(Q);
return 0;
}
29 changes: 29 additions & 0 deletions SYCL/WeakObject/weak_object_try_lock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test checks the behavior of `try_lock()` for `weak_object`.

#include "weak_object_utils.hpp"

template <typename SyclObjT> struct WeakObjectCheckTryLock {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> NullWeakObj;

std::optional<SyclObjT> TLObj = WeakObj.try_lock();
std::optional<SyclObjT> TLNull = NullWeakObj.try_lock();

assert(TLObj.has_value());
assert(!TLNull.has_value());

assert(TLObj.value() == Obj);
}
};

int main() {
sycl::queue Q;
runTest<WeakObjectCheckTryLock>(Q);
return 0;
}
Loading