summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-01-31 23:51:38 +0800
committerruki <[email protected]>2020-01-31 17:09:53 +0800
commitc36bc1c2eb92bfd9090ad3e6ed382aa40f34e8c9 (patch)
tree97928b8505980d3e46d7a11fe00f4c12e1b6afe5
parent01af47d386620ef4f4401505d85a3f36fe8243c6 (diff)
add sched_pipe_pair test
-rw-r--r--tests/modules/pipe/sched_pipe_pair.lua38
-rw-r--r--xmake/core/base/bytes.lua5
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/modules/pipe/sched_pipe_pair.lua b/tests/modules/pipe/sched_pipe_pair.lua
new file mode 100644
index 000000000..18b69d9d4
--- /dev/null
+++ b/tests/modules/pipe/sched_pipe_pair.lua
@@ -0,0 +1,38 @@
+import("core.base.pipe")
+import("core.base.scheduler")
+
+function _session_read(id, pipefile)
+ print("%s/%d: read ..", pipefile, id)
+ local result = nil
+ for i = 1, 100000 do
+ local read, data = pipefile:read(12, {block = true})
+ if read > 0 and data then
+ result = data:str()
+ end
+ end
+ print("%s/%d: read ok, data: %s", pipefile, id, result and result or "")
+ pipefile:close()
+end
+
+function _session_write(id, pipefile)
+ print("%s/%d: write ..", pipefile, id)
+ for i = 1, 100000 do
+ pipefile:write("hello xmake!", {block = true})
+ end
+ print("%s/%d: write ok", pipefile, id)
+ pipefile:close()
+end
+
+function _session(id)
+ local rpipe, wpipe = pipe.openpair(256)
+ scheduler.co_start(_session_read, id, rpipe)
+ scheduler.co_start(_session_write, id, wpipe)
+end
+
+function main(count)
+ count = count and tonumber(count) or 1
+ for i = 1, count do
+ scheduler.co_start(_session, i)
+ end
+ scheduler.runloop()
+end
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua
index 76579ab0f..d1d6d8e36 100644
--- a/xmake/core/base/bytes.lua
+++ b/xmake/core/base/bytes.lua
@@ -422,6 +422,11 @@ function _instance:__concat(other)
return new
end
+-- tostring(bytes)
+function _instance:__tostring()
+ return "<bytes: " .. self:size() .. ">"
+end
+
-- todisplay(bytes)
function _instance:__todisplay()
local parts = {}