-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all tests marked skip, no compilation errors
- Loading branch information
Showing
10 changed files
with
296 additions
and
376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ defmodule Zig.Nif do | |
end | ||
|
||
typespec = | ||
case nif.spec |> dbg do | ||
case nif.spec do | ||
false -> | ||
quote do | ||
end | ||
|
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,30 +1,33 @@ | ||
defmodule ZiglerTest.Raw.ZigCallTest do | ||
use ZiglerTest.IntegrationCase, async: true | ||
|
||
use Zig, | ||
otp_app: :zigler | ||
@moduletag :raw | ||
test "restore" | ||
|
||
# Note "raw" calls can't be called in managed threaded or yielding mode. | ||
# TODO: put warnings on this | ||
|
||
~Z""" | ||
const beam = @import("beam"); | ||
const e = @import("erl_nif"); | ||
pub fn raw_beam_term(env: beam.env, count: c_int, list: [*]const beam.term) beam.term { | ||
return beam.make(.{.count = count, .item = list[0]}, .{.env = env}); | ||
} | ||
pub fn raw_erl_nif_term(env: beam.env, count: c_int, list: [*]const e.erl_nif_term) beam.term { | ||
return beam.make(.{.count = count, .item = list[0]}, .{.env = env}); | ||
} | ||
""" | ||
|
||
test "raw call with beam.term" do | ||
assert %{count: 1, item: 1.0} = raw_beam_term(1.0) | ||
end | ||
|
||
test "raw call with erl_ttif_term" do | ||
assert %{count: 1, item: 1.0} = raw_erl_nif_term(1.0) | ||
end | ||
# use Zig, | ||
# otp_app: :zigler | ||
# | ||
# # Note "raw" calls can't be called in managed threaded or yielding mode. | ||
# # TODO: put warnings on this | ||
# | ||
# ~Z""" | ||
# const beam = @import("beam"); | ||
# const e = @import("erl_nif"); | ||
# | ||
# pub fn raw_beam_term(env: beam.env, count: c_int, list: [*]const beam.term) beam.term { | ||
# return beam.make(.{.count = count, .item = list[0]}, .{.env = env}); | ||
# } | ||
# | ||
# pub fn raw_erl_nif_term(env: beam.env, count: c_int, list: [*]const e.erl_nif_term) beam.term { | ||
# return beam.make(.{.count = count, .item = list[0]}, .{.env = env}); | ||
# } | ||
# """ | ||
# | ||
# test "raw call with beam.term" do | ||
# assert %{count: 1, item: 1.0} = raw_beam_term(1.0) | ||
# end | ||
# | ||
# test "raw call with erl_ttif_term" do | ||
# assert %{count: 1, item: 1.0} = raw_erl_nif_term(1.0) | ||
# end | ||
end |
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,60 +1,63 @@ | ||
defmodule ZiglerTest.Resource.BasicTest do | ||
use ZiglerTest.IntegrationCase, async: true | ||
|
||
use Zig, otp_app: :zigler, resources: [:StructResource, :U64Resource] | ||
|
||
~Z""" | ||
const beam = @import("beam"); | ||
const Resource = beam.Resource; | ||
const root = @import("root"); | ||
pub const Struct = struct { | ||
payload: u64, | ||
}; | ||
pub const StructResource = Resource(Struct, root, .{}); | ||
pub const U64Resource = Resource(u64, root, .{}); | ||
pub fn new_scalar(resource: u64) U64Resource { | ||
return U64Resource.create(resource, .{}) catch unreachable; | ||
} | ||
pub fn unpack_scalar(resource: U64Resource) u64 { | ||
return resource.unpack(); | ||
} | ||
pub fn increment_scalar(resource: U64Resource) void { | ||
const to_increment = resource.unpack(); | ||
return resource.update(to_increment + 1); | ||
} | ||
pub fn new_struct(s: Struct) StructResource { | ||
return StructResource.create(s, .{}) catch unreachable; | ||
} | ||
pub fn unpack_struct(resource: StructResource) Struct { | ||
return resource.unpack(); | ||
} | ||
pub fn increment_struct(resource: StructResource) void { | ||
const to_increment_struct = resource.unpack(); | ||
return resource.update(.{.payload = to_increment_struct.payload + 1}); | ||
} | ||
""" | ||
|
||
test "basic scalar resources work" do | ||
res = new_scalar(47) | ||
assert is_reference(res) | ||
assert 47 = unpack_scalar(res) | ||
increment_scalar(res) | ||
assert 48 = unpack_scalar(res) | ||
end | ||
|
||
test "basic struct resources work" do | ||
res = new_struct(%{payload: 47}) | ||
assert is_reference(res) | ||
assert %{payload: 47} = unpack_struct(res) | ||
increment_struct(res) | ||
assert %{payload: 48} = unpack_struct(res) | ||
end | ||
@moduletag :resource | ||
test "restore" | ||
|
||
# use Zig, otp_app: :zigler, resources: [:StructResource, :U64Resource] | ||
# | ||
# ~Z""" | ||
# const beam = @import("beam"); | ||
# const Resource = beam.Resource; | ||
# const root = @import("root"); | ||
# | ||
# pub const Struct = struct { | ||
# payload: u64, | ||
# }; | ||
# | ||
# pub const StructResource = Resource(Struct, root, .{}); | ||
# pub const U64Resource = Resource(u64, root, .{}); | ||
# | ||
# pub fn new_scalar(resource: u64) U64Resource { | ||
# return U64Resource.create(resource, .{}) catch unreachable; | ||
# } | ||
# | ||
# pub fn unpack_scalar(resource: U64Resource) u64 { | ||
# return resource.unpack(); | ||
# } | ||
# | ||
# pub fn increment_scalar(resource: U64Resource) void { | ||
# const to_increment = resource.unpack(); | ||
# return resource.update(to_increment + 1); | ||
# } | ||
# | ||
# pub fn new_struct(s: Struct) StructResource { | ||
# return StructResource.create(s, .{}) catch unreachable; | ||
# } | ||
# | ||
# pub fn unpack_struct(resource: StructResource) Struct { | ||
# return resource.unpack(); | ||
# } | ||
# | ||
# pub fn increment_struct(resource: StructResource) void { | ||
# const to_increment_struct = resource.unpack(); | ||
# return resource.update(.{.payload = to_increment_struct.payload + 1}); | ||
# } | ||
# """ | ||
# | ||
# test "basic scalar resources work" do | ||
# res = new_scalar(47) | ||
# assert is_reference(res) | ||
# assert 47 = unpack_scalar(res) | ||
# increment_scalar(res) | ||
# assert 48 = unpack_scalar(res) | ||
# end | ||
# | ||
# test "basic struct resources work" do | ||
# res = new_struct(%{payload: 47}) | ||
# assert is_reference(res) | ||
# assert %{payload: 47} = unpack_struct(res) | ||
# increment_struct(res) | ||
# assert %{payload: 48} = unpack_struct(res) | ||
# end | ||
end |
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,60 +1,63 @@ | ||
defmodule ZiglerTest.Resource.CleanupTest do | ||
use ZiglerTest.IntegrationCase, async: true | ||
|
||
use Zig, | ||
otp_app: :zigler, | ||
resources: [:PidResource], | ||
nifs: [ | ||
:create_released, | ||
maybe_release: [args: [[cleanup: false], []]] | ||
] | ||
|
||
~Z""" | ||
const beam = @import("beam"); | ||
const std = @import("std"); | ||
const Resource = beam.Resource; | ||
pub const PidResource = Resource(beam.pid, @import("root"), .{.Callbacks = PidResourceCallbacks}); | ||
pub const PidResourceCallbacks = struct { | ||
pub fn dtor(pid: *beam.pid) void { | ||
_ = beam.send(pid.*, .cleaned, .{.clean = false}) catch unreachable; | ||
} | ||
}; | ||
pub fn create_released(pid: beam.pid) PidResource { | ||
const resource = PidResource.create(pid, .{}) catch unreachable; | ||
return resource; | ||
} | ||
pub fn maybe_release(resource: PidResource, release: bool) void { | ||
if (release) { | ||
resource.release(); | ||
} | ||
} | ||
""" | ||
|
||
test "a function call will keep resources, with no cleanup it doesn't release" do | ||
this = self() | ||
|
||
spawn(fn -> | ||
this | ||
|> create_released() | ||
|> maybe_release(false) | ||
end) | ||
|
||
refute_receive :cleaned, 500 | ||
end | ||
|
||
test "a function call will keep resources, you can manually release" do | ||
this = self() | ||
|
||
spawn(fn -> | ||
this | ||
|> create_released() | ||
|> maybe_release(true) | ||
end) | ||
|
||
assert_receive :cleaned, 100 | ||
end | ||
@moduletag :resource | ||
test "restore" | ||
|
||
#use Zig, | ||
# otp_app: :zigler, | ||
# resources: [:PidResource], | ||
# nifs: [ | ||
# :create_released, | ||
# maybe_release: [args: [[cleanup: false], []]] | ||
# ] | ||
# | ||
#~Z""" | ||
#const beam = @import("beam"); | ||
#const std = @import("std"); | ||
#const Resource = beam.Resource; | ||
# | ||
#pub const PidResource = Resource(beam.pid, @import("root"), .{.Callbacks = PidResourceCallbacks}); | ||
# | ||
#pub const PidResourceCallbacks = struct { | ||
# pub fn dtor(pid: *beam.pid) void { | ||
# _ = beam.send(pid.*, .cleaned, .{.clean = false}) catch unreachable; | ||
# } | ||
#}; | ||
# | ||
#pub fn create_released(pid: beam.pid) PidResource { | ||
# const resource = PidResource.create(pid, .{}) catch unreachable; | ||
# return resource; | ||
#} | ||
# | ||
#pub fn maybe_release(resource: PidResource, release: bool) void { | ||
# if (release) { | ||
# resource.release(); | ||
# } | ||
#} | ||
#""" | ||
# | ||
#test "a function call will keep resources, with no cleanup it doesn't release" do | ||
# this = self() | ||
# | ||
# spawn(fn -> | ||
# this | ||
# |> create_released() | ||
# |> maybe_release(false) | ||
# end) | ||
# | ||
# refute_receive :cleaned, 500 | ||
#end | ||
# | ||
#test "a function call will keep resources, you can manually release" do | ||
# this = self() | ||
# | ||
# spawn(fn -> | ||
# this | ||
# |> create_released() | ||
# |> maybe_release(true) | ||
# end) | ||
# | ||
# assert_receive :cleaned, 100 | ||
#end | ||
end |
Oops, something went wrong.