-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested struct list segfault #108
Conversation
With
C file:
and test file:
Running above configuration results in the following error:
Above error is raised when CNode tries to parse the most inner list (“data” field of nested_struct_inner) Case 2: A struct that holds a list of structs. Exact specification used for testing below.
C file:
and test file:
Running this configuration results in a timeout to CNode
|
test/unifex/integration_test.exs
Outdated
@@ -75,6 +75,8 @@ defmodule Unifex.IntegrationTest do | |||
|> Enum.each(fn ref -> | |||
assert File.read!("test_projects/#{project}/c_src/example/_generated/#{interface}/#{ref}") == | |||
File.read!("test/fixtures/#{project}_ref_generated/#{interface}/#{ref}") | |||
|
|||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary
lib/unifex/counter.ex
Outdated
def start_link(initial_value) do | ||
Agent.start_link(fn -> initial_value end, name: __MODULE__) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can delete initial_value
var since we always start counter from 0
lib/unifex/counter.ex
Outdated
Agent.update(__MODULE__, &(&1 + 1)) | ||
Agent.get(__MODULE__, & &1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Agent.get_and_update
instead
lib/tasks/compile_unifex.ex
Outdated
def run(_args) do | ||
Counter.start_link(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start Counter
in the application module, in the supervisor tree
lib/unifex/counter.ex
Outdated
end | ||
|
||
@spec get_value() :: integer() | ||
def get_value do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_value do | |
def get_and_increment() do |
This describes better, what really happens
#pragma once | ||
|
||
#ifdef BUNDLEX_CNODE | ||
#include "cnode/example.h" | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files from _generated
shouldn't be in this PR
@@ -0,0 +1,3 @@ | |||
defmodule Nested.StructInner do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defmodule Nested.StructInner do | |
defmodule Nested.InnerStruct do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this struct is unused, forgot to remove this
@@ -52,6 +51,13 @@ type nested_struct :: %Nested.Struct{ | |||
|
|||
spec test_nested_struct(in_struct :: nested_struct) :: {:ok :: label, out_struct :: nested_struct} | |||
|
|||
type my_enum :: :option_one | :option_two | :option_three | :option_four | :option_five | |||
type nested_struct_list :: %Nested.StructList{ | |||
inner_list: [my_struct], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inner_list: [my_struct], | |
list_of_structs: [my_struct], |
Name inner_list
suggests, that this list is wrapped in something, eg. another list
|
||
spec test_nested_struct_list(in_struct :: nested_struct_list) :: {:ok :: label, out_struct :: nested_struct_list} | ||
|
||
type(my_enum :: :option_one | :option_two | :option_three | :option_four | :option_five) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the brackets
assert nil == Unifex.CNode.call(context[:cnode], :test_nil, []) | ||
end | ||
|
||
test "atom", context do | ||
assert {:ok, :unifex} = Unifex.CNode.call(context[:cnode], :test_atom, [:unifex]) | ||
end | ||
|
||
test "bool", context do | ||
assert {:ok, true} = Unifex.CNode.call(context[:cnode], :test_bool, [true]) | ||
assert {:ok, false} = Unifex.CNode.call(context[:cnode], :test_bool, [false]) | ||
refute match?({:ok, false}, Unifex.CNode.call(context[:cnode], :test_bool, [true])) | ||
end | ||
|
||
test "float", context do | ||
assert {:ok, 0.0} = Unifex.CNode.call(context[:cnode], :test_float, [0.0]) | ||
assert {:ok, 0.1} = Unifex.CNode.call(context[:cnode], :test_float, [0.1]) | ||
assert {:ok, -0.1} = Unifex.CNode.call(context[:cnode], :test_float, [-0.1]) | ||
refute match?({:ok, 1}, Unifex.CNode.call(context[:cnode], :test_float, [1.0])) | ||
end | ||
|
||
test "unsigned int", context do | ||
cnode = context[:cnode] | ||
assert {:ok, 0} = Unifex.CNode.call(cnode, :test_uint, [0]) | ||
assert {:ok, 5} = Unifex.CNode.call(cnode, :test_uint, [5]) | ||
|
||
assert_raise RuntimeError, ~r/argument.*in_uint.*unsigned/i, fn -> | ||
Unifex.CNode.call(cnode, :test_uint, [-1]) | ||
end | ||
end | ||
|
||
test "string", context do | ||
cnode = context[:cnode] | ||
|
||
big_test_string = | ||
"unifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexu | ||
nifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexuni | ||
fexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifexunifex" | ||
|
||
assert {:ok, ""} = Unifex.CNode.call(cnode, :test_string, [""]) | ||
assert {:ok, "test_string"} = Unifex.CNode.call(cnode, :test_string, ["test_string"]) | ||
assert {:ok, "-12345"} = Unifex.CNode.call(cnode, :test_string, ["-12345"]) | ||
assert {:ok, "255"} = Unifex.CNode.call(cnode, :test_string, ["255"]) | ||
assert {:ok, ^big_test_string} = Unifex.CNode.call(cnode, :test_string, [big_test_string]) | ||
end | ||
|
||
test "list as string", context do | ||
0..253 | ||
|> Enum.each(fn x -> | ||
list = [x, x + 1, x + 2] | ||
assert {:ok, ^list} = Unifex.CNode.call(context[:cnode], :test_list, [list]) | ||
end) | ||
end | ||
|
||
test "list", context do | ||
cnode = context[:cnode] | ||
assert {:ok, []} = Unifex.CNode.call(cnode, :test_list, [[]]) | ||
assert {:ok, [-1, -1, -1]} = Unifex.CNode.call(cnode, :test_list, [[-1, -1, -1]]) | ||
assert {:ok, [-10, -17, -28]} = Unifex.CNode.call(cnode, :test_list, [[-10, -17, -28]]) | ||
assert {:ok, [355, 355, 355]} = Unifex.CNode.call(cnode, :test_list, [[355, 355, 355]]) | ||
assert {:ok, [1254, 1636, 3643]} = Unifex.CNode.call(cnode, :test_list, [[1254, 1636, 3643]]) | ||
end | ||
|
||
test "list of strings", context do | ||
cnode = context[:cnode] | ||
assert {:ok, []} = Unifex.CNode.call(cnode, :test_list_of_strings, [[]]) | ||
|
||
assert {:ok, ["", "", ""]} = Unifex.CNode.call(cnode, :test_list_of_strings, [["", "", ""]]) | ||
|
||
assert {:ok, ["1", "2", "3"]} = | ||
Unifex.CNode.call(cnode, :test_list_of_strings, [["1", "2", "3"]]) | ||
|
||
assert {:ok, ["abc", "def", "ghi"]} = | ||
Unifex.CNode.call(cnode, :test_list_of_strings, [["abc", "def", "ghi"]]) | ||
end | ||
|
||
test "list of unsigned ints", context do | ||
cnode = context[:cnode] | ||
assert {:ok, [0, 1, 2]} = Unifex.CNode.call(cnode, :test_list_of_uints, [[0, 1, 2]]) | ||
end | ||
|
||
test "list with other arguments", context do | ||
cnode = context[:cnode] | ||
|
||
assert {:ok, [1, 2, 3], :other_arg} = | ||
Unifex.CNode.call(cnode, :test_list_with_other_args, [[1, 2, 3], :other_arg]) | ||
|
||
assert {:ok, [300, 400, 500], :other_arg} = | ||
Unifex.CNode.call(cnode, :test_list_with_other_args, [[300, 400, 500], :other_arg]) | ||
end | ||
|
||
test "payload", context do | ||
assert {:ok, <<2, 2, 3>>} = Unifex.CNode.call(context[:cnode], :test_payload, [<<1, 2, 3>>]) | ||
end | ||
|
||
test "pid", context do | ||
pid = self() | ||
assert {:ok, ^pid} = Unifex.CNode.call(context[:cnode], :test_pid, [pid]) | ||
end | ||
|
||
test "struct", context do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮
Bump version to |
solves membraneframework/membrane_core#719