-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testable Device-Side Assertion Failures on CPUs (#605)
* add dummy error code * embed into a struct, and change taichi_assert_format * change taichi_assert_runtime (not working now) * move ErrorMessage to LLVMRuntime * let error_code == 1 when assertion fails for further extension * add tests * fixed print_traceback overflow on OS X (#610) * add dummy error code * embed into a struct, and change taichi_assert_format * change taichi_assert_runtime (not working now) * move ErrorMessage to LLVMRuntime * let error_code == 1 when assertion fails for further extension * add tests Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
- Loading branch information
1 parent
a4b557b
commit 97e1b50
Showing
6 changed files
with
108 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,64 @@ | ||
import taichi as ti | ||
|
||
@ti.all_archs | ||
def test_assert(): | ||
return | ||
|
||
@ti.must_throw(RuntimeError) | ||
def test_assert_minimal(): | ||
ti.init(debug=True) | ||
ti.set_gdb_trigger(False) | ||
|
||
@ti.kernel | ||
def func(): | ||
assert 0 | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(RuntimeError) | ||
def test_assert_basic(): | ||
ti.init(debug=True) | ||
ti.set_gdb_trigger(False) | ||
|
||
@ti.kernel | ||
def func(): | ||
x = 20 | ||
assert 10 <= x < 20 | ||
|
||
func() | ||
|
||
|
||
@ti.all_archs | ||
def test_assert_ok(): | ||
ti.init(debug=True) | ||
ti.set_gdb_trigger(False) | ||
|
||
@ti.kernel | ||
def func(): | ||
x = 20 | ||
assert 10 <= x <= 20 | ||
|
||
func() | ||
|
||
|
||
@ti.must_throw(RuntimeError) | ||
def test_out_of_bound(): | ||
ti.init(debug=True) | ||
ti.set_gdb_trigger(False) | ||
x = ti.var(ti.i32, shape=(8, 16)) | ||
|
||
@ti.kernel | ||
def func(): | ||
x[3, 16] = 1 | ||
|
||
func() | ||
|
||
|
||
@ti.all_archs | ||
def test_not_out_of_bound(): | ||
ti.init(debug=True) | ||
ti.set_gdb_trigger(False) | ||
x = ti.var(ti.i32, shape=(8, 16)) | ||
|
||
@ti.kernel | ||
def func(): | ||
x[7, 15] = 1 | ||
|
||
func() |